🗃️ 执行数据库相关的变化 close #3457 【优化】更新部门关系SQL 拆分为多个SQL 执行,提高数据库兼容性
This commit is contained in:
1 parent
289e212aa9
commit
97f6555841
4 files changed
+50
-50
No files matched your search
@@ -14,4 +14,4 @@ spring:
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
profiles:
|
||||
active: @profiles.active@
|
||||
active: @profiles.active@
|
||||
+11
-5
@@ -35,15 +35,21 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface SysDeptRelationMapper extends PigxBaseMapper<SysDeptRelation> {
|
||||
|
||||
/**
|
||||
* 删除部门关系表数据
|
||||
* 删除部门 > 删除所有关联此部门子节点的闭包关系
|
||||
* @param id 部门ID
|
||||
*/
|
||||
void deleteDeptRelationsById(Long id);
|
||||
void deleteDeptRelationsByDeptId(Long id);
|
||||
|
||||
/**
|
||||
* 更改部分关系表数据
|
||||
* @param deptRelation
|
||||
* 删除节点数据
|
||||
* @param deptRelation 关系节点
|
||||
*/
|
||||
void updateDeptRelations(SysDeptRelation deptRelation);
|
||||
void deleteDeptRelations(SysDeptRelation deptRelation);
|
||||
|
||||
/**
|
||||
* 新增节点数据
|
||||
* @param deptRelation 关系节点
|
||||
*/
|
||||
void insertDeptRelations(SysDeptRelation deptRelation);
|
||||
|
||||
}
|
||||
+4
-2
@@ -79,7 +79,7 @@ public class SysDeptRelationServiceImpl extends ServiceImpl<SysDeptRelationMappe
|
||||
*/
|
||||
@Override
|
||||
public void deleteAllDeptRealtion(Long id) {
|
||||
baseMapper.deleteDeptRelationsById(id);
|
||||
baseMapper.deleteDeptRelationsByDeptId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +87,10 @@ public class SysDeptRelationServiceImpl extends ServiceImpl<SysDeptRelationMappe
|
||||
* @param relation
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDeptRealtion(SysDeptRelation relation) {
|
||||
baseMapper.updateDeptRelations(relation);
|
||||
baseMapper.deleteDeptRelations(relation);
|
||||
baseMapper.insertDeptRelations(relation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,52 +21,44 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.pig4cloud.pigx.admin.mapper.SysDeptRelationMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.pig4cloud.pigx.admin.api.entity.SysDeptRelation">
|
||||
<id column="ancestor" property="ancestor"/>
|
||||
<result column="descendant" property="descendant"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
ancestor, descendant
|
||||
</sql>
|
||||
|
||||
<!-- 更新部门关系 -->
|
||||
<update id="updateDeptRelations">
|
||||
DELETE FROM sys_dept_relation
|
||||
WHERE
|
||||
descendant IN ( SELECT temp.descendant FROM
|
||||
( SELECT descendant FROM sys_dept_relation WHERE ancestor = #{descendant} ) temp )
|
||||
AND ancestor IN ( SELECT temp.ancestor FROM ( SELECT ancestor FROM
|
||||
sys_dept_relation WHERE descendant = #{descendant} AND ancestor != descendant ) temp );
|
||||
<!-- 删除节点关系 -->
|
||||
<delete id="deleteDeptRelations">
|
||||
DELETE FROM sys_dept_relation
|
||||
WHERE
|
||||
descendant IN ( SELECT temp.descendant FROM
|
||||
( SELECT descendant FROM sys_dept_relation WHERE ancestor = #{descendant} ) temp )
|
||||
AND ancestor IN ( SELECT temp.ancestor FROM ( SELECT ancestor FROM
|
||||
sys_dept_relation WHERE descendant = #{descendant} AND ancestor != descendant ) temp )
|
||||
</delete>
|
||||
|
||||
<!-- 新增节点关系 -->
|
||||
<insert id="insertDeptRelations">
|
||||
INSERT INTO sys_dept_relation (ancestor, descendant)
|
||||
SELECT a.ancestor, b.descendant
|
||||
FROM sys_dept_relation a
|
||||
CROSS JOIN sys_dept_relation b
|
||||
CROSS JOIN sys_dept_relation b
|
||||
WHERE a.descendant = #{ancestor}
|
||||
AND b.ancestor = #{descendant};
|
||||
</update>
|
||||
AND b.ancestor = #{descendant}
|
||||
</insert>
|
||||
|
||||
<!--删除部门-->
|
||||
<delete id="deleteDeptRelationsById">
|
||||
DELETE
|
||||
FROM
|
||||
sys_dept_relation
|
||||
WHERE
|
||||
descendant IN (
|
||||
SELECT
|
||||
temp.descendant
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
descendant
|
||||
FROM
|
||||
sys_dept_relation
|
||||
WHERE
|
||||
ancestor = #{id}
|
||||
) temp
|
||||
)
|
||||
</delete>
|
||||
<!--删除部门 > 删除所有关联此部门子节点的闭包关系-->
|
||||
<delete id="deleteDeptRelationsByDeptId">
|
||||
DELETE
|
||||
FROM
|
||||
sys_dept_relation
|
||||
WHERE
|
||||
descendant IN (
|
||||
SELECT
|
||||
temp.descendant
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
descendant
|
||||
FROM
|
||||
sys_dept_relation
|
||||
WHERE
|
||||
ancestor = #{id}
|
||||
) temp
|
||||
)
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user