SysDeptMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.boman.system.mapper.SysDeptMapper">
  6. <resultMap type="com.boman.domain.SysDept" id="SysDeptResult">
  7. <id property="id" column="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="num" column="num" />
  19. <result property="createBy" column="create_by" />
  20. <result property="createTime" column="create_time" />
  21. <result property="updateBy" column="update_by" />
  22. <result property="updateTime" column="update_time" />
  23. </resultMap>
  24. <sql id="selectDeptVo">
  25. select d.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.boman.domain.SysDept" resultMap="SysDeptResult">
  29. <include refid="selectDeptVo"/>
  30. where d.del_flag = '0'
  31. <if test="listByParentId != null and listByParentId == false">
  32. AND (parent_id is null or parent_id = 0)
  33. </if>
  34. <if test="parentId != null and parentId != 0">
  35. AND parent_id = #{parentId}
  36. </if>
  37. <if test="deptName != null and deptName != ''">
  38. AND dept_name like concat('%', #{deptName}, '%')
  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="validateHasChirld" parameterType="java.util.List" resultMap="SysDeptResult">
  48. SELECT a.id as id, count(1) as num FROM sys_dept a LEFT JOIN sys_dept b on a.id = b.parent_id WHERE b.parent_id in
  49. <foreach collection="depts" item="dept" index="index" separator="," open="(" close=")">
  50. #{dept.id}
  51. </foreach>
  52. GROUP BY a.id
  53. </select>
  54. <select id="selectDeptListById" resultType="java.lang.Integer">
  55. select d.id
  56. from sys_dept d
  57. left join sys_role_dept rd on d.id = rd.role_id
  58. where rd.role_id = #{id}
  59. <if test="deptCheckStrictly">
  60. and d.id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.id = rd.role_id and rd.role_id = #{id})
  61. </if>
  62. order by d.parent_id, d.order_num
  63. </select>
  64. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  65. <include refid="selectDeptVo"/>
  66. where id = #{id}
  67. </select>
  68. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  69. select count(1) from sys_user where id = #{id} and del_flag = '0'
  70. </select>
  71. <select id="hasChildById" parameterType="Long" resultType="int">
  72. select count(1) from sys_dept
  73. where del_flag = '0' and parent_id = #{id}
  74. </select>
  75. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  76. select * from sys_dept where find_in_set(#{id}, ancestors)
  77. </select>
  78. <select id="getByParentId" resultMap="SysDeptResult">
  79. select * from sys_dept where parent_id = #{parentId}
  80. </select>
  81. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="java.lang.Integer">
  82. select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{id}, ancestors)
  83. </select>
  84. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  85. <include refid="selectDeptVo"/>
  86. where dept_name=#{deptName} and parent_id = #{parentId} and del_flag != 2 limit 1
  87. </select>
  88. <insert id="insertDept" parameterType="com.boman.domain.SysDept">
  89. insert into sys_dept(
  90. <if test="id != null and id != 0">id,</if>
  91. <if test="parentId != null and parentId != 0">parent_id,</if>
  92. <if test="deptName != null and deptName != ''">dept_name,</if>
  93. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  94. <if test="orderNum != null and orderNum != ''">order_num,</if>
  95. <if test="leader != null and leader != ''">leader,</if>
  96. <if test="phone != null and phone != ''">phone,</if>
  97. <if test="email != null and email != ''">email,</if>
  98. <if test="status != null">status,</if>
  99. <if test="createBy != null and createBy != ''">create_by,</if>
  100. create_time
  101. )values(
  102. <if test="id != null and id != 0">#{id},</if>
  103. <if test="parentId != null and parentId != 0">#{parentId},</if>
  104. <if test="deptName != null and deptName != ''">#{deptName},</if>
  105. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  106. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  107. <if test="leader != null and leader != ''">#{leader},</if>
  108. <if test="phone != null and phone != ''">#{phone},</if>
  109. <if test="email != null and email != ''">#{email},</if>
  110. <if test="status != null">#{status},</if>
  111. <if test="createBy != null and createBy != ''">#{createBy},</if>
  112. sysdate()
  113. )
  114. </insert>
  115. <update id="updateDept" parameterType="com.boman.domain.SysDept">
  116. update sys_dept
  117. <set>
  118. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  119. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  120. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  121. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  122. <if test="leader != null">leader = #{leader},</if>
  123. <if test="phone != null">phone = #{phone},</if>
  124. <if test="email != null">email = #{email},</if>
  125. <if test="status != null and status != ''">status = #{status},</if>
  126. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  127. update_time = sysdate()
  128. </set>
  129. where id = #{id}
  130. </update>
  131. <update id="updateDeptChildren" parameterType="java.util.List">
  132. update sys_dept set ancestors =
  133. <foreach collection="depts" item="item" index="index"
  134. separator=" " open="case id" close="end">
  135. when #{item.id} then #{item.ancestors}
  136. </foreach>
  137. where id in
  138. <foreach collection="depts" item="item" index="index"
  139. separator="," open="(" close=")">
  140. #{item.id}
  141. </foreach>
  142. </update>
  143. <update id="updateDeptStatus" parameterType="com.boman.domain.SysDept">
  144. update sys_dept
  145. <set>
  146. <if test="status != null and status != ''">status = #{status},</if>
  147. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  148. update_time = sysdate()
  149. </set>
  150. where id in (${ancestors})
  151. </update>
  152. <delete id="deleteDeptById" parameterType="Long">
  153. update sys_dept set del_flag = '2' where id = #{id}
  154. </delete>
  155. </mapper>