DeptMapper.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.juxiao.xchat.module.system.mapper.DeptMapper">
  6. <resultMap type="com.juxiao.xchat.module.system.domain.Dept" id="DeptResult">
  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. </resultMap>
  23. <sql id="selectDeptVo">
  24. 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
  25. from sys_dept d
  26. </sql>
  27. <select id="selectRoleDeptTree" parameterType="java.lang.Long" resultType="java.lang.String">
  28. select concat(d.dept_id, d.dept_name) as dept_name
  29. from sys_dept d
  30. left join sys_role_dept rd on d.dept_id = rd.dept_id
  31. where d.del_flag = '0' and rd.role_id = #{roleId}
  32. order by d.parent_id, d.order_num
  33. </select>
  34. <select id="selectDeptList" parameterType="com.juxiao.xchat.module.system.domain.Dept" resultMap="DeptResult">
  35. <include refid="selectDeptVo"/>
  36. where d.del_flag = '0'
  37. <if test="parentId != null and parentId != 0">
  38. AND parent_id = #{parentId}
  39. </if>
  40. <if test="deptName != null and deptName != ''">
  41. AND dept_name like concat('%', #{deptName}, '%')
  42. </if>
  43. <if test="status != null and status != ''">
  44. AND status = #{status}
  45. </if>
  46. <!-- 数据范围过滤 -->
  47. ${params.dataScope}
  48. order by d.parent_id, d.order_num
  49. </select>
  50. <select id="checkDeptExistUser" parameterType="java.lang.Long" resultType="int">
  51. select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
  52. </select>
  53. <select id="selectDeptCount" parameterType="com.juxiao.xchat.module.system.domain.Dept" resultType="int">
  54. select count(1) from sys_dept
  55. where del_flag = '0'
  56. <if test="deptId != null and deptId != 0"> and dept_id = #{deptId} </if>
  57. <if test="parentId != null and parentId != 0"> and parent_id = #{parentId} </if>
  58. </select>
  59. <select id="checkDeptNameUnique" resultMap="DeptResult">
  60. <include refid="selectDeptVo"/>
  61. where dept_name=#{deptName} and parent_id = #{parentId}
  62. </select>
  63. <select id="selectDeptById" parameterType="java.lang.Long" resultMap="DeptResult">
  64. select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
  65. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  66. from sys_dept d
  67. where d.dept_id = #{deptId}
  68. </select>
  69. <select id="selectChildrenDeptById" parameterType="java.lang.Long" resultMap="DeptResult">
  70. select * from sys_dept where find_in_set(#{deptId}, ancestors)
  71. </select>
  72. <insert id="insertDept" parameterType="com.juxiao.xchat.module.system.domain.Dept">
  73. insert into sys_dept(
  74. <if test="deptId != null and deptId != 0">dept_id,</if>
  75. <if test="parentId != null and parentId != 0">parent_id,</if>
  76. <if test="deptName != null and deptName != ''">dept_name,</if>
  77. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  78. <if test="orderNum != null and orderNum != ''">order_num,</if>
  79. <if test="leader != null and leader != ''">leader,</if>
  80. <if test="phone != null and phone != ''">phone,</if>
  81. <if test="email != null and email != ''">email,</if>
  82. <if test="status != null">status,</if>
  83. <if test="createBy != null and createBy != ''">create_by,</if>
  84. create_time
  85. )values(
  86. <if test="deptId != null and deptId != 0">#{deptId},</if>
  87. <if test="parentId != null and parentId != 0">#{parentId},</if>
  88. <if test="deptName != null and deptName != ''">#{deptName},</if>
  89. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  90. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  91. <if test="leader != null and leader != ''">#{leader},</if>
  92. <if test="phone != null and phone != ''">#{phone},</if>
  93. <if test="email != null and email != ''">#{email},</if>
  94. <if test="status != null">#{status},</if>
  95. <if test="createBy != null and createBy != ''">#{createBy},</if>
  96. sysdate()
  97. )
  98. </insert>
  99. <update id="updateDept" parameterType="com.juxiao.xchat.module.system.domain.Dept">
  100. update sys_dept
  101. <set>
  102. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  103. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  104. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  105. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  106. <if test="leader != null">leader = #{leader},</if>
  107. <if test="phone != null">phone = #{phone},</if>
  108. <if test="email != null">email = #{email},</if>
  109. <if test="status != null and status != ''">status = #{status},</if>
  110. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  111. update_time = sysdate()
  112. </set>
  113. where dept_id = #{deptId}
  114. </update>
  115. <update id="updateDeptChildren" parameterType="java.util.List">
  116. update sys_dept set ancestors =
  117. <foreach collection="depts" item="item" index="index"
  118. separator=" " open="case dept_id" close="end">
  119. when #{item.deptId} then #{item.ancestors}
  120. </foreach>
  121. where dept_id in
  122. <foreach collection="depts" item="item" index="index"
  123. separator="," open="(" close=")">
  124. #{item.deptId}
  125. </foreach>
  126. </update>
  127. <delete id="deleteDeptById" parameterType="java.lang.Long">
  128. update sys_dept set del_flag = '2' where dept_id = #{deptId}
  129. </delete>
  130. <update id="updateDeptStatus" parameterType="com.juxiao.xchat.module.system.domain.Dept">
  131. update sys_dept
  132. <set>
  133. <if test="status != null and status != ''">status = #{status},</if>
  134. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  135. update_time = sysdate()
  136. </set>
  137. where dept_id in (${ancestors})
  138. </update>
  139. </mapper>