From 2f0aaee82334657a9341874734dcda01854f7861 Mon Sep 17 00:00:00 2001 From: chenchen <934298133@qq.com> Date: Mon, 19 Jun 2023 17:04:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=94=AE=E5=90=8E=E6=97=A5=E5=BF=97=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/spring/SpringExpressionUtils.java | 14 ++++----- .../aftersale/AfterSaleOperateTypeEnum.java} | 13 ++++---- .../aftersale/TradeAfterSaleController.java | 19 ------------ .../AppTradeAfterSaleController.java | 3 ++ .../config/AfterSaleLogConfiguration.java | 4 +-- .../core/annotations/AfterSaleLog.java | 6 ++-- .../core/aop/AfterSaleLogAspect.java | 31 +++++++++++-------- .../aftersale/TradeAfterSaleServiceTest.java | 3 -- 8 files changed, 39 insertions(+), 54 deletions(-) rename yudao-module-mall/{yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/enums/AfterSaleStatusEnum.java => yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java} (50%) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spring/SpringExpressionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spring/SpringExpressionUtils.java index a2b97206e..d706767b9 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spring/SpringExpressionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spring/SpringExpressionUtils.java @@ -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 结果 * @author 陈賝 * @since 2023/6/18 11:20 */ - public static Map parseExpression(JoinPoint joinPoint, Object rvt, List expressionStrings) { + public static Map parseExpression(JoinPoint joinPoint, Object info, List 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 result = MapUtil.newHashMap(expressionStrings.size(), true); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/enums/AfterSaleStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java similarity index 50% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/enums/AfterSaleStatusEnum.java rename to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java index 8897216e3..93cc0b5cd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/enums/AfterSaleStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java @@ -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; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index 868b0a056..a1bf5d544 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -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 - * @author 陈賝 - * @date 2023/6/14 21:39 - */ - @PostMapping(value = "/create") - @AfterSaleLog(id = "#createReqVO.orderItemId", content = "'申请售后:售后编号['+#createReqVO.orderItemId+'] , '", operateType = AfterSaleStatusEnum.APPLY) - public CommonResult createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) { - return success(1L); -// return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO)); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/AppTradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/AppTradeAfterSaleController.java index 1982a9bdd..004f6e68a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/AppTradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/AppTradeAfterSaleController.java @@ -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 createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) { return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java index b62f384ff..901621d79 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java @@ -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 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/annotations/AfterSaleLog.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/annotations/AfterSaleLog.java index d86b42515..d1f26d7a5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/annotations/AfterSaleLog.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/annotations/AfterSaleLog.java @@ -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(); /** * 日志内容 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java index 5e76e084e..16a98a574 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java @@ -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 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 spelFormat(JoinPoint joinPoint, Object info) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); - HashMap result = Maps.newHashMapWithExpectedSize(3); + HashMap result = Maps.newHashMapWithExpectedSize(2); Map 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; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java index 7f94b6d19..68efd67a7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java @@ -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()); }