user-rate-mapper.xml 2.6 KB
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<!-- 二级费用申请 @author xiangwei -->
<mapper namespace="com.cjs.cms.dao.user.UserRateDao">

	<sql id="user_rate_field">
		id, user_id userId, user_name , trade_type , rate_type ,
		DATE_FORMAT(rate_time,'%Y-%m-%d')rate_time,
		DATE_FORMAT(rate_start,'%Y-%m-%d')rate_start,
		DATE_FORMAT(rate_end,'%Y-%m-%d')rate_end,
		rate_result ,remark
	</sql>

	<sql id="searchCondition">
		where 1 = 1
		<if test="userId != null and userId != ''"> and user_id=#{userId} </if>
		<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%') </if>
		<if test="tradeType != null and tradeType != ''"> and trade_type = #{tradeType} </if>
		<if test="rateType != null and rateType != ''"> and rate_type= #{rateType} </if>
		<if test="rateStart != null and rateStart != ''"> <![CDATA[ and rate_start >= #{rateStart}]]>
		</if>
		<if test="rateEnd != null and rateEnd != ''"> <![CDATA[ and rate_end <= #{rateEnd}]]>
		</if>
		<if test="rateResult != null and rateResult != ''"> and rate_result=#{rateResult} </if>

		<if test="rateTimeStart != null and rateTimeStart != ''"> <![CDATA[ and rate_time >= #{rateTimeStart}]]>
		</if>
		<if test="rateTimeEnd != null and rateTimeEnd != ''"> <![CDATA[ and rate_time <= #{rateTimeEnd}]]>
		</if>

	</sql>
	<select id="search" parameterType="map" resultType="UserRateInfo">
		select
		<include refid="user_rate_field" />
		from user_rate
		<include refid="searchCondition" />
		order by rate_time desc, id desc 
		<include refid="common.pageLimit" />
	</select>
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(*)
		from user_rate
		<include refid="searchCondition" />
	</select>

	<update id="updateRate" parameterType="UserRateInfo">
		update user_rate set rate_result=#{rateResult}
		<if test="rateEnd != null and rateEnd != ''">
			,rate_end=#{rateEnd}
		</if>
		<if test="rateStart != null and rateStart != ''">
			,rate_start=#{rateStart}
		</if>
		<if test="remark != null and remark != ''">
			,remark=#{remark}
		</if>
		where id=#{id}
	</update>

	<!-- 查询当天过期的用户 -->
	<select id="queryExpire" resultType="UserRateInfo" parameterType="UserRateInfo">
		select
		<include refid="user_rate_field" />
		from user_rate
		 <![CDATA[ where rate_end<=str_to_date(now(),'%Y-%m-%d')]]>
	</select>

	<!-- 拿到会员号 -->
	<select id="getRateForId" resultType="UserRateInfo"
		parameterType="int">
		select
		<include refid="user_rate_field" />
		from user_rate where id=#{id}
	</select>

</mapper>