SysDeptRelationMapper.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.qunzhixinxi.hnqz.admin.mapper.SysDeptRelationMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.qunzhixinxi.hnqz.admin.api.entity.SysDeptRelation">
  6. <id column="ancestor" property="ancestor"/>
  7. <result column="descendant" property="descendant"/>
  8. </resultMap>
  9. <!-- 通用查询结果列 -->
  10. <sql id="Base_Column_List">
  11. ancestor, descendant
  12. </sql>
  13. <!-- 更新部门关系 -->
  14. <update id="updateDeptRelations">
  15. DELETE FROM sys_dept_relation
  16. WHERE
  17. descendant IN ( SELECT temp.descendant FROM
  18. ( SELECT descendant FROM sys_dept_relation WHERE ancestor = #{descendant} ) temp )
  19. AND ancestor IN ( SELECT temp.ancestor FROM ( SELECT ancestor FROM
  20. sys_dept_relation WHERE descendant = #{descendant} AND ancestor != descendant ) temp );
  21. INSERT INTO sys_dept_relation (ancestor, descendant)
  22. SELECT a.ancestor, b.descendant
  23. FROM sys_dept_relation a
  24. CROSS JOIN sys_dept_relation b
  25. WHERE a.descendant = #{ancestor}
  26. AND b.ancestor = #{descendant};
  27. </update>
  28. <!--删除部门-->
  29. <delete id="deleteDeptRelationsById">
  30. DELETE
  31. FROM
  32. sys_dept_relation
  33. WHERE
  34. descendant IN (
  35. SELECT
  36. temp.descendant
  37. FROM
  38. (
  39. SELECT
  40. descendant
  41. FROM
  42. sys_dept_relation
  43. WHERE
  44. ancestor = #{id}
  45. ) temp
  46. )
  47. </delete>
  48. <!--删除部门-->
  49. <delete id="deleteDeptById">
  50. DELETE
  51. FROM
  52. sys_dept
  53. WHERE
  54. dept_id=#{id}
  55. </delete>
  56. <select id="selectDeptRelationsList" resultMap="BaseResultMap">
  57. SELECT *
  58. FROM sys_dept_relation
  59. WHERE ancestor = #{query.ancestor}
  60. </select>
  61. <select id="selectDeptAllDesc" resultMap="BaseResultMap">
  62. SELECT *
  63. FROM sys_dept_relation
  64. WHERE ancestor = #{query.ancestor}
  65. UNION ALL
  66. SELECT *
  67. FROM sys_dept_relation
  68. WHERE ancestor in (
  69. SELECT descendant
  70. FROM sys_dept_relation
  71. WHERE ancestor = #{query.ancestor}
  72. and
  73. descendant != ancestor
  74. )
  75. </select>
  76. <select id="selectListByAncestor" resultMap="BaseResultMap">
  77. SELECT
  78. *
  79. FROM
  80. sys_dept_relation
  81. WHERE
  82. ancestor = #{query.ancestor}
  83. and
  84. descendant != ancestor
  85. </select>
  86. <select id="selectListByDescendant" resultMap="BaseResultMap">
  87. SELECT
  88. *
  89. FROM
  90. sys_dept_relation
  91. WHERE
  92. descendant = #{query.descendant,jdbcType=BIGINT}
  93. and
  94. descendant != ancestor
  95. and
  96. ancestor != 1
  97. </select>
  98. <select id="selectByDescendantList" resultMap="BaseResultMap">
  99. SELECT
  100. *
  101. FROM
  102. sys_dept_relation
  103. WHERE
  104. descendant = #{query.descendant,jdbcType=BIGINT}
  105. </select>
  106. <select id="selectDeptRelation" resultMap="BaseResultMap">
  107. SELECT
  108. *
  109. FROM
  110. sys_dept_relation
  111. WHERE
  112. ancestor = #{query.ancestor,jdbcType=BIGINT}
  113. and
  114. descendant = #{query.descendant,jdbcType=BIGINT}
  115. </select>
  116. <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
  117. delete from sys_dept_relation
  118. where descendant = #{descendant,jdbcType=BIGINT}
  119. </delete>
  120. </mapper>