CouponReceiveMapper.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.dk.oauth.mapper.integral.CouponReceiveMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. receive_id, cp_id, coupon_id, send_id, user_wxid, assist_date, flg_valid
  8. </sql>
  9. <!-- 通用查询列Response -->
  10. <sql id="Base_Column_List_Response">
  11. tmcr.receive_id,tmcr.cp_id, tmcr.send_id, tmcr.coupon_id, tmcr.user_wxid, tmcr.assist_date, tmcr.flg_valid
  12. </sql>
  13. <!-- 通用查询映射结果 -->
  14. <resultMap id="BaseResultMap" type="com.dk.oauth.model.pojo.integral.CouponReceive">
  15. <id column="receive_id" property="receiveId"/>
  16. <result column="cp_id" property="cpId"/>
  17. <result column="coupon_id" property="couponId" typeHandler="UuidTypeHandler"/>
  18. <result column="send_id" property="sendId" typeHandler="UuidTypeHandler"/>
  19. <result column="user_wxid" property="userWxid"/>
  20. <result column="assist_date" property="assistDate" typeHandler="TimestampTypeHandler"/>
  21. <result column="flg_valid" property="flgValid"/>
  22. </resultMap>
  23. <!-- 通用查询映射结果 -->
  24. <resultMap id="BaseResultMapResponse" type="com.dk.oauth.model.response.integral.CouponReceiveResponse">
  25. <id column="receive_id" property="receiveId"/>
  26. <result column="cp_id" property="cpId"/>
  27. <result column="cp_name" property="cpName"/>
  28. <result column="coupon_id" property="couponId" typeHandler="UuidTypeHandler"/>
  29. <result column="coupon_name" property="couponName" />
  30. <result column="send_id" property="sendId" typeHandler="UuidTypeHandler"/>
  31. <result column="user_wxid" property="userWxid"/>
  32. <result column="assist_date" property="assistDate" typeHandler="TimestampTypeHandler"/>
  33. <result column="flg_valid" property="flgValid"/>
  34. </resultMap>
  35. <!-- 通用条件列 -->
  36. <sql id="Condition">
  37. <where>
  38. <if test="cpId != null and cpId != ''">
  39. AND tmcr.cp_id = #{cpId}
  40. </if>
  41. <if test="couponId != null and couponId != ''">
  42. AND tmcr.coupon_id = #{couponId}::uuid
  43. </if>
  44. <if test="sendId != null and sendId != ''">
  45. AND tmcr.send_id = #{sendId}::uuid
  46. </if>
  47. <if test="userWxid != null">
  48. AND tmcr.user_wxid = #{userWxid}
  49. </if>
  50. <if test="assistDate != null">
  51. AND tmcr.assist_date = #{assistDate}
  52. </if>
  53. <if test="flgValid != null">
  54. AND tmcr.flg_valid = #{flgValid}
  55. </if>
  56. <if test="cpName != null and cpName != ''">
  57. AND tac.cp_name LIKE concat('%',my_ex.likequery(#{cpName}),'%')
  58. </if>
  59. <if test="couponName != null and couponName != ''">
  60. AND tmc.coupon_name LIKE concat('%',my_ex.likequery(#{couponName}),'%')
  61. </if>
  62. <if test="assistFlag != null and assistFlag ">
  63. AND tmcr.assist_date >= NOW() - INTERVAL '7 DAY'
  64. </if>
  65. </where>
  66. </sql>
  67. <sql id="idsForeach">
  68. <!-- 根据主键cpId批量操作 -->
  69. WHERE receive_id in
  70. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  71. #{item}
  72. </foreach>
  73. </sql>
  74. <!-- 查询表dkic_a.t_mst_coupon_receive,(条件查询+分页)列表 -->
  75. <select id="selectByCond" resultMap="BaseResultMapResponse">
  76. SELECT
  77. <include refid="Base_Column_List_Response"/>
  78. ,tmc.coupon_name
  79. ,tac.cp_name
  80. FROM dkic_a.t_mst_coupon_receive tmcr
  81. left join dkic_a.t_mst_coupon tmc on tmc.coupon_id = tmcr.coupon_id
  82. left join dkic_a.t_a_company tac on tac.cp_id = tmcr.cp_id
  83. <include refid="Condition"/>
  84. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  85. limit #{end} offset #{start}
  86. </if>
  87. </select>
  88. <!-- 查询表dkic_a.t_mst_coupon_receive,(条件查询+分页)列表 -->
  89. <select id="countByCondNoExistCpId" resultMap="BaseResultMapResponse">
  90. SELECT
  91. count(1)
  92. FROM dkic_a.t_mst_coupon_receive tmcr
  93. <where>
  94. tmcr.flg_valid
  95. <if test="userWxid != null">
  96. AND tmcr.user_wxid = #{userWxid}
  97. </if>
  98. <if test="assistFlag != null and assistFlag ">
  99. AND tmcr.assist_date >= NOW() - INTERVAL '7 DAY'
  100. </if>
  101. </where>
  102. </select>
  103. <!-- 查询表dkic_a.t_mst_coupon_receive,(条件查询)个数 -->
  104. <select id="countByCond" resultType="Long">
  105. SELECT
  106. count(1)
  107. FROM dkic_a.t_mst_coupon_receive tmcr
  108. left join dkic_a.t_mst_coupon tmc on tmc.coupon_id = tmcr.coupon_id
  109. left join dkic_a.t_a_company tac on tac.cp_id = tmcr.cp_id
  110. <include refid="Condition"/>
  111. </select>
  112. <!-- 根据主键查询表dkic_a.t_mst_coupon_receive的一行数据 -->
  113. <select id="selectById" resultMap="BaseResultMapResponse">
  114. SELECT
  115. <include refid="Base_Column_List_Response"/>
  116. ,tmc.coupon_name
  117. ,tac.cp_name
  118. FROM dkic_a.t_mst_coupon_receive tmcr
  119. left join dkic_a.t_mst_coupon tmc on tmc.coupon_id = tmcr.coupon_id
  120. left join dkic_a.t_a_company tac on tac.cp_id = tmcr.cp_id
  121. WHERE receive_id = #{id}
  122. </select>
  123. <!-- 根据主键锁定表dkic_a.t_mst_coupon_receive的一行数据 -->
  124. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  125. SELECT
  126. <include refid="Base_Column_List"/>
  127. FROM dkic_a.t_mst_coupon_receive
  128. WHERE receive_id = #{receiveId}
  129. for update
  130. </select>
  131. <!-- 根据主键锁定表dkic_a.t_mst_coupon_receive的多行数据 -->
  132. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  133. SELECT
  134. <include refid="Base_Column_List"/>
  135. FROM dkic_a.t_mst_coupon_receive
  136. <include refid="idsForeach"/>
  137. for update
  138. </select>
  139. <insert id="insertBatch">
  140. insert into dkic_a.t_mst_coupon_receive
  141. (
  142. <trim suffixOverrides=",">
  143. cp_id,
  144. coupon_id,
  145. send_id,
  146. user_wxid,
  147. assist_date,
  148. </trim>
  149. )
  150. values
  151. <foreach collection="list" index="index" item="item" separator=",">
  152. (
  153. <trim suffixOverrides=",">
  154. #{item.cpId},
  155. #{item.couponId}::uuid,
  156. #{item.sendId}::uuid,
  157. #{item.userWxid},
  158. #{item.assistDate},
  159. </trim>
  160. )
  161. </foreach>
  162. </insert>
  163. </mapper>