售后日志优化
parent
7d0e9ea762
commit
a93b9a616f
@ -1,50 +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>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1 +0,0 @@
|
||||
cn.iocoder.yudao.framework.trade.config.YudaoAfterSaleLogAutoConfiguration
|
||||
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.aftersalelog.config;
|
||||
|
||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* trade 模块的 afterSaleLog 组件的 Configuration
|
||||
*
|
||||
* @author 陈賝
|
||||
* @since 2023/6/18 11:09
|
||||
*/
|
||||
@AutoConfiguration
|
||||
public class AfterSaleLogConfiguration {
|
||||
|
||||
@Bean
|
||||
public AfterSaleLogAspect afterSaleLogAspect() {
|
||||
return new AfterSaleLogAspect();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils;
|
||||
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
|
||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* 记录售后日志的 AOP 切面
|
||||
*
|
||||
* @author 陈賝
|
||||
* @since 2023/6/13 13:54
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
public class AfterSaleLogAspect {
|
||||
@Resource
|
||||
private AfterSaleLogService saleLogService;
|
||||
|
||||
@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)
|
||||
.setAfterSaleId(MapUtil.getLong(formatObj, "id"))
|
||||
.setContent(formatObj.get("content"))
|
||||
.setOperateType(formatObj.get("operateType"));
|
||||
// 异步存入数据库
|
||||
saleLogService.createLog(dto);
|
||||
} catch (Exception exception) {
|
||||
log.error("[afterSaleLog({}) 日志记录错误]", toJsonString(afterSaleLog), exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取描述信息
|
||||
*/
|
||||
public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
|
||||
HashMap<String, String> result = Maps.newHashMapWithExpectedSize(3);
|
||||
Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info,
|
||||
asList(afterSaleLogPoint.id(), afterSaleLogPoint.operateType().description(), afterSaleLogPoint.content()));
|
||||
// 售后ID
|
||||
String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id());
|
||||
result.put("id", id);
|
||||
// 操作类型
|
||||
String operateType = MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
|
||||
result.put("operateType", operateType);
|
||||
// 日志内容
|
||||
String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content());
|
||||
if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) {
|
||||
content += MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
|
||||
}
|
||||
result.put("content", content);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.framework.trade.core.enums;
|
||||
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums;
|
||||
|
||||
/**
|
||||
* 售后状态的枚举
|
||||
@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
|
||||
|
||||
/**
|
||||
* 交易售后日志 Service 接口
|
||||
*
|
||||
* @author 陈賝
|
||||
* @since 2023/6/12 14:18
|
||||
*/
|
||||
public interface AfterSaleLogService {
|
||||
|
||||
/**
|
||||
* 创建售后日志
|
||||
*
|
||||
* @param logDTO 日志记录
|
||||
* @author 陈賝
|
||||
* @since 2023/6/12 14:18
|
||||
*/
|
||||
void createLog(TradeAfterSaleLogCreateReqDTO logDTO);
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue