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