♻️ 重构代码。部门关系维护(jdbcurl allowMultiQueries)

This commit is contained in:
冷冷 2018-09-24 12:12:23 +08:00
parent 1af58f4e99
commit 997d1c5bc0
5 changed files with 55 additions and 30 deletions

View File

@ -39,10 +39,4 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
* @return 数据列表
*/
List<SysDept> selectDeptDtoList(String delFlag);
/**
* 删除部门关系表数据
* @param id 部门ID
*/
void deleteDeptRealtion(Integer id);
}

View File

@ -29,5 +29,17 @@ import com.github.pig.admin.model.entity.SysDeptRelation;
* @since 2018-02-12
*/
public interface SysDeptRelationMapper extends BaseMapper<SysDeptRelation> {
/**
* 删除部门关系表数据
*
* @param id 部门ID
*/
void deleteAllDeptRealtion(Integer id);
/**
* 更改部分关系表数据
*
* @param deptRelation
*/
void updateDeptRealtion(SysDeptRelation deptRelation);
}

View File

@ -98,7 +98,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
sysDept.setUpdateTime(new Date());
sysDept.setDelFlag(CommonConstant.STATUS_DEL);
this.deleteById(sysDept);
sysDeptMapper.deleteDeptRealtion(id);
sysDeptRelationMapper.deleteAllDeptRealtion(id);
return Boolean.TRUE;
}
@ -112,10 +112,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
public Boolean updateDeptById(SysDept sysDept) {
//更新部门状态
this.updateById(sysDept);
//删除部门关系
sysDeptMapper.deleteDeptRealtion(sysDept.getDeptId());
//新建部门关系
this.insertDeptRelation(sysDept);
//更新部门关系
SysDeptRelation relation = new SysDeptRelation();
relation.setAncestor(sysDept.getParentId());
relation.setDescendant(sysDept.getDeptId());
sysDeptRelationMapper.updateDeptRealtion(relation);
return null;
}

View File

@ -33,25 +33,6 @@
<sql id="Base_Column_List">
dept_id AS deptId, parent_id AS parentId, name, order_num AS orderNum, create_time AS createTime, update_time AS updateTime, del_flag AS delFlag
</sql>
<delete id="deleteDeptRealtion">
DELETE
FROM
sys_dept_relation
WHERE
descendant IN (
SELECT
temp.descendant
FROM
(
SELECT
descendant
FROM
sys_dept_relation
WHERE
ancestor = #{id}
) temp
)
</delete>
<!--关联查询部门列表-->
<select id="selectDeptDtoList" resultType="com.github.pig.admin.model.entity.SysDept">

View File

@ -30,4 +30,41 @@
ancestor, descendant
</sql>
<!-- 更新部门关系 -->
<update id="updateDeptRealtion">
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 );
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};
</update>
<!--删除部门-->
<delete id="deleteAllDeptRealtion">
DELETE
FROM
sys_dept_relation
WHERE
descendant IN (
SELECT
temp.descendant
FROM
(
SELECT
descendant
FROM
sys_dept_relation
WHERE
ancestor = #{id}
) temp
)
</delete>
</mapper>