Bladeren bron

refactor(消费服务): 优化日志格式与内容一致性

1. 统一日志格式,将耗时单位从"毫秒"调整为"ms",提升语义清晰度。
2. 调整错误日志和信息日志的输出结构,确保关键数据完整展示,包括错误信息与业务对象的JSON序列化内容。
3. 移除冗余注释,优化代码可读性与维护性。
autumnal_wind 11 maanden geleden
bovenliggende
commit
cf9cc8b8a8

+ 13 - 14
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/ConsumeBusiness.java

@@ -68,10 +68,10 @@ public class ConsumeBusiness {
         AllowConsumeValidationContext ctx = AllowConsumeValidationContext.create(bo);
         R<ErrorInfo> result = commonCheck.consumeValidation(ctx);
         if (R.isError(result)) {
-            log.error("[请求交易]-[记录有效性验证失败]-[错误: {}]-[数据:{}]", result.getData(), JSONUtil.toJsonStr(bo));
+            log.error("[请求交易]-[记录有效性验证失败]-[{}]-[{}]", JSONUtil.toJsonStr(result.getData()), JSONUtil.toJsonStr(bo));
             return result;
         }
-        log.info("[请求交易]-[记录有效性验证完成]-[耗时: {} 毫秒]-[记录:{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
+        log.info("[请求交易]-[记录有效性验证完成]-[耗时: {} ms]-[{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
 
         RemoteUserAccountVo userAccountVo = ctx.getUserAccountVo();
         RemoteCardVo userCardVo = ctx.getUserCardVo();
@@ -82,18 +82,18 @@ public class ConsumeBusiness {
         startTime = System.currentTimeMillis();
         result = requestCheck.checkConsume(bo, userAccountVo, userCardVo, termVo, mapCardLimited, cardLimitedVo);
         if (R.isError(result)) {
-            log.error("[请求交易]-[交易流程验证失败]-[错误: {}]-[数据:{}]", result.getData(), JSONUtil.toJsonStr(bo));
+            log.error("[请求交易]-[交易流程验证失败]-[{}]-[{}]", JSONUtil.toJsonStr(result.getData()), JSONUtil.toJsonStr(bo));
             return result;
         }
-        log.warn("[请求交易]-[交易流程验证完成]-[耗时: {} 毫秒]", System.currentTimeMillis() - startTime);
+        log.warn("[请求交易]-[交易流程验证完成]-[耗时: {} ms]-[{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
 
         startTime = System.currentTimeMillis();
         result = requestCheck.completeConsumeRequest(bo, userAccountVo, userCardVo, termVo, mapCardLimited, cardLimitedVo);
         if (R.isError(result)) {
-            log.error("[请求交易]-[消费原始记录失败]-[错误: {}]-[数据:{}]", result.getData(), JSONUtil.toJsonStr(bo));
+            log.error("[请求交易]-[消费原始记录失败]-[{}]-[{}]", JSONUtil.toJsonStr(result.getData()), JSONUtil.toJsonStr(bo));
             return result;
         }
-        log.info("[请求交易]-[生成原始消费记录完成]-[耗时: {} 毫秒]", System.currentTimeMillis() - startTime);
+        log.info("[请求交易]-[生成原始消费记录完成]-[耗时: {} ms]-[{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
 
         return R.ok();
     }
@@ -111,10 +111,10 @@ public class ConsumeBusiness {
         AllowConsumeValidationContext ctx = AllowConsumeValidationContext.create(bo);
         R<ErrorInfo> result = commonCheck.consumeValidation(ctx);
         if (R.isError(result)) {
-            log.error("[上传交易]-[记录有效性验证失败]-[错误: {}]-[数据:{}]", result.getData(), JSONUtil.toJsonStr(bo));
+            log.error("[上传交易]-[记录有效性验证失败]-[{}]-[{}]", JSONUtil.toJsonStr(result.getData()), JSONUtil.toJsonStr(bo));
             return result;
         }
-        log.info("[上传交易]-[记录有效性验证完成]-[耗时: {} 毫秒]-[记录:{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
+        log.info("[上传交易]-[记录有效性验证完成]-[耗时: {} ms]-[{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
 
         startTime = System.currentTimeMillis();
         List<PtBagVo> bagVos = new ArrayList<>();
@@ -124,22 +124,22 @@ public class ConsumeBusiness {
         RemoteMealTypeVo mealTypeVo = new RemoteMealTypeVo();
         result = uploadCheck.checkBill(bo, userAccountVo, termVo, bagVos, mealTypeVo);
         if (R.isError(result)) {
-            log.error("[上传交易]-[交易账单处理失败]-[错误: {}]-[数据:{}]", result.getData(), JSONUtil.toJsonStr(bo));
+            log.error("[上传交易]-[交易账单处理失败]-[{}]-[{}]", JSONUtil.toJsonStr(result.getData()), JSONUtil.toJsonStr(bo));
             return result;
         }
-        log.info("[上传交易]-[交易账单处理完成]-[耗时: {} 毫秒]-[记录:{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
+        log.info("[上传交易]-[交易账单处理完成]-[耗时: {} ms]-[{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
 
         startTime = System.currentTimeMillis();
         try {
             result = baseBusiness.postConsumeRecord(bo, userAccountVo, userCardVo, bagVos, termVo, mealTypeVo, "");
             if (R.isError(result)) {
-                log.error("[上传交易]-[交易入库失败]-[错误:{}]-[数据:{}]", result.getData(), JsonUtils.toJsonString(bo));
+                log.error("[上传交易]-[交易入库失败]-[{}]-[{}]", JSONUtil.toJsonStr(result.getData()), JsonUtils.toJsonString(bo));
                 return result;
             }
-            log.info("[上传交易]-[交易入库处理完成]-[耗时: {} 毫秒]-[记录:{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
+            log.info("[上传交易]-[交易入库处理完成]-[耗时: {} ms]-[{}]", System.currentTimeMillis() - startTime, JSONUtil.toJsonStr(bo));
             return R.ok();
         } catch (ConsumeException e) {
-            log.error("[上传交易]-[交易入库失败]-[{}]", e.getMessage(), e);
+            log.error("[上传交易]-[交易入库失败]-[{}]-[{}]", e.getMessage(), JSONUtil.toJsonStr(bo), e);
             return R.fail(new ErrorInfo(500, ApiErrorTypeConstants.EXCEPTION, e.getMessage(), ""));
         }
     }
@@ -293,7 +293,6 @@ public class ConsumeBusiness {
      * @return 对账结果对象 (ReconciliationResult)。
      * 包含处理后的结果信息,包括成功处理的记录、失败的记录以及异常详情。
      */
-
     private ReconciliationResult processRecordsInParallel(List<ConsumptionBo> records) {
         ReconciliationResult result = new ReconciliationResult();