SysDeptRelationMapper.xml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.xy.mapper.SysDeptRelationMapper">
  4. <!-- 删除部门节点关系 -->
  5. <delete id="deleteDeptRelations">
  6. DELETE
  7. FROM sys_dept_relation
  8. WHERE descendant IN (SELECT temp.descendant
  9. FROM (SELECT descendant FROM sys_dept_relation WHERE ancestor = #{descendant}) temp)
  10. AND ancestor IN (SELECT temp.ancestor
  11. FROM (SELECT ancestor
  12. FROM sys_dept_relation
  13. WHERE descendant = #{descendant}
  14. AND ancestor != descendant) temp)
  15. </delete>
  16. <!--删除部门节点关系,同时删除所有关联此部门子节点的部门关系-->
  17. <delete id="deleteDeptRelationsById">
  18. DELETE
  19. FROM sys_dept_relation
  20. WHERE descendant IN (
  21. SELECT temp.descendant
  22. FROM (
  23. SELECT descendant
  24. FROM sys_dept_relation
  25. WHERE ancestor = #{id}
  26. ) temp
  27. )
  28. </delete>
  29. <!-- 新增部门节点关系 -->
  30. <insert id="insertDeptRelations">
  31. INSERT INTO sys_dept_relation (ancestor, descendant)
  32. SELECT a.ancestor, b.descendant
  33. FROM sys_dept_relation a
  34. CROSS JOIN sys_dept_relation b
  35. WHERE a.descendant = #{ancestor}
  36. AND b.ancestor = #{descendant}
  37. </insert>
  38. </mapper>