DictMapper.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.huaxu.dao.DictMapper">
  4. <!-- 结果集 -->
  5. <resultMap type="com.huaxu.entity.Dict" id="DictMap">
  6. <result property="id" column="ID" jdbcType="INTEGER"/>
  7. <result property="dictName" column="DICT_NAME" jdbcType="VARCHAR"/>
  8. <result property="dictCode" column="DICT_CODE" jdbcType="VARCHAR"/>
  9. <result property="dictValue" column="DICT_VALUE" jdbcType="VARCHAR"/>
  10. <result property="parentDictId" column="PARENT_DICT_ID" jdbcType="INTEGER"/>
  11. <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
  12. <result property="status" column="STATUS" jdbcType="INTEGER"/>
  13. <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
  14. <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
  15. <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
  16. <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
  17. </resultMap>
  18. <!-- 二层结果集 -->
  19. <resultMap type="com.huaxu.dto.DictDto" id="DictDtoMap">
  20. <result property="parentDictId" column="PARENT_DICT_ID" jdbcType="INTEGER"/>
  21. <result property="parentDictName" column="DICT_NAME" jdbcType="VARCHAR"/>
  22. <result property="parentDictCode" column="PARENT_DICT_CODE" jdbcType="VARCHAR"/>
  23. <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
  24. <collection property="dictList" ofType="java.util.Map" javaType="list">
  25. <result property="id" column="ID" jdbcType="INTEGER"/>
  26. <result property="dictCode" column="DICT_CODE" jdbcType="VARCHAR"/>
  27. <result property="dictValue" column="DICT_VALUE" jdbcType="VARCHAR"/>
  28. </collection>
  29. </resultMap>
  30. <!-- 基本字段 -->
  31. <sql id="Base_Column_List">
  32. ID,DICT_NAME,DICT_CODE,DICT_VALUE, PARENT_DICT_ID, REMARK, STATUS, DATE_CREATE,CREATE_BY,DATE_UPDATE,UPDATE_BY</sql>
  33. <!-- 查询单个 -->
  34. <select id="selectById" resultMap="DictMap">
  35. select
  36. <include refid="Base_Column_List"/>
  37. from uims_dict
  38. where ID = #{id}
  39. </select>
  40. <!-- 查询全部 -->
  41. <select id="selectAll" resultMap="DictMap">
  42. select
  43. <include refid="Base_Column_List"/>
  44. from uims_dict
  45. </select>
  46. <!--通过实体作为筛选条件查询-->
  47. <select id="selectList" resultMap="DictMap">
  48. select
  49. <include refid="Base_Column_List"/>
  50. from uims_dict
  51. <where>
  52. <if test="id != null">
  53. and ID = #{id}
  54. </if>
  55. <if test="dictName != null and dictName != ''">
  56. and DICT_NAME = #{dictName}
  57. </if>
  58. <if test="dictCode != null and dictCode != ''">
  59. and (DICT_CODE LIKE CONCAT('%',#{dictCode},'%')
  60. or DICT_VALUE LIKE CONCAT('%',#{dictCode},'%'))
  61. </if>
  62. <if test="parentDictId != null and parentDictId != ''">
  63. and PARENT_DICT_ID = #{parentDictId}
  64. </if>
  65. <if test="parentDictCode != null and parentDictCode != ''">
  66. and PARENT_DICT_ID in (select ID from uims_dict where DICT_CODE=#{parentDictCode})
  67. </if>
  68. and STATUS =1
  69. and DICT_CODE!='-999'
  70. </where>
  71. order by DATE_CREATE
  72. </select>
  73. <!-- 新增所有列 -->
  74. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  75. insert into uims_dict(ID,DICT_NAME,DICT_CODE,DICT_VALUE,PARENT_DICT_ID, REMARK, STATUS, CREATE_BY,DATE_CREATE,UPDATE_BY,DATE_UPDATE)
  76. values ( #{id}, #{dictName}, #{dictCode}, #{dictValue}, #{parentDictId}, #{remark}, 1, #{createBy}, #{dateCreate}, #{updateBy}, #{dateUpdate})
  77. </insert>
  78. <!-- 批量新增 -->
  79. <insert id="batchInsert">
  80. insert into uims_dict(ID,DICT_NAME,DICT_CODE,DICT_VALUE,PARENT_DICT_ID, REMARK, STATUS, CREATE_BY,DATE_CREATE,UPDATE_BY,DATE_UPDATE)
  81. values
  82. <foreach collection="dicts" item="item" index="index" separator=",">
  83. (
  84. #{item.id}, #{item.dictName}, #{item.dictCode}, #{item.dictValue}, #{item.parentDictId}, #{item.remark}, 1,
  85. #{item.createBy}, #{item.dateCreate}, #{item.updateBy}, #{item.dateUpdate})
  86. </foreach>
  87. </insert>
  88. <!-- 通过主键修改数据 -->
  89. <update id="update">
  90. update uims.uims_dict
  91. <set>
  92. <if test="dictName != null and dictName != ''">
  93. DICT_NAME = #{dictName},
  94. </if>
  95. <if test="dictCode != null and dictCode != ''">
  96. DICT_CODE = #{dictCode},
  97. </if>
  98. <if test="dictValue != null and dictValue != ''">
  99. DICT_VALUE = #{dictValue},
  100. </if>
  101. <if test="parentDictId != null and parentDictId != ''">
  102. PARENT_DICT_ID = #{parentDictId},
  103. </if>
  104. <if test="remark != null and remark != ''">
  105. REMARK = #{remark},
  106. </if>
  107. <if test="status != null">
  108. STATUS = #{status},
  109. </if>
  110. <if test="createBy != null and createBy != ''">
  111. CREATE_BY = #{createBy},
  112. </if>
  113. <if test="dateCreate != null">
  114. DATE_CREATE = #{dateCreate},
  115. </if>
  116. <if test="updateBy != null and updateBy != ''">
  117. UPDATE_BY = #{updateBy},
  118. </if>
  119. <if test="dateUpdate != null">
  120. DATE_UPDATE = #{dateUpdate},
  121. </if>
  122. </set>
  123. where ID = #{id}
  124. </update>
  125. <!--通过主键删除-物理删除-->
  126. <!--<delete id="deleteById" parameterType="java.util.List">
  127. delete from uims_dict where ID IN
  128. <foreach item="item" index="index" collection="ids" open="("
  129. separator="," close=")">
  130. #{item}
  131. </foreach>
  132. or PARENT_DICT_ID in
  133. <foreach item="item" index="index" collection="ids" open="("
  134. separator="," close=")">
  135. #{item}
  136. </foreach>
  137. </delete>-->
  138. <!--通过主键删除-逻辑删除-->
  139. <update id="deleteById" parameterType="java.util.List">
  140. update uims.uims_dict
  141. set STATUS=0
  142. where ID in
  143. <foreach item="item" index="index" collection="ids" open="("
  144. separator="," close=")">
  145. #{item}
  146. </foreach>
  147. or PARENT_DICT_ID in
  148. <foreach item="item" index="index" collection="ids" open="("
  149. separator="," close=")">
  150. #{item}
  151. </foreach>
  152. </update>
  153. <!-- 总数 -->
  154. <select id="count" resultType="int">
  155. select count(*) from uims_dict
  156. </select>
  157. <select id="selectPage" resultMap="DictMap">
  158. select
  159. <include refid="Base_Column_List"/>
  160. from uims_dict
  161. <where>
  162. <if test="dict.id != null">
  163. and ID = #{dict.id}
  164. </if>
  165. <if test="dict.parentDictId == null and dict.dictCode != null and dict.dictCode != ''">
  166. and (DICT_NAME LIKE CONCAT('%',#{dict.dictCode},'%')
  167. or DICT_CODE LIKE CONCAT('%',#{dict.dictCode},'%'))
  168. </if>
  169. <if test="dict.parentDictId != null and dict.dictCode != null and dict.dictCode != ''">
  170. and (DICT_VALUE LIKE CONCAT('%',#{dict.dictCode},'%')
  171. or DICT_CODE LIKE CONCAT('%',#{dict.dictCode},'%'))
  172. </if>
  173. <if test="dict.parentDictId != null ">
  174. and PARENT_DICT_ID = #{dict.parentDictId}
  175. </if>
  176. <if test="dict.parentDictId == null">
  177. and PARENT_DICT_ID IS NULL
  178. </if>
  179. and STATUS =1
  180. and DICT_CODE!='-999'
  181. </where>
  182. order by DATE_CREATE
  183. </select>
  184. <!-- 字典编码和父配置ID数量 -->
  185. <select id="countByCodePid" resultType="int">
  186. select count(*) from uims_dict
  187. <where>
  188. <if test="dictCode != null and dictCode != ''">
  189. and DICT_CODE = #{dictCode}
  190. </if>
  191. <if test="parentDictId != null and parentDictId != ''">
  192. and PARENT_DICT_ID = #{parentDictId}
  193. </if>
  194. <if test="parentDictId == null">
  195. and PARENT_DICT_ID IS NULL
  196. </if>
  197. and STATUS =1
  198. </where>
  199. </select>
  200. <!--查询父列表-->
  201. <select id="selectParentList" resultMap="DictDtoMap">
  202. select t2.parent_dict_id,t1.dict_code parent_dict_code,t1.dict_name,t1.remark,t2.id,t2.dict_code,t2.dict_value
  203. from uims_dict t1
  204. inner join uims_dict t2 on t1.id=t2.parent_dict_id
  205. where t1.`status`=1 and t2.`status`=1
  206. <if test="remark != null and remark != ''">
  207. and t1.remark = #{remark}
  208. </if>
  209. order by t1.date_create,t2.date_create
  210. </select>
  211. </mapper>