SysDeptMapper.xml 7.7 KB

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