!182 解决修改部门时报错问题

Merge pull request !182 from 博远/master
This commit is contained in:
lengleng 2021-12-21 13:23:36 +00:00 committed by Gitee
commit 27db1e75cb
3 changed files with 32 additions and 2 deletions

View File

@ -42,5 +42,16 @@ public interface SysDeptRelationMapper extends BaseMapper<SysDeptRelation> {
* @param deptRelation
*/
void updateDeptRelations(SysDeptRelation deptRelation);
/**
* 删除部门关系
* @param deptRelation
*/
void deleteDeptRelations(SysDeptRelation deptRelation);
/**
* 新增部门关系
* @param deptRelation
*/
void insertDeptRelations(SysDeptRelation deptRelation);
}

View File

@ -84,8 +84,10 @@ public class SysDeptRelationServiceImpl extends ServiceImpl<SysDeptRelationMappe
* @param relation
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDeptRelation(SysDeptRelation relation) {
baseMapper.updateDeptRelations(relation);
baseMapper.deleteDeptRelations(relation);
baseMapper.insertDeptRelations(relation);
}
}

View File

@ -28,7 +28,24 @@
<sql id="Base_Column_List">
ancestor, descendant
</sql>
<!-- 删除机构关系 -->
<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
WHERE a.descendant = #{ancestor}
AND b.ancestor = #{descendant}
</insert>
<!-- 更新部门关系 -->
<update id="updateDeptRelations">
DELETE FROM sys_dept_relation