This commit is contained in:
张秉卓
2026-01-22 17:24:51 +08:00
parent 989dd66a20
commit ca095be435
5 changed files with 171 additions and 16 deletions

View File

@ -0,0 +1,28 @@
package com.xjrsoft.module.datalog.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class CompareResultVo<T> {
/**
* 最新版本
*/
@ApiModelProperty("最新版本")
private T newBean;
/**
* 旧版本
*/
@ApiModelProperty("旧版本")
private T oldBean;
/**
* 比对结果
*/
@ApiModelProperty("比对结果")
private List<String> diffResultList;
}

View File

@ -0,0 +1,116 @@
package com.pictc.utils;
import org.apache.commons.collections4.CollectionUtils;
import java.lang.reflect.Field;
import java.util.*;
/**
* 对象差异比较工具类
* 支持嵌套对象和List集合的比较
*/
public class ObjectDiffUtils {
/**
* 比较两个对象并返回差异信息
* @param obj1 第一个对象
* @param obj2 第二个对象
* @param <T> 对象类型
* @return 差异结果列表
*/
public static <T> List<String> compare(T obj1, T obj2) {
List<String> diffs = new ArrayList<>();
if (obj1 == null || obj2 == null) {
return diffs;
}
try {
compareFields(obj1, obj2, diffs);
} catch (Exception e) {
throw new RuntimeException("Failed to compare objects", e);
}
return diffs;
}
/**
* 递归比较对象字段
*/
private static void compareFields(Object obj1, Object obj2, List<String> diffs)
throws IllegalAccessException {
Class<?> clazz = obj1.getClass();
// 获取所有字段(包括私有字段)
Field[] fields = getAllFields(clazz);
for (Field field : fields) {
field.setAccessible(true);
Object value1 = field.get(obj1);
Object value2 = field.get(obj2);
String fieldName = field.getName();
// 检查字段类型
Class<?> fieldType = field.getType();
// 如果是List类型
if (List.class.isAssignableFrom(fieldType)) {
compareLists(value1, value2, fieldName, diffs);
}
// 如果是Map类型可选扩展
else if (Map.class.isAssignableFrom(fieldType)) {
compareMaps(value1, value2, fieldName, diffs);
}
// 基本类型、String、包装类型等
else {
compareBasicValues(value1, value2, fieldName, diffs);
}
}
}
/**
* 比较两个List
*/
private static void compareLists(Object list1, Object list2, String fieldName, List<String> diffs) {
List<?> l1 = (List<?>) list1;
List<?> l2 = (List<?>) list2;
if (l1 == null || l2 == null) {
return;
}
// 比较List大小
if (l1.size() != l2.size()) {
diffs.add(fieldName);
return;
}
// 比较List中的每个元素
for (int i = 0; i < l1.size(); i++) {
List<String> result = compare(l1.get(i), l2.get(i));
if (CollectionUtils.isNotEmpty(result)) {
for (String s : result) {
diffs.add(fieldName + "["+ i +"]." + s);
}
}
}
}
/**
* 比较两个Map可选功能
*/
private static void compareMaps(Object map1, Object map2, String path, List<String> diffs) {
// Map比较的实现可根据需要扩展
}
/**
* 比较基本值
*/
private static void compareBasicValues(Object value1, Object value2, String fieldName, List<String> diffs) {
if (!Objects.equals(value1, value2)) {
diffs.add(fieldName);
}
}
/**
* 获取类及其父类的所有字段
*/
private static Field[] getAllFields(Class<?> clazz) {
List<Field> fields = new ArrayList<>();
while (clazz != null && clazz != Object.class) {
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
clazz = clazz.getSuperclass();
}
return fields.toArray(new Field[0]);
}
}

View File

