Commit 07884ef423a9522a4be4398ab0b1cb3d1dbcde04

Authored by YunaiV
2 parents bc54e2fb 2f0aaee8

Merge branch 'mall_trade_aftersalelog' of https://gitee.com/chen934298133/ruoyi-…

…vue-pro into feature/mall_product

 Conflicts:
	yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/vo/AppTradeAfterSaleCreateReqVO.java
Showing 19 changed files with 152 additions and 239 deletions
yudao-dependencies/pom.xml
... ... @@ -98,6 +98,11 @@
98 98 </dependency>
99 99 <dependency>
100 100 <groupId>cn.iocoder.boot</groupId>
  101 + <artifactId>yudao-spring-boot-starter-biz-trade</artifactId>
  102 + <version>${revision}</version>
  103 + </dependency>
  104 + <dependency>
  105 + <groupId>cn.iocoder.boot</groupId>
101 106 <artifactId>yudao-spring-boot-starter-biz-dict</artifactId>
102 107 <version>${revision}</version>
103 108 </dependency>
... ...
yudao-framework/pom.xml
... ... @@ -31,7 +31,6 @@
31 31 <module>yudao-spring-boot-starter-biz-sms</module>
32 32  
33 33 <module>yudao-spring-boot-starter-biz-pay</module>
34   - <module>yudao-spring-boot-starter-biz-trade</module>
35 34 <module>yudao-spring-boot-starter-biz-weixin</module>
36 35 <module>yudao-spring-boot-starter-biz-social</module>
37 36 <module>yudao-spring-boot-starter-biz-tenant</module>
... ...
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spel/SpelUtil.java deleted
1   -package cn.iocoder.yudao.framework.common.util.spel;
2   -
3   -import org.aspectj.lang.JoinPoint;
4   -import org.aspectj.lang.reflect.MethodSignature;
5   -import org.springframework.core.DefaultParameterNameDiscoverer;
6   -import org.springframework.expression.EvaluationContext;
7   -import org.springframework.expression.spel.standard.SpelExpressionParser;
8   -import org.springframework.expression.spel.support.StandardEvaluationContext;
9   -
10   -// TODO @Chopper:和 SpringExpressionUtils 合并下
11   -/**
12   - * SpelUtil
13   - *
14   - * @author Chopper
15   - * @version v1.0
16   - * @since 2021-01-11 10:45
17   - */
18   -public class SpelUtil {
19   -
20   -
21   - /**
22   - * spel表达式解析器
23   - */
24   - private static SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
25   - /**
26   - * 参数名发现器
27   - */
28   - private static DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
29   -
30   - /**
31   - * 转换 jspl参数
32   - *
33   - * @param joinPoint
34   - * @param spel
35   - * @return
36   - */
37   - public static String compileParams(JoinPoint joinPoint, String spel) { //Spel表达式解析日志信息
38   - //获得方法参数名数组
39   - MethodSignature signature = (MethodSignature) joinPoint.getSignature();
40   -
41   - String[] parameterNames = parameterNameDiscoverer.getParameterNames(signature.getMethod());
42   - if (parameterNames != null && parameterNames.length > 0) {
43   - EvaluationContext context = new StandardEvaluationContext();
44   -
45   - //获取方法参数值
46   - Object[] args = joinPoint.getArgs();
47   - for (int i = 0; i < args.length; i++) {
48   - //替换spel里的变量值为实际值, 比如 #user --> user对象
49   - context.setVariable(parameterNames[i], args[i]);
50   - }
51   - return spelExpressionParser.parseExpression(spel).getValue(context).toString();
52   - }
53   - return "";
54   - }
55   -
56   - /**
57   - * 转换 jspl参数
58   - *
59   - * @param joinPoint
60   - * @param spel
61   - * @return
62   - */
63   - public static String compileParams(JoinPoint joinPoint, Object rvt, String spel) { //Spel表达式解析日志信息
64   - //获得方法参数名数组
65   - MethodSignature signature = (MethodSignature) joinPoint.getSignature();
66   -
67   - String[] parameterNames = parameterNameDiscoverer.getParameterNames(signature.getMethod());
68   - if (parameterNames != null && parameterNames.length > 0) {
69   - EvaluationContext context = new StandardEvaluationContext();
70   -
71   - //获取方法参数值
72   - Object[] args = joinPoint.getArgs();
73   - for (int i = 0; i < args.length; i++) {
74   - //替换spel里的变量值为实际值, 比如 #user --> user对象
75   - context.setVariable(parameterNames[i], args[i]);
76   - }
77   - context.setVariable("rvt", rvt);
78   - return spelExpressionParser.parseExpression(spel).getValue(context).toString();
79   - }
80   - return "";
81   - }
82   -}
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spring/SpringExpressionUtils.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.common.util.spring;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.map.MapUtil;
5 5 import cn.hutool.core.util.ArrayUtil;
  6 +import org.aspectj.lang.JoinPoint;
