PromotionProductGiftMapper.xml 7.8 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.IMPromotionProductGiftDao">
	<resultMap id="rs_PromotionRuleGiftBean" type="com.sibu.orderHelper.integral.model.PromotionProductGift">
		<result property="id" column="id" javaType="java.lang.Long" jdbcType="VARCHAR"/>
		<result property="buyLimitNum" column="buy_limit_num" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="giftProductId" column="gift_product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="giftNum" column="gift_num" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="giftTotal" column="gift_total" javaType="java.lang.Long" jdbcType="VARCHAR"/>
		<result property="surplusNum" column="surplus_num" javaType="java.lang.Long" jdbcType="VARCHAR"/>
		<result property="isDelete" column="is_delete" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="status" column="status" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="buyProductId" column="buy_product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="createDate" column="create_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
		<result property="promotionId" column="promotion_id" javaType="java.lang.Long" jdbcType="VARCHAR"/>
	</resultMap>
	<!-- 返回购买商品返回商品明 -->
	<resultMap id="promotionRuleGiftResp" type="com.sibu.orderHelper.integral.reponse.PromotionProductGiftResponse">
		<result property="id" column="id" javaType="java.lang.Long" jdbcType="VARCHAR"/>
		<result property="buyLimitNum" column="buy_limit_num" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="giftProductId" column="gift_product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="giftNum" column="gift_num" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="buyProductId" column="buy_product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="createDate" column="create_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
		<result property="giftProductName" column="gift_product_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="buyProductName" column="buy_product_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="platformType" column="platform_type" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
	</resultMap>

	<!-- 返回满金额送商品 -->
	<resultMap id="promotionMoneyGiftResp" type="com.sibu.orderHelper.integral.reponse.PromotionMoneyGiftResponse">
		<result property="id" column="id" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="buyMoney" column="bug_money" javaType="java.math.BigDecimal" jdbcType="VARCHAR"/>
		<result property="giftNum" column="gift_num" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="giftTotal" column="gift_total" javaType="java.lang.Long" jdbcType="VARCHAR"/>
		<result property="status" column="status" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="giftProductId" column="gift_product_id" javaType="java.lang.String" jdbcType="TIMESTAMP"/>
		<result property="giftProductName" column="gift_product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="createDate" column="create_date" javaType="java.util.Date" jdbcType="VARCHAR"/>
		<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="supplierName" column="supplier_name" 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_product_gift
		<trim prefix="where" prefixOverrides="and | or">
			<if test="null != id">
				AND id = #{id}
			</if>
		</trim>
	</select>
	
	<select id="list" resultMap="rs_PromotionRuleGiftBean" >
		SELECT * FROM promotion_product_gift where
		 id = #{id} 
		ORDER BY create_date desc
	</select>
	<select id="get" resultMap="rs_PromotionRuleGiftBean" parameterType="java.lang.String">
		SELECT * FROM promotion_product_gift
		where  id = #{id}
	</select>
	<insert id="save" parameterType="com.sibu.orderHelper.integral.request.PromostionProductGiftRequest">
		INSERT INTO promotion_product_gift (
			buy_limit_num,gift_product_id,gift_num,gift_total,buy_product_id,promotion_id,supplier_id,supplier_name,platform_type
		) VALUES (
			#{buyLimitNum},#{giftProductId},#{giftNum},#{giftTotal},#{buyProductId},#{promotionId},#{supplierId},#{supplierName},#{platformType}
		)
		<!-- <selectKey resultType="java.lang.String" keyProperty="id">
			<![CDATA[SELECT last_insert_id() AS id ]]>
		</selectKey> -->
	</insert>
	<update id="update" parameterType="java.util.Map">
		UPDATE promotion_product_gift
		<trim prefix="SET" suffixOverrides=",">
			<if test="null != buyLimitNum">
				buy_limit_num=#{buyLimitNum},
			</if>
			<if test="null != giftProductId">
				gift_product_id=#{giftProductId},
			</if>
			<if test="null != giftNum">
				gift_num=#{giftNum},
			</if>
			<if test="null != giftTotal">
				gift_total=#{giftTotal},
			</if>
			<if test="null != surplusNum">
				surplus_num=#{surplusNum},
			</if>
			<if test="null != isDelete">
				is_delete=#{isDelete},
			</if>
			<if test="null != status">
				status=#{status},
			</if>
			<if test="null != buyProductId">
				buy_product_id=#{buyProductId},
			</if>
			<if test="null != createDate">
				create_date=#{createDate},
			</if>
			<if test="null != promotionId">
				promotion_id=#{promotionId},
			</if>

		</trim>
		WHERE id = #{id}
	</update>
	<delete id="delete" parameterType="java.lang.Long">
		DELETE FROM promotion_product_gift WHERE id = #{id}
	</delete>
	<delete id="batchDelete" parameterType="java.util.List">
		DELETE FROM promotion_product_gift WHERE id in
		<foreach collection="list" item="item"  open="(" separator="," close=")">  
			#{item} 
		</foreach>
	</delete>
	
	<!-- 查询促销规则下的商品促销 -->
	<select id="listProductGift" resultMap="promotionRuleGiftResp" parameterType="java.lang.Long">
		SELECT gift.id, gift.buy_limit_num,gift.gift_product_id,
		gift.gift_num,gift.buy_product_id,gift.create_date,p1.name as gift_product_name,p2.name as buy_product_name
		FROM promotion_product_gift  gift
		left join im_product p1 on gift.gift_product_id =p1.im_product_id
		left join im_product p2 on gift.buy_product_id =p2.im_product_id
		 where promotion_id = #{promotionId}
		ORDER BY create_date desc
	</select>

	<select id="getPromotionProductGiftResponseById" parameterType="java.lang.Long" resultMap="promotionRuleGiftResp">
		SELECT * FROM promotion_product_gift  WHERE  id = #{id}
	</select>

	<select id="getPromotionMoneyGiftResponseById" parameterType="java.lang.Long" resultMap="promotionMoneyGiftResp">
		SELECT * FROM promotion_money_gift  WHERE  id = #{id}
	</select>


	<!-- 查询促销规则下的商品促销(商家)-->
	<select id="listSupplierProductGift" resultMap="promotionRuleGiftResp" parameterType="java.util.Map">
		SELECT gift.id, gift.buy_limit_num,gift.gift_product_id,
		gift.gift_num,gift.buy_product_id,gift.create_date,p1.name as gift_product_name,p2.name as buy_product_name
		FROM promotion_product_gift  gift
		left join im_product p1 on gift.gift_product_id =p1.im_product_id
		left join im_product p2 on gift.buy_product_id =p2.im_product_id
		where promotion_id = #{promotionId} and supplier_id = #{supplierId}
		ORDER BY create_date desc
	</select>
</mapper>