SysDeptMapper.xml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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.ruoyi.project.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,
  25. d.parent_id,
  26. d.ancestors,
  27. d.dept_name,
  28. d.order_num,
  29. d.leader,
  30. d.phone,
  31. d.email,
  32. d.status,
  33. d.del_flag,
  34. d.create_by,
  35. d.create_time
  36. from sys_dept d
  37. </sql>
  38. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  39. <include refid="selectDeptVo"/>
  40. where d.del_flag = '0'
  41. <if test="parentId != null and parentId != 0">
  42. AND parent_id = #{parentId}
  43. </if>
  44. <if test="deptName != null and deptName != ''">
  45. AND dept_name like concat(concat('%',#{deptName}),'%')
  46. </if>
  47. <if test="status != null and status != ''">
  48. AND status = #{status}
  49. </if>
  50. <!-- 数据范围过滤 -->
  51. ${params.dataScope}
  52. order by d.parent_id, d.order_num
  53. </select>
  54. <select id="selectAllDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  55. <include refid="selectDeptVo"/>
  56. where d.del_flag = '0'
  57. <if test="parentId != null and parentId != 0">
  58. AND parent_id = #{parentId}
  59. </if>
  60. <if test="deptName != null and deptName != ''">
  61. AND dept_name like concat(concat('%',#{deptName}),'%')
  62. </if>
  63. <if test="status != null and status != ''">
  64. AND status = #{status}
  65. </if>
  66. order by d.parent_id, d.order_num
  67. </select>
  68. <select id="selectDeptListByRoleId" resultType="Integer">
  69. select d.dept_id
  70. from sys_dept d
  71. left join sys_role_dept rd on d.dept_id = rd.dept_id
  72. where rd.role_id = #{roleId}
  73. <if test="deptCheckStrictly">
  74. and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id =
  75. rd.dept_id and rd.role_id = #{roleId})
  76. </if>
  77. order by d.parent_id, d.order_num
  78. </select>
  79. <select id="selectDeptListByUserId" resultType="Integer">
  80. select d.dept_id
  81. from sys_dept d
  82. left join sys_user_dept rd on d.dept_id = rd.dept_id
  83. where rd.user_id = #{userId}
  84. <if test="deptCheckStrictly">
  85. and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_user_dept rd on d.dept_id =
  86. rd.dept_id and rd.user_id = #{userId})
  87. </if>
  88. order by d.parent_id, d.order_num
  89. </select>
  90. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  91. <include refid="selectDeptVo"/>
  92. where dept_id = #{deptId}
  93. </select>
  94. <select id="selectDeptByName" parameterType="String" resultMap="SysDeptResult">
  95. <include refid="selectDeptVo"/>
  96. where dept_name = #{deptName}
  97. </select>
  98. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  99. select count(1)
  100. from sys_user
  101. where dept_id = #{deptId}
  102. and del_flag = '0'
  103. </select>
  104. <select id="hasChildByDeptId" parameterType="Long" resultType="int">
  105. select count(1)
  106. from sys_dept
  107. where del_flag = '0'
  108. and parent_id = #{deptId}
  109. and rownum <![CDATA[ <= ]]> 1
  110. </select>
  111. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  112. select *
  113. from sys_dept
  114. where FIND_IN_SET(#{deptId}, ancestors) <![CDATA[ <> ]]> 0
  115. </select>
  116. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  117. select count(*)
  118. from sys_dept
  119. where status = 0
  120. and del_flag = '0'
  121. and FIND_IN_SET(#{deptId}, ancestors)
  122. </select>
  123. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  124. <include refid="selectDeptVo"/>
  125. where dept_name=#{deptName} and parent_id = #{parentId} and rownum <![CDATA[ <= ]]> 1
  126. </select>
  127. <insert id="insertDept" parameterType="SysDept">
  128. <selectKey keyProperty="deptId" order="BEFORE" resultType="Long">
  129. select seq_sys_dept.nextval as deptId from DUAL
  130. </selectKey>
  131. insert into sys_dept(
  132. <if test="deptId != null and deptId != 0">dept_id,</if>
  133. <if test="parentId != null and parentId != 0">parent_id,</if>
  134. <if test="deptName != null and deptName != ''">dept_name,</if>
  135. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  136. <if test="orderNum != null and orderNum != ''">order_num,</if>
  137. <if test="leader != null and leader != ''">leader,</if>
  138. <if test="phone != null and phone != ''">phone,</if>
  139. <if test="email != null and email != ''">email,</if>
  140. <if test="status != null">status,</if>
  141. <if test="createBy != null and createBy != ''">create_by,</if>
  142. create_time
  143. )values(
  144. <if test="deptId != null and deptId != 0">#{deptId},</if>
  145. <if test="parentId != null and parentId != 0">#{parentId},</if>
  146. <if test="deptName != null and deptName != ''">#{deptName},</if>
  147. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  148. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  149. <if test="leader != null and leader != ''">#{leader},</if>
  150. <if test="phone != null and phone != ''">#{phone},</if>
  151. <if test="email != null and email != ''">#{email},</if>
  152. <if test="status != null">#{status},</if>
  153. <if test="createBy != null and createBy != ''">#{createBy},</if>
  154. sysdate
  155. )
  156. </insert>
  157. <delete id="delCbs">
  158. DELETE
  159. FROM SYS_USER_DEPT
  160. where DEPT_ID in (SELECT d.DEPT_ID
  161. from SYS_DEPT d
  162. LEFT JOIN SYS_DEPT d2 on d2.DEPT_ID = d.PARENT_ID
  163. where d2.DEPT_NAME = '承包商');
  164. </delete>
  165. <insert id="insertCbs" parameterType="SysDept">
  166. INSERT into SYS_USER_DEPT (USER_ID, DEPT_ID) SELECT u.USER_ID, #{deptId} from SYS_USER_DEPT u where u.DEPT_ID in (SELECT d3.DEPT_ID from SYS_DEPT d3 where d3.DEPT_NAME = '承包商')
  167. </insert>
  168. <update id="updateDept" parameterType="SysDept">
  169. update sys_dept
  170. <set>
  171. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  172. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  173. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  174. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  175. <if test="leader != null">leader = #{leader},</if>
  176. <if test="phone != null">phone = #{phone},</if>
  177. <if test="email != null">email = #{email},</if>
  178. <if test="status != null and status != ''">status = #{status},</if>
  179. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  180. update_time = sysdate
  181. </set>
  182. where dept_id = #{deptId}
  183. </update>
  184. <update id="updateDeptChildren" parameterType="java.util.List">
  185. update sys_dept set ancestors =
  186. <foreach collection="depts" item="item" index="index"
  187. separator=" " open="case dept_id" close="end">
  188. when #{item.deptId} then #{item.ancestors}
  189. </foreach>
  190. where dept_id in
  191. <foreach collection="depts" item="item" index="index"
  192. separator="," open="(" close=")">
  193. #{item.deptId}
  194. </foreach>
  195. </update>
  196. <update id="updateDeptStatus" parameterType="SysDept">
  197. update sys_dept
  198. <set>
  199. <if test="status != null and status != ''">status = #{status},</if>
  200. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  201. update_time = sysdate
  202. </set>
  203. where dept_id in (${ancestors})
  204. </update>
  205. <delete id="deleteDeptById" parameterType="Long">
  206. update sys_dept
  207. set del_flag = '2'
  208. where dept_id = #{deptId}
  209. </delete>
  210. </mapper>