parent
35df912be7
commit
59e16795be
@ -0,0 +1,54 @@
|
|||||||
|
<?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>
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package cn.iocoder.yudao.framework.trade.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.trade.core.annotations.AfterSaleLog;
|
||||||
|
import cn.iocoder.yudao.framework.trade.core.aop.AfterSaleLogAspect;
|
||||||
|
import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
@AutoConfiguration
|
||||||
|
public class YudaoAfterSaleLogAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AfterSaleLogAspect afterSaleLogAspect() {
|
||||||
|
return new AfterSaleLogAspect();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package cn.iocoder.yudao.framework.trade.core.annotations;
|
||||||
|
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 售后日志
|
||||||
|
*
|
||||||
|
* @author 陈賝
|
||||||
|
* @date 2023/6/8 17:04
|
||||||
|
*/
|
||||||
|
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface AfterSaleLog {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 售后ID
|
||||||
|
*/
|
||||||
|
String id();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作类型
|
||||||
|
*/
|
||||||
|
String operateType() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志内容
|
||||||
|
*/
|
||||||
|
String content() default "";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
package cn.iocoder.yudao.framework.trade.core.aop;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
|
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.TradeAfterSaleLogDTO;
|
||||||
|
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.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 售后日志
|
||||||
|
*
|
||||||
|
* @author 陈賝
|
||||||
|
* @date 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);
|
||||||
|
TradeAfterSaleLogDTO dto = new TradeAfterSaleLogDTO()
|
||||||
|
.setUserId(id)
|
||||||
|
.setUserType(userType)
|
||||||
|
.setAfterSaleId(Long.valueOf(formatObj.get("id")))
|
||||||
|
.setContent(formatObj.get("content"))
|
||||||
|
.setOperateType(formatObj.get("operateType"));
|
||||||
|
// 异步存入数据库
|
||||||
|
SpringUtil.getBean(AfterSaleLogService.class).insert(dto);
|
||||||
|
System.out.println(dto.toString());
|
||||||
|
} catch (Exception exception) {
|
||||||
|
log.error("日志记录错误", exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取描述信息
|
||||||
|
*/
|
||||||
|
public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
|
||||||
|
|
||||||
|
Map<String, String> result = new HashMap<>(2);
|
||||||
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
|
AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 售后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 (CharSequenceUtil.isNotEmpty(afterSaleLogPoint.operateType())) {
|
||||||
|
content += AfterSaleStatusEnum.valueOf(SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType())).description();
|
||||||
|
}
|
||||||
|
result.put("content", content);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.yudao.framework.trade.core.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 售后状态
|
||||||
|
*
|
||||||
|
* @author 陈賝
|
||||||
|
* @date 2023/6/13 13:53
|
||||||
|
*/
|
||||||
|
public enum AfterSaleStatusEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请中
|
||||||
|
*/
|
||||||
|
APPLY("申请中");
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
AfterSaleStatusEnum(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String description() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.yudao.framework.trade.core;
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package cn.iocoder.yudao.framework.trade.core.service;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogDTO;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|
||||||
|
public interface AfterSaleLogService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志记录
|
||||||
|
*
|
||||||
|
* @param logDTO 日志记录
|
||||||
|
* @author 陈賝
|
||||||
|
* @date 2023/6/12 14:18
|
||||||
|
*/
|
||||||
|
void insert(TradeAfterSaleLogDTO logDTO);
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.yudao.framework.trade;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
cn.iocoder.yudao.framework.trade.config.YudaoAfterSaleLogAutoConfiguration
|
||||||
Loading…
Reference in New Issue