Commit 60b24e36d5117bfb63248e4cbeae3890b72cb352

Authored by YunaiV
1 parent 59e16795

code review:售后日志逻辑

Showing 11 changed files with 36 additions and 51 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spel/SpelUtil.java
@@ -7,12 +7,13 @@ import org.springframework.expression.EvaluationContext; @@ -7,12 +7,13 @@ import org.springframework.expression.EvaluationContext;
7 import org.springframework.expression.spel.standard.SpelExpressionParser; 7 import org.springframework.expression.spel.standard.SpelExpressionParser;
8 import org.springframework.expression.spel.support.StandardEvaluationContext; 8 import org.springframework.expression.spel.support.StandardEvaluationContext;
9 9
  10 +// TODO @Chopper:和 SpringExpressionUtils 合并下
10 /** 11 /**
11 * SpelUtil 12 * SpelUtil
12 * 13 *
13 * @author Chopper 14 * @author Chopper
14 * @version v1.0 15 * @version v1.0
15 - * 2021-01-11 10:45 16 + * @since 2021-01-11 10:45
16 */ 17 */
17 public class SpelUtil { 18 public class SpelUtil {
18 19
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/config/YudaoAfterSaleLogAutoConfiguration.java
1 package cn.iocoder.yudao.framework.trade.config; 1 package cn.iocoder.yudao.framework.trade.config;
2 2
3 -import cn.iocoder.yudao.framework.trade.core.annotations.AfterSaleLog;  
4 import cn.iocoder.yudao.framework.trade.core.aop.AfterSaleLogAspect; 3 import cn.iocoder.yudao.framework.trade.core.aop.AfterSaleLogAspect;
5 -import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;  
6 import org.springframework.boot.autoconfigure.AutoConfiguration; 4 import org.springframework.boot.autoconfigure.AutoConfiguration;
7 import org.springframework.context.annotation.Bean; 5 import org.springframework.context.annotation.Bean;
8 6
  7 +// TODO @Chopper:和 yudao-module-trade-biz 的 framework 里
9 @AutoConfiguration 8 @AutoConfiguration
10 public class YudaoAfterSaleLogAutoConfiguration { 9 public class YudaoAfterSaleLogAutoConfiguration {
11 10
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/annotations/AfterSaleLog.java
1 package cn.iocoder.yudao.framework.trade.core.annotations; 1 package cn.iocoder.yudao.framework.trade.core.annotations;
2 2
3 -import org.aspectj.lang.annotation.Aspect;  
4 -import org.springframework.stereotype.Component;  
5 -  
6 import java.lang.annotation.*; 3 import java.lang.annotation.*;
7 4
8 /** 5 /**
9 * 售后日志 6 * 售后日志
10 * 7 *
11 * @author 陈賝 8 * @author 陈賝
12 - * @date 2023/6/8 17:04 9 + * @since 2023/6/8 17:04
13 */ 10 */
14 @Target({ElementType.METHOD,ElementType.TYPE}) 11 @Target({ElementType.METHOD,ElementType.TYPE})
15 @Retention(RetentionPolicy.RUNTIME) 12 @Retention(RetentionPolicy.RUNTIME)
@@ -17,10 +14,11 @@ import java.lang.annotation.*; @@ -17,10 +14,11 @@ import java.lang.annotation.*;
17 public @interface AfterSaleLog { 14 public @interface AfterSaleLog {
18 15
19 /** 16 /**
20 - * 售后ID 17 + * 售后 ID
21 */ 18 */
22 String id(); 19 String id();
23 20
  21 + // TODO @陈賝:是不是改成一个操作的枚举?
24 /** 22 /**
25 * 操作类型 23 * 操作类型
26 */ 24 */
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/aop/AfterSaleLogAspect.java
1 package cn.iocoder.yudao.framework.trade.core.aop; 1 package cn.iocoder.yudao.framework.trade.core.aop;
2 2
3 -import cn.hutool.core.text.CharSequenceUtil; 3 +import cn.hutool.core.util.StrUtil;
4 import cn.hutool.extra.spring.SpringUtil; 4 import cn.hutool.extra.spring.SpringUtil;
5 import cn.iocoder.yudao.framework.common.util.spel.SpelUtil; 5 import cn.iocoder.yudao.framework.common.util.spel.SpelUtil;
6 import cn.iocoder.yudao.framework.trade.core.annotations.AfterSaleLog; 6 import cn.iocoder.yudao.framework.trade.core.annotations.AfterSaleLog;
7 -import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogDTO; 7 +import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
8 import cn.iocoder.yudao.framework.trade.core.enums.AfterSaleStatusEnum; 8 import cn.iocoder.yudao.framework.trade.core.enums.AfterSaleStatusEnum;
9 import cn.iocoder.yudao.framework.trade.core.service.AfterSaleLogService; 9 import cn.iocoder.yudao.framework.trade.core.service.AfterSaleLogService;
10 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; 10 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
11 import lombok.extern.slf4j.Slf4j; 11 import lombok.extern.slf4j.Slf4j;
12 import org.aspectj.lang.JoinPoint; 12 import org.aspectj.lang.JoinPoint;
13 import org.aspectj.lang.annotation.AfterReturning; 13 import org.aspectj.lang.annotation.AfterReturning;
14 -import org.aspectj.lang.annotation.Around;  
15 import org.aspectj.lang.annotation.Aspect; 14 import org.aspectj.lang.annotation.Aspect;
16 import org.aspectj.lang.reflect.MethodSignature; 15 import org.aspectj.lang.reflect.MethodSignature;
17 -import org.springframework.stereotype.Component;  
18 16
19 import java.util.HashMap; 17 import java.util.HashMap;
20 import java.util.Map; 18 import java.util.Map;
21 19
22 /** 20 /**
23 - * 售后日志 21 + * 记录售后日志的 AOP 切面
24 * 22 *
25 * @author 陈賝 23 * @author 陈賝
26 - * @date 2023/6/13 13:54 24 + * @since 2023/6/13 13:54
27 */ 25 */
28 @Slf4j 26 @Slf4j
29 @Aspect 27 @Aspect
@@ -32,20 +30,20 @@ public class AfterSaleLogAspect { @@ -32,20 +30,20 @@ public class AfterSaleLogAspect {
32 @AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info") 30 @AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info")
33 public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) { 31 public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) {
34 try { 32 try {
35 - //日志对象拼接 33 + // 日志对象拼接
36 Integer userType = WebFrameworkUtils.getLoginUserType(); 34 Integer userType = WebFrameworkUtils.getLoginUserType();
37 Long id = WebFrameworkUtils.getLoginUserId(); 35 Long id = WebFrameworkUtils.getLoginUserId();
38 Map<String, String> formatObj = spelFormat(joinPoint, info); 36 Map<String, String> formatObj = spelFormat(joinPoint, info);
39 - TradeAfterSaleLogDTO dto = new TradeAfterSaleLogDTO()  
40 - .setUserId(id)  
41 - .setUserType(userType) 37 + TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO()
  38 + .setUserId(id).setUserType(userType)
  39 +// MapUtil.getLong() TODO @陈賝:试试这个方法
42 .setAfterSaleId(Long.valueOf(formatObj.get("id"))) 40 .setAfterSaleId(Long.valueOf(formatObj.get("id")))
43 .setContent(formatObj.get("content")) 41 .setContent(formatObj.get("content"))
44 .setOperateType(formatObj.get("operateType")); 42 .setOperateType(formatObj.get("operateType"));
45 - // 异步存入数据库 43 + // 异步存入数据库 TODO 可以注入哈;
46 SpringUtil.getBean(AfterSaleLogService.class).insert(dto); 44 SpringUtil.getBean(AfterSaleLogService.class).insert(dto);
47 - System.out.println(dto.toString());  
48 } catch (Exception exception) { 45 } catch (Exception exception) {
  46 + // TODO @陈賝:日志要记录下参数哈,不然排查问题不好搞;
49 log.error("日志记录错误", exception); 47 log.error("日志记录错误", exception);
50 } 48 }
51 } 49 }
@@ -54,34 +52,22 @@ public class AfterSaleLogAspect { @@ -54,34 +52,22 @@ public class AfterSaleLogAspect {
54 * 获取描述信息 52 * 获取描述信息
55 */ 53 */
56 public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) { 54 public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
57 -  
58 - Map<String, String> result = new HashMap<>(2);  
59 MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 55 MethodSignature signature = (MethodSignature) joinPoint.getSignature();
60 AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); 56 AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
61 -  
62 - /*  
63 - * 售后ID  
64 - */ 57 + Map<String, String> result = new HashMap<>(2); // TODO @陈賝:Maps.newExpectedXXX(3)
  58 + // 售后ID
65 String id = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.id()); 59 String id = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.id());
66 result.put("id", id); 60 result.put("id", id);
67 -  
68 - /*  
69 - * 操作类型  
70 - */ 61 + // 操作类型
71 String operateType = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType()); 62 String operateType = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType());
72 result.put("operateType", operateType); 63 result.put("operateType", operateType);
73 -  
74 - /*  
75 - * 日志内容  
76 - */ 64 + // 日志内容
77 String content = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.content()); 65 String content = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.content());
78 - if (CharSequenceUtil.isNotEmpty(afterSaleLogPoint.operateType())) { 66 + if (StrUtil.isNotEmpty(afterSaleLogPoint.operateType())) {
79 content += AfterSaleStatusEnum.valueOf(SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType())).description(); 67 content += AfterSaleStatusEnum.valueOf(SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType())).description();
80 } 68 }
81 result.put("content", content); 69 result.put("content", content);
82 return result; 70 return result;
83 -  
84 } 71 }
85 72
86 -  
87 } 73 }
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/dto/TradeAfterSaleLogDTO.java renamed to yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/dto/TradeAfterSaleLogCreateReqDTO.java
@@ -3,13 +3,14 @@ package cn.iocoder.yudao.framework.trade.core.dto; @@ -3,13 +3,14 @@ package cn.iocoder.yudao.framework.trade.core.dto;
3 import lombok.AllArgsConstructor; 3 import lombok.AllArgsConstructor;
4 import lombok.Data; 4 import lombok.Data;
5 import lombok.NoArgsConstructor; 5 import lombok.NoArgsConstructor;
6 -import lombok.experimental.Accessors;  
7 6
  7 +/**
  8 + * 售后日志的创建 Request DTO
  9 + */
8 @Data 10 @Data
9 @NoArgsConstructor 11 @NoArgsConstructor
10 @AllArgsConstructor 12 @AllArgsConstructor
11 -@Accessors(chain = true)  
12 -public class TradeAfterSaleLogDTO { 13 +public class TradeAfterSaleLogCreateReqDTO {
13 14
14 /** 15 /**
15 * 编号 16 * 编号
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/enums/AfterSaleStatusEnum.java
1 package cn.iocoder.yudao.framework.trade.core.enums; 1 package cn.iocoder.yudao.framework.trade.core.enums;
2 2
3 /** 3 /**
4 - * 售后状态 4 + * 售后状态的枚举
5 * 5 *
6 * @author 陈賝 6 * @author 陈賝
7 - * @date 2023/6/13 13:53 7 + * @since 2023/6/13 13:53
8 */ 8 */
9 public enum AfterSaleStatusEnum { 9 public enum AfterSaleStatusEnum {
10 10
@@ -23,5 +23,4 @@ public enum AfterSaleStatusEnum { @@ -23,5 +23,4 @@ public enum AfterSaleStatusEnum {
23 return description; 23 return description;
24 } 24 }
25 25
26 -  
27 } 26 }
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/package-info.java deleted
1 -package cn.iocoder.yudao.framework.trade.core;  
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/core/service/AfterSaleLogService.java
1 package cn.iocoder.yudao.framework.trade.core.service; 1 package cn.iocoder.yudao.framework.trade.core.service;
2 2
3 -import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogDTO;  
4 -import org.springframework.scheduling.annotation.Async; 3 +import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
5 4
  5 +// TODO @陈賝:类注释
6 public interface AfterSaleLogService { 6 public interface AfterSaleLogService {
7 7
8 /** 8 /**
9 - * 日志记录 9 + * 创建售后日志
10 * 10 *
11 * @param logDTO 日志记录 11 * @param logDTO 日志记录
12 * @author 陈賝 12 * @author 陈賝
13 - * @date 2023/6/12 14:18 13 + * @since 2023/6/12 14:18
14 */ 14 */
15 - void insert(TradeAfterSaleLogDTO logDTO); 15 + // TODO @陈賝:createLog 方法名
  16 + void insert(TradeAfterSaleLogCreateReqDTO logDTO);
  17 +
16 } 18 }
yudao-framework/yudao-spring-boot-starter-biz-trade/src/main/java/cn/iocoder/yudao/framework/trade/package-info.java deleted
1 -package cn.iocoder.yudao.framework.trade;  
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java
@@ -112,7 +112,7 @@ public class TradeAfterSaleController { @@ -112,7 +112,7 @@ public class TradeAfterSaleController {
112 return success(true); 112 return success(true);
113 } 113 }
114 114
115 - 115 + // TODO @陈賝:后续要删除下
116 /** 116 /**
117 * 售后日志测试 117 * 售后日志测试
118 * 118 *
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/vo/AppTradeAfterSaleCreateReqVO.java
@@ -32,6 +32,7 @@ public class AppTradeAfterSaleCreateReqVO { @@ -32,6 +32,7 @@ public class AppTradeAfterSaleCreateReqVO {
32 @NotNull(message = "申请原因不能为空") 32 @NotNull(message = "申请原因不能为空")
33 private String applyReason; 33 private String applyReason;
34 34
  35 + // TODO @陈賝:这个参数不应该有呀。
35 /** 36 /**
36 * @see AfterSaleStatusEnum 37 * @see AfterSaleStatusEnum
37 */ 38 */