Files
wx-cashier-service/src/main/resources/mapper/TbActivateInRecordMapper.xml
2024-11-09 09:31:30 +08:00

263 lines
11 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.chaozhanggui.system.cashierservice.dao.TbActivateInRecordMapper">
<resultMap type="com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord" id="TbActivateInRecordMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="vipUserId" column="vip_user_id" jdbcType="INTEGER"/>
<result property="couponId" column="coupon_id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="type" column="type" jdbcType="INTEGER"/>
<result property="proId" column="pro_id" jdbcType="INTEGER"/>
<result property="fullAmount" column="full_amount" jdbcType="INTEGER"/>
<result property="discountAmount" column="discount_amount" jdbcType="INTEGER"/>
<result property="num" column="num" jdbcType="INTEGER"/>
<result property="overNum" column="over_num" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="sourceActId" column="source_act_id" jdbcType="INTEGER"/>
<result property="sourceFlowId" column="source_flow_id" jdbcType="INTEGER"/>
<result property="useStartTime" column="use_start_time" jdbcType="TIMESTAMP"/>
<result property="useEndTime" column="use_end_time" jdbcType="TIMESTAMP"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="couponJson" column="coupon_json" jdbcType="VARCHAR"/>
<result property="source" column="source" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, num, over_num, shop_id, source_act_id, source_flow_id, use_start_time, use_end_time, create_time, update_time, coupon_json,source </sql>
<!--查询单个-->
<select id="queryById" resultMap="TbActivateInRecordMap">
select
<include refid="Base_Column_List"/>
from tb_activate_in_record
where id = #{id}
</select>
<select id="queryByVipIdAndShopId" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo">
SELECT
inRecord.shop_id as shopId,
inRecord.id as id,
inRecord.full_amount as fullAmount,
inRecord.discount_amount as discountAmount,
inRecord.coupon_id as couponId,
pro.id as proId,
CASE
WHEN inRecord.type = 1 THEN inRecord.NAME
WHEN inRecord.type = 2 THEN pro.NAME
END AS `name`,
inRecord.type,
inRecord.over_num as num,
inRecord.use_end_time as endTime
FROM
tb_activate_in_record inRecord
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id
<if test="shopId != null and shopId != ''">
and pro.shop_id = #{shopId}
</if>
WHERE
inRecord.vip_user_id in
<foreach item="item" index="index" collection="vipUserIds" open="(" separator="," close=")">
#{item}
</foreach>
<if test="shopId != null and shopId != ''">
and inRecord.shop_id = #{shopId}
</if>
and inRecord.over_num != 0
and inRecord.use_start_time &lt; now()
and inRecord.use_end_time &gt; now()
order by inRecord.use_end_time asc
</select>
<select id="queryByVipIdAndShopIdExpire" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo">
SELECT
inRecord.shop_id as shopId,
CASE
WHEN inRecord.type = 1 THEN inRecord.NAME
WHEN inRecord.type = 2 THEN pro.NAME
END AS `name`,
inRecord.type,
inRecord.over_num as num,
inRecord.use_end_time as endTime
FROM
tb_activate_in_record inRecord
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id
<if test="shopId != null and shopId != ''">
and pro.shop_id = #{shopId}
</if>
WHERE
inRecord.vip_user_id in
<foreach item="item" index="index" collection="vipUserIds" open="(" separator="," close=")">
#{item}
</foreach>
<if test="shopId != null and shopId != ''">
and inRecord.shop_id = #{shopId}
</if>
and inRecord.over_num != 0
and inRecord.use_end_time &lt; now()
order by inRecord.use_end_time asc
</select>
<!--查询剩余商品优惠卷数量-->
<select id="countCouponNum" resultType="INTEGER">
SELECT
ifnull(sum(over_num), 0)
FROM
tb_activate_in_record record
INNER JOIN tb_shop_user vip ON record.vip_user_id = vip.id AND vip.user_id = #{userId}
</select>
<!--查询指定行数据-->
<select id="queryAll" resultMap="TbActivateInRecordMap">
select
<include refid="Base_Column_List"/>
from tb_activate_in_record
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="vipUserId != null">
and vip_user_id = #{vipUserId}
</if>
<if test="couponId != null">
and coupon_id = #{couponId}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
<if test="type != null">
and type = #{type}
</if>
<if test="proId != null">
and pro_id = #{proId}
</if>
<if test="fullAmount != null">
and full_amount = #{fullAmount}
</if>
<if test="discountAmount != null">
and discount_amount = #{discountAmount}
</if>
<if test="num != null">
and num = #{num}
</if>
<if test="overNum != null">
and over_num = #{overNum}
</if>
<if test="shopId != null">
and shop_id = #{shopId}
</if>
<if test="sourceActId != null">
and source_act_id = #{sourceActId}
</if>
<if test="sourceFlowId != null">
and source_flow_id = #{sourceFlowId}
</if>
<if test="useStartTime != null">
and use_start_time = #{useStartTime}
</if>
<if test="useEndTime != null">
and use_end_time = #{useEndTime}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
<if test="couponJson != null and couponJson != ''">
and coupon_json = #{couponJson}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into tb_activate_in_record(vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, num, over_num, shop_id, source_act_id, source_flow_id, use_start_time, use_end_time, create_time, update_time, coupon_json,source)
values (#{vipUserId}, #{couponId}, #{name}, #{type}, #{proId}, #{fullAmount}, #{discountAmount}, #{num}, #{overNum}, #{shopId}, #{sourceActId}, #{sourceFlowId}, #{useStartTime}, #{useEndTime}, #{createTime}, #{updateTime}, #{couponJson} , #{source})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into tb_activate_in_record(vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, num, over_num, shop_id, source_act_id, source_flow_id, use_start_time, use_end_time, create_time, update_time, coupon_json, source)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.vipUserId}, #{entity.couponId}, #{entity.name}, #{entity.type}, #{entity.proId}, #{entity.fullAmount}, #{entity.discountAmount}, #{entity.num}, #{entity.overNum}, #{entity.shopId}, #{entity.sourceActId}, #{entity.sourceFlowId}, #{entity.useStartTime}, #{entity.useEndTime}, #{entity.createTime}, #{entity.updateTime}, #{entity.couponJson}, #{entity.source})
</foreach>
</insert>
<!--通过主键修改数据-->
<update id="update">
update tb_activate_in_record
<set>
<if test="vipUserId != null">
vip_user_id = #{vipUserId},
</if>
<if test="couponId != null">
coupon_id = #{couponId},
</if>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="type != null">
type = #{type},
</if>
<if test="proId != null">
pro_id = #{proId},
</if>
<if test="fullAmount != null">
full_amount = #{fullAmount},
</if>
<if test="discountAmount != null">
discount_amount = #{discountAmount},
</if>
<if test="num != null">
num = #{num},
</if>
<if test="overNum != null">
over_num = #{overNum},
</if>
<if test="shopId != null">
shop_id = #{shopId},
</if>
<if test="sourceActId != null">
source_act_id = #{sourceActId},
</if>
<if test="sourceFlowId != null">
source_flow_id = #{sourceFlowId},
</if>
<if test="useStartTime != null">
use_start_time = #{useStartTime},
</if>
<if test="useEndTime != null">
use_end_time = #{useEndTime},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="couponJson != null and couponJson != ''">
coupon_json = #{couponJson},
</if>
</set>
where id = #{id}
</update>
<update id="updateOverNum">
update tb_activate_in_record
set over_num = #{overNum}
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from tb_activate_in_record where id = #{id}
</delete>
</mapper>