Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
查尔斯-BUG万象集
Continew Admin
提交
1319cb32
Continew Admin
项目概览
查尔斯-BUG万象集
/
Continew Admin
8 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
1319cb32
编写于
2月 16, 2023
作者:
查尔斯-BUG万象集
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化:使用 MyBatis Plus ChainWrapper 优化部分 QueryWrapper 的写法
上级
56449263
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
77 addition
and
30 deletion
+77
-30
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseServiceImpl.java
...va/top/charles7c/cnadmin/common/base/BaseServiceImpl.java
+52
-0
continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java
...harles7c/cnadmin/system/service/impl/DeptServiceImpl.java
+17
-19
continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/RoleServiceImpl.java
...harles7c/cnadmin/system/service/impl/RoleServiceImpl.java
+8
-11
未找到文件。
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseServiceImpl.java
浏览文件 @
1319cb32
...
@@ -32,6 +32,11 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
...
@@ -32,6 +32,11 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
import
com.baomidou.mybatisplus.core.metadata.TableInfoHelper
;
import
com.baomidou.mybatisplus.core.metadata.TableInfoHelper
;
import
com.baomidou.mybatisplus.core.toolkit.Assert
;
import
com.baomidou.mybatisplus.core.toolkit.Assert
;
import
com.baomidou.mybatisplus.core.toolkit.ReflectionKit
;
import
com.baomidou.mybatisplus.core.toolkit.ReflectionKit
;
import
com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper
;
import
com.baomidou.mybatisplus.extension.toolkit.ChainWrappers
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
...
@@ -246,4 +251,51 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C ext
...
@@ -246,4 +251,51 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C ext
protected
Class
<
D
>
currentDetailVoClass
()
{
protected
Class
<
D
>
currentDetailVoClass
()
{
return
(
Class
<
D
>)
ReflectionKit
.
getSuperClassGenericType
(
this
.
getClass
(),
BaseServiceImpl
.
class
,
3
);
return
(
Class
<
D
>)
ReflectionKit
.
getSuperClassGenericType
(
this
.
getClass
(),
BaseServiceImpl
.
class
,
3
);
}
}
/**
* 链式查询
*
* @return QueryWrapper 的包装类
*/
protected
QueryChainWrapper
<
T
>
query
()
{
return
ChainWrappers
.
queryChain
(
baseMapper
);
}
/**
* 链式查询(lambda 式)
*
* @return LambdaQueryWrapper 的包装类
*/
protected
LambdaQueryChainWrapper
<
T
>
lambdaQuery
()
{
return
ChainWrappers
.
lambdaQueryChain
(
baseMapper
,
entityClass
);
}
/**
* 链式查询(lambda 式)
*
* @param entity
* 实体对象
* @return LambdaQueryWrapper 的包装类
*/
protected
LambdaQueryChainWrapper
<
T
>
lambdaQuery
(
T
entity
)
{
return
ChainWrappers
.
lambdaQueryChain
(
baseMapper
,
entity
);
}
/**
* 链式更改
*
* @return UpdateWrapper 的包装类
*/
protected
UpdateChainWrapper
<
T
>
update
()
{
return
ChainWrappers
.
updateChain
(
baseMapper
);
}
/**
* 链式更改(lambda 式)
*
* @return LambdaUpdateWrapper 的包装类
*/
protected
LambdaUpdateChainWrapper
<
T
>
lambdaUpdate
()
{
return
ChainWrappers
.
lambdaUpdateChain
(
baseMapper
);
}
}
}
continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java
浏览文件 @
1319cb32
...
@@ -26,8 +26,6 @@ import lombok.RequiredArgsConstructor;
...
@@ -26,8 +26,6 @@ import lombok.RequiredArgsConstructor;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.lang.tree.Tree
;
import
cn.hutool.core.lang.tree.Tree
;
...
@@ -62,8 +60,8 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
...
@@ -62,8 +60,8 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Long
create
(
DeptRequest
request
)
{
public
Long
create
(
DeptRequest
request
)
{
String
deptName
=
request
.
getDeptName
();
String
deptName
=
request
.
getDeptName
();
boolean
isExist
=
this
.
checkNameExist
(
deptName
,
request
.
getParentId
(),
request
.
getDeptId
());
boolean
isExist
s
=
this
.
checkNameExists
(
deptName
,
request
.
getParentId
(),
request
.
getDeptId
());
CheckUtils
.
throwIf
(()
->
isExist
,
String
.
format
(
"新增失败,'%s'已存在"
,
deptName
));
CheckUtils
.
throwIf
(()
->
isExist
s
,
String
.
format
(
"新增失败,'%s'已存在"
,
deptName
));
// 保存信息
// 保存信息
request
.
setStatus
(
DisEnableStatusEnum
.
ENABLE
);
request
.
setStatus
(
DisEnableStatusEnum
.
ENABLE
);
...
@@ -74,8 +72,8 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
...
@@ -74,8 +72,8 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
DeptRequest
request
)
{
public
void
update
(
DeptRequest
request
)
{
String
deptName
=
request
.
getDeptName
();
String
deptName
=
request
.
getDeptName
();
boolean
isExist
=
this
.
checkNameExist
(
deptName
,
request
.
getParentId
(),
request
.
getDeptId
());
boolean
isExist
s
=
this
.
checkNameExists
(
deptName
,
request
.
getParentId
(),
request
.
getDeptId
());
CheckUtils
.
throwIf
(()
->
isExist
,
String
.
format
(
"新增
失败,'%s'已存在"
,
deptName
));
CheckUtils
.
throwIf
(()
->
isExist
s
,
String
.
format
(
"修改
失败,'%s'已存在"
,
deptName
));
super
.
update
(
request
);
super
.
update
(
request
);
}
}
...
@@ -85,7 +83,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
...
@@ -85,7 +83,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
public
void
delete
(
List
<
Long
>
ids
)
{
public
void
delete
(
List
<
Long
>
ids
)
{
CheckUtils
.
throwIf
(()
->
userService
.
countByDeptIds
(
ids
)
>
0
,
"所选部门存在用户关联,请解除关联后重试"
);
CheckUtils
.
throwIf
(()
->
userService
.
countByDeptIds
(
ids
)
>
0
,
"所选部门存在用户关联,请解除关联后重试"
);
super
.
delete
(
ids
);
super
.
delete
(
ids
);
baseMapper
.
delete
(
Wrappers
.<
DeptDO
>
lambdaQuery
().
in
(
DeptDO:
:
getParentId
,
ids
)
);
super
.
lambdaUpdate
().
in
(
DeptDO:
:
getParentId
,
ids
).
remove
(
);
}
}
@Override
@Override
...
@@ -109,18 +107,18 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
...
@@ -109,18 +107,18 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
*/
*/
private
List
<
DeptVO
>
deDuplication
(
List
<
DeptVO
>
list
)
{
private
List
<
DeptVO
>
deDuplication
(
List
<
DeptVO
>
list
)
{
List
<
DeptVO
>
deDuplicationList
=
new
ArrayList
<>();
List
<
DeptVO
>
deDuplicationList
=
new
ArrayList
<>();
for
(
DeptVO
outer
Dept
:
list
)
{
for
(
DeptVO
outer
:
list
)
{
boolean
flag
=
true
;
boolean
flag
=
true
;
for
(
DeptVO
inner
Dept
:
list
)
{
for
(
DeptVO
inner
:
list
)
{
// 忽略重复子列表
// 忽略重复子列表
if
(
inner
Dept
.
getDeptId
().
equals
(
outerDept
.
getParentId
()))
{
if
(
inner
.
getDeptId
().
equals
(
outer
.
getParentId
()))
{
flag
=
false
;
flag
=
false
;
break
;
break
;
}
}
}
}
if
(
flag
)
{
if
(
flag
)
{
deDuplicationList
.
add
(
outer
Dept
);
deDuplicationList
.
add
(
outer
);
}
}
}
}
return
deDuplicationList
;
return
deDuplicationList
;
...
@@ -153,17 +151,17 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
...
@@ -153,17 +151,17 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
/**
/**
* 检查名称是否存在
* 检查名称是否存在
*
*
* @param
deptN
ame
* @param
n
ame
*
部门
名称
* 名称
* @param parentId
* @param parentId
* 上级
部门
ID
* 上级 ID
* @param
deptI
d
* @param
i
d
*
部门
ID
* ID
* @return 是否存在
* @return 是否存在
*/
*/
private
boolean
checkNameExist
(
String
deptName
,
Long
parentId
,
Long
deptI
d
)
{
private
boolean
checkNameExist
s
(
String
name
,
Long
parentId
,
Long
i
d
)
{
return
baseMapper
.
exists
(
Wrappers
.<
DeptDO
>
lambdaQuery
().
eq
(
DeptDO:
:
getDeptName
,
deptName
)
return
super
.
lambdaQuery
().
eq
(
DeptDO:
:
getDeptName
,
name
).
eq
(
DeptDO:
:
getParentId
,
parentId
)
.
eq
(
DeptDO:
:
getParentId
,
parentId
).
ne
(
deptId
!=
null
,
DeptDO:
:
getDeptId
,
deptId
)
);
.
ne
(
id
!=
null
,
DeptDO:
:
getDeptId
,
id
).
exists
(
);
}
}
@Override
@Override
...
...
continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/RoleServiceImpl.java
浏览文件 @
1319cb32
...
@@ -23,8 +23,6 @@ import lombok.RequiredArgsConstructor;
...
@@ -23,8 +23,6 @@ import lombok.RequiredArgsConstructor;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
top.charles7c.cnadmin.common.base.BaseServiceImpl
;
import
top.charles7c.cnadmin.common.base.BaseServiceImpl
;
import
top.charles7c.cnadmin.common.enums.DisEnableStatusEnum
;
import
top.charles7c.cnadmin.common.enums.DisEnableStatusEnum
;
import
top.charles7c.cnadmin.common.util.validate.CheckUtils
;
import
top.charles7c.cnadmin.common.util.validate.CheckUtils
;
...
@@ -54,7 +52,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
...
@@ -54,7 +52,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Long
create
(
RoleRequest
request
)
{
public
Long
create
(
RoleRequest
request
)
{
String
roleName
=
request
.
getRoleName
();
String
roleName
=
request
.
getRoleName
();
boolean
isExist
=
this
.
checkNameExist
(
roleName
,
request
.
getRoleId
());
boolean
isExist
=
this
.
checkNameExist
s
(
roleName
,
request
.
getRoleId
());
CheckUtils
.
throwIf
(()
->
isExist
,
String
.
format
(
"新增失败,'%s'已存在"
,
roleName
));
CheckUtils
.
throwIf
(()
->
isExist
,
String
.
format
(
"新增失败,'%s'已存在"
,
roleName
));
// 保存信息
// 保存信息
...
@@ -66,7 +64,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
...
@@ -66,7 +64,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
RoleRequest
request
)
{
public
void
update
(
RoleRequest
request
)
{
String
roleName
=
request
.
getRoleName
();
String
roleName
=
request
.
getRoleName
();
boolean
isExist
=
this
.
checkNameExist
(
roleName
,
request
.
getRoleId
());
boolean
isExist
=
this
.
checkNameExist
s
(
roleName
,
request
.
getRoleId
());
CheckUtils
.
throwIf
(()
->
isExist
,
String
.
format
(
"修改失败,'%s'已存在"
,
roleName
));
CheckUtils
.
throwIf
(()
->
isExist
,
String
.
format
(
"修改失败,'%s'已存在"
,
roleName
));
super
.
update
(
request
);
super
.
update
(
request
);
...
@@ -82,14 +80,13 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
...
@@ -82,14 +80,13 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
/**
/**
* 检查名称是否存在
* 检查名称是否存在
*
*
* @param
roleN
ame
* @param
n
ame
*
角色
名称
* 名称
* @param
roleI
d
* @param
i
d
*
角色
ID
* ID
* @return 是否存在
* @return 是否存在
*/
*/
private
boolean
checkNameExist
(
String
roleName
,
Long
roleId
)
{
private
boolean
checkNameExists
(
String
name
,
Long
id
)
{
return
baseMapper
.
exists
(
Wrappers
.<
RoleDO
>
lambdaQuery
().
eq
(
RoleDO:
:
getRoleName
,
roleName
).
ne
(
roleId
!=
null
,
return
super
.
lambdaQuery
().
eq
(
RoleDO:
:
getRoleName
,
name
).
ne
(
id
!=
null
,
RoleDO:
:
getRoleId
,
id
).
exists
();
RoleDO:
:
getRoleId
,
roleId
));
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录