PromotionRuleMapper.xml 6.1 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" >
<mapper namespace="com.sibu.orderHelper.integral.web.dao.IMPromotionRuleDao">
	<resultMap id="rs_PromotionRuleBean" type="com.sibu.orderHelper.integral.model.PromotionRule">
		<result property="id" column="id" javaType="java.lang.Long" jdbcType="VARCHAR"/>
		<result property="name" column="name" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="status" column="status" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="prority" column="prority" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="startDate" column="start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
		<result property="endDate" column="end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
		<result property="isLimit" column="is_limit" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="limitNum" column="limit_num" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="ruleDesc" column="rule_desc" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="type" column="type" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="createDate" column="create_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
		<result property="isDelete" column="is_delete" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="platformType" column="platform_type" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
	</resultMap>
	<select id="count" resultType="java.lang.Integer" >
		SELECT COUNT(id) FROM promotion_rule
		<trim prefix="where" prefixOverrides="and | or">
			<if test="null != id">
				AND id = #{id}
			</if>
		</trim>
	</select>
	<select id="list" resultMap="rs_PromotionRuleBean" parameterType="java.util.Map" >
		SELECT * FROM promotion_rule where 1=1 and is_delete=0
		<if test="name!=null and name!=''">
			and name like concat('%',#{name},'%')
		</if>
		<if test="status !=null">
			and status=#{status}
		</if>
		<if test="type!=null and type!=''">
			and type =#{type}
		</if>
		<if test="startDt != null and startDt != ''">
			and start_date >=#{startDt}
		</if>
		<if test="endDt != null and endDt != ''">
	  	<![CDATA[
	  		and end_date<= #{endDt}
	  	]]>
	  	</if>
		<if test="supplierId !='' and supplierId !=null">
			and supplier_id=#{supplierId}
		</if>
	  	ORDER BY create_date desc
		limit ${(pageNow-1)*pageSize}, ${pageSize} 
		
	</select>
	<select id="get" resultMap="rs_PromotionRuleBean" parameterType="java.lang.Long">
		SELECT * FROM promotion_rule
		where  id = #{id}
	</select>
	<insert id="save" parameterType="com.sibu.orderHelper.integral.model.PromotionRule">
		INSERT INTO promotion_rule (
			name,status,prority,start_date,end_date,is_limit,limit_num,rule_desc,type,supplier_id,supplier_name,platform_type
		) VALUES (
			#{name},#{status},#{prority},#{startDate},#{endDate},#{isLimit},#{limitNum},#{ruleDesc},#{type},#{supplierId},#{supplierName},#{platformType}
		)
	</insert>
	<update id="update" parameterType="java.util.Map">
		UPDATE promotion_rule
		<trim prefix="SET" suffixOverrides=",">
			<if test="null != name">
				name=#{name},
			</if>
			<if test="null != status">
				status=#{status},
			</if>
			<if test="null != prority">
				prority=#{prority},
			</if>
			<if test="null != startDate">
				start_date=#{startDate},
			</if>
			<if test="null != endDate">
				end_date=#{endDate},
			</if>
			<if test="null != isLimit">
				is_limit=#{isLimit},
			</if>
			<if test="null != limitNum">
				limit_num=#{limitNum},
			</if>
			<if test="null != ruleDesc">
				rule_desc=#{ruleDesc},
			</if>
			<if test="null != type">
				type=#{type},
			</if>

		</trim>
		WHERE id = #{id}
	</update>
	<!-- 逻辑删除促销 -->
	<delete id="delete" parameterType="java.lang.Long">
		update promotion_rule set is_delete = 1 WHERE id = #{id}
	</delete>
	<delete id="batchDelete" parameterType="java.util.List">
		DELETE FROM promotion_rule WHERE id in
		<foreach collection="list" item="item"  open="(" separator="," close=")">  
			#{item} 
		</foreach>
	</delete>
	<!-- 查询同一时间内是否有相同的促销规则 -->
	<select id="selectTimePromotionNum" parameterType="java.util.Map" resultType="java.lang.Integer">
	SELECT COUNT(1) FROM `promotion_rule` rule WHERE is_delete=0 and rule.type=#{type}
		AND (
				(start_date &lt;= #{startDt} AND end_date >= #{startDt}) OR
				(start_date &lt;= #{endDt} AND end_date >=#{endDt}) OR
				(start_date>=#{startDt} AND end_date &lt;= #{endDt})
			)
		<if test="id !=null">
			and id !=#{id}
		</if>
	</select>

	<!-- 获取数据列表(商家) -->
	<select id="listSupplier" resultMap="rs_PromotionRuleBean" parameterType="java.util.Map" >
		SELECT * FROM promotion_rule where 1=1 and is_delete=0 and supplier_id = #{supplierId}
		<if test="name!=null and name!=''">
			and name like concat('%',#{name},'%')
		</if>
		<if test="status !=null">
			and status=#{status}
		</if>
		<if test="type!=null and type!=''">
			and type =#{type}
		</if>
		<if test="startDt != null">
			and start_date >=#{startDt}
		</if>
		<if test="endDt != null">
			<![CDATA[
	  		and end_date<= #{endDt}
	  	]]>
		</if>
		ORDER BY create_date desc
		limit ${(pageNow-1)*pageSize}, ${pageSize}

	</select>


	<!-- 查询同一时间内是否有相同的促销规则 根据平台或商家-->
	<select id="selectTimePromotionNumByPlatform" parameterType="java.util.Map" resultType="java.lang.Integer">
		SELECT COUNT(1) FROM `promotion_rule` rule WHERE is_delete=0 and rule.type=#{type} and platform_type = #{platformType}
		AND (
		(start_date &lt;= #{startDt} AND end_date >= #{startDt}) OR
		(start_date &lt;= #{endDt} AND end_date >=#{endDt}) OR
		(start_date>=#{startDt} AND end_date &lt;= #{endDt})
		)
		<if test="id !=null">
			and id !=#{id}
		</if>
		<if test="supplierId !=null and supplierId!=''">
			and supplier_id = #{supplierId}
		</if>
	</select>


</mapper>