Commit 2865c28a9f8768f805db262da10fdc5bdbb71477

Authored by chenchen
1 parent 75afab1f

售后日志优化,map->抽方法

yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java
@@ -54,7 +54,7 @@ public class TradeAfterSaleLogDO extends BaseDO { @@ -54,7 +54,7 @@ public class TradeAfterSaleLogDO extends BaseDO {
54 * 54 *
55 * 枚举 {@link AfterSaleOperateTypeEnum} 55 * 枚举 {@link AfterSaleOperateTypeEnum}
56 */ 56 */
57 - private String operateType; 57 + private Integer operateType;
58 /** 58 /**
59 * 操作明细 59 * 操作明细
60 */ 60 */
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java
@@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil; @@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil;
4 import cn.hutool.core.util.ObjectUtil; 4 import cn.hutool.core.util.ObjectUtil;
5 import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; 5 import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils;
6 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; 6 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
  7 +import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
7 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog; 8 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
8 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; 9 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
9 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; 10 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
@@ -47,13 +48,12 @@ public class AfterSaleLogAspect { @@ -47,13 +48,12 @@ public class AfterSaleLogAspect {
47 // 日志对象拼接 48 // 日志对象拼接
48 Integer userType = WebFrameworkUtils.getLoginUserType(); 49 Integer userType = WebFrameworkUtils.getLoginUserType();
49 Long id = WebFrameworkUtils.getLoginUserId(); 50 Long id = WebFrameworkUtils.getLoginUserId();
50 - Map<String, String> formatObj = spelFormat(joinPoint, info);  
51 TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO() 51 TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO()
52 .setUserId(id) 52 .setUserId(id)
53 .setUserType(userType) 53 .setUserType(userType)
54 - .setAfterSaleId(MapUtil.getLong(formatObj, ID))  
55 - .setOperateType(MapUtil.getStr(formatObj, OPERATE_TYPE))  
56 - .setContent(MapUtil.getStr(formatObj, CONTENT)); 54 + .setAfterSaleId(getAfterSaleId(joinPoint, info, afterSaleLog.id()))
  55 + .setOperateType(afterSaleLog.operateType().getType())
  56 + .setContent(getContent(joinPoint, info, afterSaleLog));
57 // 异步存入数据库 57 // 异步存入数据库
58 afterSaleLogService.createLog(dto); 58 afterSaleLogService.createLog(dto);
59 } catch (Exception exception) { 59 } catch (Exception exception) {
@@ -64,26 +64,49 @@ public class AfterSaleLogAspect { @@ -64,26 +64,49 @@ public class AfterSaleLogAspect {
64 /** 64 /**
65 * 获取描述信息 65 * 获取描述信息
66 */ 66 */
67 - public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) { 67 + private static Map<String, Object> spelFormat(JoinPoint joinPoint, Object info) {
68 MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 68 MethodSignature signature = (MethodSignature) joinPoint.getSignature();
69 AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); 69 AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
70 - HashMap<String, String> result = Maps.newHashMapWithExpectedSize(2);  
71 - Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info, 70 + return SpringExpressionUtils.parseExpression(joinPoint, info,
72 asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); 71 asList(afterSaleLogPoint.id(), afterSaleLogPoint.content()));
73 - // TODO @chenchen:是不是抽成 3 个方法好点;毕竟 map 太抽象了;;  
74 - // 售后ID  
75 - String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id());  
76 - result.put(ID, id);  
77 - // 操作类型  
78 - String operateType = afterSaleLogPoint.operateType().description();  
79 - result.put(OPERATE_TYPE, operateType);  
80 - // 日志内容  
81 - String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content());  
82 - if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) {  
83 - content += operateType;  
84 - }  
85 - result.put(CONTENT, content);  
86 - return result;  
87 } 72 }
88 73
  74 + /**
  75 + * 获取售后ID
  76 + */
  77 + private static Long getAfterSaleId(JoinPoint joinPoint, Object info, String spel) {
  78 + Map<String, Object> spelMap = spelFormat(joinPoint, info);
  79 + return MapUtil.getLong(spelMap, spel);
  80 + }
  81 +
  82 + /**
  83 + * 获取解析后的日志内容
  84 + */
  85 + private static String getContent(JoinPoint joinPoint, Object info, AfterSaleLog afterSaleLog) {
  86 + Map<String, Object> spelMap = spelFormat(joinPoint, info);
  87 + StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLog.content()));
  88 + AfterSaleOperateTypeEnum afterSaleOperateTypeEnum = afterSaleLog.operateType();
  89 + return ObjectUtil.isNotNull(afterSaleOperateTypeEnum) ?
  90 + content.append(afterSaleOperateTypeEnum.getDescription()).toString() : content.toString();
  91 + }
  92 +
  93 + // public static Map<String, Object> spelFormat(JoinPoint joinPoint, Object info) {
  94 + // MethodSignature signature = (MethodSignature) joinPoint.getSignature();
  95 + // AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
  96 + // HashMap<String, Object> result = Maps.newHashMapWithExpectedSize(2);
  97 + // Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info,
  98 + // asList(afterSaleLogPoint.id(), afterSaleLogPoint.content()));
  99 + //
  100 + // // 售后ID
  101 + // result.put(ID, MapUtil.getLong(spelMap, afterSaleLogPoint.id()));
  102 + // // 操作类型
  103 + // result.put(OPERATE_TYPE, afterSaleLogPoint.operateType().getType());
  104 + // // 日志内容
  105 + // StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLogPoint.content()));
  106 + //
  107 + // result.put(CONTENT, ObjectUtil.isNotNull(afterSaleLogPoint.operateType()) ?
  108 + // content.append(afterSaleLogPoint.operateType().getDescription()).toString() : content.toString());
  109 + // return result;
  110 + // }
  111 +
89 } 112 }
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java
@@ -37,7 +37,7 @@ public class TradeAfterSaleLogCreateReqDTO { @@ -37,7 +37,7 @@ public class TradeAfterSaleLogCreateReqDTO {
37 /** 37 /**
38 * 操作类型 38 * 操作类型
39 */ 39 */
40 - private String operateType; 40 + private Integer operateType;
41 /** 41 /**
42 * 操作明细 42 * 操作明细
43 */ 43 */
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java
@@ -393,7 +393,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa @@ -393,7 +393,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
393 .setUserId(userId) 393 .setUserId(userId)
394 .setUserType(userType) 394 .setUserType(userType)
395 .setAfterSaleId(afterSale.getId()) 395 .setAfterSaleId(afterSale.getId())
396 - .setOperateType(afterStatus.toString()); 396 + .setOperateType(afterStatus);
397 // TODO 废弃,待删除 397 // TODO 废弃,待删除
398 this.createLog(logDTO); 398 this.createLog(logDTO);
399 } 399 }