point-record-mapper.xml 4.02 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 tongxiaochuan -->
<mapper namespace="com.cjs.cms.dao.user.point.PointRecordDao">

	<sql id="point_record_field">
		id, active_id, user_id, otc_code,otc_name,occur_count, remain_count, post_count,
		expired_date, business_type, remark, gift_by, create_at, create_by
	</sql>
   
   <sql id="searchCondition">
	    where 1=1
		<if test="userId != null and userId != ''"> and user_id=#{userId} </if>
		<if test="otcCode != null and otcCode != ''"> and otc_code=#{otcCode} </if>
		<if test="appendType != null and appendType !=''">
		 and business_type in 
		<foreach collection="appendType" item="item" index="index" open="(" separator="," close=")">#{item}</foreach> 
		</if>
		<if test="activeId != null and activeId != ''"> and active_id=#{activeId} </if>
		<if test="businessType != null and businessType != ''"> and business_type=#{businessType} </if>
		<if test="startDate != null and startDate != ''"> <![CDATA[ and create_at >= #{startDate}]]> </if>
		<if test="endDate != null and endDate != ''"> <![CDATA[ and create_at <= DATE_ADD(#{endDate}, INTERVAL 1 day)]]> </if>
	</sql>
   

	<insert id="insert" parameterType="PointRecordInfo">
		insert into point_record(active_id, user_id, occur_count, remain_count, post_count, expired_date, otc_code,otc_name,
			business_type, remark, gift_by, create_at, create_by) 
		values(#{activeId}, #{userId}, #{occurCount}, #{remainCount}, #{postCount}, #{expiredDate}, #{otcCode}, #{otcName}, 
			#{businessType}, #{remark}, #{giftBy}, CURRENT_TIMESTAMP, #{createBy})
	</insert>
	
	<update id="update" parameterType="PointRecordInfo">
		update point_record set
			occur_count = #{occurCount}, remain_count = #{remainCount}, post_count = #{postCount},
			remark = #{remark}
		where id = #{id}
	</update>

	<!-- 查询过期待作废积分 -->
	<select id="queryExpired" resultType="PointRecordInfo">
		select <include refid="point_record_field" />
		from point_record
		<![CDATA[where expired_date < now() and remain_count > 0 and expired_date is not null]]>
		order by user_id
	</select>
	
	<sql id="queryCondition">
		<if test="businessType != null and businessType != ''">
			and business_type = #{businessType} 
		</if>
		<if test="startDate != null and startDate != ''">
			<![CDATA[and create_at >= #{startDate} ]]>
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[and create_at <= #{endDate} ]]>
		</if>
		<if test="flag != null and flag != ''">
			<![CDATA[and instr(gift_by, #{flag}) > 0 ]]>
		</if>
	</sql>
	
	<select id="search" parameterType="map" resultType="PointRecordInfo">
		select <include refid="point_record_field" />
		from point_record
		<include refid="searchCondition" />
		order by id desc
		<include refid="common.pageLimit" />
	</select>
	
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(*)
		from point_record
		<include refid="searchCondition" />
	</select>
	
	<select id="searchOccurCount" parameterType="map" resultType="double">
	    select  IFNULL(sum(occur_count),0)
	    from point_record
		<include refid="searchCondition" />
	</select>
	
	<select id="queryRecordByCondition" parameterType="map" resultType="PointRecordInfo">
		select <include refid="point_record_field" /> 
		from point_record 
		where user_id = #{userId} and active_id = #{activeId} 
		<include refid="queryCondition" />
	</select>
	
	<!-- 查询新开户用户配额发放记录 -->
	<select id="queryRecordByConditions" parameterType="map" resultType="PointRecordInfo">
		select <include refid="point_record_field" /> 
		from point_record 
		<include refid="queryRecordConditions" />
	</select>
	
	<sql id="queryRecordConditions">
		where occur_count = 20 
		<if test="userId != null and userId != ''">
			and user_id = #{userId} 
		</if>
		<if test="activeId != null and activeId != ''">
			and active_id = #{activeId} 
		</if>
		<if test="businessType != null and businessType != ''">
			and business_type = #{businessType} 
		</if>
	</sql>
</mapper>