Browse Source

查看订单详情

lipf 2 months ago
parent
commit
a9027b03da

+ 106 - 0
commons/src/main/java/com/jzg/commons/util/JsonDiffUtil.java

@@ -0,0 +1,106 @@
+package com.jzg.commons.util;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.util.*;
+
+public class JsonDiffUtil {
+
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 比较两个JSON字符串的差异。
+     *
+     * @param jsonStr1 第一个JSON字符串
+     * @param jsonStr2 第二个JSON字符串
+     * @param ignoreFieldSet 需要忽略的字段名列表(支持嵌套字段,如 "data.order.createTime")
+     * @return 一个Map,键为差异字段的路径,值为一个包含两个值的列表 [值1, 值2]
+     */
+    public static Map<String, List<String>> compareJson(String jsonStr1, String jsonStr2, Set<String> ignoreFieldSet) {
+        Map<String, List<String>> differences = new LinkedHashMap<>(); // 使用LinkedHashMap保持插入顺序
+        //Set<String> ignoreFieldSet = new HashSet<>(Arrays.asList(ignoreFields));
+
+        try {
+            JsonNode node1 = objectMapper.readTree(jsonStr1);
+            JsonNode node2 = objectMapper.readTree(jsonStr2);
+            compareNodes(node1, node2, "", differences, ignoreFieldSet);
+        } catch (IOException e) {
+            differences.put("解析错误", Arrays.asList("JSON格式无效", e.getMessage()));
+        }
+
+        return differences;
+    }
+
+    /**
+     * 递归比较两个JsonNode节点
+     */
+    private static void compareNodes(JsonNode node1, JsonNode node2, String currentPath, Map<String, List<String>> differences, Set<String> ignoreFields) {
+        // 1. 检查当前路径是否需要被忽略
+        if (ignoreFields.contains(currentPath)) {
+            return;
+        }
+
+        // 2. 处理节点类型不同的情况
+        if (node1.getNodeType() != node2.getNodeType()) {
+            differences.put(currentPath, Arrays.asList(node1.toString(), node2.toString()));
+            return;
+        }
+
+        // 3. 根据节点类型进行比较
+        switch (node1.getNodeType()) {
+            case OBJECT:
+                compareObjects(node1, node2, currentPath, differences, ignoreFields);
+                break;
+            case ARRAY:
+                compareArrays(node1, node2, currentPath, differences, ignoreFields);
+                break;
+            default:
+                // 对于值节点(文本、数字、布尔、null)
+                if (!node1.equals(node2)) {
+                    differences.put(currentPath, Arrays.asList(node1.asText(), node2.asText()));
+                }
+                break;
+        }
+    }
+
+    /**
+     * 比较两个JSON对象
+     */
+    private static void compareObjects(JsonNode node1, JsonNode node2, String currentPath, Map<String, List<String>> differences, Set<String> ignoreFields) {
+        Set<String> allFieldNames = new HashSet<>();
+        node1.fieldNames().forEachRemaining(allFieldNames::add);
+        node2.fieldNames().forEachRemaining(allFieldNames::add);
+
+        for (String fieldName : allFieldNames) {
+            // 构建当前字段的完整路径,例如 "data.order.orderNo"
+            String fieldPath = currentPath.isEmpty() ? fieldName : currentPath + "." + fieldName;
+
+            if (!node1.has(fieldName)) {
+                differences.put(fieldPath, Arrays.asList("字段不存在", node2.get(fieldName).toString()));
+            } else if (!node2.has(fieldName)) {
+                differences.put(fieldPath, Arrays.asList(node1.get(fieldName).toString(), "字段不存在"));
+            } else {
+                compareNodes(node1.get(fieldName), node2.get(fieldName), fieldPath, differences, ignoreFields);
+            }
+        }
+    }
+
+    /**
+     * 比较两个JSON数组
+     * 注意:此方法按索引顺序比较。如果数组元素顺序可能不同但内容相同,需要更复杂的逻辑。
+     */
+    private static void compareArrays(JsonNode node1, JsonNode node2, String currentPath, Map<String, List<String>> differences, Set<String> ignoreFields) {
+        if (node1.size() != node2.size()) {
+            differences.put(currentPath, Arrays.asList("数组长度: " + node1.size(), "数组长度: " + node2.size()));
+        }
+
+        int minSize = Math.min(node1.size(), node2.size());
+        for (int i = 0; i < minSize; i++) {
+            // 构建数组元素的路径,例如 "data.imageVoList[0].imageCode"
+            String elementPath = currentPath + "[" + i + "]";
+            compareNodes(node1.get(i), node2.get(i), elementPath, differences, ignoreFields);
+        }
+    }
+}

+ 30 - 12
tenant/insurance/quotation-summary/src/main/java/com/jzg/quotation/summary/aop/OrderOperationLogAspect.java

@@ -16,14 +16,13 @@ import com.jzg.commons.entity.quote.vo.aggregated.*;
 import com.jzg.commons.entity.vo.AdjustAllRefundVo;
 import com.jzg.commons.entity.vo.AdjustAllRefundVo;
 import com.jzg.commons.entity.vo.PtlAgreementCostRatioVo;
 import com.jzg.commons.entity.vo.PtlAgreementCostRatioVo;
 import com.jzg.commons.entity.vo.QuestionOrder;
 import com.jzg.commons.entity.vo.QuestionOrder;
+import com.jzg.commons.util.JsonDiffUtil;
 import com.jzg.quotation.commons.constant.SpElMapping;
 import com.jzg.quotation.commons.constant.SpElMapping;
 import com.jzg.quotation.commons.utils.SpElFieldExtractor;
 import com.jzg.quotation.commons.utils.SpElFieldExtractor;
 import com.jzg.quotation.summary.aop.aspect.OrderOperationLog;
 import com.jzg.quotation.summary.aop.aspect.OrderOperationLog;
 import com.jzg.quotation.summary.constants.QuoteNumberConstant;
 import com.jzg.quotation.summary.constants.QuoteNumberConstant;
-import com.jzg.quotation.summary.service.InsOrderAdjustService;
-import com.jzg.quotation.summary.service.InsOrdersCarInfoService;
-import com.jzg.quotation.summary.service.InsOrdersService;
-import com.jzg.quotation.summary.service.InsOrdersTrackService;
+import com.jzg.quotation.summary.service.*;
+import com.jzg.quotation.taikang.crawler.JsonUtil;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Aspect;
@@ -38,9 +37,10 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
 import org.springframework.expression.spel.support.StandardEvaluationContext;
 import org.springframework.expression.spel.support.StandardEvaluationContext;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.*;
 
 
 @Aspect
 @Aspect
 @Component
 @Component
