IntegralShareMapper.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.IntegralShareMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. share_id, cp_id, user_id, tactic_id, share_date, end_date, flg_valid,integral_type
  8. </sql>
  9. <!-- 通用查询列Response -->
  10. <sql id="Base_Column_List_Response">
  11. tmis.share_id, tmis.cp_id, tmis.user_id, tmis.tactic_id, tmis.share_date, tmis.end_date, tmis.flg_valid,tmis.integral_type
  12. </sql>
  13. <!-- 通用查询映射结果 -->
  14. <resultMap id="BaseResultMap" type="com.dk.oauth.model.pojo.integral.IntegralShare">
  15. <id column="share_id" property="shareId" typeHandler="UuidTypeHandler"/>
  16. <result column="cp_id" property="cpId"/>
  17. <result column="user_id" property="userId" typeHandler="UuidTypeHandler"/>
  18. <result column="tactic_id" property="tacticId" typeHandler="UuidTypeHandler"/>
  19. <result column="share_date" property="shareDate" typeHandler="TimestampTypeHandler"/>
  20. <result column="end_date" property="endDate" typeHandler="TimestampTypeHandler"/>
  21. <result column="flg_valid" property="flgValid"/>
  22. <result column="integral_type" property="integralType"/>
  23. </resultMap>
  24. <!-- 通用查询映射结果 -->
  25. <resultMap id="BaseResultMapResponse" type="com.dk.oauth.model.response.integral.IntegralShareResponse">
  26. <id column="share_id" property="shareId" typeHandler="UuidTypeHandler"/>
  27. <result column="cp_id" property="cpId"/>
  28. <result column="user_id" property="userId" typeHandler="UuidTypeHandler"/>
  29. <result column="tactic_id" property="tacticId" typeHandler="UuidTypeHandler"/>
  30. <result column="share_date" property="shareDate" typeHandler="TimestampTypeHandler"/>
  31. <result column="end_date" property="endDate" typeHandler="TimestampTypeHandler"/>
  32. <result column="flg_valid" property="flgValid"/>
  33. <result column="cp_name" property="cpName"/>
  34. <result column="integral_type" property="integralType"/>
  35. <result column="integral_type_name" property="integralTypeName"/>
  36. <result column="number_of_shares" property="numberOfShares"/>
  37. </resultMap>
  38. <!-- 通用条件列 -->
  39. <sql id="Condition">
  40. <where>
  41. <if test="cpId != null and cpId != ''">
  42. AND tmis.cp_id = #{cpId}
  43. </if>
  44. <if test="tacticId != null and tacticId != ''">
  45. AND tmis.tactic_id = #{tacticId}::uuid
  46. </if>
  47. <if test="userId != null and userId != ''">
  48. AND tmis.user_id = #{userId}::uuid
  49. </if>
  50. <if test="shareDate != null">
  51. AND tmis.share_date = #{shareDate}
  52. </if>
  53. <if test="endDate != null">
  54. AND tmis.end_date = #{endDate}
  55. </if>
  56. <if test="flgValid != null">
  57. AND tmis.flg_valid = #{flgValid}
  58. </if>
  59. <if test="shareDateFlag != null and shareDateFlag ">
  60. AND tmis.share_date >= NOW() - INTERVAL '1 DAY'
  61. </if>
  62. <if test="integralType != null and integralType != ''">
  63. AND tmis.integral_type = #{integralType}
  64. </if>
  65. </where>
  66. </sql>
  67. <sql id="idsForeach">
  68. <!-- 根据主键cpId批量操作 -->
  69. WHERE share_id in
  70. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  71. #{item}
  72. </foreach>
  73. </sql>
  74. <!-- 查询表dkic_a.t_mst_integral_share,(条件查询+分页)列表 -->
  75. <select id="selectByCond" resultMap="BaseResultMapResponse">
  76. SELECT
  77. <include refid="Base_Column_List_Response"/>
  78. ,tac.cp_name
  79. ,sys.f_get_name_i18n(tdk.kind_name_i18n,#{i18n}) as integral_type_name
  80. FROM dkic_a.t_mst_integral_share tmis
  81. left join dkic_a.t_a_company tac on tac.cp_id = tmis.cp_id
  82. LEFT JOIN sys.t_data_kind tdk ON tmis.integral_type = tdk.kind_code
  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_integral_share,(条件查询)个数 -->
  89. <select id="countByCond" resultType="Long">
  90. SELECT
  91. count(1)
  92. FROM dkic_a.t_mst_integral_share tmis
  93. left join dkic_a.t_a_company tac on tac.cp_id = tmis.cp_id
  94. LEFT JOIN sys.t_data_kind tdk ON tmis.integral_type = tdk.kind_code
  95. <include refid="Condition"/>
  96. </select>
  97. <!-- 根据主键查询表dkic_a.t_mst_integral_share的一行数据 -->
  98. <select id="selectById" resultMap="BaseResultMapResponse">
  99. SELECT
  100. <include refid="Base_Column_List_Response"/>
  101. ,tac.cp_name
  102. ,sys.f_get_name_i18n(tdk.kind_name_i18n,#{i18n}) as integral_type_name
  103. FROM dkic_a.t_mst_integral_share tmis
  104. left join dkic_a.t_a_company tac on tac.cp_id = tmis.cp_id
  105. LEFT JOIN sys.t_data_kind tdk ON tmis.integral_type = tdk.kind_code
  106. WHERE share_id = #{id}::uuid
  107. </select>
  108. <!-- 根据主键锁定表dkic_a.t_mst_integral_share的一行数据 -->
  109. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  110. SELECT
  111. <include refid="Base_Column_List"/>
  112. FROM dkic_a.t_mst_integral_share
  113. WHERE share_id = #{shareId}::uuid
  114. for update
  115. </select>
  116. <!-- 根据主键锁定表dkic_a.t_mst_integral_share的多行数据 -->
  117. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  118. SELECT
  119. <include refid="Base_Column_List"/>
  120. FROM dkic_a.t_mst_integral_share
  121. <include refid="idsForeach"/>
  122. for update
  123. </select>
  124. <insert id="insertBatch">
  125. insert into dkic_a.t_mst_integral_share
  126. (
  127. <trim suffixOverrides=",">
  128. tactic_id,
  129. share_date,
  130. end_date,
  131. user_id,
  132. cp_id,
  133. integral_type,
  134. </trim>
  135. )
  136. values
  137. <foreach collection="list" index="index" item="item" separator=",">
  138. (
  139. <trim suffixOverrides=",">
  140. #{item.tacticId}::uuid,
  141. #{item.shareDate},
  142. #{item.endDate},
  143. #{item.userId}::uuid,
  144. #{item.cpId},
  145. #{item.integralType},
  146. </trim>
  147. )
  148. </foreach>
  149. </insert>
  150. <!-- 查询历史记录(条件查询+分页)列表 -->
  151. <select id="selectHistoryRecordByCond" resultMap="BaseResultMapResponse">
  152. SELECT
  153. <include refid="Base_Column_List_Response"/>
  154. ,tac.cp_name
  155. ,sys.f_get_name_i18n(tdk.kind_name_i18n,#{i18n}) as integral_type_name
  156. ,(select count(1) from dkic_a.t_mst_integral_item tmii where tmii.cp_id = tmis.cp_id) as number_of_shares
  157. FROM dkic_a.t_mst_integral_share tmis
  158. left join dkic_a.t_a_company tac on tac.cp_id = tmis.cp_id
  159. LEFT JOIN sys.t_data_kind tdk ON tmis.integral_type = tdk.kind_code
  160. <include refid="Condition"/>
  161. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  162. limit #{end} offset #{start}
  163. </if>
  164. </select>
  165. </mapper>