6 7 import org.aspectj.lang.ProceedingJoinPoint;
7 8 import org.aspectj.lang.reflect.MethodSignature;
8 9 import org.springframework.core.DefaultParameterNameDiscoverer;
... ... @@ -24,7 +25,13 @@ import java.util.Map;
24 25 */
25 26 public class SpringExpressionUtils {
26 27  
  28 + /**
  29 + * spel表达式解析器
  30 + */
27 31 private static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
  32 + /**
  33 + * 参数名发现器
  34 + */
28 35 private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new DefaultParameterNameDiscoverer();
29 36  
30 37 private SpringExpressionUtils() {
... ... @@ -33,7 +40,7 @@ public class SpringExpressionUtils {
33 40 /**
34 41 * 从切面中,单个解析 EL 表达式的结果
35 42 *
36   - * @param joinPoint 切面点
  43 + * @param joinPoint 切面点
37 44 * @param expressionString EL 表达式数组
38 45 * @return 执行界面
39 46 */
... ... @@ -45,7 +52,7 @@ public class SpringExpressionUtils {
45 52 /**
46 53 * 从切面中,批量解析 EL 表达式的结果
47 54 *
48   - * @param joinPoint 切面点
  55 + * @param joinPoint 切面点
49 56 * @param expressionStrings EL 表达式数组
50 57 * @return 结果,key 为表达式,value 为对应值
51 58 */
... ... @@ -79,4 +86,47 @@ public class SpringExpressionUtils {
79 86 });
80 87 return result;
81 88 }
  89 +
  90 + /**
  91 + * JoinPoint 切面 批量解析 EL 表达式,转换 jspl参数
  92 + *
  93 + * @param joinPoint 切面点
  94 + * @param info 返回值
  95 + * @param expressionStrings EL 表达式数组
  96 + * @return Map<String, Object> 结果
  97 + * @author 陈賝
  98 + * @since 2023/6/18 11:20
  99 + */
  100 + public static Map<String, Object> parseExpression(JoinPoint joinPoint, Object info, List<String> expressionStrings) {
  101 + // 如果为空,则不进行解析
  102 + if (CollUtil.isEmpty(expressionStrings)) {
  103 + return MapUtil.newHashMap();
  104 + }
  105 +
  106 + // 第一步,构建解析的上下文 EvaluationContext
  107 + // 通过 joinPoint 获取被注解方法
  108 + MethodSignature signature = (MethodSignature) joinPoint.getSignature();
  109 + Method method = signature.getMethod();
  110 + // 使用 spring 的 ParameterNameDiscoverer 获取方法形参名数组
  111 + String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method);
  112 + // Spring 的表达式上下文对象
  113 + EvaluationContext context = new StandardEvaluationContext();
  114 + if (ArrayUtil.isNotEmpty(parameterNames)) {
  115 + //获取方法参数值
  116 + Object[] args = joinPoint.getArgs();
  117 + for (int i = 0; i < args.length; i++) {
  118 + //替换spel里的变量值为实际值, 比如 #user --> user对象
  119 + context.setVariable(parameterNames[i], args[i]);
  120 + }
  121 + context.setVariable("info", info);
  122 + }
  123 + // 第二步,逐个参数解析
  124 + Map<String, Object> result = MapUtil.newHashMap(expressionStrings.size(), true);
  125 + expressionStrings.forEach(key -> {
  126 + Object value = EXPRESSION_PARSER.parseExpression(key).getValue(context);
  127 + result.put(key, value);
  128 + });
  129 + return result;
  130 + }
  131 +
82 132 }
... ...
yudao-framework/yudao-spring-boot-starter-biz-trade/pom.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project xmlns="http://maven.apache.org/POM/4.0.0"
3   - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4   - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5   - <parent>
6   - <groupId>cn.iocoder.boot</groupId>
7   - <artifactId>yudao-framework</artifactId>
8   - <version>${revision}</version>
9   - </parent>
10   - <modelVersion>4.0.0</modelVersion>
11   - <artifactId>yudao-spring-boot-starter-biz-trade</artifactId>
12   - <packaging>jar</packaging>
13   -
14   - <name>${project.artifactId}</name>
15   - <description>交易模块</description>
16   - <url>https://github.com/YunaiV/ruoyi-vue-pro</url>
17   -
18   - <dependencies>
19   - <dependency>
20   - <groupId>cn.iocoder.boot</groupId>
21   - <artifactId>yudao-common</artifactId>
22   - </dependency>
23   -
24   - <!-- Spring 核心 -->
25   - <dependency>
26   - <groupId>org.springframework.boot</groupId>
27   - <artifactId>spring-boot-starter-aop</artifactId>
28   - </dependency>
29   -
30   - <!-- Web 相关 -->
31   - <dependency>
32   - <groupId>cn.iocoder.boot</groupId>
33   - <artifactId>yudao-spring-boot-starter-web</artifactId>
34   - <scope>provided</scope>
35   - </dependency>
36   -
37   - <!-- 业务组件 -->
38   - <dependency>
39   - <groupId>cn.iocoder.boot</groupId>
40   - <artifactId>yudao-module-system-api</artifactId> <!-- 需要使用它,进行操作日志的记录 -->
41   - <version>${revision}</version>
42   - </dependency>
43   -
44   - <!-- 工具类相关 -->
45   - <dependency>
46   - <groupId>com.google.guava</groupId>
47   - <artifactId>guava</artifactId>
48   - </dependency>
49   - <dependency>
50   - <groupId>cn.iocoder.boot</groupId>
51   - <artifactId>yudao-spring-boot-starter-security</artifactId>
52   - </dependency>
53   - </dependencies>
54   -</project>
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/config/YudaoAfterSaleLogAutoConfiguration.java deleted
1   -package cn.iocoder.yudao.framework.trade.config;
2   -
3   -import cn.iocoder.yudao.framework.trade.core.aop.AfterSaleLogAspect;
4   -import org.springframework.boot.autoconfigure.AutoConfiguration;
5   -import org.springframework.context.annotation.Bean;
6   -
7   -// TODO @Chopper:和 yudao-module-trade-biz 的 framework 里
8   -@AutoConfiguration
9   -public class YudaoAfterSaleLogAutoConfiguration {
10   -
11   - @Bean
12   - public AfterSaleLogAspect afterSaleLogAspect() {
13   - return new AfterSaleLogAspect();
14   - }
15   -
16   -}
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted
1   -cn.iocoder.yudao.framework.trade.config.YudaoAfterSaleLogAutoConfiguration
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/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.framework.trade.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/pom.xml
... ... @@ -58,11 +58,6 @@
58 58 <groupId>cn.iocoder.boot</groupId>
59 59 <artifactId>yudao-spring-boot-starter-biz-ip</artifactId>
60 60 </dependency>
61   - <dependency>
62   - <groupId>cn.iocoder.boot</groupId>
63   - <artifactId>yudao-spring-boot-starter-biz-trade</artifactId>
64   - <version>${revision}</version>
65   - </dependency>
66 61  
67 62 <!-- Web 相关 -->
68 63 <dependency>
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java
... ... @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.admin.aftersale;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.framework.trade.core.annotations.AfterSaleLog;
7 6 import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
8 7 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
9 8 import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
... ... @@ -12,7 +11,6 @@ import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSal
12 11 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO;
13 12 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO;
14 13 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO;
15   -import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
16 14 import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
17 15 import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
18 16 import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
... ... @@ -112,20 +110,4 @@ public class TradeAfterSaleController {
112 110 return success(true);
113 111 }
114 112  
115   - // TODO @陈賝:后续要删除下
116   - /**
117   - * 售后日志测试
118   - *
119   - * @param createReqVO
120   - * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Long>
121   - * @author 陈賝
122   - * @date 2023/6/14 21:39
123   - */
124   - @PostMapping(value = "/create")
125   - @AfterSaleLog(id = "#createReqVO.orderItemId", content = "'申请售后:售后编号['+#createReqVO.orderItemId+'] , '", operateType = "#createReqVO.operateType")
126   - public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
127   - return success(1L);
128   -// return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
129   - }
130   -
131 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/controller/app/aftersale/vo/AppTradeAfterSaleCreateReqVO.java
1 1 package cn.iocoder.yudao.module.trade.controller.app.aftersale.vo;
2 2  
3 3 import cn.iocoder.yudao.framework.common.validation.InEnum;
4   -import cn.iocoder.yudao.framework.trade.core.enums.AfterSaleStatusEnum;
5 4 import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum;
6 5 import io.swagger.v3.oas.annotations.media.Schema;
7 6 import lombok.Data;
... ... @@ -32,14 +31,6 @@ public class AppTradeAfterSaleCreateReqVO {
32 31 @NotNull(message = "申请原因不能为空")
33 32 private String applyReason;
34 33  
35   - // TODO @陈賝:这个参数不应该有呀。
36   - /**
37   - * @see AfterSaleStatusEnum
38   - */
39   - @Schema(description = "操作类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
40   - @NotNull(message = "操作类型不能为空")
41   - private String operateType;
42   -
43 34 @Schema(description = "补充描述", example = "商品质量不好")
44 35 private String applyDescription;
45 36  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.framework.aftersalelog.config;
  2 +
  3 +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect;
  4 +import org.springframework.context.annotation.Bean;
  5 +import org.springframework.context.annotation.Configuration;
  6 +
  7 +/**
  8 + * trade 模块的 afterSaleLog 组件的 Configuration
  9 + *
  10 + * @author 陈賝
  11 + * @since 2023/6/18 11:09
  12 + */
  13 +@Configuration(proxyBeanMethods = false)
  14 +public class AfterSaleLogConfiguration {
  15 +
  16 + @Bean
  17 + public AfterSaleLogAspect afterSaleLogAspect() {
  18 + return new AfterSaleLogAspect();
  19 + }
  20 +
  21 +}
... ...
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/annotations/AfterSaleLog.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/annotations/AfterSaleLog.java
1   -package cn.iocoder.yudao.framework.trade.core.annotations;
  1 +package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations;
  2 +
  3 +import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
2 4  
3 5 import java.lang.annotation.*;
4 6  
... ... @@ -8,7 +10,7 @@ import java.lang.annotation.*;
8 10 * @author 陈賝
9 11 * @since 2023/6/8 17:04
10 12 */
11   -@Target({ElementType.METHOD,ElementType.TYPE})
  13 +@Target({ElementType.METHOD, ElementType.TYPE})
12 14 @Retention(RetentionPolicy.RUNTIME)
13 15 @Documented
14 16 public @interface AfterSaleLog {
... ... @@ -18,11 +20,10 @@ public @interface AfterSaleLog {
18 20 */
19 21 String id();
20 22  
21   - // TODO @陈賝:是不是改成一个操作的枚举?
22 23 /**
23 24 * 操作类型
24 25 */
25   - String operateType() default "";
  26 + AfterSaleOperateTypeEnum operateType();
26 27  
27 28 /**
28 29 * 日志内容
... ...
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/aop/AfterSaleLogAspect.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java
1   -package cn.iocoder.yudao.framework.trade.core.aop;
  1 +package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop;
2 2  
3   -import cn.hutool.core.util.StrUtil;
4   -import cn.hutool.extra.spring.SpringUtil;
5   -import cn.iocoder.yudao.framework.common.util.spel.SpelUtil;
6   -import cn.iocoder.yudao.framework.trade.core.annotations.AfterSaleLog;
7   -import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
8   -import cn.iocoder.yudao.framework.trade.core.enums.AfterSaleStatusEnum;
9   -import cn.iocoder.yudao.framework.trade.core.service.AfterSaleLogService;
  3 +import cn.hutool.core.map.MapUtil;
  4 +import cn.hutool.core.util.ObjectUtil;
  5 +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils;
10 6 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
  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 +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
  10 +import com.google.common.collect.Maps;
11 11 import lombok.extern.slf4j.Slf4j;
12 12 import org.aspectj.lang.JoinPoint;
13 13 import org.aspectj.lang.annotation.AfterReturning;
14 14 import org.aspectj.lang.annotation.Aspect;
15 15 import org.aspectj.lang.reflect.MethodSignature;
16 16  
  17 +import javax.annotation.Resource;
17 18 import java.util.HashMap;
18 19 import java.util.Map;
19 20  
  21 +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
  22 +import static java.util.Arrays.asList;
  23 +
20 24 /**
21 25 * 记录售后日志的 AOP 切面
22 26 *
... ... @@ -26,7 +30,14 @@ import java.util.Map;
26 30 @Slf4j
27 31 @Aspect
28 32 public class AfterSaleLogAspect {
  33 + @Resource
  34 + private AfterSaleLogService saleLogService;
  35 +
  36 + private final static String OPERATE_TYPE = "operateType", ID = "id", CONTENT = "content";
29 37  
  38 + /**
  39 + * 切面存入日志
  40 + */
30 41 @AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info")
31 42 public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) {
32 43 try {
... ... @@ -35,16 +46,15 @@ public class AfterSaleLogAspect {
35 46 Long id = WebFrameworkUtils.getLoginUserId();
36 47 Map<String, String> formatObj = spelFormat(joinPoint, info);
37 48 TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO()
38   - .setUserId(id).setUserType(userType)
39   -// MapUtil.getLong() TODO @陈賝:试试这个方法
40   - .setAfterSaleId(Long.valueOf(formatObj.get("id")))
41   - .setContent(formatObj.get("content"))
42   - .setOperateType(formatObj.get("operateType"));
43   - // 异步存入数据库 TODO 可以注入哈;
44   - SpringUtil.getBean(AfterSaleLogService.class).insert(dto);
  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));
  54 + // 异步存入数据库
  55 + saleLogService.createLog(dto);
45 56 } catch (Exception exception) {
46   - // TODO @陈賝:日志要记录下参数哈,不然排查问题不好搞;
47   - log.error("日志记录错误", exception);
  57 + log.error("[afterSaleLog({}) 日志记录错误]", toJsonString(afterSaleLog), exception);
48 58 }
49 59 }
50 60  
... ... @@ -54,19 +64,21 @@ public class AfterSaleLogAspect {
54 64 public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
55 65 MethodSignature signature = (MethodSignature) joinPoint.getSignature();
56 66 AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
57   - Map<String, String> result = new HashMap<>(2); // TODO @陈賝:Maps.newExpectedXXX(3)
  67 + HashMap<String, String> result = Maps.newHashMapWithExpectedSize(2);
  68 + Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info,
  69 + asList(afterSaleLogPoint.id(), afterSaleLogPoint.content()));
58 70 // 售后ID
59   - String id = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.id());
60   - result.put("id", id);
  71 + String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id());
  72 + result.put(ID, id);
