SysDeptMapper.xml 7.4 KB

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