SaleChannelMapper.xml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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.mdm.mapper.mst.SaleChannelMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. channel_id, channel_code, channel_name, sys_code, display_no, remarks, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user ,flg_default
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.SaleChannel">
  11. <id column="channel_id" property="channelId"/>
  12. <result column="channel_code" property="channelCode"/>
  13. <result column="channel_name" property="channelName"/>
  14. <result column="sys_code" property="sysCode"/>
  15. <result column="display_no" property="displayNo"/>
  16. <result column="remarks" property="remarks"/>
  17. <result column="flg_valid" property="flgValid"/>
  18. <result column="cp_id" property="cpId"/>
  19. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  20. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  21. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  22. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  23. <result column="op_app_code" property="opAppCode"/>
  24. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  25. <result column="op_db_user" property="opDbUser"/>
  26. <result column="flg_default" property="flgDefault"/>
  27. </resultMap>
  28. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mst.SaleChannelResponse">
  29. <id column="channel_id" property="channelId"/>
  30. <result column="channel_code" property="channelCode"/>
  31. <result column="channel_name" property="channelName"/>
  32. <result column="sys_code" property="sysCode"/>
  33. <result column="display_no" property="displayNo"/>
  34. <result column="remarks" property="remarks"/>
  35. <result column="flg_valid" property="flgValid"/>
  36. <result column="cp_id" property="cpId"/>
  37. </resultMap>
  38. <!-- 通用条件列 -->
  39. <sql id="Condition">
  40. <where>
  41. <if test="channelCode != null and channelCode != ''">
  42. AND channel_code LIKE concat('%',my_ex.likequery(#{channelCode}),'%')
  43. </if>
  44. <if test="channelName != null and channelName != ''">
  45. AND channel_name LIKE concat('%',my_ex.likequery(#{channelName}),'%')
  46. </if>
  47. <if test="sysCode != null and sysCode != ''">
  48. AND sys_code = #{sysCode}
  49. </if>
  50. <if test="displayNo != null">
  51. AND display_no = #{displayNo}
  52. </if>
  53. <if test="remarks != null and remarks != ''">
  54. AND remarks = #{remarks}
  55. </if>
  56. <if test="flgValid != null">
  57. AND flg_valid = #{flgValid}
  58. </if>
  59. <if test="cpId != null">
  60. AND cp_id = #{cpId}
  61. </if>
  62. <if test="opCreateTime != null">
  63. AND op_create_time = #{opCreateTime}
  64. </if>
  65. <if test="opCreateUserId != null and opCreateUserId != ''">
  66. AND op_create_user_id = #{opCreateUserId}
  67. </if>
  68. <if test="opUpdateTime != null">
  69. AND op_update_time = #{opUpdateTime}
  70. </if>
  71. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  72. AND op_update_user_id = #{opUpdateUserId}
  73. </if>
  74. <if test="opAppCode != null and opAppCode != ''">
  75. AND op_app_code = #{opAppCode}
  76. </if>
  77. <if test="opTimestamp != null">
  78. AND op_timestamp = #{opTimestamp}
  79. </if>
  80. <if test="opDbUser != null and opDbUser != ''">
  81. AND op_db_user = #{opDbUser}
  82. </if>
  83. <if test="flgValidList != null and flgValidList.size()>0">
  84. AND flg_valid =
  85. any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  86. </if>
  87. <if test="flgDefault != null">
  88. AND flg_default = #{flgDefault}
  89. </if>
  90. <if test="searchText != null">
  91. AND (channel_name like concat('%', my_ex.likequery(#{searchText}) , '%')
  92. OR channel_code like concat('%', my_ex.likequery(#{searchText}) , '%')
  93. OR remarks like concat('%', my_ex.likequery(#{searchText}) , '%')
  94. )
  95. </if>
  96. </where>
  97. </sql>
  98. <sql id="idsForeach">
  99. <!-- 根据主键channelId批量操作 -->
  100. WHERE channel_id in
  101. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  102. #{item}
  103. </foreach>
  104. </sql>
  105. <!-- 查询表t_mst_sale_channel,(条件查询+分页)列表 -->
  106. <select id="selectByCond" resultMap="BaseResultMapResponse">
  107. SELECT
  108. <include refid="Base_Column_List"/>
  109. FROM dkic_b.t_mst_sale_channel
  110. <include refid="Condition"/>
  111. order by CASE WHEN flg_default = true THEN 0 ELSE 1 END, display_no
  112. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  113. limit #{end} offset #{start}
  114. </if>
  115. </select>
  116. <!-- 查询表t_mst_sale_channel,(条件查询)个数 -->
  117. <select id="countByCond" resultType="Long">
  118. SELECT
  119. count(1)
  120. FROM dkic_b.t_mst_sale_channel
  121. <include refid="Condition"/>
  122. </select>
  123. <!-- 根据主键查询表t_mst_sale_channel的一行数据 -->
  124. <select id="selectById" resultMap="BaseResultMap">
  125. SELECT
  126. <include refid="Base_Column_List"/>
  127. FROM dkic_b.t_mst_sale_channel
  128. WHERE channel_id = #{id}::uuid
  129. </select>
  130. <!-- 根据主键锁定表t_mst_sale_channel的一行数据 -->
  131. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  132. SELECT
  133. <include refid="Base_Column_List"/>
  134. FROM dkic_b.t_mst_sale_channel
  135. WHERE channel_id = #{channelId}
  136. for update
  137. </select>
  138. <!-- 根据主键锁定表t_mst_sale_channel的多行数据 -->
  139. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  140. SELECT
  141. <include refid="Base_Column_List"/>
  142. FROM dkic_b.t_mst_sale_channel
  143. <include refid="idsForeach"/>
  144. for update
  145. </select>
  146. <insert id="insertBatch">
  147. insert into dkic_b.t_mst_sale_channel
  148. (
  149. <trim suffixOverrides=",">
  150. channel_code,
  151. channel_name,
  152. sys_code,
  153. display_no,
  154. remarks,
  155. cp_id,
  156. op_app_code,
  157. flg_default,
  158. </trim>
  159. )
  160. values
  161. <foreach collection="list" index="index" item="item" separator=",">
  162. (
  163. <trim suffixOverrides=",">
  164. #{item.channelCode},
  165. #{item.channelName},
  166. #{item.sysCode},
  167. #{item.displayNo},
  168. #{item.remarks},
  169. #{item.cpId},
  170. #{item.opAppCode},
  171. #{item.flgDefault},
  172. </trim>
  173. )
  174. </foreach>
  175. </insert>
  176. <update id="updateBatchSaleChannelDisplayNo">
  177. <foreach collection="list" index="index" item="item" separator=";">
  178. UPDATE dkic_b.t_mst_sale_channel
  179. SET
  180. display_no = #{item.displayNo}
  181. WHERE channel_id = #{item.id}::uuid
  182. </foreach>
  183. </update>
  184. <update id="updateFlgDefault">
  185. UPDATE dkic_b.t_mst_sale_channel
  186. SET
  187. flg_default = false
  188. WHERE cp_id = #{id} AND (flg_default = true OR flg_default is null)
  189. </update>
  190. </mapper>