@@ -60,7 +60,8 @@ public class OrderOperationLogAspect {
 
 
     @Autowired
     @Autowired
     private SpElFieldExtractor fieldExtractor;
     private SpElFieldExtractor fieldExtractor;
-
+    @Autowired
+    private InsFeeAuditService insFeeAuditService;
     @Autowired
     @Autowired
     private InsOrderAdjustService insOrderAdjustService;
     private InsOrderAdjustService insOrderAdjustService;
 
 
@@ -162,8 +163,11 @@ public class OrderOperationLogAspect {
             case 15:
             case 15:
                 logger.info("费用调整log.orderSpEl()=[{}]",log.orderSpEl());
                 logger.info("费用调整log.orderSpEl()=[{}]",log.orderSpEl());
                 PtlAgreementCostRatioVo vo = parser.parseExpression(log.orderSpEl()).getValue(context, PtlAgreementCostRatioVo.class);
                 PtlAgreementCostRatioVo vo = parser.parseExpression(log.orderSpEl()).getValue(context, PtlAgreementCostRatioVo.class);
+                QuoteEchoVo detailVoOld = insFeeAuditService.auditInfo(vo.getOrderNo());
                 result = joinPoint.proceed();
                 result = joinPoint.proceed();
-                this.saveCostInfo(result,log, vo);
+                QuoteEchoVo detailVoNew = insFeeAuditService.auditInfo(vo.getOrderNo());
+                Map<String, List<String>> diffMap = JsonDiffUtil.compareJson(JSONUtil.toJsonStr(detailVoOld), JSONUtil.toJsonStr(detailVoNew), new HashSet<>());
+                this.saveCostInfo(result,log, vo,diffMap);
                 break;
                 break;
             // 批量修改比例
             // 批量修改比例
             case 16:
             case 16:
@@ -255,7 +259,7 @@ public class OrderOperationLogAspect {
      * @author lipf
      * @author lipf
      * @date 2026/7/8 15:28
      * @date 2026/7/8 15:28
      */
      */
-    private void saveCostInfo(Object result, OrderOperationLog log, PtlAgreementCostRatioVo vo) {
+    private void saveCostInfo(Object result, OrderOperationLog log, PtlAgreementCostRatioVo vo,Map<String, List<String>> diffMap) {
         InsOrdersTrack track = new InsOrdersTrack();
         InsOrdersTrack track = new InsOrdersTrack();
         String orderNo = vo.getOrderNo();
         String orderNo = vo.getOrderNo();
         track.setModule(log.module());
         track.setModule(log.module());
@@ -273,8 +277,22 @@ public class OrderOperationLogAspect {
             track.setResult("要进行费用调整的订单不存在");
             track.setResult("要进行费用调整的订单不存在");
         }
         }
         track.setStatus(1);
         track.setStatus(1);
-        track.setChangeBefore("");
-        track.setChangeAfter("费用调整完成");
+        if(CollUtil.isNotEmpty(diffMap)){
+            List<String> oldItems = new ArrayList<>(diffMap.keySet());
+            List<String> newItems = new ArrayList<>(diffMap.keySet());
+            diffMap.forEach((path, values) ->{
+                        System.out.println("路径: " + path + " -> 值1: " + values.get(0) + " | 值2: " + values.get(1));
+                        oldItems.add(path + ": " + values.get(0));
+                        newItems.add(path + ": " + values.get(1));
+                    }
+            );
+            logger.info("oldItem=[{}]", JSONUtil.toJsonStr(oldItems));
+            logger.info("newItem=[{}]", JSONUtil.toJsonStr(newItems));
+
+            track.setChangeBefore(String.join("\r\n", oldItems));
+            track.setChangeAfter(String.join("\r\n", newItems));
+        }
+
         track.setOrderNo(orderNo);
         track.setOrderNo(orderNo);
         track.setResult(JSONUtil.toJsonStr(result));
         track.setResult(JSONUtil.toJsonStr(result));
         traceService.save(track);
         traceService.save(track);

+ 6 - 6
tenant/organization/src/main/java/com/jzg/organization/aop/OrderOperationLogAspect.java

@@ -55,12 +55,12 @@ public class OrderOperationLogAspect {
         Object result = null;
         Object result = null;
         switch (log.optType().getCode()){
         switch (log.optType().getCode()){
             // 费用调整
             // 费用调整
-            case 15:
-                logger.info("费用调整log.orderSpEl()=[{}]",log.orderSpEl());
-                PtlAgreementCostRatioVo vo = parser.parseExpression(log.orderSpEl()).getValue(context, PtlAgreementCostRatioVo.class);
-                result = joinPoint.proceed();
-                this.saveCostInfo(result,log, vo);
-                break;
+//            case 15:
+//                logger.info("费用调整log.orderSpEl()=[{}]",log.orderSpEl());
+//                PtlAgreementCostRatioVo vo = parser.parseExpression(log.orderSpEl()).getValue(context, PtlAgreementCostRatioVo.class);
+//                result = joinPoint.proceed();
+//                this.saveCostInfo(result,log, vo);
+//                break;
             // 批量修改比例
             // 批量修改比例
             case 16:
             case 16:
                 logger.info("批量修改比例.log.orderSpEl()=[{}]",log.orderSpEl());
                 logger.info("批量修改比例.log.orderSpEl()=[{}]",log.orderSpEl());