Commit 2f0aaee82334657a9341874734dcda01854f7861

Authored by chenchen
1 parent b7c0fef6

售后日志优化

yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spring/SpringExpressionUtils.java
... ... @@ -25,8 +25,6 @@ import java.util.Map;
25 25 */
26 26 public class SpringExpressionUtils {
27 27  
28   -
29   -
30 28 /**
31 29 * spel表达式解析器
32 30 */
... ... @@ -92,14 +90,14 @@ public class SpringExpressionUtils {
92 90 /**
93 91 * JoinPoint 切面 批量解析 EL 表达式,转换 jspl参数
94 92 *
95   - * @param joinPoint 切面点
96   - * @param rvt 返回值
97   - * @param expressionStrings EL 表达式数组
98   - * @return java.lang.String 结果
  93 + * @param joinPoint 切面点
  94 + * @param info 返回值
  95 + * @param expressionStrings EL 表达式数组
  96 + * @return Map<String, Object> 结果
99 97 * @author 陈賝
100 98 * @since 2023/6/18 11:20
101 99 */
102   - public static Map<String, Object> parseExpression(JoinPoint joinPoint, Object rvt, List<String> expressionStrings) {
  100 + public static Map<String, Object> parseExpression(JoinPoint joinPoint, Object info, List<String> expressionStrings) {
103 101 // 如果为空,则不进行解析
104 102 if (CollUtil.isEmpty(expressionStrings)) {
105 103 return MapUtil.newHashMap();
... ... @@ -120,7 +118,7 @@ public class SpringExpressionUtils {
120 118 //替换spel里的变量值为实际值, 比如 #user --> user对象
121 119 context.setVariable(parameterNames[i], args[i]);
122 120 }
123   - context.setVariable("rvt", rvt);
  121 + context.setVariable("info", info);
124 122 }
125 123 // 第二步,逐个参数解析
126 124 Map<String, Object> result = MapUtil.newHashMap(expressionStrings.size(), true);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/enums/AfterSaleStatusEnum.java renamed to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java
1   -package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums;
  1 +package cn.iocoder.yudao.module.trade.enums.aftersale;
2 2  
3 3 /**
4   - * 售后状态的枚举
  4 + * 售后操作类型的枚举
5 5 *
6 6 * @author 陈賝
7 7 * @since 2023/6/13 13:53
8 8 */
9   -public enum AfterSaleStatusEnum {
  9 +public enum AfterSaleOperateTypeEnum {
10 10  
11 11 /**
12   - * 申请中
  12 + * 用户申请
13 13 */
14   - APPLY("申请中");
  14 + APPLY("用户申请"),
  15 + ;
15 16  
16 17 private final String description;
17 18  
18   - AfterSaleStatusEnum(String description) {
  19 + AfterSaleOperateTypeEnum(String description) {
19 20 this.description = description;
20 21 }
21 22  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java
... ... @@ -11,11 +11,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSal
11 11 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO;
12 12 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO;
13 13 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO;
14   -import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
15 14 import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
16 15 import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
17   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
18   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums.AfterSaleStatusEnum;
19 16 import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
20 17 import io.swagger.v3.oas.annotations.Operation;
21 18 import io.swagger.v3.oas.annotations.Parameter;
... ... @@ -113,20 +110,4 @@ public class TradeAfterSaleController {
113 110 return success(true);
114 111 }
115 112  
116   - // TODO @陈賝:后续要删除下
117   - /**
118   - * 售后日志测试
119   - *
120   - * @param createReqVO
121   - * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Long>
122   - * @author 陈賝
123   - * @date 2023/6/14 21:39
124   - */
125   - @PostMapping(value = "/create")
126   - @AfterSaleLog(id = "#createReqVO.orderItemId", content = "'申请售后:售后编号['+#createReqVO.orderItemId+'] , '", operateType = AfterSaleStatusEnum.APPLY)
127   - public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
128   - return success(1L);
129   -// return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
130   - }
131   -
132 113 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/AppTradeAfterSaleController.java
... ... @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSa
6 6 import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO;
7 7 import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSalePageItemRespVO;
8 8 import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO;
  9 +import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
  10 +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
9 11 import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
10 12 import io.swagger.v3.oas.annotations.Operation;
11 13 import io.swagger.v3.oas.annotations.Parameter;
... ... @@ -78,6 +80,7 @@ public class AppTradeAfterSaleController {
78 80  
79 81 @PostMapping(value = "/create")
80 82 @Operation(summary = "申请售后")
  83 + @AfterSaleLog(id = "#info.data", content = "'申请售后:售后编号['+#info.data+'],订单编号['+#createReqVO.orderItemId+'], '", operateType = AfterSaleOperateTypeEnum.APPLY)
81 84 public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
82 85 return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
83 86 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java
1 1 package cn.iocoder.yudao.module.trade.framework.aftersalelog.config;
2 2  
3 3 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect;
4   -import org.springframework.boot.autoconfigure.AutoConfiguration;
5 4 import org.springframework.context.annotation.Bean;
  5 +import org.springframework.context.annotation.Configuration;
6 6  
7 7 /**
8 8 * trade 模块的 afterSaleLog 组件的 Configuration
... ... @@ -10,7 +10,7 @@ import org.springframework.context.annotation.Bean;
10 10 * @author 陈賝
11 11 * @since 2023/6/18 11:09
12 12 */
13   -@AutoConfiguration
  13 +@Configuration(proxyBeanMethods = false)
14 14 public class AfterSaleLogConfiguration {
15 15  
16 16 @Bean
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/annotations/AfterSaleLog.java
1 1 package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations;
2 2  
3   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums.AfterSaleStatusEnum;
  3 +import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
4 4  
5 5 import java.lang.annotation.*;
6 6  
... ... @@ -10,7 +10,7 @@ import java.lang.annotation.*;
10 10 * @author 陈賝
11 11 * @since 2023/6/8 17:04
12 12 */
13   -@Target({ElementType.METHOD,ElementType.TYPE})
  13 +@Target({ElementType.METHOD, ElementType.TYPE})
14 14 @Retention(RetentionPolicy.RUNTIME)
15 15 @Documented
16 16 public @interface AfterSaleLog {
... ... @@ -23,7 +23,7 @@ public @interface AfterSaleLog {
23 23 /**
24 24 * 操作类型
25 25 */
26   - AfterSaleStatusEnum operateType() default AfterSaleStatusEnum.APPLY;
  26 + AfterSaleOperateTypeEnum operateType();
27 27  
28 28 /**
29 29 * 日志内容
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java
... ... @@ -4,13 +4,12 @@ import cn.hutool.core.map.MapUtil;
4 4 import cn.hutool.core.util.ObjectUtil;
5 5 import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils;
6 6 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
7   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
8 7 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
  8 +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
9 9 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
10 10 import com.google.common.collect.Maps;
11 11 import lombok.extern.slf4j.Slf4j;
12 12 import org.aspectj.lang.JoinPoint;
13   -import org.aspectj.lang.ProceedingJoinPoint;
14 13 import org.aspectj.lang.annotation.AfterReturning;
15 14 import org.aspectj.lang.annotation.Aspect;
16 15 import org.aspectj.lang.reflect.MethodSignature;
... ... @@ -34,6 +33,11 @@ public class AfterSaleLogAspect {
34 33 @Resource
35 34 private AfterSaleLogService saleLogService;
36 35  
  36 + private final static String OPERATE_TYPE = "operateType", ID = "id", CONTENT = "content";
  37 +
  38 + /**
  39 + * 切面存入日志
  40 + */
37 41 @AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info")
38 42 public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) {
39 43 try {
... ... @@ -42,10 +46,11 @@ public class AfterSaleLogAspect {
42 46 Long id = WebFrameworkUtils.getLoginUserId();
43 47 Map<String, String> formatObj = spelFormat(joinPoint, info);
44 48 TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO()
45   - .setUserId(id).setUserType(userType)
46   - .setAfterSaleId(MapUtil.getLong(formatObj, "id"))
47   - .setContent(formatObj.get("content"))
48   - .setOperateType(formatObj.get("operateType"));
  49 + .setUserId(id)
  50 + .setUserType(userType)
  51 + .setAfterSaleId(MapUtil.getLong(formatObj, ID))
  52 + .setOperateType(MapUtil.getStr(formatObj, OPERATE_TYPE))
  53 + .setContent(MapUtil.getStr(formatObj, CONTENT));
49 54 // 异步存入数据库
50 55 saleLogService.createLog(dto);
51 56 } catch (Exception exception) {
... ... @@ -59,21 +64,21 @@ public class AfterSaleLogAspect {
59 64 public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
60 65 MethodSignature signature = (MethodSignature) joinPoint.getSignature();
61 66 AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
62   - HashMap<String, String> result = Maps.newHashMapWithExpectedSize(3);
  67 + HashMap<String, String> result = Maps.newHashMapWithExpectedSize(2);
63 68 Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info,
64   - asList(afterSaleLogPoint.id(), afterSaleLogPoint.operateType().description(), afterSaleLogPoint.content()));
  69 + asList(afterSaleLogPoint.id(), afterSaleLogPoint.content()));
65 70 // 售后ID
66 71 String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id());
67   - result.put("id", id);
  72 + result.put(ID, id);
68 73 // 操作类型
69   - String operateType = MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
70   - result.put("operateType", operateType);
  74 + String operateType = afterSaleLogPoint.operateType().description();
  75 + result.put(OPERATE_TYPE, operateType);
71 76 // 日志内容
72 77 String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content());
73 78 if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) {
74   - content += MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
  79 + content += operateType;
75 80 }
76   - result.put("content", content);
  81 + result.put(CONTENT, content);
77 82 return result;
78 83 }
79 84  
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java
... ... @@ -66,7 +66,6 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
66 66 AppTradeAfterSaleCreateReqVO createReqVO = new AppTradeAfterSaleCreateReqVO()
67 67 .setOrderItemId(1L).setRefundPrice(100).setWay(TradeAfterSaleWayEnum.RETURN_AND_REFUND.getWay())
68 68 .setApplyReason("退钱").setApplyDescription("快退")
69   - .setOperateType("APPLY")
70 69 .setApplyPicUrls(asList("https://www.baidu.com/1.png", "https://www.baidu.com/2.png"));
71 70 // mock 方法(交易订单项)
72 71 TradeOrderItemDO orderItem = randomPojo(TradeOrderItemDO.class, o -> {
... ... @@ -103,8 +102,6 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
103 102 assertEquals(afterSaleLog.getUserType(), UserTypeEnum.MEMBER.getValue());
104 103 assertEquals(afterSaleLog.getAfterSaleId(), afterSaleId);
105 104 assertPojoEquals(afterSale, orderItem, "id", "creator", "createTime", "updater", "updateTime");
106   -// assertNull(afterSaleLog.getBeforeStatus());
107   -// assertEquals(afterSaleLog.getAfterStatus(), TradeAfterSaleStatusEnum.APPLY.getStatus());
108 105 assertEquals(afterSaleLog.getContent(), TradeAfterSaleStatusEnum.APPLY.getContent());
109 106 }
110 107  
... ...