point-active-mapper.xml 3.95 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.PointActiveDao">

	<sql id="point_active_field">
		id, name, type, start_date, end_date, gift_amount, gift_remain, expired_date,
		executer, remark, status, create_at, create_by
	</sql>

	<insert id="insert" parameterType="PointActiveInfo"
		useGeneratedKeys="true" keyProperty="id">
		insert into point_active(name,
		type, start_date, end_date, gift_amount, gift_remain, expired_date, executer, remark, status,
		create_at, create_by) 
		values(#{name}, #{type}, #{startDate}, #{endDate}, #{giftAmount}, #{giftRemain}, #{expiredDate}, #{executer},
		#{remark}, #{status}, CURRENT_TIMESTAMP, #{createBy})
	</insert>

	<resultMap type="PointActiveInfo" id="ConfigInfo">
		<id property="id" column="id" />
		<result property="name" column="name" />
		<result property="type" column="type" />
		<result property="startDate" column="start_date" />
		<result property="endDate" column="end_date" />
		<result property="giftAmount" column="gift_amount"/>
		<result property="giftRemain" column="gift_remain"/>
		<result property="expiredDate" column="expired_date" />
		<result property="executer" column="executer" />
		<result property="remark" column="remark" />
		<result property="status" column="status" />
		<result property="createAt" column="create_at" />
		<result property="createBy" column="create_by" />
		<collection property="rules" ofType="PointRuleInfo" column="id"
			select="queryRules" />
	</resultMap>


	<select id="queryRules" parameterType="int" resultType="PointRuleInfo">
		select * from point_rule where active_id = #{id} order by sort asc 
	</select>

	<select id="queryActiveById" parameterType="int" resultMap="ConfigInfo">
		select <include refid="point_active_field" /> 
		from point_active 
		where id = #{id}
	</select>

	<update id="update" parameterType="PointActiveInfo">
		update point_active set name = #{name}, type = #{type}, start_date = #{startDate}, 
		end_date = #{endDate}, gift_amount = #{giftAmount}, gift_remain = #{giftRemain}, expired_date = #{expiredDate},
		executer = #{executer}, remark = #{remark}, status = #{status}, 
		create_at = CURRENT_TIMESTAMP, create_by = #{createBy} 
		where id = #{id}
	</update>
	
	<sql id="searchCondition">
		where 1=1 
		<if test="name != null and name != ''">
			and name = #{name} 
		</if>
		<if test="type != null and type != ''">
			and type = #{type} 
		</if>
		<if test="status != null and status != ''">
			and status = #{status} 
		</if>
		<if test="startDate != null and startDate != ''">
			<![CDATA[and start_date >= #{startDate} ]]> 
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[and end_date <= #{endDate} ]]>
		</if>
		<if test="nowDate != null and nowDate != ''">
			and #{nowDate} between start_date and end_date
		</if>
	</sql>
	
	<select id="search" parameterType="map" resultMap="ConfigInfo">
		select <include refid="point_active_field" /> 
		from point_active 
		<include refid="searchCondition" />
		order by id desc 
		<include refid="common.pageLimit" />
	</select>
	
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(1) from point_active 
		<include refid="searchCondition" />
	</select>
	
	<update id="updateStatus" parameterType="map">
		update point_active set status = #{status} 
		where id = #{id}
	</update>
	
	<select id="queryActive" parameterType="map" resultMap="ConfigInfo">
		select <include refid="point_active_field" /> 
		from point_active 
		<include refid="searchCondition" />
	</select>
	
		<!-- 更新剩余配额数量 -->
	<update id="updateGiftRemain" parameterType="PointActiveInfo">
		update point_active set gift_remain = #{giftRemain} 
		where id = #{id} 
	</update>
	
	<select id="queryAll" resultType="PointActiveInfo">
		select <include refid="point_active_field" /> 
		from point_active where status != '0'
	</select>
	
</mapper>