Commit a736e392 authored by fangxinjiang's avatar fangxinjiang

项目规则配置-fxj

parent 72f7b228
......@@ -42,6 +42,7 @@ import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
......@@ -336,6 +337,7 @@ public class TAutoMainRelServiceImpl extends ServiceImpl<TAutoMainRelMapper, TAu
* @param entity 包含要更新的关联信息的实体对象
* @return 返回一个表示操作结果的响应对象
*/
@Transactional
public R<Boolean> updateAsso(TAutoMainRelAddVo entity) {
// 获取当前用户信息
YifuUser user = SecurityUtils.getUser();
......@@ -492,7 +494,11 @@ private R<Boolean> checkItemRepeat(List<SysAutoDictItem> autoDictItems, Map<Stri
}
/**
* @Author fxj
* @Description 功能概述:dictItemHandle 方法用于处理字典项的更新或新增操作,同时记录差异字段。
* @Date 17:09 2025/3/20
**/
private void dictItemHandle(YifuUser user,
TAutoMainRel autoMainRel,
SysAutoDict autoDict,
......@@ -501,49 +507,49 @@ private R<Boolean> checkItemRepeat(List<SysAutoDictItem> autoDictItems, Map<Stri
List<SysAutoDictItem> oldAutoDictItems) {
if (Common.isNotNull(autoDictItems)){
// 初始化旧字典项映射
Map<Long, SysAutoDictItem> oldItemMap = null;
if (Common.isNotNull(oldAutoDictItems)){
oldItemMap = oldAutoDictItems.stream().collect(Collectors.toMap(SysAutoDictItem::getId, v->v));
}
SysAutoDictItem oldItem;
String diffKey;
StringBuilder difkeys = new StringBuilder("");
List<String> ignore = new ArrayList<>();
ignore.add("value,sortOrder");
// 初始化差异字段存储
Set<String> diffKeysSet = new HashSet<>();
List<String> ignoreFields = Arrays.asList("value", "sortOrder");
for(SysAutoDictItem sysAutoDictItem : autoDictItems){
initDictItem(sysAutoDictItem, user, autoDict, autoMainRel);
if (Common.isNotNull(sysAutoDictItem.getId())){
oldItem = null==oldItemMap?null:oldItemMap.get(sysAutoDictItem.getId());
if (Common.isNotNull(oldItem)){
diffKey = HrEquator.comparisonValueIgnoreField(oldItem, sysAutoDictItem,ignore);
if (Common.isNotNull(diffKey)){
if (Common.isEmpty(difkeys.toString())){
difkeys.append(diffKey);
}else {
difkeys.append(CommonConstants.COMMA_STRING);
difkeys.append(diffKey);
}
if (Common.isNotNull(oldItem)) {
diffKey = HrEquator.comparisonValueIgnoreField(oldItem, sysAutoDictItem, ignoreFields);
if (Common.isNotNull(diffKey)) {
diffKeysSet.add(diffKey);
}
}
autoDictItemMapper.updateById(sysAutoDictItem);
}else {
if (Common.isEmpty(difkeys.toString())){
difkeys.append(itemsLabel);
}else {
difkeys.append(CommonConstants.COMMA_STRING);
difkeys.append(itemsLabel);
try {
autoDictItemMapper.updateById(sysAutoDictItem);
} catch (Exception e) {
// 记录异常日志并继续处理其他项
log.error("Failed to update dictionary item with ID: {}", sysAutoDictItem.getId(), e);
}
}else {
diffKeysSet.add(itemsLabel);
sysAutoDictItem.setCreateTime(LocalDateTime.now());
sysAutoDictItem.setCreateBy(user.getId());
sysAutoDictItem.setCreateName(user.getNickname());
autoDictItemMapper.insert(sysAutoDictItem);
try {
autoDictItemMapper.insert(sysAutoDictItem);
} catch (Exception e) {
// 记录异常日志并继续处理其他项
log.error("Failed to insert dictionary item: {}", sysAutoDictItem, e);
}
}
}
if (!Common.isEmpty(difkeys.toString())){
String[] keys = difkeys.toString().split(CommonConstants.COMMA_STRING);
String keysStr = Arrays.stream(keys).distinct().collect(Collectors.joining(CommonConstants.COMMA_STRING));
diffKeyMap.put("postType",keysStr);
// 将差异字段集合转换为字符串并存入 diffKeyMap
if (!diffKeysSet.isEmpty()) {
String keysStr = String.join(CommonConstants.COMMA_STRING, diffKeysSet);
diffKeyMap.put("postType", keysStr);
}
}
}
......
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