diff --git a/sql/mysql/optional/mall_trade_log.sql b/sql/mysql/optional/mall_trade_log.sql new file mode 100644 index 000000000..683c6a27a --- /dev/null +++ b/sql/mysql/optional/mall_trade_log.sql @@ -0,0 +1,3 @@ +ALTER TABLE `ruoyi-vue-pro`.`trade_after_sale_log` + ADD COLUMN `before_status` int NOT NULL COMMENT '售前状态' AFTER `id`, + ADD COLUMN `after_status` int NOT NULL COMMENT '售后状态' AFTER `before_status`; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java index 24f1f44b7..1441f9cf6 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExcelVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; 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 5be54e207..ef3e75c7d 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 @@ -8,8 +8,10 @@ import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSa import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleRespVO; import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum; +import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.util.AfterSaleLogUtils; import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -71,6 +73,8 @@ public class AppTradeAfterSaleController { @Operation(summary = "申请售后") @AfterSaleLog(id = "#info.data", content = "'申请售后:售后编号['+#info.data+'],订单编号['+#createReqVO.orderItemId+'], '", operateType = AfterSaleOperateTypeEnum.APPLY) public CommonResult createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) { + AfterSaleLogUtils.setBeforeStatus(0); + AfterSaleLogUtils.setAfterStatus(TradeAfterSaleStatusEnum.APPLY.getStatus()); 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/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 93186edf1..f554d9a15 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 @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop; 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.operatelog.core.service.OperateLog; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; @@ -33,9 +34,26 @@ public class AfterSaleLogAspect { @Resource private AfterSaleLogService afterSaleLogService; - - // TODO chenchen: 这个分 3 行把; - private final static String OPERATE_TYPE = "operateType", ID = "id", CONTENT = "content"; + /** + * 售前状态 + */ + private static final ThreadLocal BEFORE_STATUS = new ThreadLocal<>(); + /** + * 售后状态 + */ + private static final ThreadLocal AFTER_STATUS = new ThreadLocal<>(); + /** + * 操作类型 + */ + private final static String OPERATE_TYPE = "operateType"; + /** + * ID + */ + private final static String ID = "id"; + /** + * 操作明细 + */ + private final static String CONTENT = "content"; /** * 切面存入日志 @@ -52,11 +70,15 @@ public class AfterSaleLogAspect { .setUserType(userType) .setAfterSaleId(MapUtil.getLong(formatObj, ID)) .setOperateType(MapUtil.getStr(formatObj, OPERATE_TYPE)) + .setBeforeStatus(BEFORE_STATUS.get()) + .setAfterStatus(AFTER_STATUS.get()) .setContent(MapUtil.getStr(formatObj, CONTENT)); // 异步存入数据库 afterSaleLogService.createLog(dto); } catch (Exception exception) { log.error("[doAfterReturning][afterSaleLog({}) 日志记录错误]", toJsonString(afterSaleLog), exception); + }finally { + clearThreadLocal(); } } @@ -85,4 +107,17 @@ public class AfterSaleLogAspect { return result; } + public static void setBeforeStatus(Integer beforestatus) { + BEFORE_STATUS.set(beforestatus); + } + + public static void setAfterStatus(Integer afterStatus) { + AFTER_STATUS.set(afterStatus); + } + + private static void clearThreadLocal() { + AFTER_STATUS.remove(); + BEFORE_STATUS.remove(); + } + } 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..19c1086ee 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 @@ -42,5 +42,13 @@ public class TradeAfterSaleLogCreateReqDTO { * 操作明细 */ private String content; + /** + * 售前状态 + */ + private Integer beforeStatus; + /** + * 售后状态 + */ + private Integer afterStatus; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/util/AfterSaleLogUtils.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/util/AfterSaleLogUtils.java new file mode 100644 index 000000000..3f8327dc0 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/util/AfterSaleLogUtils.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.util; + + +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect; + +/** + * 操作日志工具类 + * 目前主要的作用,是提供给业务代码,记录操作明细和拓展字段 + * + * @author 芋道源码 + */ +public class AfterSaleLogUtils { + + public static void setBeforeStatus(Integer status) { + AfterSaleLogAspect.setBeforeStatus(status); + } + + public static void setAfterStatus(Integer status) { + AfterSaleLogAspect.setAfterStatus(status); + } + +}