61 73 // 操作类型
62   - String operateType = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType());
63   - result.put("operateType", operateType);
  74 + String operateType = afterSaleLogPoint.operateType().description();
  75 + result.put(OPERATE_TYPE, operateType);
64 76 // 日志内容
65   - String content = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.content());
66   - if (StrUtil.isNotEmpty(afterSaleLogPoint.operateType())) {
67   - content += AfterSaleStatusEnum.valueOf(SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType())).description();
  77 + String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content());
  78 + if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) {
  79 + content += operateType;
68 80 }
69   - result.put("content", content);
  81 + result.put(CONTENT, content);
70 82 return result;
71 83 }
72 84  
... ...
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/dto/TradeAfterSaleLogCreateReqDTO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java
1   -package cn.iocoder.yudao.framework.trade.core.dto;
  1 +package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto;
2 2  
3 3 import lombok.AllArgsConstructor;
4 4 import lombok.Data;
... ... @@ -6,6 +6,9 @@ import lombok.NoArgsConstructor;
6 6  
7 7 /**
8 8 * 售后日志的创建 Request DTO
  9 + *
  10 + * @author 陈賝
  11 + * @since 2023/6/19 09:54
9 12 */
10 13 @Data
11 14 @NoArgsConstructor
... ... @@ -18,7 +21,7 @@ public class TradeAfterSaleLogCreateReqDTO {
18 21 private Long id;
19 22 /**
20 23 * 用户编号
21   - *
  24 + * <p>
22 25 * 关联 1:AdminUserDO 的 id 字段
23 26 * 关联 2:MemberUserDO 的 id 字段
24 27 */
... ...
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/service/AfterSaleLogService.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java
1   -package cn.iocoder.yudao.framework.trade.core.service;
  1 +package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service;
2 2  
3   -import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
4 3  
5   -// TODO @陈賝:类注释
  4 +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
  5 +
  6 +/**
  7 + * 交易售后日志 Service 接口
  8 + *
  9 + * @author 陈賝
  10 + * @since 2023/6/12 14:18
  11 + */
6 12 public interface AfterSaleLogService {
7 13  
8 14 /**
... ... @@ -12,7 +18,6 @@ public interface AfterSaleLogService {
12 18 * @author 陈賝
13 19 * @since 2023/6/12 14:18
14 20 */
15   - // TODO @陈賝:createLog 方法名
16   - void insert(TradeAfterSaleLogCreateReqDTO logDTO);
  21 + void createLog(TradeAfterSaleLogCreateReqDTO logDTO);
17 22  
18 23 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java
... ... @@ -5,8 +5,6 @@ import cn.hutool.core.util.RandomUtil;
5 5 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
6 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 7 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
8   -import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
9   -import cn.iocoder.yudao.framework.trade.core.service.AfterSaleLogService;
10 8 import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
11 9 import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
12 10 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDisagreeReqVO;
... ... @@ -26,6 +24,8 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleTypeEnum;
26 24 import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum;
27 25 import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum;
28 26 import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
  27 +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
  28 +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
29 29 import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
30 30 import cn.iocoder.yudao.module.trade.service.order.TradeOrderService;
31 31 import lombok.extern.slf4j.Slf4j;
... ... @@ -40,6 +40,7 @@ import javax.annotation.Resource;
40 40 import java.time.LocalDateTime;
41 41  
42 42 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  43 +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
43 44 import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
44 45  
45 46 /**
... ... @@ -394,7 +395,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
394 395 .setAfterSaleId(afterSale.getId())
395 396 .setOperateType(afterStatus.toString());
396 397 // TODO 废弃,待删除
397   - this.insert(logDTO);
  398 + this.createLog(logDTO);
398 399 }
399 400  
400 401 /**
... ... @@ -406,7 +407,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
406 407 */
407 408 @Override
408 409 @Async
409   - public void insert(TradeAfterSaleLogCreateReqDTO logDTO) {
  410 + public void createLog(TradeAfterSaleLogCreateReqDTO logDTO) {
410 411 try {
411 412 TradeAfterSaleLogDO afterSaleLog = new TradeAfterSaleLogDO()
412 413 .setUserId(logDTO.getUserId())
... ... @@ -416,7 +417,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
416 417 .setContent(logDTO.getContent());
417 418 tradeAfterSaleLogMapper.insert(afterSaleLog);
418 419 }catch (Exception exception){
419   - log.error("日志记录错误", exception);
  420 + log.error("[request({}) 日志记录错误]", toJsonString(logDTO), exception);
420 421 }
421 422 }
422 423 }
... ...
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  
... ...