189 lines
6.9 KiB
XML
189 lines
6.9 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.TbActivateOutRecordMapper">
|
|
|
|
<resultMap type="com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord" id="TbActivateOutRecordMap">
|
|
<result property="id" column="id" jdbcType="INTEGER"/>
|
|
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
|
|
<result property="orderId" column="order_id" jdbcType="VARCHAR"/>
|
|
<result property="giveId" column="give_id" jdbcType="INTEGER"/>
|
|
<result property="vipUserId" column="vip_user_id" jdbcType="INTEGER"/>
|
|
<result property="type" column="type" jdbcType="INTEGER"/>
|
|
<result property="useNum" column="use_num" jdbcType="INTEGER"/>
|
|
<result property="refNum" column="ref_num" jdbcType="INTEGER"/>
|
|
<result property="status" column="status" jdbcType="VARCHAR"/>
|
|
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
|
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
|
</resultMap>
|
|
|
|
<sql id="Base_Column_List">
|
|
id
|
|
, shop_id, order_id, give_id, vip_user_id, type, use_num, ref_num, status, create_time, update_time </sql>
|
|
|
|
<!--查询单个-->
|
|
<select id="queryById" resultMap="TbActivateOutRecordMap">
|
|
select
|
|
<include refid="Base_Column_List"/>
|
|
|
|
from tb_activate_out_record
|
|
where id = #{id}
|
|
</select>
|
|
|
|
<select id="queryByVipIdAndShopId" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo">
|
|
SELECT
|
|
shop.shop_name as shopName,
|
|
CASE
|
|
WHEN outRecord.type = 1 THEN inRecord.name
|
|
WHEN outRecord.type = 2 THEN pro.NAME
|
|
END AS `name`,
|
|
outRecord.type,
|
|
outRecord.use_num-outRecord.ref_num as num
|
|
FROM
|
|
tb_activate_out_record outRecord
|
|
INNER JOIN tb_shop_info shop on outRecord.shop_id = shop.id
|
|
INNER JOIN tb_activate_in_record inRecord
|
|
on outRecord.give_id = inRecord.id
|
|
<if test="shopId != null and shopId != ''">
|
|
and inRecord.shop_id = #{shopId}
|
|
</if>
|
|
LEFT JOIN tb_product pro
|
|
ON inRecord.pro_id = pro.id
|
|
<if test="shopId != null and shopId != ''">
|
|
and pro.shop_id = #{shopId}
|
|
</if>
|
|
WHERE
|
|
outRecord.vip_user_id in
|
|
<foreach item="item" index="index" collection="vipUserIds" open="(" separator="," close=")">
|
|
#{item}
|
|
</foreach>
|
|
<if test="shopId != null and shopId != ''">
|
|
and outRecord.shop_id = #{shopId}
|
|
</if>
|
|
and outRecord.status = 'closed'
|
|
and outRecord.use_num-outRecord.ref_num >0
|
|
order by outRecord.create_time desc
|
|
</select>
|
|
|
|
<!--查询指定行数据-->
|
|
<select id="queryAll" resultMap="TbActivateOutRecordMap">
|
|
select
|
|
<include refid="Base_Column_List"/>
|
|
|
|
from tb_activate_out_record
|
|
<where>
|
|
<if test="id != null">
|
|
and id = #{id}
|
|
</if>
|
|
<if test="shopId != null">
|
|
and shop_id = #{shopId}
|
|
</if>
|
|
<if test="orderId != null and orderId != ''">
|
|
and order_id = #{orderId}
|
|
</if>
|
|
<if test="giveId != null">
|
|
and give_id = #{giveId}
|
|
</if>
|
|
<if test="vipUserId != null">
|
|
and vip_user_id = #{vipUserId}
|
|
</if>
|
|
<if test="type != null">
|
|
and type = #{type}
|
|
</if>
|
|
<if test="useNum != null">
|
|
and use_num = #{useNum}
|
|
</if>
|
|
<if test="refNum != null">
|
|
and ref_num = #{refNum}
|
|
</if>
|
|
<if test="status != null and status != ''">
|
|
and status = #{status}
|
|
</if>
|
|
<if test="createTime != null">
|
|
and create_time = #{createTime}
|
|
</if>
|
|
<if test="updateTime != null">
|
|
and update_time = #{updateTime}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
|
|
<!--新增所有列-->
|
|
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
|
|
insert into tb_activate_out_record(shop_id, order_id, give_id, vip_user_id, type, use_num, ref_num, status,
|
|
create_time, update_time)
|
|
values (#{shopId}, #{orderId}, #{giveId}, #{vipUserId}, #{type}, #{useNum}, #{refNum}, #{status}, #{createTime},
|
|
#{updateTime})
|
|
</insert>
|
|
|
|
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
|
|
insert into tb_activate_out_record(shop_id, order_id, give_id, vip_user_id, type, use_num, ref_num, status,
|
|
create_time, update_time)
|
|
values
|
|
<foreach collection="entities" item="entity" separator=",">
|
|
(#{entity.shopId}, #{entity.orderId}, #{entity.giveId}, #{entity.vipUserId}, #{entity.type},
|
|
#{entity.useNum}, #{entity.refNum}, #{entity.status}, #{entity.createTime}, #{entity.updateTime})
|
|
</foreach>
|
|
</insert>
|
|
|
|
<!--通过主键修改数据-->
|
|
<update id="update">
|
|
update tb_activate_out_record
|
|
<set>
|
|
<if test="shopId != null">
|
|
shop_id = #{shopId},
|
|
</if>
|
|
<if test="orderId != null and orderId != ''">
|
|
order_id = #{orderId},
|
|
</if>
|
|
<if test="giveId != null">
|
|
give_id = #{giveId},
|
|
</if>
|
|
<if test="vipUserId != null">
|
|
vip_user_id = #{vipUserId},
|
|
</if>
|
|
<if test="type != null">
|
|
type = #{type},
|
|
</if>
|
|
<if test="useNum != null">
|
|
use_num = #{useNum},
|
|
</if>
|
|
<if test="refNum != null">
|
|
ref_num = #{refNum},
|
|
</if>
|
|
<if test="status != null and status != ''">
|
|
status = #{status},
|
|
</if>
|
|
<if test="createTime != null">
|
|
create_time = #{createTime},
|
|
</if>
|
|
<if test="updateTime != null">
|
|
update_time = #{updateTime},
|
|
</if>
|
|
</set>
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<update id="updateByOrderIdAndStatus">
|
|
update tb_activate_out_record
|
|
set
|
|
status = 'closed'
|
|
where order_id = #{orderId}
|
|
</update>
|
|
|
|
<update id="updateRefNum">
|
|
update tb_activate_out_record
|
|
set ref_num = ref_num + #{refNum}
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<!--通过主键删除-->
|
|
<delete id="deleteById">
|
|
delete
|
|
from tb_activate_out_record
|
|
where id = #{id}
|
|
</delete>
|
|
|
|
</mapper>
|
|
|