SysDeptMapper.xml 7.5 KB

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