售后日志优化

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

@ -25,8 +25,6 @@ import java.util.Map;
*/
public class SpringExpressionUtils {
/**
* spel表达式解析器
*/
@ -92,14 +90,14 @@ public class SpringExpressionUtils {
/**
* JoinPoint 切面 批量解析 EL 表达式转换 jspl参数
*
* @param joinPoint 切面点
* @param rvt 返回值
* @param expressionStrings EL 表达式数组
* @return java.lang.String 结果
* @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 rvt, List<String> expressionStrings) {
public static Map<String, Object> parseExpression(JoinPoint joinPoint, Object info, List<String> expressionStrings) {
// 如果为空则不进行解析
if (CollUtil.isEmpty(expressionStrings)) {
return MapUtil.newHashMap();
@ -120,7 +118,7 @@ public class SpringExpressionUtils {
//替换spel里的变量值为实际值 比如 #user --> user对象
context.setVariable(parameterNames[i], args[i]);
}
context.setVariable("rvt", rvt);
context.setVariable("info", info);
}
// 第二步逐个参数解析
Map<String, Object> result = MapUtil.newHashMap(expressionStrings.size(), true);

View File

@ -1,21 +1,22 @@
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums;
package cn.iocoder.yudao.module.trade.enums.aftersale;
/**
* 售后状态的枚举
* 售后操作类型的枚举
*
* @author 陈賝
* @since 2023/6/13 13:53
*/
public enum AfterSaleStatusEnum {
public enum AfterSaleOperateTypeEnum {
/**
* 申请
* 用户申请
*/
APPLY("申请中");
APPLY("用户申请"),
;
private final String description;
AfterSaleStatusEnum(String description) {
AfterSaleOperateTypeEnum(String description) {
this.description = description;
}

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

@ -66,7 +66,6 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
AppTradeAfterSaleCreateReqVO createReqVO = new AppTradeAfterSaleCreateReqVO()
.setOrderItemId(1L).setRefundPrice(100).setWay(TradeAfterSaleWayEnum.RETURN_AND_REFUND.getWay())
.setApplyReason("退钱").setApplyDescription("快退")
.setOperateType("APPLY")
.setApplyPicUrls(asList("https://www.baidu.com/1.png", "https://www.baidu.com/2.png"));
// mock 方法交易订单项
TradeOrderItemDO orderItem = randomPojo(TradeOrderItemDO.class, o -> {
@ -103,8 +102,6 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
assertEquals(afterSaleLog.getUserType(), UserTypeEnum.MEMBER.getValue());
assertEquals(afterSaleLog.getAfterSaleId(), afterSaleId);
assertPojoEquals(afterSale, orderItem, "id", "creator", "createTime", "updater", "updateTime");
// assertNull(afterSaleLog.getBeforeStatus());
// assertEquals(afterSaleLog.getAfterStatus(), TradeAfterSaleStatusEnum.APPLY.getStatus());
assertEquals(afterSaleLog.getContent(), TradeAfterSaleStatusEnum.APPLY.getContent());
}