Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
查尔斯-BUG万象集
Continew Admin
提交
59d9fd33
Continew Admin
项目概览
查尔斯-BUG万象集
/
Continew Admin
10 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
分析
仓库
DevOps
项目成员
Pages
Continew Admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
59d9fd33
编写于
3月 26, 2023
作者:
查尔斯-BUG万象集
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化:优化修改部门的代码逻辑
1.启用部门,其所有上级部门需要处于启用状态;禁用部门,其所有下级部门需要处于禁用状态 2.新增部门时,默认为禁用状态
上级
bc54acd6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
10 deletion
+44
-10
continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java
...harles7c/cnadmin/system/service/impl/DeptServiceImpl.java
+44
-10
未找到文件。
continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java
浏览文件 @
59d9fd33
...
...
@@ -70,7 +70,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
CheckUtils
.
throwIf
(
isExists
,
"新增失败,[{}] 已存在"
,
name
);
request
.
setAncestors
(
this
.
getAncestors
(
request
.
getParentId
()));
request
.
setStatus
(
DisEnableStatusEnum
.
EN
ABLE
);
request
.
setStatus
(
DisEnableStatusEnum
.
DIS
ABLE
);
return
super
.
add
(
request
);
}
...
...
@@ -81,15 +81,27 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
boolean
isExists
=
this
.
checkNameExists
(
name
,
request
.
getParentId
(),
id
);
CheckUtils
.
throwIf
(
isExists
,
"修改失败,[{}] 已存在"
,
name
);
DeptDO
oldDept
=
super
.
getById
(
id
);
String
oldName
=
oldDept
.
getName
();
DisEnableStatusEnum
newStatus
=
request
.
getStatus
();
Long
oldParentId
=
oldDept
.
getParentId
();
if
(
DataTypeEnum
.
SYSTEM
.
equals
(
oldDept
.
getType
()))
{
CheckUtils
.
throwIfEqual
(
DisEnableStatusEnum
.
DISABLE
,
request
.
getStatus
(),
"[{}] 是系统内置部门,不允许禁用"
,
oldDept
.
getName
());
CheckUtils
.
throwIfNotEqual
(
request
.
getParentId
(),
oldDept
.
getParentId
(),
"[{}] 是系统内置部门,不允许变更上级部门"
,
oldDept
.
getName
());
CheckUtils
.
throwIfEqual
(
DisEnableStatusEnum
.
DISABLE
,
newStatus
,
"[{}] 是系统内置部门,不允许禁用"
,
oldName
);
CheckUtils
.
throwIfNotEqual
(
request
.
getParentId
(),
oldParentId
,
"[{}] 是系统内置部门,不允许变更上级部门"
,
oldName
);
}
// 启用/禁用部门
if
(
ObjectUtil
.
notEqual
(
newStatus
,
oldDept
.
getStatus
()))
{
List
<
DeptDO
>
children
=
this
.
listChildren
(
id
);
long
enabledChildrenCount
=
children
.
stream
().
filter
(
d
->
DisEnableStatusEnum
.
ENABLE
.
equals
(
d
.
getStatus
())).
count
();
CheckUtils
.
throwIf
(
DisEnableStatusEnum
.
DISABLE
.
equals
(
newStatus
)
&&
enabledChildrenCount
>
0
,
"禁用 [{}] 前,请先禁用其所有下级部门"
,
oldName
);
DeptDO
oldParentDept
=
this
.
getByParentId
(
oldParentId
);
CheckUtils
.
throwIf
(
DisEnableStatusEnum
.
ENABLE
.
equals
(
newStatus
)
&&
DisEnableStatusEnum
.
DISABLE
.
equals
(
oldParentDept
.
getStatus
()),
"启用 [{}] 前,请先启用其所有上级部门"
,
oldName
);
}
// 变更上级部门
if
(
ObjectUtil
.
notEqual
(
request
.
getParentId
(),
old
Dept
.
getParentId
()
))
{
if
(
ObjectUtil
.
notEqual
(
request
.
getParentId
(),
old
ParentId
))
{
// 更新祖级列表
String
newAncestors
=
this
.
getAncestors
(
request
.
getParentId
());
request
.
setAncestors
(
newAncestors
);
...
...
@@ -147,15 +159,38 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
/**
* 获取祖级列表
*
*
* @param parentId
* 上级部门
* @return 祖级列表
*/
private
String
getAncestors
(
Long
parentId
)
{
DeptDO
parentDept
=
this
.
getByParentId
(
parentId
);
return
String
.
format
(
"%s,%s"
,
parentDept
.
getAncestors
(),
parentId
);
}
/**
* 根据上级部门 ID 查询
*
* @param parentId
* 上级部门 ID
* @return 上级部门信息
*/
private
DeptDO
getByParentId
(
Long
parentId
)
{
DeptDO
parentDept
=
baseMapper
.
selectById
(
parentId
);
CheckUtils
.
throwIfNull
(
parentDept
,
"上级部门不存在"
);
return
String
.
format
(
"%s,%s"
,
parentDept
.
getAncestors
(),
parentId
);
return
parentDept
;
}
/**
* 查询子部门列表
*
* @param id
* ID
* @return 子部门列表
*/
private
List
<
DeptDO
>
listChildren
(
Long
id
)
{
return
baseMapper
.
lambdaQuery
().
apply
(
String
.
format
(
"find_in_set(%s, `ancestors`)"
,
id
)).
list
();
}
/**
...
...
@@ -169,8 +204,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
* ID
*/
private
void
updateChildrenAncestors
(
String
newAncestors
,
String
oldAncestors
,
Long
id
)
{
List
<
DeptDO
>
children
=
baseMapper
.
lambdaQuery
().
apply
(
String
.
format
(
"find_in_set(%s, `ancestors`)"
,
id
)).
list
();
List
<
DeptDO
>
children
=
this
.
listChildren
(
id
);
if
(
CollUtil
.
isEmpty
(
children
))
{
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录