DictionaryDataMapper.xml 8.8 KB

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