CouponUseMapper.xml 7.4 KB

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