SysDeptMapper.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.xingxi.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="deptType" column="deptType" />
  12. <result property="orderNum" column="order_num" />
  13. <result property="leader" column="leader" />
  14. <result property="phone" column="phone" />
  15. <result property="email" column="email" />
  16. <result property="status" column="status" />
  17. <result property="delFlag" column="del_flag" />
  18. <result property="parentName" column="parent_name" />
  19. <result property="createUser" column="create_by" />
  20. <result property="createTime" column="create_time" />
  21. <result property="updateUser" column="update_by" />
  22. <result property="updateTime" column="update_time" />
  23. </resultMap>
  24. <sql id="selectDeptVo">
  25. select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.deptType, 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="selectRoleDeptTree" parameterType="Long" resultType="String">
  29. select concat(d.dept_id, d.dept_name) as dept_name
  30. from sys_dept d
  31. left join sys_role_dept rd on d.dept_id = rd.dept_id
  32. where d.del_flag = '0' and rd.role_id = #{roleId}
  33. order by d.parent_id, d.order_num
  34. </select>
  35. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  36. <include refid="selectDeptVo"/>
  37. where d.del_flag = '0'
  38. <if test="deptId != null and deptId != 0">
  39. AND dept_id = #{deptId}
  40. </if>
  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="deptType != null and deptType != ''">
  48. AND deptType = #{deptType}
  49. </if>
  50. <if test="status != null and status != ''">
  51. AND status = #{status}
  52. </if>
  53. <!-- 数据范围过滤 -->
  54. ${params.dataScope}
  55. order by d.parent_id, d.order_num
  56. </select>
  57. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  58. select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
  59. </select>
  60. <select id="selectDeptCount" parameterType="SysDept" resultType="int">
  61. select count(1) from sys_dept
  62. where del_flag = '0'
  63. <if test="deptId != null and deptId != 0"> and dept_id = #{deptId} </if>
  64. <if test="parentId != null and parentId != 0"> and parent_id = #{parentId} </if>
  65. </select>
  66. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  67. <include refid="selectDeptVo"/>
  68. where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
  69. </select>
  70. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  71. select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.deptType, d.order_num, d.leader, d.phone, d.email, d.status,
  72. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  73. from sys_dept d
  74. where d.dept_id = #{deptId}
  75. </select>
  76. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  77. select * from sys_dept where find_in_set(#{deptId}, ancestors)
  78. </select>
  79. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  80. select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
  81. </select>
  82. <insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
  83. insert into sys_dept(
  84. <if test="deptId != null and deptId != 0">dept_id,</if>
  85. <if test="parentId != null and parentId != 0">parent_id,</if>
  86. <if test="deptName != null and deptName != ''">dept_name,</if>
  87. <if test="deptType != null and deptType != ''">deptType,</if>
  88. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  89. <if test="orderNum != null">order_num,</if>
  90. <if test="leader != null and leader != ''">leader,</if>
  91. <if test="phone != null and phone != ''">phone,</if>
  92. <if test="email != null and email != ''">email,</if>
  93. <if test="status != null">status,</if>
  94. <if test="createUser != null and createUser != ''">create_by,</if>
  95. create_time
  96. )values(
  97. <if test="deptId != null and deptId != 0">#{deptId},</if>
  98. <if test="parentId != null and parentId != 0">#{parentId},</if>
  99. <if test="deptName != null and deptName != ''">#{deptName},</if>
  100. <if test="deptType != null and deptType != ''">#{deptType},</if>
  101. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  102. <if test="orderNum != null">#{orderNum},</if>
  103. <if test="leader != null and leader != ''">#{leader},</if>
  104. <if test="phone != null and phone != ''">#{phone},</if>
  105. <if test="email != null and email != ''">#{email},</if>
  106. <if test="status != null">#{status},</if>
  107. <if test="createUser != null and createUser != ''">#{createUser},</if>
  108. sysdate()
  109. )
  110. </insert>
  111. <update id="updateDept" parameterType="SysDept">
  112. update sys_dept
  113. <set>
  114. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  115. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  116. <if test="deptType != null and deptType != ''">deptType = #{deptType},</if>
  117. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  118. <if test="orderNum != null">order_num = #{orderNum},</if>
  119. <if test="leader != null">leader = #{leader},</if>
  120. <if test="phone != null">phone = #{phone},</if>
  121. <if test="email != null">email = #{email},</if>
  122. <if test="status != null and status != ''">status = #{status},</if>
  123. <if test="updateUser != null and updateUser != ''">update_by = #{updateUser},</if>
  124. update_time = sysdate()
  125. </set>
  126. where dept_id = #{deptId}
  127. </update>
  128. <update id="updateDeptChildren" parameterType="java.util.List">
  129. update sys_dept set ancestors =
  130. <foreach collection="depts" item="item" index="index"
  131. separator=" " open="case dept_id" close="end">
  132. when #{item.deptId} then #{item.ancestors}
  133. </foreach>
  134. where dept_id in
  135. <foreach collection="depts" item="item" index="index"
  136. separator="," open="(" close=")">
  137. #{item.deptId}
  138. </foreach>
  139. </update>
  140. <delete id="deleteDeptById" parameterType="Long">
  141. update sys_dept set del_flag = '2' where dept_id = #{deptId}
  142. </delete>
  143. <update id="updateDeptStatusNormal" parameterType="Long">
  144. update sys_dept set status = '0' where dept_id in
  145. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  146. #{deptId}
  147. </foreach>
  148. </update>
  149. </mapper>