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