diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java index 168eb741f..1e18bf6e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java @@ -54,7 +54,7 @@ public class TradeAfterSaleLogDO extends BaseDO { * * 枚举 {@link AfterSaleOperateTypeEnum} */ - private String operateType; + private Integer 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 5ff16d38a..cdb2c0a48 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,6 +4,7 @@ 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.enums.aftersale.AfterSaleOperateTypeEnum; 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; @@ -47,13 +48,12 @@ public class AfterSaleLogAspect { // 日志对象拼接 Integer userType = WebFrameworkUtils.getLoginUserType(); Long id = WebFrameworkUtils.getLoginUserId(); - Map formatObj = spelFormat(joinPoint, info); TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO() .setUserId(id) .setUserType(userType) - .setAfterSaleId(MapUtil.getLong(formatObj, ID)) - .setOperateType(MapUtil.getStr(formatObj, OPERATE_TYPE)) - .setContent(MapUtil.getStr(formatObj, CONTENT)); + .setAfterSaleId(getAfterSaleId(joinPoint, info, afterSaleLog.id())) + .setOperateType(afterSaleLog.operateType().getType()) + .setContent(getContent(joinPoint, info, afterSaleLog)); // 异步存入数据库 afterSaleLogService.createLog(dto); } catch (Exception exception) { @@ -64,26 +64,49 @@ public class AfterSaleLogAspect { /** * 获取描述信息 */ - public static Map spelFormat(JoinPoint joinPoint, Object info) { + private static Map spelFormat(JoinPoint joinPoint, Object info) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); - HashMap result = Maps.newHashMapWithExpectedSize(2); - Map spelMap = SpringExpressionUtils.parseExpression(joinPoint, info, + return SpringExpressionUtils.parseExpression(joinPoint, info, asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); - // TODO @chenchen:是不是抽成 3 个方法好点;毕竟 map 太抽象了;; - // 售后ID - String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id()); - result.put(ID, id); - // 操作类型 - String operateType = afterSaleLogPoint.operateType().description(); - result.put(OPERATE_TYPE, operateType); - // 日志内容 - String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content()); - if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) { - content += operateType; - } - result.put(CONTENT, content); - return result; } + /** + * 获取售后ID + */ + private static Long getAfterSaleId(JoinPoint joinPoint, Object info, String spel) { + Map spelMap = spelFormat(joinPoint, info); + return MapUtil.getLong(spelMap, spel); + } + + /** + * 获取解析后的日志内容 + */ + private static String getContent(JoinPoint joinPoint, Object info, AfterSaleLog afterSaleLog) { + Map spelMap = spelFormat(joinPoint, info); + StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLog.content())); + AfterSaleOperateTypeEnum afterSaleOperateTypeEnum = afterSaleLog.operateType(); + return ObjectUtil.isNotNull(afterSaleOperateTypeEnum) ? + content.append(afterSaleOperateTypeEnum.getDescription()).toString() : content.toString(); + } + + // public static Map spelFormat(JoinPoint joinPoint, Object info) { + // MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + // AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); + // HashMap result = Maps.newHashMapWithExpectedSize(2); + // Map spelMap = SpringExpressionUtils.parseExpression(joinPoint, info, + // asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); + // + // // 售后ID + // result.put(ID, MapUtil.getLong(spelMap, afterSaleLogPoint.id())); + // // 操作类型 + // result.put(OPERATE_TYPE, afterSaleLogPoint.operateType().getType()); + // // 日志内容 + // StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLogPoint.content())); + // + // result.put(CONTENT, ObjectUtil.isNotNull(afterSaleLogPoint.operateType()) ? + // content.append(afterSaleLogPoint.operateType().getDescription()).toString() : content.toString()); + // return result; + // } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java index 7beac68cf..1b2c640a2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java @@ -37,7 +37,7 @@ public class TradeAfterSaleLogCreateReqDTO { /** * 操作类型 */ - private String operateType; + private Integer operateType; /** * 操作明细 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index a5fa11c9e..1ebfe5664 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -393,7 +393,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa .setUserId(userId) .setUserType(userType) .setAfterSaleId(afterSale.getId()) - .setOperateType(afterStatus.toString()); + .setOperateType(afterStatus); // TODO 废弃,待删除 this.createLog(logDTO); }