SysDeptMapper.xml 7.8 KB

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