SysDeptMapper.xml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.doc.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. </resultMap>
  23. <sql id="selectDeptVo">
  24. select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
  25. d.del_flag, d.create_by, d.create_time from sys_dept d
  26. </sql>
  27. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  28. <include refid="selectDeptVo"/>
  29. where d.del_flag = '0'
  30. <if test="deptId != null and deptId != 0">
  31. AND dept_id = #{deptId}
  32. </if>
  33. <if test="parentId != null and parentId != 0">
  34. AND parent_id = #{parentId}
  35. </if>
  36. <if test="deptName != null and deptName != ''">
  37. AND dept_name like concat('%', #{deptName}, '%')
  38. </if>
  39. <if test="status != null and status != ''">
  40. AND status = #{status}
  41. </if>
  42. <!-- 数据范围过滤 -->
  43. ${params.dataScope}
  44. order by d.parent_id, d.order_num
  45. </select>
  46. <select id="selectDeptListByRoleId" resultType="Long">
  47. select d.dept_id
  48. from sys_dept d
  49. left join sys_role_dept rd on d.dept_id = rd.dept_id
  50. where rd.role_id = #{roleId}
  51. <if test="deptCheckStrictly">
  52. and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id =
  53. rd.dept_id and rd.role_id = #{roleId})
  54. </if>
  55. order by d.parent_id, d.order_num
  56. </select>
  57. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  58. select d.dept_id,
  59. d.parent_id,
  60. d.ancestors,
  61. d.dept_name,
  62. d.order_num,
  63. d.leader,
  64. d.phone,
  65. d.email,
  66. d.status,
  67. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  68. from sys_dept d
  69. where d.dept_id = #{deptId}
  70. </select>
  71. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  72. select count(1)
  73. from sys_user
  74. where dept_id = #{deptId}
  75. and del_flag = '0'
  76. </select>
  77. <select id="hasChildByDeptId" parameterType="Long" resultType="int">
  78. select count(1)
  79. from sys_dept
  80. where del_flag = '0'
  81. and parent_id = #{deptId} limit 1
  82. </select>
  83. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  84. select *
  85. from sys_dept
  86. where find_in_set(#{deptId}, ancestors)
  87. </select>
  88. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  89. select count(*)
  90. from sys_dept
  91. where status = 0
  92. and del_flag = '0'
  93. and find_in_set(#{deptId}, ancestors)
  94. </select>
  95. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  96. <include refid="selectDeptVo"/>
  97. where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
  98. </select>
  99. <insert id="insertDept" parameterType="SysDept">
  100. insert into sys_dept(
  101. <if test="deptId != null and deptId != 0">dept_id,</if>
  102. <if test="parentId != null and parentId != 0">parent_id,</if>
  103. <if test="deptName != null and deptName != ''">dept_name,</if>
  104. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  105. <if test="orderNum != null">order_num,</if>
  106. <if test="leader != null and leader != ''">leader,</if>
  107. <if test="phone != null and phone != ''">phone,</if>
  108. <if test="email != null and email != ''">email,</if>
  109. <if test="status != null">status,</if>
  110. <if test="createBy != null and createBy != ''">create_by,</if>
  111. create_time
  112. )values(
  113. <if test="deptId != null and deptId != 0">#{deptId},</if>
  114. <if test="parentId != null and parentId != 0">#{parentId},</if>
  115. <if test="deptName != null and deptName != ''">#{deptName},</if>
  116. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  117. <if test="orderNum != null">#{orderNum},</if>
  118. <if test="leader != null and leader != ''">#{leader},</if>
  119. <if test="phone != null and phone != ''">#{phone},</if>
  120. <if test="email != null and email != ''">#{email},</if>
  121. <if test="status != null">#{status},</if>
  122. <if test="createBy != null and createBy != ''">#{createBy},</if>
  123. sysdate()
  124. )
  125. </insert>
  126. <update id="updateDept" parameterType="SysDept">
  127. update sys_dept
  128. <set>
  129. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  130. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  131. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  132. <if test="orderNum != null">order_num = #{orderNum},</if>
  133. <if test="leader != null">leader = #{leader},</if>
  134. <if test="phone != null">phone = #{phone},</if>
  135. <if test="email != null">email = #{email},</if>
  136. <if test="status != null and status != ''">status = #{status},</if>
  137. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  138. update_time = sysdate()
  139. </set>
  140. where dept_id = #{deptId}
  141. </update>
  142. <update id="updateDeptChildren" parameterType="java.util.List">
  143. update sys_dept set ancestors =
  144. <foreach collection="depts" item="item" index="index"
  145. separator=" " open="case dept_id" close="end">
  146. when #{item.deptId} then #{item.ancestors}
  147. </foreach>
  148. where dept_id in
  149. <foreach collection="depts" item="item" index="index"
  150. separator="," open="(" close=")">
  151. #{item.deptId}
  152. </foreach>
  153. </update>
  154. <update id="updateDeptStatusNormal" parameterType="Long">
  155. update sys_dept set status = '0' where dept_id in
  156. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  157. #{deptId}
  158. </foreach>
  159. </update>
  160. <delete id="deleteDeptById" parameterType="Long">
  161. update sys_dept
  162. set del_flag = '2'
  163. where dept_id = #{deptId}
  164. </delete>
  165. </mapper>