mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-02 03:34:58 +08:00
code review:售后日志逻辑
This commit is contained in:
parent
59e16795be
commit
60b24e36d5
@ -7,12 +7,13 @@ 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
|
||||
* 2021-01-11 10:45
|
||||
* @since 2021-01-11 10:45
|
||||
*/
|
||||
public class SpelUtil {
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
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;
|
||||
|
||||
// TODO @Chopper:和 yudao-module-trade-biz 的 framework 里
|
||||
@AutoConfiguration
|
||||
public class YudaoAfterSaleLogAutoConfiguration {
|
||||
|
||||
|
@ -1,15 +1,12 @@
|
||||
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
|
||||
* @since 2023/6/8 17:04
|
||||
*/
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ -17,10 +14,11 @@ import java.lang.annotation.*;
|
||||
public @interface AfterSaleLog {
|
||||
|
||||
/**
|
||||
* 售后ID
|
||||
* 售后 ID
|
||||
*/
|
||||
String id();
|
||||
|
||||
// TODO @陈賝:是不是改成一个操作的枚举?
|
||||
/**
|
||||
* 操作类型
|
||||
*/
|
||||
|
@ -1,29 +1,27 @@
|
||||
package cn.iocoder.yudao.framework.trade.core.aop;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
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.TradeAfterSaleLogDTO;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* 售后日志
|
||||
* 记录售后日志的 AOP 切面
|
||||
*
|
||||
* @author 陈賝
|
||||
* @date 2023/6/13 13:54
|
||||
* @since 2023/6/13 13:54
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@ -32,20 +30,20 @@ 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)
|
||||
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);
|
||||
System.out.println(dto.toString());
|
||||
} catch (Exception exception) {
|
||||
// TODO @陈賝:日志要记录下参数哈,不然排查问题不好搞;
|
||||
log.error("日志记录错误", exception);
|
||||
}
|
||||
}
|
||||
@ -54,34 +52,22 @@ public class AfterSaleLogAspect {
|
||||
* 获取描述信息
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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 (CharSequenceUtil.isNotEmpty(afterSaleLogPoint.operateType())) {
|
||||
if (StrUtil.isNotEmpty(afterSaleLogPoint.operateType())) {
|
||||
content += AfterSaleStatusEnum.valueOf(SpelUtil.compileParams(joinPoint, info, afterSaleLogPoint.operateType())).description();
|
||||
}
|
||||
result.put("content", content);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,13 +3,14 @@ package cn.iocoder.yudao.framework.trade.core.dto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 售后日志的创建 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class TradeAfterSaleLogDTO {
|
||||
public class TradeAfterSaleLogCreateReqDTO {
|
||||
|
||||
/**
|
||||
* 编号
|
@ -1,10 +1,10 @@
|
||||
package cn.iocoder.yudao.framework.trade.core.enums;
|
||||
|
||||
/**
|
||||
* 售后状态
|
||||
* 售后状态的枚举
|
||||
*
|
||||
* @author 陈賝
|
||||
* @date 2023/6/13 13:53
|
||||
* @since 2023/6/13 13:53
|
||||
*/
|
||||
public enum AfterSaleStatusEnum {
|
||||
|
||||
@ -23,5 +23,4 @@ public enum AfterSaleStatusEnum {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.trade.core;
|
@ -1,16 +1,18 @@
|
||||
package cn.iocoder.yudao.framework.trade.core.service;
|
||||
|
||||
import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogDTO;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import cn.iocoder.yudao.framework.trade.core.dto.TradeAfterSaleLogCreateReqDTO;
|
||||
|
||||
// TODO @陈賝:类注释
|
||||
public interface AfterSaleLogService {
|
||||
|
||||
/**
|
||||
* 日志记录
|
||||
* 创建售后日志
|
||||
*
|
||||
* @param logDTO 日志记录
|
||||
* @author 陈賝
|
||||
* @date 2023/6/12 14:18
|
||||
* @since 2023/6/12 14:18
|
||||
*/
|
||||
void insert(TradeAfterSaleLogDTO logDTO);
|
||||
// TODO @陈賝:createLog 方法名
|
||||
void insert(TradeAfterSaleLogCreateReqDTO logDTO);
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.trade;
|
@ -112,7 +112,7 @@ public class TradeAfterSaleController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
// TODO @陈賝:后续要删除下
|
||||
/**
|
||||
* 售后日志测试
|
||||
*
|
||||
|
@ -32,6 +32,7 @@ public class AppTradeAfterSaleCreateReqVO {
|
||||
@NotNull(message = "申请原因不能为空")
|
||||
private String applyReason;
|
||||
|
||||
// TODO @陈賝:这个参数不应该有呀。
|
||||
/**
|
||||
* @see AfterSaleStatusEnum
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user