SysDeptMapper.xml 7.1 KB

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