SysDeptMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zd.system.mapper.SysDeptMapper">
  6. <resultMap type="com.zd.model.entity.SysDept" id="SysDeptResult">
  7. <id property="deptId" column="dept_id"/>
  8. <result property="parentId" column="parent_id"/>
  9. <result property="ancestors" column="ancestors"/>
  10. <result property="deptName" column="dept_name"/>
  11. <result property="deptNum" column="dept_num"/>
  12. <result property="orderNum" column="order_num"/>
  13. <result property="leader" column="leader"/>
  14. <result property="phone" column="phone"/>
  15. <result property="email" column="email"/>
  16. <result property="status" column="status"/>
  17. <result property="delFlag" column="del_flag"/>
  18. <result property="parentName" column="parent_name"/>
  19. <result property="createBy" column="create_by"/>
  20. <result property="createTime" column="create_time"/>
  21. <result property="updateBy" column="update_by"/>
  22. <result property="updateTime" column="update_time"/>
  23. <result property="deptImg" column="dept_img"/>
  24. <result property="deptSign" column="dept_sign"/>
  25. <result property="isLower" column="is_lower"/>
  26. </resultMap>
  27. <sql id="selectDeptVo">
  28. select d.dept_id,
  29. d.parent_id,
  30. d.ancestors,
  31. d.dept_name,
  32. d.dept_num,
  33. d.order_num,
  34. d.leader,
  35. d.phone,
  36. d.email,
  37. d.status,
  38. d.del_flag,
  39. d.create_by,
  40. d.create_time,
  41. d.dept_img,
  42. d.dept_sign,
  43. d.is_lower
  44. from sys_dept d
  45. </sql>
  46. <select id="selectDeptList" parameterType="com.zd.model.entity.SysDept" resultMap="SysDeptResult">
  47. <include refid="selectDeptVo"/>
  48. where d.del_flag = '0'
  49. <if test="parentId != null and parentId != 0">
  50. AND parent_id = #{parentId}
  51. </if>
  52. <if test="deptName != null and deptName != ''">
  53. AND dept_name like concat('%', #{deptName}, '%')
  54. </if>
  55. <if test="status != null and status != ''">
  56. AND status = #{status}
  57. </if>
  58. <!-- 数据范围过滤 -->
  59. ${params.dataScope}
  60. order by d.parent_id, d.order_num
  61. </select>
  62. <select id="treeselectByUser" parameterType="com.zd.model.entity.SysDept" resultMap="SysDeptResult">
  63. <include refid="selectDeptVo"/>
  64. where d.del_flag = '0'
  65. <if test="parentId != null and parentId != 0">
  66. AND find_in_set(#{parentId}, ancestors)
  67. </if>
  68. <if test="deptName != null and deptName != ''">
  69. AND dept_name like concat('%', #{deptName}, '%')
  70. </if>
  71. <if test="status != null and status != ''">
  72. AND status = #{status}
  73. </if>
  74. <!-- 数据范围过滤 -->
  75. ${params.dataScope}
  76. order by d.parent_id, d.order_num
  77. </select>
  78. <select id="selectDeptListByRoleId" resultType="java.lang.Integer">
  79. select d.dept_id
  80. from sys_dept d
  81. left join sys_role_dept rd on d.dept_id = rd.dept_id
  82. where rd.role_id = #{roleId}
  83. <if test="deptCheckStrictly">
  84. and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id =
  85. rd.dept_id and rd.role_id = #{roleId})
  86. </if>
  87. order by d.parent_id, d.order_num
  88. </select>
  89. <select id="selectDeptById" resultMap="SysDeptResult">
  90. <include refid="selectDeptVo"/>
  91. where dept_id = #{deptId}
  92. </select>
  93. <select id="checkDeptExistUser" resultType="int">
  94. select count(1)
  95. from sys_user
  96. where dept_id = #{deptId}
  97. and del_flag = '0'
  98. </select>
  99. <select id="hasChildByDeptId" resultType="int">
  100. select count(1)
  101. from sys_dept
  102. where del_flag = '0'
  103. and parent_id = #{deptId}
  104. </select>
  105. <select id="selectChildrenDeptById" resultMap="SysDeptResult">
  106. select *
  107. from sys_dept
  108. where find_in_set(#{deptId}, ancestors)
  109. </select>
  110. <select id="selectNormalChildrenDeptById" resultType="java.lang.Integer">
  111. select count(*)
  112. from sys_dept
  113. where status = 0
  114. and del_flag = '0'
  115. and find_in_set(#{deptId}, ancestors)
  116. </select>
  117. <select id="selectDownDeptListById" resultMap="SysDeptResult">
  118. SELECT *
  119. FROM sys_dept WHERE STATUS = 0 AND del_flag = '0' AND parent_id = #{parentId} order by order_num asc
  120. </select>
  121. <select id="selectMaxNumChildrenDeptById" resultType="java.lang.Integer">
  122. SELECT CASE WHEN MAX(order_num) IS NOT NULL THEN MAX(order_num)+1 ELSE 0 END
  123. FROM sys_dept WHERE STATUS = 0 AND del_flag = '0' AND parent_id = #{parentId}
  124. </select>
  125. <select id="selectChildrenDeptListById" resultMap="SysDeptResult">
  126. SELECT dt.* FROM sys_dept dt WHERE dt.STATUS = 0 AND dt.del_flag = '0'
  127. AND FIND_IN_SET(#{deptId}, dt.ancestors) ORDER BY dt.order_num ASC
  128. </select>
  129. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  130. <include refid="selectDeptVo"/>
  131. where dept_name=#{deptName}
  132. and parent_id = #{parentId}
  133. <if test="delFlag != null and delFlag != ''">
  134. AND del_flag = #{delFlag}
  135. </if>
  136. limit 1
  137. </select>
  138. <select id="getDeptNameUnique" resultMap="SysDeptResult">
  139. <include refid="selectDeptVo"/>
  140. where dept_name=#{deptName} limit 1
  141. </select>
  142. <select id="selectLayoutOrderByUserId" resultType="java.util.Map">
  143. select dept_id deptId,
  144. dept_class_name name,
  145. case
  146. when parent_id = (select dept_id from sys_user where user_id = #{userId})
  147. then 0
  148. else data_sort end as dataSort
  149. from sys_dept
  150. where dept_class_name is not null
  151. ORDER BY dataSort
  152. </select>
  153. <select id="selectAllParentId" resultType="java.lang.String">
  154. select group_concat(ancestors) from sys_dept where dept_id in
  155. <foreach item="id" collection="ids" open="(" separator="," close=")">
  156. #{id}
  157. </foreach>
  158. </select>
  159. <select id="selectBuildsList" resultMap="SysDeptResult">
  160. <include refid="selectDeptVo"/>
  161. where d.del_flag = '0' and
  162. d.parent_id in (select dept_id from sys_dept where parent_id = 100)
  163. ${params.dataScope}
  164. </select>
  165. <select id="selectLevelByUserId" resultType="java.lang.Integer">
  166. select count(1) from sys_dept where dept_id = (select dept_id from sys_user where user_id = #{userId} and user_type = '11' limit 1) and parent_id = 0
  167. </select>
  168. <select id="queryDeptSignByUserId" resultType="java.lang.String">
  169. select
  170. case when a.dept_sign is not null then a.dept_sign
  171. when (select dept_sign from sys_dept where dept_id = a.parent_id and is_lower = 1) is not null
  172. then (select dept_sign from sys_dept where dept_id = a.parent_id and is_lower = 1)
  173. else (select dept_sign from sys_dept where dept_id = replace(replace(a.ancestors, concat(',', a.parent_id), ''), '0,', '') and is_lower = 1)
  174. end
  175. from (
  176. select dept_sign, dept_id, parent_id, ancestors
  177. from sys_dept
  178. where dept_id = (select dept_id from sys_user where user_id = #{userId})
  179. )a
  180. </select>
  181. <select id="selectDeptListByCollege" resultType="com.zd.model.entity.SysDept">
  182. <include refid="selectDeptVo"/>
  183. where d.del_flag = '0' AND parent_id in (select dept_id from sys_dept where parent_id = 0)
  184. <if test="deptName != null and deptName != ''">
  185. AND dept_name like concat('%', #{deptName}, '%')
  186. </if>
  187. <if test="status != null and status != ''">
  188. AND status = #{status}
  189. </if>
  190. <!-- 数据范围过滤 -->
  191. ${params.dataScope}
  192. order by d.parent_id, d.order_num
  193. </select>
  194. <insert id="insertDept" parameterType="com.zd.model.entity.SysDept">
  195. insert into sys_dept(
  196. <if test="deptId != null and deptId != 0">dept_id,</if>
  197. <if test="parentId != null and parentId != 0">parent_id,</if>
  198. <if test="deptNum != null and deptNum != ''">dept_num,</if>
  199. <if test="deptName != null and deptName != ''">dept_name,</if>
  200. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  201. <if test="orderNum != null and orderNum != ''">order_num,</if>
  202. <if test="leader != null and leader != ''">leader,</if>
  203. <if test="phone != null and phone != ''">phone,</if>
  204. <if test="email != null and email != ''">email,</if>
  205. <if test="status != null">status,</if>
  206. <if test="createBy != null and createBy != ''">create_by,</if>
  207. create_time
  208. )values(
  209. <if test="deptId != null and deptId != 0">#{deptId},</if>
  210. <if test="parentId != null and parentId != 0">#{parentId},</if>
  211. <if test="deptNum != null and deptNum != ''">#{deptNum},</if>
  212. <if test="deptName != null and deptName != ''">#{deptName},</if>
  213. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  214. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  215. <if test="leader != null and leader != ''">#{leader},</if>
  216. <if test="phone != null and phone != ''">#{phone},</if>
  217. <if test="email != null and email != ''">#{email},</if>
  218. <if test="status != null">#{status},</if>
  219. <if test="createBy != null and createBy != ''">#{createBy},</if>
  220. sysdate()
  221. )
  222. </insert>
  223. <update id="updateDept" parameterType="com.zd.model.entity.SysDept">
  224. update sys_dept
  225. <set>
  226. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  227. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  228. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  229. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  230. <if test="leader != null">leader = #{leader},</if>
  231. <if test="phone != null">phone = #{phone},</if>
  232. <if test="email != null">email = #{email},</if>
  233. <if test="status != null and status != ''">status = #{status},</if>
  234. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  235. <if test="deptSign != null and deptSign != ''">dept_sign = #{deptSign},</if>
  236. <if test="isLower != null">is_lower = #{isLower},</if>
  237. update_time = sysdate()
  238. </set>
  239. where dept_id = #{deptId}
  240. </update>
  241. <update id="updateDeptChildren" parameterType="java.util.List">
  242. update sys_dept set ancestors =
  243. <foreach collection="depts" item="item" index="index"
  244. separator=" " open="case dept_id" close="end">
  245. when #{item.deptId} then #{item.ancestors}
  246. </foreach>
  247. where dept_id in
  248. <foreach collection="depts" item="item" index="index"
  249. separator="," open="(" close=")">
  250. #{item.deptId}
  251. </foreach>
  252. </update>
  253. <update id="updateDeptStatusNormal" >
  254. update sys_dept set status = '0' where dept_id in
  255. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  256. #{deptId}
  257. </foreach>
  258. </update>
  259. <delete id="deleteDeptById" >
  260. update sys_dept
  261. set del_flag = '2'
  262. where dept_id = #{deptId}
  263. </delete>
  264. </mapper>