453 lines
16 KiB
XML
453 lines
16 KiB
XML
<?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.zhwl.coupon.mapper.ZdyCouponMapper">
|
|
|
|
<resultMap type="ZdyCoupon" id="ZdyCouponResult">
|
|
<result property="id" column="id"/>
|
|
<result property="type" column="type"/>
|
|
<result property="storeCategory" column="store_category"/>
|
|
<result property="storeId" column="store_id"/>
|
|
<result property="storeName" column="store_name"/>
|
|
<result property="name" column="name"/>
|
|
<result property="method" column="method"/>
|
|
<result property="spendAmount" column="spend_amount"/>
|
|
<result property="couponAmount" column="coupon_amount"/>
|
|
<result property="startSaleTime" column="start_sale_time"/>
|
|
<result property="endSaleTime" column="end_sale_time"/>
|
|
<result property="startUseTime" column="start_use_time"/>
|
|
<result property="endUseTime" column="end_use_time"/>
|
|
<result property="inventory" column="inventory"/>
|
|
<result property="stock" column="stock"/>
|
|
<result property="status" column="status"/>
|
|
<result property="userClaimLimit" column="user_claim_limit"/>
|
|
<result property="createTime" column="create_time"/>
|
|
<result property="createBy" column="create_by"/>
|
|
<result property="updateTime" column="update_time"/>
|
|
<result property="updateBy" column="update_by"/>
|
|
<result property="descr" column="descr"/>
|
|
<result property="memo" column="memo"/>
|
|
<result property="applicability" column="applicability"/>
|
|
</resultMap>
|
|
|
|
<sql id="selectZdyCouponVo">
|
|
select id,
|
|
type,
|
|
store_category,
|
|
store_id,
|
|
store_name,
|
|
name,
|
|
method,
|
|
spend_amount,
|
|
coupon_amount,
|
|
start_sale_time,
|
|
end_sale_time,
|
|
start_use_time,
|
|
end_use_time,
|
|
inventory,
|
|
stock,
|
|
status,
|
|
user_claim_limit,
|
|
create_time,
|
|
create_by,
|
|
update_time,
|
|
update_by,
|
|
descr,
|
|
memo,
|
|
applicability
|
|
from zdy_coupon
|
|
</sql>
|
|
|
|
<select id="selectZdyCouponList" parameterType="ZdyCoupon" resultMap="ZdyCouponResult">
|
|
<include refid="selectZdyCouponVo"/>
|
|
<where>
|
|
<if test="type != null and type != ''">
|
|
and type = #{type}
|
|
</if>
|
|
<if test="storeCategory != null and storeCategory != ''">
|
|
and store_category = #{storeCategory}
|
|
</if>
|
|
<if test="storeId != null ">
|
|
and store_id = #{storeId}
|
|
</if>
|
|
<if test="storeName != null ">
|
|
and store_name = #{storeName}
|
|
</if>
|
|
<if test="name != null and name != ''">
|
|
and name like concat('%', #{name}, '%')
|
|
</if>
|
|
<if test="method != null and method != ''">
|
|
and method = #{method}
|
|
</if>
|
|
<if test="spendAmount != null ">
|
|
and spend_amount = #{spendAmount}
|
|
</if>
|
|
<if test="couponAmount != null ">
|
|
and coupon_amount = #{couponAmount}
|
|
</if>
|
|
<if test="startSaleTime != null ">
|
|
and start_sale_time = #{startSaleTime}
|
|
</if>
|
|
<if test="endSaleTime != null ">
|
|
and end_sale_time = #{endSaleTime}
|
|
</if>
|
|
<if test="startUseTime != null ">
|
|
and start_use_time = #{startUseTime}
|
|
</if>
|
|
<if test="endUseTime != null ">
|
|
and end_use_time = #{endUseTime}
|
|
</if>
|
|
<if test="inventory != null ">
|
|
and inventory = #{inventory}
|
|
</if>
|
|
<if test="stock != null ">
|
|
and stock = #{stock}
|
|
</if>
|
|
<if test="status != null and status != ''">
|
|
and status = #{status}
|
|
</if>
|
|
<if test="userClaimLimit != null ">
|
|
and user_claim_limit = #{userClaimLimit}
|
|
</if>
|
|
<if test="descr != null and descr != ''">
|
|
and descr = #{descr}
|
|
</if>
|
|
<if test="memo != null and memo != ''">
|
|
and memo = #{memo}
|
|
</if>
|
|
<if test="applicability != null and applicability != ''">
|
|
and applicability = #{applicability}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<select id="selectZdyCouponById" parameterType="Long"
|
|
resultMap="ZdyCouponResult">
|
|
<include refid="selectZdyCouponVo"/>
|
|
where id = #{id}
|
|
</select>
|
|
|
|
<resultMap id="ZdyCouponVoResult" type="zdyCouponVo" extends="ZdyCouponResult">
|
|
<result property="canGetNum" column="canGetNum"/>
|
|
</resultMap>
|
|
<select id="selectRedeemableList" resultMap="ZdyCouponVoResult">
|
|
SELECT
|
|
zc.*,
|
|
(zc.user_claim_limit - IFNULL(cur.used_count, 0)) AS canGetNum
|
|
FROM
|
|
zdy_coupon zc
|
|
LEFT JOIN (
|
|
SELECT
|
|
coupon_id,
|
|
COUNT(1) AS used_count
|
|
FROM
|
|
zdy_coupon_use_record
|
|
WHERE
|
|
user_id = #{userId}
|
|
GROUP BY
|
|
coupon_id
|
|
) cur ON zc.id = cur.coupon_id
|
|
WHERE
|
|
zc.end_sale_time >= #{currentDate} and #{currentDate} >= zc.start_sale_time
|
|
AND zc.stock > 0
|
|
AND zc.status IN ('1', '2')
|
|
AND zc.user_claim_limit > IFNULL(cur.used_count, 0);
|
|
</select>
|
|
<select id="selectRedeemedList" resultMap="ZdyCouponResult">
|
|
SELECT
|
|
cur.id as id,
|
|
cur.status,
|
|
cp.type,
|
|
cp.store_category,
|
|
cp.store_id,
|
|
cp.store_name,
|
|
cp.name,
|
|
cp.method,
|
|
cp.spend_amount,
|
|
cp.coupon_amount,
|
|
cp.start_sale_time,
|
|
cp.end_sale_time,
|
|
cp.start_use_time,
|
|
cp.end_use_time,
|
|
cp.inventory,
|
|
cp.stock,
|
|
cp.user_claim_limit,
|
|
cp.create_time,
|
|
cp.create_by,
|
|
cp.update_time,
|
|
cp.update_by,
|
|
cp.descr,
|
|
cp.memo,
|
|
cp.applicability
|
|
FROM
|
|
zdy_coupon cp
|
|
LEFT JOIN zdy_coupon_use_record cur ON cp.id = cur.coupon_id
|
|
WHERE
|
|
cur.user_id =#{userId}
|
|
<if test="status != null and status!=''">
|
|
and cur.status = #{status}
|
|
</if>
|
|
|
|
</select>
|
|
<resultMap id="UsableCouponResult" type="ZdyRedeemedCouponVo" extends="ZdyCouponResult">
|
|
<result property="goodsIds" column="goodsIds"/>
|
|
<result property="storeIds" column="storeIds"/>
|
|
</resultMap>
|
|
<select id="selectUsableList" resultMap="UsableCouponResult">
|
|
SELECT
|
|
cur.id AS id,
|
|
cur.status,
|
|
cp.type,
|
|
cp.store_category,
|
|
cp.store_id,
|
|
cp.store_name,
|
|
cp.name,
|
|
cp.method,
|
|
cp.spend_amount,
|
|
cp.coupon_amount,
|
|
cp.start_sale_time,
|
|
cp.end_sale_time,
|
|
cp.start_use_time,
|
|
cp.end_use_time,
|
|
cp.inventory,
|
|
cp.stock,
|
|
cp.user_claim_limit,
|
|
cp.create_time,
|
|
cp.create_by,
|
|
cp.update_time,
|
|
cp.update_by,
|
|
cp.descr,
|
|
cp.memo,
|
|
cp.applicability,
|
|
GROUP_CONCAT( DISTINCT ci.goods_id ) AS goodsIds,
|
|
GROUP_CONCAT( DISTINCT ci.store_id ) AS storeIds
|
|
FROM
|
|
zdy_coupon_use_record cur
|
|
LEFT JOIN zdy_coupon cp ON cp.id = cur.coupon_id
|
|
LEFT JOIN zdy_coupon_item AS ci ON ci.coupon_id = cp.id
|
|
WHERE cur.STATUS = 2 and #{currentDate} BETWEEN cur.start_use_time and cur.end_use_time and cur.user_id = #{userId}
|
|
AND ( ISNULL( cp.store_category ) OR cp.store_category = #{storeCategory} )
|
|
AND ( ISNULL( cp.store_id ) OR cp.store_id in
|
|
<foreach collection="storeIds" item="storeId" open="(" close=")" separator=",">
|
|
#{storeId}
|
|
</foreach>)
|
|
AND ( cp.applicability = 1 OR EXISTS (
|
|
SELECT 1 FROM zdy_coupon_item ci WHERE ci.coupon_id = cur.coupon_id
|
|
AND ( ci.goods_id in
|
|
<foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
|
|
#{goodsId}
|
|
</foreach>
|
|
OR ( ISNULL(ci.goods_id) AND ci.store_id in
|
|
<foreach collection="storeIds" item="storeId" open="(" close=")" separator=",">
|
|
#{storeId}
|
|
</foreach>)
|
|
)
|
|
)
|
|
)
|
|
GROUP BY cur.id
|
|
</select>
|
|
<select id="selectZdyCouponByIdForUpdate" parameterType="Long"
|
|
resultMap="ZdyCouponResult">
|
|
<include refid="selectZdyCouponVo"/>
|
|
where id = #{id} for update
|
|
</select>
|
|
|
|
<insert id="insertZdyCoupon" parameterType="ZdyCouponAllDto" useGeneratedKeys="true" keyProperty="id">
|
|
insert into zdy_coupon
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="type != null">type,
|
|
</if>
|
|
<if test="storeCategory != null">store_category,
|
|
</if>
|
|
<if test="storeId != null">store_id,
|
|
</if>
|
|
<if test="storeName != null">store_name,
|
|
</if>
|
|
<if test="name != null">name,
|
|
</if>
|
|
<if test="method != null">method,
|
|
</if>
|
|
<if test="spendAmount != null">spend_amount,
|
|
</if>
|
|
<if test="couponAmount != null">coupon_amount,
|
|
</if>
|
|
<if test="startSaleTime != null">start_sale_time,
|
|
</if>
|
|
<if test="endSaleTime != null">end_sale_time,
|
|
</if>
|
|
<if test="startUseTime != null">start_use_time,
|
|
</if>
|
|
<if test="endUseTime != null">end_use_time,
|
|
</if>
|
|
<if test="inventory != null">inventory,
|
|
</if>
|
|
<if test="stock != null">stock,
|
|
</if>
|
|
<if test="status != null">status,
|
|
</if>
|
|
<if test="userClaimLimit != null">user_claim_limit,
|
|
</if>
|
|
<if test="createTime != null">create_time,
|
|
</if>
|
|
<if test="createBy != null">create_by,
|
|
</if>
|
|
<if test="updateTime != null">update_time,
|
|
</if>
|
|
<if test="updateBy != null">update_by,
|
|
</if>
|
|
<if test="descr != null">descr,
|
|
</if>
|
|
<if test="memo != null">memo,
|
|
</if>
|
|
<if test="applicability != null">applicability,
|
|
</if>
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="type != null">#{type},
|
|
</if>
|
|
<if test="storeCategory != null">#{storeCategory},
|
|
</if>
|
|
<if test="storeId != null">#{storeId},
|
|
</if>
|
|
<if test="storeName != null">#{storeName},
|
|
</if>
|
|
<if test="name != null">#{name},
|
|
</if>
|
|
<if test="method != null">#{method},
|
|
</if>
|
|
<if test="spendAmount != null">#{spendAmount},
|
|
</if>
|
|
<if test="couponAmount != null">#{couponAmount},
|
|
</if>
|
|
<if test="startSaleTime != null">#{startSaleTime},
|
|
</if>
|
|
<if test="endSaleTime != null">#{endSaleTime},
|
|
</if>
|
|
<if test="startUseTime != null">#{startUseTime},
|
|
</if>
|
|
<if test="endUseTime != null">#{endUseTime},
|
|
</if>
|
|
<if test="inventory != null">#{inventory},
|
|
</if>
|
|
<if test="stock != null">#{stock},
|
|
</if>
|
|
<if test="status != null">#{status},
|
|
</if>
|
|
<if test="userClaimLimit != null">#{userClaimLimit},
|
|
</if>
|
|
<if test="createTime != null">#{createTime},
|
|
</if>
|
|
<if test="createBy != null">#{createBy},
|
|
</if>
|
|
<if test="updateTime != null">#{updateTime},
|
|
</if>
|
|
<if test="updateBy != null">#{updateBy},
|
|
</if>
|
|
<if test="descr != null">#{descr},
|
|
</if>
|
|
<if test="memo != null">#{memo},
|
|
</if>
|
|
<if test="applicability != null">#{applicability},
|
|
</if>
|
|
</trim>
|
|
</insert>
|
|
|
|
<update id="updateZdyCoupon" parameterType="ZdyCoupon">
|
|
update zdy_coupon
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="type != null">type =
|
|
#{type},
|
|
</if>
|
|
<if test="storeCategory != null">store_category =
|
|
#{storeCategory},
|
|
</if>
|
|
<if test="storeId != null">store_id =
|
|
#{storeId},
|
|
</if>
|
|
<if test="storeName != null">store_name =
|
|
#{storeName},
|
|
</if>
|
|
<if test="name != null">name =
|
|
#{name},
|
|
</if>
|
|
<if test="method != null">method =
|
|
#{method},
|
|
</if>
|
|
<if test="spendAmount != null">spend_amount =
|
|
#{spendAmount},
|
|
</if>
|
|
<if test="couponAmount != null">coupon_amount =
|
|
#{couponAmount},
|
|
</if>
|
|
<if test="startSaleTime != null">start_sale_time =
|
|
#{startSaleTime},
|
|
</if>
|
|
<if test="endSaleTime != null">end_sale_time =
|
|
#{endSaleTime},
|
|
</if>
|
|
<if test="startUseTime != null">start_use_time =
|
|
#{startUseTime},
|
|
</if>
|
|
<if test="endUseTime != null">end_use_time =
|
|
#{endUseTime},
|
|
</if>
|
|
<if test="inventory != null">inventory =
|
|
#{inventory},
|
|
</if>
|
|
<if test="stock != null">stock =
|
|
#{stock},
|
|
</if>
|
|
<if test="status != null">status =
|
|
#{status},
|
|
</if>
|
|
<if test="userClaimLimit != null">user_claim_limit =
|
|
#{userClaimLimit},
|
|
</if>
|
|
<if test="createTime != null">create_time =
|
|
#{createTime},
|
|
</if>
|
|
<if test="createBy != null">create_by =
|
|
#{createBy},
|
|
</if>
|
|
<if test="updateTime != null">update_time =
|
|
#{updateTime},
|
|
</if>
|
|
<if test="updateBy != null">update_by =
|
|
#{updateBy},
|
|
</if>
|
|
<if test="descr != null">descr =
|
|
#{descr},
|
|
</if>
|
|
<if test="memo != null">memo =
|
|
#{memo},
|
|
</if>
|
|
<if test="applicability != null">applicability =
|
|
#{applicability},
|
|
</if>
|
|
</trim>
|
|
where id = #{id}
|
|
</update>
|
|
<update id="updateZdyCouponStatus">
|
|
UPDATE zdy_coupon
|
|
SET STATUS = (CASE
|
|
WHEN #{currentDate} > end_use_time THEN '3'
|
|
WHEN #{currentDate} >= start_use_time THEN '2'
|
|
ELSE STATUS END)
|
|
WHERE STATUS IN ('1', '2');
|
|
</update>
|
|
|
|
<delete id="deleteZdyCouponById" parameterType="Long">
|
|
delete
|
|
from zdy_coupon
|
|
where id = #{id}
|
|
</delete>
|
|
|
|
<delete id="deleteZdyCouponByIds" parameterType="String">
|
|
delete from zdy_coupon where id in
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</delete>
|
|
</mapper>
|