Commit 72f7b228 authored by fangxinjiang's avatar fangxinjiang

项目规则配置-fxj

parent 0cd4bcfd
...@@ -236,73 +236,93 @@ public class TAutoMainRelServiceImpl extends ServiceImpl<TAutoMainRelMapper, TAu ...@@ -236,73 +236,93 @@ public class TAutoMainRelServiceImpl extends ServiceImpl<TAutoMainRelMapper, TAu
**/ **/
@Override @Override
public R<Boolean> saveAsso(TAutoMainRelAddVo entity) { public R<Boolean> saveAsso(TAutoMainRelAddVo entity) {
// 校验用户信息
YifuUser user = SecurityUtils.getUser(); YifuUser user = SecurityUtils.getUser();
if (Common.isEmpty(user)){ if (Common.isEmpty(user)){
return R.failed(CommonConstants.USER_FAIL); 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); return R.failed(CommonConstants.PARAM_IS_NOT_ERROR);
} }
TAutoMainRel autoMainRel = entity.getAutoMainRel(); TAutoMainRel autoMainRel = entity.getAutoMainRel();
if (Common.isEmpty(autoMainRel) if (Common.isEmpty(autoMainRel.getDeptId()) || Common.isEmpty(autoMainRel.getDeptNo())) {
|| Common.isEmpty(autoMainRel.getDeptId())
|| Common.isEmpty(autoMainRel.getDeptNo())){
return R.failed(CommonConstants.PARAM_IS_NOT_ERROR); return R.failed(CommonConstants.PARAM_IS_NOT_ERROR);
} }
TAutoMainRel existRel = baseMapper.selectOne(Wrappers.<TAutoMainRel>query().lambda() try {
.eq(TAutoMainRel::getDeptNo,autoMainRel.getDeptNo()).last(CommonConstants.LAST_ONE_SQL)); // 校验是否存在重复规则配置
if (!Common.isEmpty(existRel)){ TAutoMainRel existRel = baseMapper.selectOne(Wrappers.<TAutoMainRel>query().lambda()
return R.failed("已存在对应项目规则配置!"); .eq(TAutoMainRel::getDeptNo,autoMainRel.getDeptNo()).last(CommonConstants.LAST_ONE_SQL));
} if (!Common.isEmpty(existRel)){
SysAutoDict autoDict = autoDictMapper.selectOne(Wrappers.<SysAutoDict>query().lambda() return R.failed("已存在对应项目规则配置!");
.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());
} }
} // 获取岗位字典
//新增岗位字典 SysAutoDict autoDict = autoDictMapper.selectOne(Wrappers.<SysAutoDict>query().lambda()
List<SysAutoDictItem> autoDictItems = entity.getAutoDictItems(); .eq(SysAutoDict::getType,CommonConstants.POST_TYPE).last(CommonConstants.LAST_ONE_SQL));
Set<String> repeatItems = new HashSet<>(); if (Common.isEmpty(autoDict)){
for (SysAutoDictItem item:autoDictItems) { return R.failed(CommonConstants.INIT_DATA_GET_FAIL);
if (repeatItems.contains(item.getLabel())) { }
// 校验员工规则信息
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); return R.failed(itemsLabelRepeat);
}else{
repeatItems.add(item.getLabel());
} }
} //新增主表
//新增主表 autoMainRel.setRuleUpdatePerson(user.getNickname());
autoMainRel.setRuleUpdatePerson(user.getNickname()); autoMainRel.setRuleUpdateTime(DateUtil.getCurrentDateTime());
autoMainRel.setRuleUpdateTime(DateUtil.getCurrentDateTime()); int res = baseMapper.insert(autoMainRel);
int res = baseMapper.insert(autoMainRel); if (res <= CommonConstants.ZERO_INT){
if (res <= CommonConstants.ZERO_INT){ return R.failed(CommonConstants.SAVE_FAILED);
return R.failed(CommonConstants.SAVE_FAILED); }
} // 新增字典项
if (Common.isNotNull(autoDictItems)) {
if (Common.isNotNull(autoDictItems)) { for (SysAutoDictItem sysAutoDictItem:autoDictItems){
for (SysAutoDictItem sysAutoDictItem:autoDictItems){ //初始化字典信息
//初始化字典信息 initDictItem(sysAutoDictItem, user, autoDict, autoMainRel);
initDictItem(sysAutoDictItem, user, autoDict, autoMainRel); sysAutoDictItem.setCreateTime(LocalDateTime.now());
sysAutoDictItem.setCreateTime(LocalDateTime.now()); sysAutoDictItem.setCreateBy(user.getId());
sysAutoDictItem.setCreateBy(user.getId()); sysAutoDictItem.setCreateName(user.getNickname());
sysAutoDictItem.setCreateName(user.getNickname()); autoDictItemMapper.insert(sysAutoDictItem);
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()); private boolean checkDictItemsForDuplicates(List<SysAutoDictItem> autoDictItems) {
autoEmpRuleInfoMapper.insert(autoEmpRuleInfo); 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 * @Author fxj
...@@ -310,113 +330,168 @@ public class TAutoMainRelServiceImpl extends ServiceImpl<TAutoMainRelMapper, TAu ...@@ -310,113 +330,168 @@ public class TAutoMainRelServiceImpl extends ServiceImpl<TAutoMainRelMapper, TAu
* @Date 10:24 2025/3/14 * @Date 10:24 2025/3/14
**/ **/
@Override @Override
/**
* 更新关联信息方法
*
* @param entity 包含要更新的关联信息的实体对象
* @return 返回一个表示操作结果的响应对象
*/
public R<Boolean> updateAsso(TAutoMainRelAddVo entity) { public R<Boolean> updateAsso(TAutoMainRelAddVo entity) {
YifuUser user = SecurityUtils.getUser(); // 获取当前用户信息
if (Common.isEmpty(user)){ YifuUser user = SecurityUtils.getUser();
return R.failed(CommonConstants.USER_FAIL); // 如果用户信息为空,则返回用户获取失败的响应
} if (Common.isEmpty(user)){
if (Common.isEmpty(entity)){ return R.failed(CommonConstants.USER_FAIL);
return R.failed(CommonConstants.PARAM_IS_NOT_ERROR); }
} // 如果传入的实体对象为空,则返回参数错误的响应
TAutoMainRel autoMainRel = entity.getAutoMainRel(); if (Common.isEmpty(entity)){
if (Common.isEmpty(autoMainRel) || Common.isEmpty(autoMainRel.getId())){ return R.failed(CommonConstants.PARAM_IS_NOT_ERROR);
return R.failed(CommonConstants.PARAM_IS_NOT_ERROR); }
} // 获取实体对象中的关联信息
TAutoMainRel autoMainRelOld = baseMapper.selectById(autoMainRel.getId()); TAutoMainRel autoMainRel = entity.getAutoMainRel();
if (!Common.isNotNull(autoMainRelOld)){ // 如果关联信息或其ID为空,则返回参数错误的响应
return R.failed(CommonConstants.PARAM_IS_NOT_ERROR); if (Common.isEmpty(autoMainRel) || Common.isEmpty(autoMainRel.getId())){
} 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)); // 根据ID查询原有的关联信息
if (Common.isEmpty(autoDict)){ TAutoMainRel autoMainRelOld = baseMapper.selectById(autoMainRel.getId());
return R.failed(CommonConstants.INIT_DATA_GET_FAIL); // 如果查询结果为空,则返回参数错误的响应
} if (!Common.isNotNull(autoMainRelOld)){
TAutoEmpRuleInfo autoEmpRuleNew = entity.getAutoEmpRuleInfo(); return R.failed(CommonConstants.PARAM_IS_NOT_ERROR);
TAutoEmpRuleInfo autoEmpRuleOld = null; }
if (Common.isNotNull(autoEmpRuleNew)){ // 查询岗位字典信息
if (!Common.isNotNull(autoEmpRuleNew.getId())){ SysAutoDict autoDict = autoDictMapper.selectOne(Wrappers.<SysAutoDict>query().lambda()
return R.failed(CommonConstants.PARAM_IS_NOT_ERROR); .eq(SysAutoDict::getType,CommonConstants.POST_TYPE).last(CommonConstants.LAST_ONE_SQL));
} // 如果岗位字典信息为空,则返回数据初始化失败的响应
autoEmpRuleOld = autoEmpRuleInfoMapper.selectById(autoEmpRuleNew.getId()); if (Common.isEmpty(autoDict)){
ExcelUtil<TAutoEmpRuleInfo> excelUtil = new ExcelUtil<>(TAutoEmpRuleInfo.class); return R.failed(CommonConstants.INIT_DATA_GET_FAIL);
ErrorMessage errorMessage = excelUtil.checkEntity(autoEmpRuleNew,0); }
if (Common.isNotNull(errorMessage)){ // 获取实体对象中的员工规则信息
return R.failed(errorMessage.getMessage()); TAutoEmpRuleInfo autoEmpRuleNew = entity.getAutoEmpRuleInfo();
} TAutoEmpRuleInfo autoEmpRuleOld = null;
} // 如果员工规则信息不为空
//更新岗位字典 if (Common.isNotNull(autoEmpRuleNew)){
List<SysAutoDictItem> autoDictItems = entity.getAutoDictItems(); // 如果员工规则信息的ID为空,则返回参数错误的响应
Map<String,SysAutoDictItem> repeatItems = new HashMap<>(); if (!Common.isNotNull(autoEmpRuleNew.getId())){
//更新岗位字典 return R.failed(CommonConstants.PARAM_IS_NOT_ERROR);
List<SysAutoDictItem> oldAutoDictItems = autoDictItemMapper.selectList(Wrappers.<SysAutoDictItem>query() }
.lambda().eq(SysAutoDictItem::getDeptNo,autoMainRel.getDeptNo()) // 根据ID查询原有的员工规则信息
.eq(SysAutoDictItem::getDisable,CommonConstants.ZERO_STRING)); autoEmpRuleOld = autoEmpRuleInfoMapper.selectById(autoEmpRuleNew.getId());
if (Common.isNotNull(oldAutoDictItems)){ // 创建Excel工具对象
repeatItems = oldAutoDictItems.stream().collect(Collectors.toMap(SysAutoDictItem::getLabel,v->v)); ExcelUtil<TAutoEmpRuleInfo> excelUtil = new ExcelUtil<>(TAutoEmpRuleInfo.class);
} // 检查员工规则信息的有效性
//检验岗位字典是否重复 ErrorMessage errorMessage = excelUtil.checkEntity(autoEmpRuleNew,0);
R<Boolean> checkRes = checkItemRepeat(autoDictItems, repeatItems); // 如果检查结果不为空,则返回检查错误信息的响应
if (checkRes != null){ if (Common.isNotNull(errorMessage)){
return checkRes; return R.failed(errorMessage.getMessage());
} }
//更新主表 }
autoMainRel.setRuleUpdatePerson(user.getNickname()); // 更新岗位字典
autoMainRel.setRuleUpdateTime(DateUtil.getCurrentDateTime()); List<SysAutoDictItem> autoDictItems = entity.getAutoDictItems();
baseMapper.updateById(autoMainRel); Map<String,SysAutoDictItem> repeatItems = new HashMap<>();
Map<String,String> diffKeyMap = new HashMap<>(); // 更新岗位字典
Map<String,Object> oldMap = new HashMap<>(); List<SysAutoDictItem> oldAutoDictItems = autoDictItemMapper.selectList(Wrappers.<SysAutoDictItem>query()
Map<String,Object> newMap = new HashMap<>(); .lambda().eq(SysAutoDictItem::getDeptNo,autoMainRel.getDeptNo())
if (!autoMainRel.getPostFlag().equals(autoMainRelOld.getPostFlag())){ .eq(SysAutoDictItem::getDisable,CommonConstants.ZERO_STRING));
oldMap.put("oldRuleRel",autoMainRelOld); // 如果查询到旧的岗位字典项
newMap.put("newRuleRel",autoMainRel); if (Common.isNotNull(oldAutoDictItems)){
diffKeyMap.put("ruleRel","postFlag"); 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); dictItemHandle(user, autoMainRel, autoDict, diffKeyMap, autoDictItems,oldAutoDictItems);
oldMap.put("oldItems",oldAutoDictItems); oldMap.put("oldItems",oldAutoDictItems);
newMap.put("newItems",autoDictItems); newMap.put("newItems",autoDictItems);
//更新档案管理规则 // 更新档案管理规则
if (Common.isNotNull(autoEmpRuleNew)){ if (Common.isNotNull(autoEmpRuleNew)){
oldMap.put("oldEmpRule",autoEmpRuleOld); oldMap.put("oldEmpRule",autoEmpRuleOld);
newMap.put("newEmpRule",autoEmpRuleNew); newMap.put("newEmpRule",autoEmpRuleNew);
List<String> ignoreFields = new ArrayList<>(); List<String> ignoreFields = new ArrayList<>();
ignoreFields.add("mainId"); ignoreFields.add("mainId");
ignoreFields.add("createBy"); ignoreFields.add("createBy");
ignoreFields.add("createName"); ignoreFields.add("createName");
ignoreFields.add("createTime"); ignoreFields.add("createTime");
ignoreFields.add("deptId"); ignoreFields.add("deptId");
String differenceKey = HrEquator.comparisonValueIgnoreField(autoEmpRuleOld, autoEmpRuleNew,ignoreFields); String differenceKey = HrEquator.comparisonValueIgnoreField(autoEmpRuleOld, autoEmpRuleNew,ignoreFields);
if (!Common.isEmpty(differenceKey)){ if (!Common.isEmpty(differenceKey)){
diffKeyMap.put("empRule",differenceKey); diffKeyMap.put("empRule",differenceKey);
} }
autoEmpRuleNew.setDeptNo(autoMainRel.getDeptNo()); autoEmpRuleNew.setDeptNo(autoMainRel.getDeptNo());
autoEmpRuleNew.setDeptId(autoMainRel.getDeptId()); autoEmpRuleNew.setDeptId(autoMainRel.getDeptId());
autoEmpRuleNew.setMainId(autoMainRel.getId()); autoEmpRuleNew.setMainId(autoMainRel.getId());
autoEmpRuleInfoMapper.updateById(autoEmpRuleNew); autoEmpRuleInfoMapper.updateById(autoEmpRuleNew);
} }
//插入变更日志 // 插入变更日志
insertLog(autoMainRel, diffKeyMap, oldMap, newMap); insertLog(autoMainRel, diffKeyMap, oldMap, newMap);
return R.ok(true,CommonConstants.UPDATE_SUCCESS); // 返回更新成功的响应
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 * @param autoDictItems 字典项列表,用于检查重复的标签
&& item.getLabel().equals(checkItem.getLabel()) * @param repeatItems 一个映射,用于跟踪已经遇到的字典项,键为字典项标签
&& CommonConstants.ZERO_STRING.equals(checkItem.getDisable()) * @return 如果存在重复且未被禁用的字典项,则返回一个表示失败的结果对象;
&& (Common.isEmpty(checkItem.getId()) || !checkItem.getId().equals(item.getId())) * 否则,返回 null 表示检查通过或输入参数为空
){ */
return R.failed(itemsLabelRepeat); private R<Boolean> checkItemRepeat(List<SysAutoDictItem> autoDictItems, Map<String, SysAutoDictItem> repeatItems) {
} // 校验输入参数是否为 null
repeatItems.put(item.getLabel(),item); if (Common.isEmpty(autoDictItems) || Common.isEmpty(repeatItems)) {
} return null; // 根据业务需求决定返回值
} }
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, private void dictItemHandle(YifuUser user,
TAutoMainRel autoMainRel, TAutoMainRel autoMainRel,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment