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
This commit is contained in:
YunaiV
2023-06-23 21:37:21 +08:00
21 changed files with 212 additions and 299 deletions

View File

@ -31,7 +31,6 @@
<module>yudao-spring-boot-starter-biz-sms</module>
<module>yudao-spring-boot-starter-biz-pay</module>
<module>yudao-spring-boot-starter-biz-trade</module>
<module>yudao-spring-boot-starter-biz-weixin</module>
<module>yudao-spring-boot-starter-biz-social</module>
<module>yudao-spring-boot-starter-biz-tenant</module>

View File

@ -1,82 +0,0 @@
package cn.iocoder.yudao.framework.common.util.spel;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
// TODO @Chopper和 SpringExpressionUtils 合并下
/**
* SpelUtil
*
* @author Chopper
* @version v1.0
* @since 2021-01-11 10:45
*/
public class SpelUtil {
/**
* spel表达式解析器
*/
private static SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
/**
* 参数名发现器
*/
private static DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
/**
* 转换 jspl参数
*
* @param joinPoint
* @param spel
* @return
*/
public static String compileParams(JoinPoint joinPoint, String spel) { //Spel表达式解析日志信息
//获得方法参数名数组
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
String[] parameterNames = parameterNameDiscoverer.getParameterNames(signature.getMethod());
if (parameterNames != null && parameterNames.length > 0) {
EvaluationContext context = new StandardEvaluationContext();
//获取方法参数值
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
//替换spel里的变量值为实际值 比如 #user --> user对象
context.setVariable(parameterNames[i], args[i]);
}
return spelExpressionParser.parseExpression(spel).getValue(context).toString();
}
return "";
}
/**
* 转换 jspl参数
*
* @param joinPoint
* @param spel
* @return
*/
public static String compileParams(JoinPoint joinPoint, Object rvt, String spel) { //Spel表达式解析日志信息
//获得方法参数名数组
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
String[] parameterNames = parameterNameDiscoverer.getParameterNames(signature.getMethod());
if (parameterNames != null && parameterNames.length > 0) {
EvaluationContext context = new StandardEvaluationContext();
//获取方法参数值
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
//替换spel里的变量值为实际值 比如 #user --> user对象
context.setVariable(parameterNames[i], args[i]);
}
context.setVariable("rvt", rvt);
return spelExpressionParser.parseExpression(spel).getValue(context).toString();
}
return "";
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.common.util.spring;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.DefaultParameterNameDiscoverer;
@ -24,7 +25,13 @@ import java.util.Map;
*/
public class SpringExpressionUtils {
/**
* spel表达式解析器
*/
private static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
/**
* 参数名发现器
*/
private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new DefaultParameterNameDiscoverer();
private SpringExpressionUtils() {
@ -33,7 +40,7 @@ public class SpringExpressionUtils {
/**
* 从切面中,单个解析 EL 表达式的结果
*
* @param joinPoint 切面点
* @param joinPoint 切面点
* @param expressionString EL 表达式数组
* @return 执行界面
*/
@ -45,7 +52,7 @@ public class SpringExpressionUtils {
/**
* 从切面中,批量解析 EL 表达式的结果
*
* @param joinPoint 切面点
* @param joinPoint 切面点
* @param expressionStrings EL 表达式数组
* @return 结果key 为表达式value 为对应值
*/
@ -79,4 +86,47 @@ public class SpringExpressionUtils {
});
return result;
}
/**
* JoinPoint 切面 批量解析 EL 表达式,转换 jspl参数
*
* @param joinPoint 切面点
* @param info 返回值
* @param expressionStrings EL 表达式数组
* @return Map<String, Object> 结果
* @author 陈賝
* @since 2023/6/18 11:20
*/
public static Map<String, Object> parseExpression(JoinPoint joinPoint, Object info, List<String> expressionStrings) {
// 如果为空,则不进行解析
if (CollUtil.isEmpty(expressionStrings)) {
return MapUtil.newHashMap();
}
// 第一步,构建解析的上下文 EvaluationContext
// 通过 joinPoint 获取被注解方法
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
// 使用 spring 的 ParameterNameDiscoverer 获取方法形参名数组
String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method);
// Spring 的表达式上下文对象
EvaluationContext context = new StandardEvaluationContext();
if (ArrayUtil.isNotEmpty(parameterNames)) {
//获取方法参数值
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
//替换spel里的变量值为实际值 比如 #user --> user对象
context.setVariable(parameterNames[i], args[i]);
}
context.setVariable("info", info);
}
// 第二步,逐个参数解析
Map<String, Object> result = MapUtil.newHashMap(expressionStrings.size(), true);
expressionStrings.forEach(key -> {
Object value = EXPRESSION_PARSER.parseExpression(key).getValue(context);
result.put(key, value);
});
return result;
}
}

View File

@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-framework</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yudao-spring-boot-starter-biz-trade</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>交易模块</description>
<url>https://github.com/YunaiV/ruoyi-vue-pro</url>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-common</artifactId>
</dependency>
<!-- Spring 核心 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<!-- 业务组件 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-api</artifactId> <!-- 需要使用它,进行操作日志的记录 -->
<version>${revision}</version>
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,16 +0,0 @@
package cn.iocoder.yudao.framework.trade.config;
import cn.iocoder.yudao.framework.trade.core.aop.AfterSaleLogAspect;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
// TODO @Chopper和 yudao-module-trade-biz 的 framework 里
@AutoConfiguration
public class YudaoAfterSaleLogAutoConfiguration {
@Bean
public AfterSaleLogAspect afterSaleLogAspect() {
return new AfterSaleLogAspect();
}
}

View File

@ -1,32 +0,0 @@
package cn.iocoder.yudao.framework.trade.core.annotations;
import java.lang.annotation.*;
/**
* 售后日志
*
* @author 陈賝
* @since 2023/6/8 17:04
*/
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AfterSaleLog {
/**
* 售后 ID
*/
String id();
// TODO @陈賝:是不是改成一个操作的枚举?
/**
* 操作类型
*/
String operateType() default "";
/**
* 日志内容
*/
String content() default "";
}

View File

@ -1,73 +0,0 @@
package cn.iocoder.yudao.framework.trade.core.aop;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.util.spel.SpelUtil;
import cn.iocoder.yudao.framework.trade.core.annotations.AfterSaleLog;
import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
import cn.iocoder.yudao.framework.trade.core.enums.AfterSaleStatusEnum;
import cn.iocoder.yudao.framework.trade.core.service.AfterSaleLogService;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import java.util.HashMap;
import java.util.Map;
/**
* 记录售后日志的 AOP 切面
*
* @author 陈賝
* @since 2023/6/13 13:54
*/
@Slf4j
@Aspect
public class AfterSaleLogAspect {
@AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info")
public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) {
try {
// 日志对象拼接
Integer userType = WebFrameworkUtils.getLoginUserType();
Long id = WebFrameworkUtils.getLoginUserId();
Map<String, String> formatObj = spelFormat(joinPoint, info);
TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO()
.setUserId(id).setUserType(userType)
// MapUtil.getLong() TODO @陈賝:试试这个方法
.setAfterSaleId(Long.valueOf(formatObj.get("id")))
.setContent(formatObj.get("content"))
.setOperateType(formatObj.get("operateType"));
// 异步存入数据库 TODO 可以注入哈;
SpringUtil.getBean(AfterSaleLogService.class).insert(dto);
} catch (Exception exception) {
// TODO @陈賝:日志要记录下参数哈,不然排查问题不好搞;
log.error("日志记录错误", exception);
}
}
/**
* 获取描述信息
*/
public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
Map<String, String> result = new HashMap<>(2); // TODO @陈賝Maps.newExpectedXXX(3)
// 售后ID
String id = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.id());
result.put("id", id);
// 操作类型
String operateType = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType());
result.put("operateType", operateType);
// 日志内容
String content = SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.content());
if (StrUtil.isNotEmpty(afterSaleLogPoint.operateType())) {
content += AfterSaleStatusEnum.valueOf(SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType())).description();
}
result.put("content", content);
return result;
}
}

View File

@ -1,43 +0,0 @@
package cn.iocoder.yudao.framework.trade.core.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 售后日志的创建 Request DTO
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TradeAfterSaleLogCreateReqDTO {
/**
* 编号
*/
private Long id;
/**
* 用户编号
*
* 关联 1AdminUserDO 的 id 字段
* 关联 2MemberUserDO 的 id 字段
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 售后编号
*/
private Long afterSaleId;
/**
* 操作类型
*/
private String operateType;
/**
* 操作明细
*/
private String content;
}

View File

@ -1,26 +0,0 @@
package cn.iocoder.yudao.framework.trade.core.enums;
/**
* 售后状态的枚举
*
* @author 陈賝
* @since 2023/6/13 13:53
*/
public enum AfterSaleStatusEnum {
/**
* 申请中
*/
APPLY("申请中");
private final String description;
AfterSaleStatusEnum(String description) {
this.description = description;
}
public String description() {
return description;
}
}

View File

@ -1,18 +0,0 @@
package cn.iocoder.yudao.framework.trade.core.service;
import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
// TODO @陈賝:类注释
public interface AfterSaleLogService {
/**
* 创建售后日志
*
* @param logDTO 日志记录
* @author 陈賝
* @since 2023/6/12 14:18
*/
// TODO @陈賝createLog 方法名
void insert(TradeAfterSaleLogCreateReqDTO logDTO);
}

View File

@ -1 +0,0 @@
cn.iocoder.yudao.framework.trade.config.YudaoAfterSaleLogAutoConfiguration