SysDeptMapper.xml 7.0 KB

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