@ -5,6 +5,7 @@ import com.github.yulichang.extension.mapping.base.MPJDeepService;
import com.github.yulichang.extension.mapping.base.MPJRelationService;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.module.approve.ApproveDto;
import com.xjrsoft.module.datalog.vo.CompareResultVo;
import com.xjrsoft.module.dayPlan.dto.LngPngApproPageDto;
import com.xjrsoft.module.dayPlan.dto.UpdateLngPngApproDto;
import com.xjrsoft.module.dayPlan.entity.LngPngAppro;
@ -12,7 +13,6 @@ import com.xjrsoft.module.dayPlan.vo.LngPngApproPageVo;
import com.xjrsoft.module.dayPlan.vo.LngPngApproVo;
import javax.validation.Valid;
import java.util.List;
/**
* @title: service
@ -33,5 +33,5 @@ public interface IPngApproService extends MPJBaseService<LngPngAppro>, MPJDeepSe
void approveJSZ(@Valid ApproveDto<UpdateLngPngApproDto> dto);
List<LngPngApproVo> compare(Long orgId);
CompareResultVo<LngPngApproVo> compare(Long orgId);
}

View File

@ -12,11 +12,13 @@ import com.pictc.enums.BusinessCode;
import com.pictc.enums.ExceptionCommonCode;
import com.pictc.jdbc.JdbcTools;
import com.pictc.jdbc.model.JdbcParam;
import com.pictc.utils.ObjectDiffUtils;
import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.common.exception.BusinessException;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.module.approve.ApproveDto;
import com.xjrsoft.module.datalog.vo.CompareResultVo;
import com.xjrsoft.module.dayPlan.dto.LngPngApproPageDto;
import com.xjrsoft.module.dayPlan.dto.UpdateLngPngApproDto;
import com.xjrsoft.module.dayPlan.dto.UpdateLngPngApproPurDto;
@ -36,6 +38,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -81,7 +84,7 @@ public class PngApproServiceImpl extends MPJBaseServiceImpl<LngPngApproMapper, L
}
@Override
public List<LngPngApproVo> compare(Long orgId) {
public CompareResultVo<LngPngApproVo> compare(Long orgId) {
List<LngPngApproVo> voList = this.baseMapper.getListByOrgId(orgId);
if(CollectionUtils.isEmpty(voList)) {
throw new BusinessException(BusinessCode.of(10500,"找不到此数据"));
@ -90,7 +93,16 @@ public class PngApproServiceImpl extends MPJBaseServiceImpl<LngPngApproMapper, L
List<LngPngApproPurVo> lngPngApproPurList = this.baseMapper.queryLngPngApproPurList(vo.getId());
vo.setLngPngApproPurList(lngPngApproPurList);
}
return voList;
CompareResultVo<LngPngApproVo> vo = new CompareResultVo<>();
LngPngApproVo newBean = voList.get(0);
vo.setNewBean(newBean);
if (voList.size() > 1) {
LngPngApproVo oldBean = voList.get(1);
List<String> diffResultList = ObjectDiffUtils.compare(newBean, oldBean);
vo.setOldBean(oldBean);
vo.setDiffResultList(diffResultList);
}
return vo;
}
@Override
@ -170,15 +182,15 @@ public class PngApproServiceImpl extends MPJBaseServiceImpl<LngPngApproMapper, L
SaSession tokenSession = StpUtil.getTokenSession();
UserDto user = tokenSession.get(GlobalConstant.LOGIN_USER_INFO_KEY, new UserDto());
for (UpdateLngPngApproDto lngPngApproDto : data) {
LngPngAppro lngPngAppro = this.baseMapper.selectById(lngPngApproDto.getId());
if(lngPngAppro == null) {
throw new BusinessException(BusinessCode.of(10500,"找不到此数据"));
LocalDateTime datePlan = lngPngApproDto.getDatePlan();
if(datePlan == null) {
throw new BusinessException(BusinessCode.of(10500,"没有计划日期"));
}
List<JdbcParam> params = Lists.newArrayList();
JdbcParam outParam = JdbcParam.ofString(null).setOut(true);
params.add(outParam);
params.add(JdbcParam.ofString(user.getStaCode()));
params.add(JdbcParam.ofLocalDateTime(lngPngAppro.getDatePlan()));
params.add(JdbcParam.ofLocalDateTime(datePlan));
params.add(JdbcParam.ofString(dto.getResult()));
params.add(JdbcParam.ofString(dto.getRemark()));
params.add(JdbcParam.ofLong(user.getId()));
@ -202,15 +214,15 @@ public class PngApproServiceImpl extends MPJBaseServiceImpl<LngPngApproMapper, L
SaSession tokenSession = StpUtil.getTokenSession();
UserDto user = tokenSession.get(GlobalConstant.LOGIN_USER_INFO_KEY, new UserDto());
for (UpdateLngPngApproDto lngPngApproDto : data) {
LngPngAppro lngPngAppro = this.baseMapper.selectById(lngPngApproDto.getId());
if(lngPngAppro == null) {
throw new BusinessException(BusinessCode.of(10500,"找不到此数据"));
LocalDateTime datePlan = lngPngApproDto.getDatePlan();
if(datePlan == null) {
throw new BusinessException(BusinessCode.of(10500,"没有计划日期"));
}
List<JdbcParam> params = Lists.newArrayList();
JdbcParam outParam = JdbcParam.ofString(null).setOut(true);
params.add(outParam);
params.add(JdbcParam.ofString(user.getStaCode()));
params.add(JdbcParam.ofLocalDateTime(lngPngAppro.getDatePlan()));
params.add(JdbcParam.ofLocalDateTime(datePlan));
params.add(JdbcParam.ofString(dto.getResult()));
params.add(JdbcParam.ofString(dto.getRemark()));
params.add(JdbcParam.ofLong(user.getId()));

View File

@ -1,9 +1,6 @@
package com.xjrsoft.module.sales.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import com.github.yulichang.annotation.EntityMapping;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -52,11 +49,13 @@ public class LngCustomerGroup implements Serializable {
* 起始日期
*/
@ApiModelProperty("起始日期")
@TableField(updateStrategy = FieldStrategy.IGNORED)
private LocalDateTime dateFrom;
/**
* 结束日期
*/
@ApiModelProperty("结束日期")
@TableField(updateStrategy = FieldStrategy.IGNORED)
private LocalDateTime dateTo;
/**
* 备注