SysDeptMapper.xml 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. <result property="otherId" column="other_id"/>
  23. </resultMap>
  24. <sql id="selectDeptVo">
  25. 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,d.other_id
  26. from sys_dept d
  27. </sql>
  28. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  29. <include refid="selectDeptVo"/>
  30. where d.del_flag = '0'
  31. <if test="deptId != null and deptId != 0">
  32. AND dept_id = #{deptId}
  33. </if>
  34. <if test="otherId != null and otherId != 0">
  35. AND other_id = #{otherId}
  36. </if>
  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. <if test="params.dataScope != null and params.dataScope != ''">
  48. AND ( ${params.dataScope} )
  49. </if>
  50. order by d.parent_id, d.order_num
  51. </select>
  52. <select id="selectDeptListByRoleId" resultType="Integer">
  53. select d.dept_id
  54. from sys_dept d
  55. left join sys_role_dept rd on d.dept_id = rd.dept_id
  56. where rd.role_id = #{roleId}
  57. <if test="deptCheckStrictly">
  58. 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})
  59. </if>
  60. order by d.parent_id, d.order_num
  61. </select>
  62. <update id="updateDeptChildren" parameterType="java.util.List">
  63. update sys_dept set ancestors =
  64. <foreach collection="depts" item="item" index="index"
  65. separator=" " open="case dept_id" close="end">
  66. when #{item.deptId} then #{item.ancestors}
  67. </foreach>
  68. where dept_id in
  69. <foreach collection="depts" item="item" index="index"
  70. separator="," open="(" close=")">
  71. #{item.deptId}
  72. </foreach>
  73. </update>
  74. </mapper>