SysDeptMapper.xml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.ruoyi.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="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="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  28. <include refid="selectDeptVo"/>
  29. where d.del_flag = '0'
  30. <if test="deptId != null and deptId != 0">
  31. AND dept_id = #{deptId}
  32. </if>
  33. <if test="parentId != null and parentId != 0">
  34. AND parent_id = #{parentId}
  35. </if>
  36. <if test="deptName != null and deptName != ''">
  37. AND dept_name like concat('%', #{deptName}, '%')
  38. </if>
  39. <if test="status != null and status != ''">
  40. AND status = #{status}
  41. </if>
  42. <!-- 数据范围过滤 -->
  43. <if test="params.dataScope != null and params.dataScope != ''">
  44. AND ( ${params.dataScope} )
  45. </if>
  46. order by d.parent_id, d.order_num
  47. </select>
  48. <select id="selectDeptListByRoleId" resultType="Integer">
  49. select d.dept_id
  50. from sys_dept d
  51. left join sys_role_dept rd on d.dept_id = rd.dept_id
  52. where rd.role_id = #{roleId}
  53. <if test="deptCheckStrictly">
  54. 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})
  55. </if>
  56. order by d.parent_id, d.order_num
  57. </select>
  58. <update id="updateDeptChildren" parameterType="java.util.List">
  59. update sys_dept set ancestors =
  60. <foreach collection="depts" item="item" index="index"
  61. separator=" " open="case dept_id" close="end">
  62. when #{item.deptId} then #{item.ancestors}
  63. </foreach>
  64. where dept_id in
  65. <foreach collection="depts" item="item" index="index"
  66. separator="," open="(" close=")">
  67. #{item.deptId}
  68. </foreach>
  69. </update>
  70. </mapper>