CouponSendMapper.xml 5.6 KB

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