| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?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.dk.oauth.mapper.integral.CouponSendMapper">
- <!-- 通用设置 -->
- <!-- 通用查询列 -->
- <sql id="Base_Column_List">
- send_id,cp_id, coupon_id, send_date, end_date, user_num, flg_valid,send_staff,send_user
- </sql>
- <!-- 通用查询列Response -->
- <sql id="Base_Column_List_Response">
- tmcs.send_id,tmcs.cp_id, tmcs.coupon_id, tmcs.send_date, tmcs.end_date, tmcs.user_num,
- tmcs.flg_valid,tmcs.send_staff,tmcs.send_user
- </sql>
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dk.oauth.model.pojo.integral.CouponSend">
- <id column="send_id" property="sendId" typeHandler="UuidTypeHandler"/>
- <result column="cp_id" property="cpId"/>
- <result column="coupon_id" property="couponId" typeHandler="UuidTypeHandler"/>
- <result column="send_date" property="sendDate" typeHandler="TimestampTypeHandler"/>
- <result column="end_date" property="endDate" typeHandler="TimestampTypeHandler"/>
- <result column="user_num" property="userNum"/>
- <result column="flg_valid" property="flgValid"/>
- <result column="send_staff" property="sendStaff"/>
- <result column="send_user" property="sendUser" typeHandler="UuidTypeHandler"/>
- </resultMap>
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMapResponse" type="com.dk.oauth.model.response.integral.CouponSendResponse">
- <id column="send_id" property="sendId" typeHandler="UuidTypeHandler"/>
- <result column="cp_id" property="cpId"/>
- <result column="coupon_id" property="couponId" typeHandler="UuidTypeHandler"/>
- <result column="send_date" property="sendDate" typeHandler="TimestampTypeHandler"/>
- <result column="end_date" property="endDate" typeHandler="TimestampTypeHandler"/>
- <result column="user_num" property="userNum"/>
- <result column="flg_valid" property="flgValid"/>
- <result column="cp_name" property="cpName"/>
- <result column="coupon_name" property="couponName"/>
- <result column="send_staff" property="sendStaff"/>
- <result column="coupon_receive_count" property="couponReceiveCount"/>
- <result column="send_user" property="sendUser" typeHandler="UuidTypeHandler"/>
- </resultMap>
- <!-- 通用条件列 -->
- <sql id="Condition">
- <where>
- <if test="cpId != null and cpId != ''">
- AND tmcs.cp_id = #{cpId}
- </if>
- <if test="couponId != null and couponId != ''">
- AND tmcs.coupon_id = #{couponId}::uuid
- </if>
- <if test="sendDate != null">
- AND tmcs.send_date = #{sendDate}
- </if>
- <if test="endDate != null">
- AND tmcs.end_date = #{endDate}
- </if>
- <if test="userNum != null">
- AND tmcs.user_num = #{userNum}
- </if>
- <if test="flgValid != null">
- AND tmcs.flg_valid = #{flgValid}
- </if>
- <if test="cpName != null and cpName != ''">
- AND tac.cp_name LIKE concat('%',my_ex.likequery(#{cpName}),'%')
- </if>
- <if test="couponName != null and couponName != ''">
- AND tmc.coupon_name LIKE concat('%',my_ex.likequery(#{couponName}),'%')
- </if>
- <if test="sendUser != null and sendUser != ''">
- AND tmcs.send_user = #{sendUser}::uuid
- </if>
- </where>
- </sql>
- <sql id="idsForeach">
- <!-- 根据主键cpId批量操作 -->
- WHERE send_id in
- <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </sql>
- <!-- 查询表dkic_a.t_mst_coupon_send,(条件查询+分页)列表 -->
- <select id="selectByCond" resultMap="BaseResultMapResponse">
- SELECT
- <include refid="Base_Column_List_Response"/>
- ,tac.cp_name
- ,tmc.coupon_name
- FROM dkic_a.t_mst_coupon_send tmcs
- left join dkic_a.t_a_company tac on tac.cp_id = tmcs.cp_id
- left join dkic_a.t_mst_coupon tmc on tmc.coupon_id = tmcs.coupon_id
- <include refid="Condition"/>
- <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
- limit #{end} offset #{start}
- </if>
- </select>
- <!-- 查询表dkic_a.t_mst_coupon_send,(条件查询+分页)列表 -->
- <select id="selectByCondHistory" resultMap="BaseResultMapResponse">
- SELECT
- <include refid="Base_Column_List_Response"/>
- ,tac.cp_name
- ,tmc.coupon_name
- ,(select count(tmcr.send_id) from dkic_a.t_mst_coupon_receive tmcr where tmcr.send_id = tmcs.send_id ) coupon_receive_count
- FROM dkic_a.t_mst_coupon_send tmcs
- left join dkic_a.t_a_company tac on tac.cp_id = tmcs.cp_id
- left join dkic_a.t_mst_coupon tmc on tmc.coupon_id = tmcs.coupon_id
- <include refid="Condition"/>
- order by tmcs.send_date desc
- <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
- limit #{end} offset #{start}
- </if>
- </select>
- <!-- 查询表dkic_a.t_mst_coupon_send,(条件查询)个数 -->
- <select id="countByCond" resultType="Long">
- SELECT
- count(1)
- FROM dkic_a.t_mst_coupon_send tmcs
- <include refid="Condition"/>
- </select>
- <!-- 根据主键查询表dkic_a.t_mst_coupon_send的一行数据 -->
- <select id="selectById" resultMap="BaseResultMapResponse">
- SELECT
- <include refid="Base_Column_List_Response"/>
- ,tac.cp_name
- ,tmc.coupon_name
- FROM dkic_a.t_mst_coupon_send tmcs
- left join dkic_a.t_a_company tac on tac.cp_id = tmcs.cp_id
- left join dkic_a.t_mst_coupon tmc on tmc.coupon_id = tmcs.coupon_id
- WHERE tmcs.send_id = #{sendId}::uuid
- </select>
- <!-- 根据主键锁定表dkic_a.t_mst_coupon_send的一行数据 -->
- <select id="selectByIdForUpdate" resultMap="BaseResultMap">
- SELECT
- <include refid="Base_Column_List"/>
- FROM dkic_a.t_mst_coupon_send
- WHERE send_id = #{sendId}::uuid
- for update
- </select>
- <!-- 根据主键锁定表dkic_a.t_mst_coupon_send的多行数据 -->
- <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
- SELECT
- <include refid="Base_Column_List"/>
- FROM dkic_a.t_mst_coupon_send
- <include refid="idsForeach"/>
- for update
- </select>
- <insert id="insertBatch">
- insert into dkic_a.t_mst_coupon_send
- (
- <trim suffixOverrides=",">
- cp_id,
- coupon_id,
- send_date,
- end_date,
- user_num,
- </trim>
- )
- values
- <foreach collection="list" index="index" item="item" separator=",">
- (
- <trim suffixOverrides=",">
- #{item.cpId},
- #{item.couponId}::uuid,
- #{item.sendDate},
- #{item.endDate},
- #{item.userNum},
- </trim>
- )
- </foreach>
- </insert>
- <!-- 根据公司id和优惠券id查询截止时间 -->
- <select id="selectEndTime" resultMap="BaseResultMapResponse">
- SELECT end_date
- FROM dkic_a.t_mst_coupon_send
- WHERE send_id = #{sendId}::uuid
- </select>
- <select id="selectCouponSendItem" resultType="java.util.Map">
- select
- tmcs.send_id as "sendId",
- tmcs.cp_id as "cpId",
- tmcs.coupon_id as "couponId",
- tmcs.send_date as "sendDate",
- tmcs.end_date as "endDate",
- tmcs.user_num as "userNum",
- tmcs.send_staff as "sendStaff",
- tmcs.send_user as "sendUser",
- ( select COUNT (1) from dkic_a.t_mst_coupon_receive tmcr
- where tmcr.send_id = tmcs.send_id
- ) as "userHelpNum",
- now() as "nowTime"
- from dkic_a.t_mst_coupon_send tmcs
- left join dkic_a.t_mst_coupon tmc
- on tmc.coupon_id = tmcs.coupon_id
- where tmcs.flg_valid
- AND tmcs.send_user = #{sendUser}::uuid
- and ( select COUNT (1) from dkic_a.t_mst_coupon_receive tmcr
- where tmcr.send_id = tmcs.send_id
- ) < tmc.user_num
- and tmcs.cp_id = #{cpId}
- and tmcs.end_date > now()
- ORDER BY tmcs.send_date desc
- limit 1
- </select>
- </mapper>
|