UnitMapper.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.UnitMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. unit_id, unit_code, unit_name, decimal_places, 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
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.Unit">
  11. <id column="unit_id" property="unitId"/>
  12. <result column="unit_code" property="unitCode"/>
  13. <result column="unit_name" property="unitName"/>
  14. <result column="decimal_places" property="decimalPlaces"/>
  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. </resultMap>
  27. <!-- 通用查询映射结果 -->
  28. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mst.UnitResponse">
  29. <id column="unit_id" property="unitId"/>
  30. <result column="unit_code" property="unitCode"/>
  31. <result column="unit_name" property="unitName"/>
  32. <result column="decimal_places" property="decimalPlaces"/>
  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. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  38. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  39. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  40. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  41. <result column="op_app_code" property="opAppCode"/>
  42. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  43. <result column="op_db_user" property="opDbUser"/>
  44. </resultMap>
  45. <!-- 通用条件列 -->
  46. <sql id="Condition">
  47. <where>
  48. <if test="unitCode != null and unitCode != ''">
  49. AND unit_code LIKE concat('%',my_ex.likequery(#{unitCode}),'%')
  50. </if>
  51. <if test="unitName != null and unitName != ''">
  52. AND unit_name LIKE concat('%',my_ex.likequery(#{unitName}),'%')
  53. </if>
  54. <if test="decimalPlaces != null">
  55. AND decimal_places = #{decimalPlaces}
  56. </if>
  57. <if test="displayNo != null">
  58. AND display_no = #{displayNo}
  59. </if>
  60. <if test="remarks != null and remarks != ''">
  61. AND remarks = #{remarks}
  62. </if>
  63. <if test="flgValid != null">
  64. AND flg_valid = #{flgValid}
  65. </if>
  66. <if test="cpId != null">
  67. AND cp_id = #{cpId}
  68. </if>
  69. <if test="opCreateTime != null">
  70. AND op_create_time = #{opCreateTime}
  71. </if>
  72. <if test="opCreateUserId != null and opCreateUserId != ''">
  73. AND op_create_user_id = #{opCreateUserId}
  74. </if>
  75. <if test="opUpdateTime != null">
  76. AND op_update_time = #{opUpdateTime}
  77. </if>
  78. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  79. AND op_update_user_id = #{opUpdateUserId}
  80. </if>
  81. <if test="opAppCode != null and opAppCode != ''">
  82. AND op_app_code = #{opAppCode}
  83. </if>
  84. <if test="opTimestamp != null">
  85. AND op_timestamp = #{opTimestamp}
  86. </if>
  87. <if test="opDbUser != null and opDbUser != ''">
  88. AND op_db_user = #{opDbUser}
  89. </if>
  90. <if test="flgValidList != null and flgValidList.size()>0">
  91. AND flg_valid =
  92. any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  93. </if>
  94. <if test="searchText != null">
  95. AND (unit_code like concat('%', my_ex.likequery(#{searchText}) , '%')
  96. OR unit_name like concat('%', my_ex.likequery(#{searchText}) , '%')
  97. OR remarks like concat('%', my_ex.likequery(#{searchText}) , '%')
  98. )
  99. </if>
  100. </where>
  101. </sql>
  102. <sql id="idsForeach">
  103. <!-- 根据主键unitId批量操作 -->
  104. WHERE unit_id in
  105. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  106. #{item}
  107. </foreach>
  108. </sql>
  109. <!-- 查询表t_mst_unit,(条件查询+分页)列表 -->
  110. <select id="selectByCond" resultMap="BaseResultMap">
  111. SELECT
  112. <include refid="Base_Column_List"/>
  113. FROM dkic_b.t_mst_unit
  114. <include refid="Condition"/>
  115. order by display_no asc
  116. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  117. limit #{end} offset #{start}
  118. </if>
  119. </select>
  120. <!-- 查询表t_mst_unit,(条件查询)个数 -->
  121. <select id="countByCond" resultType="Long">
  122. SELECT
  123. count(1)
  124. FROM dkic_b.t_mst_unit
  125. <include refid="Condition"/>
  126. </select>
  127. <!-- 根据主键查询表t_mst_unit的一行数据 -->
  128. <select id="selectById" resultMap="BaseResultMap">
  129. SELECT
  130. <include refid="Base_Column_List"/>
  131. FROM dkic_b.t_mst_unit
  132. WHERE unit_id = #{id}::uuid
  133. </select>
  134. <!-- 根据主键锁定表t_mst_unit的一行数据 -->
  135. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  136. SELECT
  137. <include refid="Base_Column_List"/>
  138. FROM dkic_b.t_mst_unit
  139. WHERE unit_id = #{unitId}
  140. for update
  141. </select>
  142. <!-- 根据主键锁定表t_mst_unit的多行数据 -->
  143. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  144. SELECT
  145. <include refid="Base_Column_List"/>
  146. FROM dkic_b.t_mst_unit
  147. <include refid="idsForeach"/>
  148. for update
  149. </select>
  150. <insert id="insertBatch">
  151. insert into dkic_b.t_mst_unit
  152. (
  153. <trim suffixOverrides=",">
  154. unit_code,
  155. unit_name,
  156. decimal_places,
  157. display_no,
  158. remarks,
  159. cp_id,
  160. op_app_code,
  161. </trim>
  162. )
  163. values
  164. <foreach collection="list" index="index" item="item" separator=",">
  165. (
  166. <trim suffixOverrides=",">
  167. #{item.unitCode},
  168. #{item.unitName},
  169. #{item.decimalPlaces},
  170. #{item.displayNo},
  171. #{item.remarks},
  172. #{item.cpId},
  173. #{item.opAppCode},
  174. </trim>
  175. )
  176. </foreach>
  177. </insert>
  178. <!-- 校验名称不重复 -->
  179. <select id="checkNameDuplicated" resultType="java.lang.Long">
  180. SELECT COUNT(unit_id)
  181. FROM dkic_b.t_mst_unit
  182. WHERE
  183. cp_id = #{cpId}
  184. AND flg_valid = TRUE
  185. <!-- 通过判断id是否存在判断为新增操作还是修改操作 -->
  186. <if test="unitId != null and unitId != ''">
  187. AND unit_id != #{unitId}::uuid
  188. </if>
  189. <if test="unitName != null and unitName != ''">
  190. AND unit_name = #{unitName}
  191. </if>
  192. </select>
  193. <!-- 根据名称查ID -->
  194. <select id="selectByUuId" resultMap="BaseResultMapResponse">
  195. SELECT unit_id
  196. FROM dkic_b.t_mst_unit
  197. WHERE
  198. cp_id = #{cpId}
  199. AND flg_valid = TRUE
  200. <if test="unitName != null and unitName != ''">
  201. AND unit_name = #{unitName}
  202. </if>
  203. </select>
  204. </mapper>