售后日志优化

This commit is contained in:
chenchen
2023-06-19 17:04:07 +08:00
parent b7c0fef63f
commit 2f0aaee823
8 changed files with 39 additions and 54 deletions

View File

@@ -11,11 +11,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSal
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums.AfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -113,20 +110,4 @@ public class TradeAfterSaleController {
return success(true);
}
// TODO @陈賝:后续要删除下
/**
* 售后日志测试
*
* @param createReqVO
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Long>
* @author 陈賝
* @date 2023/6/14 21:39
*/
@PostMapping(value = "/create")
@AfterSaleLog(id = "#createReqVO.orderItemId", content = "'申请售后:售后编号['+#createReqVO.orderItemId+'] , '", operateType = AfterSaleStatusEnum.APPLY)
public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
return success(1L);
// return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
}
}

View File

@@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSa
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSalePageItemRespVO;
import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -78,6 +80,7 @@ public class AppTradeAfterSaleController {
@PostMapping(value = "/create")
@Operation(summary = "申请售后")
@AfterSaleLog(id = "#info.data", content = "'申请售后:售后编号['+#info.data+'],订单编号['+#createReqVO.orderItemId+'], '", operateType = AfterSaleOperateTypeEnum.APPLY)
public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
}

View File

@@ -1,8 +1,8 @@
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;
import org.springframework.context.annotation.Configuration;
/**
* trade 模块的 afterSaleLog 组件的 Configuration
@@ -10,7 +10,7 @@ import org.springframework.context.annotation.Bean;
* @author 陈賝
* @since 2023/6/18 11:09
*/
@AutoConfiguration
@Configuration(proxyBeanMethods = false)
public class AfterSaleLogConfiguration {
@Bean

View File

@@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums.AfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
import java.lang.annotation.*;
@@ -10,7 +10,7 @@ import java.lang.annotation.*;
* @author 陈賝
* @since 2023/6/8 17:04
*/
@Target({ElementType.METHOD,ElementType.TYPE})
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AfterSaleLog {
@@ -23,7 +23,7 @@ public @interface AfterSaleLog {
/**
* 操作类型
*/
AfterSaleStatusEnum operateType() default AfterSaleStatusEnum.APPLY;
AfterSaleOperateTypeEnum operateType();
/**
* 日志内容

View File

@@ -4,13 +4,12 @@ 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.dto.TradeAfterSaleLogCreateReqDTO;
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;
@@ -34,6 +33,11 @@ public class AfterSaleLogAspect {
@Resource
private AfterSaleLogService saleLogService;
private final static String OPERATE_TYPE = "operateType", ID = "id", CONTENT = "content";
/**
* 切面存入日志
*/
@AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info")
public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) {
try {
@@ -42,10 +46,11 @@ public class AfterSaleLogAspect {
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"));
.setUserId(id)
.setUserType(userType)
.setAfterSaleId(MapUtil.getLong(formatObj, ID))
.setOperateType(MapUtil.getStr(formatObj, OPERATE_TYPE))
.setContent(MapUtil.getStr(formatObj, CONTENT));
// 异步存入数据库
saleLogService.createLog(dto);
} catch (Exception exception) {
@@ -59,21 +64,21 @@ public class AfterSaleLogAspect {
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);
HashMap<String, String> result = Maps.newHashMapWithExpectedSize(2);
Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info,
asList(afterSaleLogPoint.id(), afterSaleLogPoint.operateType().description(), afterSaleLogPoint.content()));
asList(afterSaleLogPoint.id(), afterSaleLogPoint.content()));
// 售后ID
String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id());
result.put("id", id);
result.put(ID, id);
// 操作类型
String operateType = MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
result.put("operateType", operateType);
String operateType = afterSaleLogPoint.operateType().description();
result.put(OPERATE_TYPE, operateType);
// 日志内容
String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content());
if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) {
content += MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
content += operateType;
}
result.put("content", content);
result.put(CONTENT, content);
return result;
}

View File

@@ -1,26 +0,0 @@
package cn.iocoder.yudao.module.trade.framework.aftersalelog.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;
}
}