Commit 284506b3561205a8bb68631a464c3c2adb59a985
1 parent
f492797f
mall 下单日志
Showing
10 changed files
with
328 additions
and
1 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/OrderOperateTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.enums.aftersale; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | +import lombok.RequiredArgsConstructor; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 订单操作类型的枚举 | |
| 8 | + * | |
| 9 | + * @author 陈賝 | |
| 10 | + * @since 2023/7/6 15:31 | |
| 11 | + */ | |
| 12 | +@RequiredArgsConstructor | |
| 13 | +@Getter | |
| 14 | +public enum OrderOperateTypeEnum { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 用户下单 | |
| 18 | + */ | |
| 19 | + ORDER(0, "用户下单"), | |
| 20 | + ; | |
| 21 | + | |
| 22 | + // 类型 | |
| 23 | + private final Integer type; | |
| 24 | + // 描述 | |
| 25 | + private final String description; | |
| 26 | + | |
| 27 | + public String description() { | |
| 28 | + return description; | |
| 29 | + } | |
| 30 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java
| ... | ... | @@ -14,8 +14,12 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderI |
| 14 | 14 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 15 | 15 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 16 | 16 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| 17 | +import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum; | |
| 18 | +import cn.iocoder.yudao.module.trade.enums.aftersale.OrderOperateTypeEnum; | |
| 17 | 19 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; |
| 20 | +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog; | |
| 18 | 21 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| 22 | +import cn.iocoder.yudao.module.trade.framework.order.core.annotations.OrderLog; | |
| 19 | 23 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; |
| 20 | 24 | import com.google.common.collect.Maps; |
| 21 | 25 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -66,6 +70,7 @@ public class AppTradeOrderController { |
| 66 | 70 | @PostMapping("/create") |
| 67 | 71 | @Operation(summary = "创建订单") |
| 68 | 72 | @PreAuthenticated |
| 73 | + @OrderLog(id = "#info.id", content = "'创建订单:支付订单编号['+#info.payOrderId+'], 订单编号['+#info.id+'], '", operateType = OrderOperateTypeEnum.ORDER) | |
| 69 | 74 | public CommonResult<AppTradeOrderCreateRespVO> createOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO) { |
| 70 | 75 | TradeOrderDO order = tradeOrderService.createOrder(getLoginUserId(), getClientIP(), createReqVO); |
| 71 | 76 | return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/OrderLogDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.dal.dataobject.order; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 订单日志 DO | |
| 12 | + * | |
| 13 | + * @author 陈賝 | |
| 14 | + */ | |
| 15 | +@TableName("trade_order_log") | |
| 16 | +@KeySequence("trade_order_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class OrderLogDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 订单号 | |
| 32 | + */ | |
| 33 | + private Long orderId; | |
| 34 | + /** | |
| 35 | + * 订单日志信息 | |
| 36 | + */ | |
| 37 | + private String content; | |
| 38 | + /** | |
| 39 | + * 操作类型 | |
| 40 | + */ | |
| 41 | + private Integer operateType; | |
| 42 | + /** | |
| 43 | + * 创建者ID | |
| 44 | + */ | |
| 45 | + private Long userId; | |
| 46 | + /** | |
| 47 | + * 创建者类型 | |
| 48 | + */ | |
| 49 | + private Integer userType; | |
| 50 | + | |
| 51 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/OrderLogMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.dal.mysql.order; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.trade.dal.dataobject.order.OrderLogDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 订单日志 Mapper | |
| 9 | + * | |
| 10 | + * @author 陈賝 | |
| 11 | + */ | |
| 12 | +@Mapper | |
| 13 | +public interface OrderLogMapper extends BaseMapperX<OrderLogDO> { | |
| 14 | + | |
| 15 | + | |
| 16 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/config/TradeOrderConfig.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.framework.order.config; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect; | |
| 4 | +import cn.iocoder.yudao.module.trade.framework.order.core.aop.OrderLogAspect; | |
| 3 | 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 6 | +import org.springframework.context.annotation.Bean; | |
| 4 | 7 | import org.springframework.context.annotation.Configuration; |
| 5 | 8 | |
| 6 | 9 | // TODO @LeeYan9: 可以直接给 TradeOrderProperties 一个 @Component生效哈 |
| 10 | + | |
| 7 | 11 | /** |
| 8 | 12 | * @author LeeYan9 |
| 9 | 13 | * @since 2022-09-15 |
| ... | ... | @@ -11,4 +15,9 @@ import org.springframework.context.annotation.Configuration; |
| 11 | 15 | @Configuration |
| 12 | 16 | @EnableConfigurationProperties(TradeOrderProperties.class) |
| 13 | 17 | public class TradeOrderConfig { |
| 18 | + | |
| 19 | + @Bean | |
| 20 | + public OrderLogAspect orderLogAspect() { | |
| 21 | + return new OrderLogAspect(); | |
| 22 | + } | |
| 14 | 23 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/annotations/OrderLog.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.framework.order.core.annotations; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.trade.enums.aftersale.OrderOperateTypeEnum; | |
| 4 | + | |
| 5 | +import java.lang.annotation.*; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 订单日志AOP注解 | |
| 9 | + * | |
| 10 | + * @author 陈賝 | |
| 11 | + * @since 2023/7/6 15:37 | |
| 12 | + */ | |
| 13 | +@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.TYPE}) | |
| 14 | +@Retention(RetentionPolicy.RUNTIME) | |
| 15 | +@Documented | |
| 16 | +public @interface OrderLog { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 日志内容 | |
| 20 | + */ | |
| 21 | + String content(); | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 订单编号 | |
| 25 | + */ | |
| 26 | + String id(); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 操作类型 | |
| 30 | + */ | |
| 31 | + OrderOperateTypeEnum operateType(); | |
| 32 | + | |
| 33 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/OrderLogAspect.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.framework.order.core.aop; | |
| 2 | + | |
| 3 | + | |
| 4 | +import cn.hutool.core.map.MapUtil; | |
| 5 | +import cn.hutool.core.util.ObjectUtil; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; | |
| 7 | +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; | |
| 8 | +import cn.iocoder.yudao.module.trade.enums.aftersale.OrderOperateTypeEnum; | |
| 9 | +import cn.iocoder.yudao.module.trade.framework.order.core.annotations.OrderLog; | |
| 10 | +import cn.iocoder.yudao.module.trade.framework.order.core.dto.TradeOrderLogCreateReqDTO; | |
| 11 | +import cn.iocoder.yudao.module.trade.framework.order.core.service.OrderLogService; | |
| 12 | +import lombok.extern.slf4j.Slf4j; | |
| 13 | +import org.aspectj.lang.JoinPoint; | |
| 14 | +import org.aspectj.lang.annotation.AfterReturning; | |
| 15 | +import org.aspectj.lang.annotation.Aspect; | |
| 16 | +import org.aspectj.lang.reflect.MethodSignature; | |
| 17 | + | |
| 18 | +import javax.annotation.Resource; | |
| 19 | +import java.util.Map; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; | |
| 22 | +import static java.util.Arrays.asList; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 记录订单操作日志的 AOP 切面 | |
| 26 | + * | |
| 27 | + * @author 陈賝 | |
| 28 | + * @since 2023/6/13 13:54 | |
| 29 | + */ | |
| 30 | +@Slf4j | |
| 31 | +@Aspect | |
| 32 | +public class OrderLogAspect { | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private OrderLogService orderLogService; | |
| 36 | + | |
| 37 | + @AfterReturning(pointcut = "@annotation(orderLog)", returning = "info") | |
| 38 | + public void doAfterReturning(JoinPoint joinPoint, OrderLog orderLog, Object info) { | |
| 39 | + try { | |
| 40 | + // 日志对象拼接 | |
| 41 | + Integer userType = WebFrameworkUtils.getLoginUserType(); | |
| 42 | + Long id = WebFrameworkUtils.getLoginUserId(); | |
| 43 | + TradeOrderLogCreateReqDTO dto = new TradeOrderLogCreateReqDTO() | |
| 44 | + .setUserId(id) | |
| 45 | + .setUserType(userType) | |
| 46 | + .setOrderId(getAfterSaleId(joinPoint, info, orderLog.id())) | |
| 47 | + .setOperateType(orderLog.operateType().getType()) | |
| 48 | + .setContent(getContent(joinPoint, info, orderLog)); | |
| 49 | + // 异步存入数据库 | |
| 50 | + orderLogService.createLog(dto); | |
| 51 | + } catch (Exception exception) { | |
| 52 | + log.error("[doAfterReturning][orderLog({}) 订单日志错误]", toJsonString(orderLog), exception); | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 获取描述信息 | |
| 58 | + */ | |
| 59 | + private static Map<String, Object> spelFormat(JoinPoint joinPoint, Object info) { | |
| 60 | + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | |
| 61 | + OrderLog afterSaleLogPoint = signature.getMethod().getAnnotation(OrderLog.class); | |
| 62 | + return SpringExpressionUtils.parseExpression(joinPoint, info, | |
| 63 | + asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); | |
| 64 | + } | |
| 65 | + | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * 获取订单ID | |
| 69 | + */ | |
| 70 | + private static Long getAfterSaleId(JoinPoint joinPoint, Object info, String spel) { | |
| 71 | + Map<String, Object> spelMap = spelFormat(joinPoint, info); | |
| 72 | + return MapUtil.getLong(spelMap, spel); | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * 获取解析后的日志内容 | |
| 77 | + */ | |
| 78 | + private static String getContent(JoinPoint joinPoint, Object info, OrderLog afterSaleLog) { | |
| 79 | + Map<String, Object> spelMap = spelFormat(joinPoint, info); | |
| 80 | + StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLog.content())); | |
| 81 | + OrderOperateTypeEnum operateTypeEnum = afterSaleLog.operateType(); | |
| 82 | + return ObjectUtil.isNotNull(operateTypeEnum) ? | |
| 83 | + content.append(operateTypeEnum.getDescription()).toString() : content.toString(); | |
| 84 | + } | |
| 85 | + | |
| 86 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/dto/TradeOrderLogCreateReqDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.framework.order.core.dto; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.NoArgsConstructor; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 订单日志的创建 Request DTO | |
| 9 | + * | |
| 10 | + * @author 陈賝 | |
| 11 | + * @since 2023/7/6 15:27 | |
| 12 | + */ | |
| 13 | +@Data | |
| 14 | +@NoArgsConstructor | |
| 15 | +@AllArgsConstructor | |
| 16 | +public class TradeOrderLogCreateReqDTO { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 编号 | |
| 20 | + */ | |
| 21 | + private Long id; | |
| 22 | + /** | |
| 23 | + * 用户编号 | |
| 24 | + * <p> | |
| 25 | + * 关联 1:AdminUserDO 的 id 字段 | |
| 26 | + * 关联 2:MemberUserDO 的 id 字段 | |
| 27 | + */ | |
| 28 | + private Long userId; | |
| 29 | + /** | |
| 30 | + * 用户类型 | |
| 31 | + */ | |
| 32 | + private Integer userType; | |
| 33 | + /** | |
| 34 | + * 订单编号 | |
| 35 | + */ | |
| 36 | + private Long orderId; | |
| 37 | + /** | |
| 38 | + * 操作类型 | |
| 39 | + */ | |
| 40 | + private Integer operateType; | |
| 41 | + /** | |
| 42 | + * 操作明细 | |
| 43 | + */ | |
| 44 | + private String content; | |
| 45 | + | |
| 46 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/service/OrderLogService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.framework.order.core.service; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.trade.framework.order.core.dto.TradeOrderLogCreateReqDTO; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 交易下单日志 Service 接口 | |
| 7 | + * | |
| 8 | + * @author 陈賝 | |
| 9 | + * @since 2023/7/6 15:44 | |
| 10 | + */ | |
| 11 | +public interface OrderLogService { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 创建交易下单日志 | |
| 15 | + * | |
| 16 | + * @param logDTO 日志记录 | |
| 17 | + * @author 陈賝 | |
| 18 | + * @since 2023/7/6 15:45 | |
| 19 | + */ | |
| 20 | + void createLog(TradeOrderLogCreateReqDTO logDTO); | |
| 21 | + | |
| 22 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java
| ... | ... | @@ -31,16 +31,21 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageRe |
| 31 | 31 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; |
| 32 | 32 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; |
| 33 | 33 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 34 | +import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO; | |
| 34 | 35 | import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; |
| 35 | 36 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 37 | +import cn.iocoder.yudao.module.trade.dal.dataobject.order.OrderLogDO; | |
| 36 | 38 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 37 | 39 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| 40 | +import cn.iocoder.yudao.module.trade.dal.mysql.order.OrderLogMapper; | |
| 38 | 41 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; |
| 39 | 42 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; |
| 40 | 43 | import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; |
| 41 | 44 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; |
| 42 | 45 | import cn.iocoder.yudao.module.trade.enums.order.*; |
| 43 | 46 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| 47 | +import cn.iocoder.yudao.module.trade.framework.order.core.dto.TradeOrderLogCreateReqDTO; | |
| 48 | +import cn.iocoder.yudao.module.trade.framework.order.core.service.OrderLogService; | |
| 44 | 49 | import cn.iocoder.yudao.module.trade.service.cart.TradeCartService; |
| 45 | 50 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; |
| 46 | 51 | import cn.iocoder.yudao.module.trade.service.price.TradePriceService; |
| ... | ... | @@ -57,6 +62,7 @@ import java.util.*; |
| 57 | 62 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 58 | 63 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 59 | 64 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; |
| 65 | +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; | |
| 60 | 66 | import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_ORDER_NOT_FOUND; |
| 61 | 67 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 62 | 68 | |
| ... | ... | @@ -68,11 +74,13 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 68 | 74 | */ |
| 69 | 75 | @Service |
| 70 | 76 | @Slf4j |
| 71 | -public class TradeOrderServiceImpl implements TradeOrderService { | |
| 77 | +public class TradeOrderServiceImpl implements TradeOrderService, OrderLogService { | |
| 72 | 78 | |
| 73 | 79 | @Resource |
| 74 | 80 | private TradeOrderMapper tradeOrderMapper; |
| 75 | 81 | @Resource |
| 82 | + private OrderLogMapper orderLogMapper; | |
| 83 | + @Resource | |
| 76 | 84 | private TradeOrderItemMapper tradeOrderItemMapper; |
| 77 | 85 | |
| 78 | 86 | @Resource |
| ... | ... | @@ -568,4 +576,25 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 568 | 576 | TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())); |
| 569 | 577 | } |
| 570 | 578 | |
| 579 | + /** | |
| 580 | + * 创建交易下单日志 | |
| 581 | + * | |
| 582 | + * @param logDTO 日志记录 | |
| 583 | + * @author 陈賝 | |
| 584 | + * @since 2023/7/6 15:45 | |
| 585 | + */ | |
| 586 | + @Override | |
| 587 | + public void createLog(TradeOrderLogCreateReqDTO logDTO) { | |
| 588 | + try { | |
| 589 | + OrderLogDO orderLogDO = new OrderLogDO() | |
| 590 | + .setUserId(logDTO.getUserId()) | |
| 591 | + .setUserType(logDTO.getUserType()) | |
| 592 | + .setOrderId(logDTO.getOrderId()) | |
| 593 | + .setOperateType(logDTO.getOperateType()) | |
| 594 | + .setContent(logDTO.getContent()); | |
| 595 | + orderLogMapper.insert(orderLogDO); | |
| 596 | + } catch (Exception exception) { | |
| 597 | + log.error("[createLog][request({}) 日志记录错误]", toJsonString(logDTO), exception); | |
| 598 | + } | |
| 599 | + } | |
| 571 | 600 | } | ... | ... |