Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangxinjiang
yifu-mvp
Commits
72f7b228
Commit
72f7b228
authored
Mar 20, 2025
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目规则配置-fxj
parent
0cd4bcfd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
230 additions
and
155 deletions
+230
-155
TAutoMainRelServiceImpl.java
...1/yifu/archives/service/impl/TAutoMainRelServiceImpl.java
+230
-155
No files found.
yifu-archives/yifu-archives-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/service/impl/TAutoMainRelServiceImpl.java
View file @
72f7b228
...
...
@@ -236,73 +236,93 @@ public class TAutoMainRelServiceImpl extends ServiceImpl<TAutoMainRelMapper, TAu
**/
@Override
public
R
<
Boolean
>
saveAsso
(
TAutoMainRelAddVo
entity
)
{
// 校验用户信息
YifuUser
user
=
SecurityUtils
.
getUser
();
if
(
Common
.
isEmpty
(
user
)){
return
R
.
failed
(
CommonConstants
.
USER_FAIL
);
}
if
(
Common
.
isEmpty
(
entity
)){
// 校验入参
if
(
Common
.
isEmpty
(
entity
)
||
Common
.
isEmpty
(
entity
.
getAutoMainRel
()))
{
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
TAutoMainRel
autoMainRel
=
entity
.
getAutoMainRel
();
if
(
Common
.
isEmpty
(
autoMainRel
)
||
Common
.
isEmpty
(
autoMainRel
.
getDeptId
())
||
Common
.
isEmpty
(
autoMainRel
.
getDeptNo
())){
if
(
Common
.
isEmpty
(
autoMainRel
.
getDeptId
())
||
Common
.
isEmpty
(
autoMainRel
.
getDeptNo
()))
{
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
TAutoMainRel
existRel
=
baseMapper
.
selectOne
(
Wrappers
.<
TAutoMainRel
>
query
().
lambda
()
.
eq
(
TAutoMainRel:
:
getDeptNo
,
autoMainRel
.
getDeptNo
()).
last
(
CommonConstants
.
LAST_ONE_SQL
));
if
(!
Common
.
isEmpty
(
existRel
)){
return
R
.
failed
(
"已存在对应项目规则配置!"
);
}
SysAutoDict
autoDict
=
autoDictMapper
.
selectOne
(
Wrappers
.<
SysAutoDict
>
query
().
lambda
()
.
eq
(
SysAutoDict:
:
getType
,
CommonConstants
.
POST_TYPE
).
last
(
CommonConstants
.
LAST_ONE_SQL
));
if
(
Common
.
isEmpty
(
autoDict
)){
return
R
.
failed
(
CommonConstants
.
INIT_DATA_GET_FAIL
);
}
TAutoEmpRuleInfo
autoEmpRuleInfo
=
entity
.
getAutoEmpRuleInfo
();
if
(
Common
.
isNotNull
(
autoEmpRuleInfo
)){
ExcelUtil
<
TAutoEmpRuleInfo
>
excelUtil
=
new
ExcelUtil
<>(
TAutoEmpRuleInfo
.
class
);
ErrorMessage
errorMessage
=
excelUtil
.
checkEntity
(
autoEmpRuleInfo
,
0
);
if
(
Common
.
isNotNull
(
errorMessage
)){
return
R
.
failed
(
errorMessage
.
getMessage
());
try
{
// 校验是否存在重复规则配置
TAutoMainRel
existRel
=
baseMapper
.
selectOne
(
Wrappers
.<
TAutoMainRel
>
query
().
lambda
()
.
eq
(
TAutoMainRel:
:
getDeptNo
,
autoMainRel
.
getDeptNo
()).
last
(
CommonConstants
.
LAST_ONE_SQL
));
if
(!
Common
.
isEmpty
(
existRel
)){
return
R
.
failed
(
"已存在对应项目规则配置!"
);
}
}
//新增岗位字典
List
<
SysAutoDictItem
>
autoDictItems
=
entity
.
getAutoDictItems
();
Set
<
String
>
repeatItems
=
new
HashSet
<>();
for
(
SysAutoDictItem
item:
autoDictItems
)
{
if
(
repeatItems
.
contains
(
item
.
getLabel
()))
{
// 获取岗位字典
SysAutoDict
autoDict
=
autoDictMapper
.
selectOne
(
Wrappers
.<
SysAutoDict
>
query
().
lambda
()
.
eq
(
SysAutoDict:
:
getType
,
CommonConstants
.
POST_TYPE
).
last
(
CommonConstants
.
LAST_ONE_SQL
));
if
(
Common
.
isEmpty
(
autoDict
)){
return
R
.
failed
(
CommonConstants
.
INIT_DATA_GET_FAIL
);
}
// 校验员工规则信息
TAutoEmpRuleInfo
autoEmpRuleInfo
=
entity
.
getAutoEmpRuleInfo
();
if
(
Common
.
isNotNull
(
autoEmpRuleInfo
)){
ExcelUtil
<
TAutoEmpRuleInfo
>
excelUtil
=
new
ExcelUtil
<>(
TAutoEmpRuleInfo
.
class
);
ErrorMessage
errorMessage
=
excelUtil
.
checkEntity
(
autoEmpRuleInfo
,
0
);
if
(
Common
.
isNotNull
(
errorMessage
)){
return
R
.
failed
(
errorMessage
.
getMessage
());
}
}
// 校验字典项是否有重复标签
List
<
SysAutoDictItem
>
autoDictItems
=
entity
.
getAutoDictItems
();
Set
<
String
>
repeatItems
=
new
HashSet
<>();
if
(!
checkDictItemsForDuplicates
(
autoDictItems
))
{
return
R
.
failed
(
itemsLabelRepeat
);
}
else
{
repeatItems
.
add
(
item
.
getLabel
());
}
}
//新增主表
autoMainRel
.
setRuleUpdatePerson
(
user
.
getNickname
());
autoMainRel
.
setRuleUpdateTime
(
DateUtil
.
getCurrentDateTime
());
int
res
=
baseMapper
.
insert
(
autoMainRel
);
if
(
res
<=
CommonConstants
.
ZERO_INT
){
return
R
.
failed
(
CommonConstants
.
SAVE_FAILED
);
}
if
(
Common
.
isNotNull
(
autoDictItems
))
{
for
(
SysAutoDictItem
sysAutoDictItem:
autoDictItems
){
//初始化字典信息
initDictItem
(
sysAutoDictItem
,
user
,
autoDict
,
autoMainRel
);
sysAutoDictItem
.
setCreateTime
(
LocalDateTime
.
now
());
sysAutoDictItem
.
setCreateBy
(
user
.
getId
());
sysAutoDictItem
.
setCreateName
(
user
.
getNickname
());
autoDictItemMapper
.
insert
(
sysAutoDictItem
);
//新增主表
autoMainRel
.
setRuleUpdatePerson
(
user
.
getNickname
());
autoMainRel
.
setRuleUpdateTime
(
DateUtil
.
getCurrentDateTime
());
int
res
=
baseMapper
.
insert
(
autoMainRel
);
if
(
res
<=
CommonConstants
.
ZERO_INT
){
return
R
.
failed
(
CommonConstants
.
SAVE_FAILED
);
}
// 新增字典项
if
(
Common
.
isNotNull
(
autoDictItems
))
{
for
(
SysAutoDictItem
sysAutoDictItem:
autoDictItems
){
//初始化字典信息
initDictItem
(
sysAutoDictItem
,
user
,
autoDict
,
autoMainRel
);
sysAutoDictItem
.
setCreateTime
(
LocalDateTime
.
now
());
sysAutoDictItem
.
setCreateBy
(
user
.
getId
());
sysAutoDictItem
.
setCreateName
(
user
.
getNickname
());
autoDictItemMapper
.
insert
(
sysAutoDictItem
);
}
}
//新增档案规则
if
(
Common
.
isNotNull
(
autoEmpRuleInfo
)){
autoEmpRuleInfo
.
setDeptNo
(
autoMainRel
.
getDeptNo
());
autoEmpRuleInfo
.
setDeptId
(
autoMainRel
.
getDeptId
());
autoEmpRuleInfo
.
setMainId
(
autoMainRel
.
getId
());
autoEmpRuleInfoMapper
.
insert
(
autoEmpRuleInfo
);
}
return
R
.
ok
();
}
catch
(
Exception
e
){
// 捕获异常并返回友好提示
return
R
.
failed
(
"系统异常:"
+
e
.
getMessage
());
}
//新增档案规则
if
(
Common
.
isNotNull
(
autoEmpRuleInfo
)){
autoEmpRuleInfo
.
setDeptNo
(
autoMainRel
.
getDeptNo
());
autoEmpRuleInfo
.
setDeptId
(
autoMainRel
.
getDeptId
());
autoEmpRuleInfo
.
setMainId
(
autoMainRel
.
getId
());
autoEmpRuleInfoMapper
.
insert
(
autoEmpRuleInfo
);
}
/**
* 检查字典项是否有重复标签
*/
private
boolean
checkDictItemsForDuplicates
(
List
<
SysAutoDictItem
>
autoDictItems
)
{
Set
<
String
>
repeatItems
=
new
HashSet
<>();
for
(
SysAutoDictItem
item
:
autoDictItems
)
{
if
(
Common
.
isEmpty
(
item
.
getLabel
()))
{
return
false
;
// 标签为空视为无效
}
if
(!
repeatItems
.
add
(
item
.
getLabel
()))
{
return
false
;
// 标签重复
}
}
return
R
.
ok
()
;
return
true
;
}
/**
* @Author fxj
...
...
@@ -310,113 +330,168 @@ public class TAutoMainRelServiceImpl extends ServiceImpl<TAutoMainRelMapper, TAu
* @Date 10:24 2025/3/14
**/
@Override
/**
* 更新关联信息方法
*
* @param entity 包含要更新的关联信息的实体对象
* @return 返回一个表示操作结果的响应对象
*/
public
R
<
Boolean
>
updateAsso
(
TAutoMainRelAddVo
entity
)
{
YifuUser
user
=
SecurityUtils
.
getUser
();
if
(
Common
.
isEmpty
(
user
)){
return
R
.
failed
(
CommonConstants
.
USER_FAIL
);
}
if
(
Common
.
isEmpty
(
entity
)){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
TAutoMainRel
autoMainRel
=
entity
.
getAutoMainRel
();
if
(
Common
.
isEmpty
(
autoMainRel
)
||
Common
.
isEmpty
(
autoMainRel
.
getId
())){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
TAutoMainRel
autoMainRelOld
=
baseMapper
.
selectById
(
autoMainRel
.
getId
());
if
(!
Common
.
isNotNull
(
autoMainRelOld
)){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
SysAutoDict
autoDict
=
autoDictMapper
.
selectOne
(
Wrappers
.<
SysAutoDict
>
query
().
lambda
()
.
eq
(
SysAutoDict:
:
getType
,
CommonConstants
.
POST_TYPE
).
last
(
CommonConstants
.
LAST_ONE_SQL
));
if
(
Common
.
isEmpty
(
autoDict
)){
return
R
.
failed
(
CommonConstants
.
INIT_DATA_GET_FAIL
);
}
TAutoEmpRuleInfo
autoEmpRuleNew
=
entity
.
getAutoEmpRuleInfo
();
TAutoEmpRuleInfo
autoEmpRuleOld
=
null
;
if
(
Common
.
isNotNull
(
autoEmpRuleNew
)){
if
(!
Common
.
isNotNull
(
autoEmpRuleNew
.
getId
())){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
autoEmpRuleOld
=
autoEmpRuleInfoMapper
.
selectById
(
autoEmpRuleNew
.
getId
());
ExcelUtil
<
TAutoEmpRuleInfo
>
excelUtil
=
new
ExcelUtil
<>(
TAutoEmpRuleInfo
.
class
);
ErrorMessage
errorMessage
=
excelUtil
.
checkEntity
(
autoEmpRuleNew
,
0
);
if
(
Common
.
isNotNull
(
errorMessage
)){
return
R
.
failed
(
errorMessage
.
getMessage
());
}
}
//更新岗位字典
List
<
SysAutoDictItem
>
autoDictItems
=
entity
.
getAutoDictItems
();
Map
<
String
,
SysAutoDictItem
>
repeatItems
=
new
HashMap
<>();
//更新岗位字典
List
<
SysAutoDictItem
>
oldAutoDictItems
=
autoDictItemMapper
.
selectList
(
Wrappers
.<
SysAutoDictItem
>
query
()
.
lambda
().
eq
(
SysAutoDictItem:
:
getDeptNo
,
autoMainRel
.
getDeptNo
())
.
eq
(
SysAutoDictItem:
:
getDisable
,
CommonConstants
.
ZERO_STRING
));
if
(
Common
.
isNotNull
(
oldAutoDictItems
)){
repeatItems
=
oldAutoDictItems
.
stream
().
collect
(
Collectors
.
toMap
(
SysAutoDictItem:
:
getLabel
,
v
->
v
));
}
//检验岗位字典是否重复
R
<
Boolean
>
checkRes
=
checkItemRepeat
(
autoDictItems
,
repeatItems
);
if
(
checkRes
!=
null
){
return
checkRes
;
}
//更新主表
autoMainRel
.
setRuleUpdatePerson
(
user
.
getNickname
());
autoMainRel
.
setRuleUpdateTime
(
DateUtil
.
getCurrentDateTime
());
baseMapper
.
updateById
(
autoMainRel
);
Map
<
String
,
String
>
diffKeyMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
oldMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
newMap
=
new
HashMap
<>();
if
(!
autoMainRel
.
getPostFlag
().
equals
(
autoMainRelOld
.
getPostFlag
())){
oldMap
.
put
(
"oldRuleRel"
,
autoMainRelOld
);
newMap
.
put
(
"newRuleRel"
,
autoMainRel
);
diffKeyMap
.
put
(
"ruleRel"
,
"postFlag"
);
}
// 获取当前用户信息
YifuUser
user
=
SecurityUtils
.
getUser
();
// 如果用户信息为空,则返回用户获取失败的响应
if
(
Common
.
isEmpty
(
user
)){
return
R
.
failed
(
CommonConstants
.
USER_FAIL
);
}
// 如果传入的实体对象为空,则返回参数错误的响应
if
(
Common
.
isEmpty
(
entity
)){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
// 获取实体对象中的关联信息
TAutoMainRel
autoMainRel
=
entity
.
getAutoMainRel
();
// 如果关联信息或其ID为空,则返回参数错误的响应
if
(
Common
.
isEmpty
(
autoMainRel
)
||
Common
.
isEmpty
(
autoMainRel
.
getId
())){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
// 根据ID查询原有的关联信息
TAutoMainRel
autoMainRelOld
=
baseMapper
.
selectById
(
autoMainRel
.
getId
());
// 如果查询结果为空,则返回参数错误的响应
if
(!
Common
.
isNotNull
(
autoMainRelOld
)){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
// 查询岗位字典信息
SysAutoDict
autoDict
=
autoDictMapper
.
selectOne
(
Wrappers
.<
SysAutoDict
>
query
().
lambda
()
.
eq
(
SysAutoDict:
:
getType
,
CommonConstants
.
POST_TYPE
).
last
(
CommonConstants
.
LAST_ONE_SQL
));
// 如果岗位字典信息为空,则返回数据初始化失败的响应
if
(
Common
.
isEmpty
(
autoDict
)){
return
R
.
failed
(
CommonConstants
.
INIT_DATA_GET_FAIL
);
}
// 获取实体对象中的员工规则信息
TAutoEmpRuleInfo
autoEmpRuleNew
=
entity
.
getAutoEmpRuleInfo
();
TAutoEmpRuleInfo
autoEmpRuleOld
=
null
;
// 如果员工规则信息不为空
if
(
Common
.
isNotNull
(
autoEmpRuleNew
)){
// 如果员工规则信息的ID为空,则返回参数错误的响应
if
(!
Common
.
isNotNull
(
autoEmpRuleNew
.
getId
())){
return
R
.
failed
(
CommonConstants
.
PARAM_IS_NOT_ERROR
);
}
// 根据ID查询原有的员工规则信息
autoEmpRuleOld
=
autoEmpRuleInfoMapper
.
selectById
(
autoEmpRuleNew
.
getId
());
// 创建Excel工具对象
ExcelUtil
<
TAutoEmpRuleInfo
>
excelUtil
=
new
ExcelUtil
<>(
TAutoEmpRuleInfo
.
class
);
// 检查员工规则信息的有效性
ErrorMessage
errorMessage
=
excelUtil
.
checkEntity
(
autoEmpRuleNew
,
0
);
// 如果检查结果不为空,则返回检查错误信息的响应
if
(
Common
.
isNotNull
(
errorMessage
)){
return
R
.
failed
(
errorMessage
.
getMessage
());
}
}
// 更新岗位字典
List
<
SysAutoDictItem
>
autoDictItems
=
entity
.
getAutoDictItems
();
Map
<
String
,
SysAutoDictItem
>
repeatItems
=
new
HashMap
<>();
// 更新岗位字典
List
<
SysAutoDictItem
>
oldAutoDictItems
=
autoDictItemMapper
.
selectList
(
Wrappers
.<
SysAutoDictItem
>
query
()
.
lambda
().
eq
(
SysAutoDictItem:
:
getDeptNo
,
autoMainRel
.
getDeptNo
())
.
eq
(
SysAutoDictItem:
:
getDisable
,
CommonConstants
.
ZERO_STRING
));
// 如果查询到旧的岗位字典项
if
(
Common
.
isNotNull
(
oldAutoDictItems
)){
repeatItems
=
oldAutoDictItems
.
stream
().
collect
(
Collectors
.
toMap
(
SysAutoDictItem:
:
getLabel
,
v
->
v
));
}
// 检验岗位字典是否重复
R
<
Boolean
>
checkRes
=
checkItemRepeat
(
autoDictItems
,
repeatItems
);
// 如果检验结果不为空,则返回检验结果
if
(
checkRes
!=
null
){
return
checkRes
;
}
// 更新主表
autoMainRel
.
setRuleUpdatePerson
(
user
.
getNickname
());
autoMainRel
.
setRuleUpdateTime
(
DateUtil
.
getCurrentDateTime
());
baseMapper
.
updateById
(
autoMainRel
);
// 初始化差异键值对映射
Map
<
String
,
String
>
diffKeyMap
=
new
HashMap
<>();
// 初始化旧数据和新数据映射
Map
<
String
,
Object
>
oldMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
newMap
=
new
HashMap
<>();
// 比较并记录关联信息的变化
if
(!
autoMainRel
.
getPostFlag
().
equals
(
autoMainRelOld
.
getPostFlag
())){
oldMap
.
put
(
"oldRuleRel"
,
autoMainRelOld
);
newMap
.
put
(
"newRuleRel"
,
autoMainRel
);
diffKeyMap
.
put
(
"ruleRel"
,
"postFlag"
);
}
//处理岗位字典数据
dictItemHandle
(
user
,
autoMainRel
,
autoDict
,
diffKeyMap
,
autoDictItems
,
oldAutoDictItems
);
oldMap
.
put
(
"oldItems"
,
oldAutoDictItems
);
newMap
.
put
(
"newItems"
,
autoDictItems
);
//更新档案管理规则
if
(
Common
.
isNotNull
(
autoEmpRuleNew
)){
oldMap
.
put
(
"oldEmpRule"
,
autoEmpRuleOld
);
newMap
.
put
(
"newEmpRule"
,
autoEmpRuleNew
);
List
<
String
>
ignoreFields
=
new
ArrayList
<>();
ignoreFields
.
add
(
"mainId"
);
ignoreFields
.
add
(
"createBy"
);
ignoreFields
.
add
(
"createName"
);
ignoreFields
.
add
(
"createTime"
);
ignoreFields
.
add
(
"deptId"
);
String
differenceKey
=
HrEquator
.
comparisonValueIgnoreField
(
autoEmpRuleOld
,
autoEmpRuleNew
,
ignoreFields
);
if
(!
Common
.
isEmpty
(
differenceKey
)){
diffKeyMap
.
put
(
"empRule"
,
differenceKey
);
}
autoEmpRuleNew
.
setDeptNo
(
autoMainRel
.
getDeptNo
());
autoEmpRuleNew
.
setDeptId
(
autoMainRel
.
getDeptId
());
autoEmpRuleNew
.
setMainId
(
autoMainRel
.
getId
());
autoEmpRuleInfoMapper
.
updateById
(
autoEmpRuleNew
);
}
//插入变更日志
insertLog
(
autoMainRel
,
diffKeyMap
,
oldMap
,
newMap
);
return
R
.
ok
(
true
,
CommonConstants
.
UPDATE_SUCCESS
);
// 处理岗位字典数据
dictItemHandle
(
user
,
autoMainRel
,
autoDict
,
diffKeyMap
,
autoDictItems
,
oldAutoDictItems
);
oldMap
.
put
(
"oldItems"
,
oldAutoDictItems
);
newMap
.
put
(
"newItems"
,
autoDictItems
);
// 更新档案管理规则
if
(
Common
.
isNotNull
(
autoEmpRuleNew
)){
oldMap
.
put
(
"oldEmpRule"
,
autoEmpRuleOld
);
newMap
.
put
(
"newEmpRule"
,
autoEmpRuleNew
);
List
<
String
>
ignoreFields
=
new
ArrayList
<>();
ignoreFields
.
add
(
"mainId"
);
ignoreFields
.
add
(
"createBy"
);
ignoreFields
.
add
(
"createName"
);
ignoreFields
.
add
(
"createTime"
);
ignoreFields
.
add
(
"deptId"
);
String
differenceKey
=
HrEquator
.
comparisonValueIgnoreField
(
autoEmpRuleOld
,
autoEmpRuleNew
,
ignoreFields
);
if
(!
Common
.
isEmpty
(
differenceKey
)){
diffKeyMap
.
put
(
"empRule"
,
differenceKey
);
}
autoEmpRuleNew
.
setDeptNo
(
autoMainRel
.
getDeptNo
());
autoEmpRuleNew
.
setDeptId
(
autoMainRel
.
getDeptId
());
autoEmpRuleNew
.
setMainId
(
autoMainRel
.
getId
());
autoEmpRuleInfoMapper
.
updateById
(
autoEmpRuleNew
);
}
// 插入变更日志
insertLog
(
autoMainRel
,
diffKeyMap
,
oldMap
,
newMap
);
// 返回更新成功的响应
return
R
.
ok
(
true
,
CommonConstants
.
UPDATE_SUCCESS
);
}
private
R
<
Boolean
>
checkItemRepeat
(
List
<
SysAutoDictItem
>
autoDictItems
,
Map
<
String
,
SysAutoDictItem
>
repeatItems
)
{
SysAutoDictItem
checkItem
;
for
(
SysAutoDictItem
item:
autoDictItems
)
{
if
(
Common
.
isNotNull
(
repeatItems
))
{
checkItem
=
repeatItems
.
get
(
item
.
getLabel
());
if
(
null
!=
checkItem
&&
item
.
getLabel
().
equals
(
checkItem
.
getLabel
())
&&
CommonConstants
.
ZERO_STRING
.
equals
(
checkItem
.
getDisable
())
&&
(
Common
.
isEmpty
(
checkItem
.
getId
())
||
!
checkItem
.
getId
().
equals
(
item
.
getId
()))
){
return
R
.
failed
(
itemsLabelRepeat
);
}
repeatItems
.
put
(
item
.
getLabel
(),
item
);
}
}
return
null
;
}
/**
* 检查字典项列表中是否存在重复的标签
* 此方法用于确保在同一字典下不存在重复的字典项标签
* 它通过比较给定的字典项列表与一个用于跟踪重复项的映射来实现这一点
*
* @param autoDictItems 字典项列表,用于检查重复的标签
* @param repeatItems 一个映射,用于跟踪已经遇到的字典项,键为字典项标签
* @return 如果存在重复且未被禁用的字典项,则返回一个表示失败的结果对象;
* 否则,返回 null 表示检查通过或输入参数为空
*/
private
R
<
Boolean
>
checkItemRepeat
(
List
<
SysAutoDictItem
>
autoDictItems
,
Map
<
String
,
SysAutoDictItem
>
repeatItems
)
{
// 校验输入参数是否为 null
if
(
Common
.
isEmpty
(
autoDictItems
)
||
Common
.
isEmpty
(
repeatItems
))
{
return
null
;
// 根据业务需求决定返回值
}
for
(
SysAutoDictItem
item
:
autoDictItems
)
{
if
(
Common
.
isEmpty
(
item
)
||
Common
.
isEmpty
(
item
.
getLabel
()))
{
continue
;
// 跳过无效的 item
}
SysAutoDictItem
checkItem
=
repeatItems
.
get
(
item
.
getLabel
());
if
(
checkItem
!=
null
)
{
// 检查是否存在重复项
if
(
CommonConstants
.
ZERO_STRING
.
equals
(
checkItem
.
getDisable
())
&&
(
Common
.
isEmpty
(
checkItem
.
getId
())
||
!
checkItem
.
getId
().
equals
(
item
.
getId
())))
{
return
R
.
failed
(
itemsLabelRepeat
);
}
}
// 将当前 item 放入 repeatItems 中
try
{
repeatItems
.
put
(
item
.
getLabel
(),
item
);
}
catch
(
Exception
e
)
{
// 捕获异常并记录日志(根据实际需求决定是否抛出)
log
.
error
(
"校验字典重复时异常: "
+
e
.
getMessage
());
return
R
.
failed
(
"Internal error occurred"
);
}
}
return
null
;
}
private
void
dictItemHandle
(
YifuUser
user
,
TAutoMainRel
autoMainRel
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment