SysDeptMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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.sundot.airport.system.mapper.SysDeptMapper">
  6. <resultMap type="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="orderNum" column="order_num"/>
  12. <result property="leader" column="leader"/>
  13. <result property="phone" column="phone"/>
  14. <result property="email" column="email"/>
  15. <result property="status" column="status"/>
  16. <result property="delFlag" column="del_flag"/>
  17. <result property="parentName" column="parent_name"/>
  18. <result property="createBy" column="create_by"/>
  19. <result property="createTime" column="create_time"/>
  20. <result property="updateBy" column="update_by"/>
  21. <result property="updateTime" column="update_time"/>
  22. <result property="deptType" column="dept_type"/>
  23. <result property="deptTypeDesc" column="dept_type_desc"/>
  24. </resultMap>
  25. <sql id="selectDeptVo">
  26. select d.dept_id,
  27. d.parent_id,
  28. d.ancestors,
  29. d.dept_name,
  30. d.order_num,
  31. d.leader,
  32. d.phone,
  33. d.email,
  34. d.status,
  35. d.del_flag,
  36. d.create_by,
  37. d.create_time,
  38. d.dept_type,
  39. d.dept_type_desc
  40. from sys_dept d
  41. </sql>
  42. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  43. <include refid="selectDeptVo"/>
  44. where d.del_flag = '0'
  45. <if test="deptId != null and deptId != 0">
  46. AND dept_id = #{deptId}
  47. </if>
  48. <if test="parentId != null and parentId != 0">
  49. AND parent_id = #{parentId}
  50. </if>
  51. <if test="deptName != null and deptName != ''">
  52. AND dept_name like concat('%', #{deptName}, '%')
  53. </if>
  54. <if test="status != null and status != ''">
  55. AND status = #{status}
  56. </if>
  57. <if test="deptType != null and deptType != ''">
  58. AND dept_type = #{deptType}
  59. </if>
  60. <if test="deptTypeDesc != null and deptTypeDesc != ''">
  61. AND dept_type_desc = #{deptTypeDesc}
  62. </if>
  63. <!-- 数据范围过滤 -->
  64. ${params.dataScope}
  65. order by d.parent_id, d.order_num
  66. </select>
  67. <select id="selectDeptListByRoleId" resultType="Long">
  68. select d.dept_id
  69. from sys_dept d
  70. left join sys_role_dept rd on d.dept_id = rd.dept_id
  71. where rd.role_id = #{roleId}
  72. <if test="deptCheckStrictly">
  73. and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id =
  74. rd.dept_id and rd.role_id = #{roleId})
  75. </if>
  76. order by d.parent_id, d.order_num
  77. </select>
  78. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  79. select d.dept_id,
  80. d.parent_id,
  81. d.ancestors,
  82. d.dept_name,
  83. d.order_num,
  84. d.leader,
  85. d.phone,
  86. d.email,
  87. d.status,
  88. d.dept_type,
  89. d.dept_type_desc,
  90. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  91. from sys_dept d
  92. where d.dept_id = #{deptId}
  93. </select>
  94. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  95. select count(1)
  96. from sys_user
  97. where dept_id = #{deptId}
  98. and del_flag = '0'
  99. </select>
  100. <select id="hasChildByDeptId" parameterType="Long" resultType="int">
  101. select count(1)
  102. from sys_dept
  103. where del_flag = '0'
  104. and parent_id = #{deptId} limit 1
  105. </select>
  106. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  107. select *
  108. from sys_dept
  109. where find_in_set(#{deptId}, ancestors)
  110. </select>
  111. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  112. select count(*)
  113. from sys_dept
  114. where status = 0
  115. and del_flag = '0'
  116. and find_in_set(#{deptId}, ancestors)
  117. </select>
  118. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  119. <include refid="selectDeptVo"/>
  120. where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
  121. </select>
  122. <select id="selectAllDept" parameterType="Long" resultMap="SysDeptResult">
  123. SELECT *
  124. FROM sys_dept
  125. WHERE FIND_IN_SET(dept_id, (select ancestors from sys_dept where dept_id = #{deptId}))
  126. and del_flag = '0'
  127. union all
  128. SELECT *
  129. FROM sys_dept
  130. WHERE dept_id = #{deptId}
  131. and del_flag = '0'
  132. </select>
  133. <insert id="insertDept" parameterType="SysDept">
  134. insert into sys_dept(
  135. <if test="deptId != null and deptId != 0">dept_id,</if>
  136. <if test="parentId != null and parentId != 0">parent_id,</if>
  137. <if test="deptName != null and deptName != ''">dept_name,</if>
  138. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  139. <if test="orderNum != null">order_num,</if>
  140. <if test="leader != null and leader != ''">leader,</if>
  141. <if test="phone != null and phone != ''">phone,</if>
  142. <if test="email != null and email != ''">email,</if>
  143. <if test="status != null">status,</if>
  144. <if test="createBy != null and createBy != ''">create_by,</if>
  145. <if test="deptType != null and deptType != ''">dept_type,</if>
  146. <if test="deptTypeDesc != null and deptTypeDesc != ''">dept_type_desc,</if>
  147. create_time
  148. )values(
  149. <if test="deptId != null and deptId != 0">#{deptId},</if>
  150. <if test="parentId != null and parentId != 0">#{parentId},</if>
  151. <if test="deptName != null and deptName != ''">#{deptName},</if>
  152. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  153. <if test="orderNum != null">#{orderNum},</if>
  154. <if test="leader != null and leader != ''">#{leader},</if>
  155. <if test="phone != null and phone != ''">#{phone},</if>
  156. <if test="email != null and email != ''">#{email},</if>
  157. <if test="status != null">#{status},</if>
  158. <if test="createBy != null and createBy != ''">#{createBy},</if>
  159. <if test="deptType != null and deptType != ''">#{deptType},</if>
  160. <if test="deptTypeDesc != null and deptTypeDesc != ''">#{deptTypeDesc},</if>
  161. sysdate()
  162. )
  163. </insert>
  164. <update id="updateDept" parameterType="SysDept">
  165. update sys_dept
  166. <set>
  167. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  168. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  169. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  170. <if test="orderNum != null">order_num = #{orderNum},</if>
  171. <if test="leader != null">leader = #{leader},</if>
  172. <if test="phone != null">phone = #{phone},</if>
  173. <if test="email != null">email = #{email},</if>
  174. <if test="status != null and status != ''">status = #{status},</if>
  175. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  176. <if test="deptType != null and deptType != ''">dept_type = #{deptType},</if>
  177. <if test="deptTypeDesc != null and deptTypeDesc != ''">dept_type_desc = #{deptTypeDesc},</if>
  178. update_time = sysdate()
  179. </set>
  180. where dept_id = #{deptId}
  181. </update>
  182. <update id="updateDeptChildren" parameterType="java.util.List">
  183. update sys_dept set ancestors =
  184. <foreach collection="depts" item="item" index="index"
  185. separator=" " open="case dept_id" close="end">
  186. when #{item.deptId} then #{item.ancestors}
  187. </foreach>
  188. where dept_id in
  189. <foreach collection="depts" item="item" index="index"
  190. separator="," open="(" close=")">
  191. #{item.deptId}
  192. </foreach>
  193. </update>
  194. <update id="updateDeptStatusNormal" parameterType="Long">
  195. update sys_dept set status = '0' where dept_id in
  196. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  197. #{deptId}
  198. </foreach>
  199. </update>
  200. <delete id="deleteDeptById" parameterType="Long">
  201. update sys_dept
  202. set del_flag = '2'
  203. where dept_id = #{deptId}
  204. </delete>
  205. <select id="deptLeader" resultType="com.sundot.airport.common.core.domain.entity.SysUser">
  206. select su.*
  207. from sys_user su
  208. inner join sys_user_role sur on su.user_id = sur.user_id
  209. inner join sys_role sr on sr.role_id = sur.role_id
  210. where su.dept_id = #{deptId}
  211. and sr.role_key = #{roleType}
  212. </select>
  213. <select id="selectDeptInfo" parameterType="com.sundot.airport.common.core.domain.entity.SysDept"
  214. resultMap="SysDeptResult">
  215. SELECT *
  216. FROM sys_dept
  217. WHERE FIND_IN_SET(#{deptId}, ancestors)
  218. <if test="deptType != null and deptType != ''">and dept_type = #{deptType}</if>
  219. and del_flag = '0'
  220. union all
  221. SELECT *
  222. FROM sys_dept
  223. WHERE dept_id = #{deptId}
  224. and del_flag = '0'
  225. </select>
  226. <select id="selectDeptByIdList" resultMap="SysDeptResult">
  227. select d.dept_id,
  228. d.parent_id,
  229. d.ancestors,
  230. d.dept_name,
  231. d.order_num,
  232. d.leader,
  233. d.phone,
  234. d.email,
  235. d.status,
  236. d.dept_type,
  237. d.dept_type_desc,
  238. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  239. from sys_dept d
  240. where d.dept_id in
  241. <foreach collection="list" item="item" open="(" separator="," close=")">
  242. #{item}
  243. </foreach>
  244. </select>
  245. <select id="deptRole" resultType="com.sundot.airport.common.core.domain.entity.SysUser">
  246. select su.*
  247. from sys_user su
  248. inner join sys_user_role sur on su.user_id = sur.user_id
  249. inner join sys_role sr on sr.role_id = sur.role_id
  250. where su.dept_id = #{deptId}
  251. and sr.role_key in
  252. <foreach collection="list" item="item" open="(" separator="," close=")">
  253. #{item}
  254. </foreach>
  255. </select>
  256. </mapper>