Просмотр исходного кода

更新发货的订单订阅和推送

Yangzw 11 месяцев назад
Родитель
Сommit
0d8e6f7086
13 измененных файлов с 588 добавлено и 18 удалено
  1. 2 0
      feifan-module-mall/feifan-module-trade-api/src/main/java/cn/newfeifan/mall/module/trade/enums/ErrorCodeConstants.java
  2. 23 12
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/order/TradeOrderController.java
  3. 94 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/OrderCallbackLogsController.java
  4. 33 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/vo/OrderCallbackLogsPageReqVO.java
  5. 37 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/vo/OrderCallbackLogsRespVO.java
  6. 29 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/vo/OrderCallbackLogsSaveReqVO.java
  7. 44 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/dataobject/ordercallbacklogs/OrderCallbackLogsDO.java
  8. 29 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/mysql/ordercallbacklogs/OrderCallbackLogsMapper.java
  9. 6 6
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderUpdateServiceImpl.java
  10. 63 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/ordercallbacklogs/OrderCallbackLogsService.java
  11. 77 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/ordercallbacklogs/OrderCallbackLogsServiceImpl.java
  12. 12 0
      feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/ordercallbacklogs/OrderCallbackLogsMapper.xml
  13. 139 0
      feifan-module-mall/feifan-module-trade-biz/src/test/java/cn/newfeifan/mall/module/trade/service/ordercallbacklogs/OrderCallbackLogsServiceImplTest.java

+ 2 - 0
feifan-module-mall/feifan-module-trade-api/src/main/java/cn/newfeifan/mall/module/trade/enums/ErrorCodeConstants.java

@@ -94,5 +94,7 @@ public interface ErrorCodeConstants {
     ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1_011_008_003, "您当前最多可提现 {} 元");
     ErrorCode NOT_SUFFICIENT_FUNDS = new ErrorCode(1_011_008_004, "账号无可用单量,需要充值");
     ErrorCode CALLBACK_PARAMETER_ERROR = new ErrorCode(1_011_008_005, "第三方回调参数为Null");
+    ErrorCode ORDER_CALLBACK_LOGS_NOT_EXISTS = new ErrorCode(1_011_008_007, "回调日志不存在");
+    ErrorCode CREATE_TRADE_ORDER_LOGS_ERROR = new ErrorCode(1_011_008_008, "创建第三方日志异常");
 
 }

+ 23 - 12
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/order/TradeOrderController.java

@@ -26,6 +26,9 @@ import cn.newfeifan.mall.module.trade.service.delivery.DeliveryExpressService;
 import cn.newfeifan.mall.module.trade.service.order.TradeOrderLogService;
 import cn.newfeifan.mall.module.trade.service.order.TradeOrderQueryService;
 import cn.newfeifan.mall.module.trade.service.order.TradeOrderUpdateService;
+import cn.newfeifan.mall.module.trade.service.ordercallbacklogs.OrderCallbackLogsService;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
 import com.kuaidi100.sdk.response.SubscribeResp;
@@ -51,6 +54,7 @@ import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils
 import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.convertSet;
 import static cn.newfeifan.mall.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.CALLBACK_PARAMETER_ERROR;
+import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.CREATE_TRADE_ORDER_LOGS_ERROR;
 
 @Tag(name = "管理后台 - 交易订单")
 @RestController
@@ -81,6 +85,9 @@ public class TradeOrderController {
     @Resource
     private PayAppService appService;
 
+    @Resource
+    private OrderCallbackLogsService orderCallbackLogsService;
+
     @GetMapping("/page")
     @Operation(summary = "获得交易订单分页")
     @PreAuthorize("@ss.hasPermission('trade:order:query')")
@@ -170,11 +177,12 @@ public class TradeOrderController {
         Map<String, Object> map = gson.fromJson(param, Map.class);
         Map<String, Object> lastResult = (Map<String, Object>) map.get("lastResult");
         String state = (String) lastResult.get("state");
+        TradeOrderDO order = tradeOrderQueryService.getOrderById(Long.valueOf(orderId));
 
         //建议记录一下这个回调的内容,方便出问题后双方排查问题
         log.debug("快递100订阅推送回调结果|{}|{}", param, sign);
         //订阅时传的salt,没有可以忽略
-        String salt = "";
+        String salt = order.getLogisticsNo();
         String ourSign = SignUtils.sign(param + salt);
         log.info("订单:{},回调param:{}", orderId, param);
         SubscribeResp subscribeResp = new SubscribeResp();
@@ -183,23 +191,26 @@ public class TradeOrderController {
         subscribeResp.setMessage("成功");
         //加密如果相等,属于快递100推送;否则可以忽略掉当前请求
         if (ourSign.equals(sign)) {
-            //TODO 业务处理
-
             //判断订单状态是否是已签收
             if (state.equals(TradeOrderStateEnum.RECEIVED.getState())) {
-                TradeOrderDO order = tradeOrderQueryService.getOrderById(Long.valueOf(orderId));
-                if (order != null) {
-                    List<Map<String, Object>> dataList = (List<Map<String, Object>>) lastResult.get("data");
-                    Map<String, Object> firstData = dataList.get(0);
-                    //保存签收时间
-                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
-                    order.setReceivingTime(LocalDateTime.parse(firstData.get("time").toString(), formatter));
-                    tradeOrderUpdateService.updateOrderById(order);
-                }
+                List<Map<String, Object>> dataList = (List<Map<String, Object>>) lastResult.get("data");
+                Map<String, Object> firstData = dataList.get(0);
+                //保存签收时间
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
+                order.setReceivingTime(LocalDateTime.parse(firstData.get("time").toString(), formatter));
+                tradeOrderUpdateService.updateOrderById(order);
             }
 
+            //添加到日志
+            ObjectMapper mapper = new ObjectMapper();
+            try {
+                orderCallbackLogsService.create(orderId,param,mapper.writeValueAsString(lastResult),lastResult.get("status").toString());
+            } catch (JsonProcessingException e) {
+                throw exception(CREATE_TRADE_ORDER_LOGS_ERROR);
+            }
             return subscribeResp;
         }
+        orderCallbackLogsService.create(orderId,param,null,lastResult.get("status").toString());
         return null;
     }
 

+ 94 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/OrderCallbackLogsController.java

@@ -0,0 +1,94 @@
+package cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs;
+
+import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.security.access.prepost.PreAuthorize;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Operation;
+
+import javax.validation.*;
+import javax.servlet.http.*;
+import java.util.*;
+import java.io.IOException;
+
+import cn.newfeifan.mall.framework.common.pojo.PageParam;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.common.pojo.CommonResult;
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
+
+import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;
+
+import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
+import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.*;
+
+import cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo.*;
+import cn.newfeifan.mall.module.trade.dal.dataobject.ordercallbacklogs.OrderCallbackLogsDO;
+import cn.newfeifan.mall.module.trade.service.ordercallbacklogs.OrderCallbackLogsService;
+
+@Tag(name = "管理后台 - 第三方回调日志")
+@RestController
+@RequestMapping("/trade/order-callback-logs")
+@Validated
+public class OrderCallbackLogsController {
+
+    @Resource
+    private OrderCallbackLogsService orderCallbackLogsService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建第三方回调日志")
+    @PreAuthorize("@ss.hasPermission('trade:order-callback-logs:create')")
+    public CommonResult<Long> createOrderCallbackLogs(@Valid @RequestBody OrderCallbackLogsSaveReqVO createReqVO) {
+        return success(orderCallbackLogsService.createOrderCallbackLogs(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新第三方回调日志")
+    @PreAuthorize("@ss.hasPermission('trade:order-callback-logs:update')")
+    public CommonResult<Boolean> updateOrderCallbackLogs(@Valid @RequestBody OrderCallbackLogsSaveReqVO updateReqVO) {
+        orderCallbackLogsService.updateOrderCallbackLogs(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除第三方回调日志")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('trade:order-callback-logs:delete')")
+    public CommonResult<Boolean> deleteOrderCallbackLogs(@RequestParam("id") Long id) {
+        orderCallbackLogsService.deleteOrderCallbackLogs(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得第三方回调日志")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('trade:order-callback-logs:query')")
+    public CommonResult<OrderCallbackLogsRespVO> getOrderCallbackLogs(@RequestParam("id") Long id) {
+        OrderCallbackLogsDO orderCallbackLogs = orderCallbackLogsService.getOrderCallbackLogs(id);
+        return success(BeanUtils.toBean(orderCallbackLogs, OrderCallbackLogsRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得第三方回调日志分页")
+    @PreAuthorize("@ss.hasPermission('trade:order-callback-logs:query')")
+    public CommonResult<PageResult<OrderCallbackLogsRespVO>> getOrderCallbackLogsPage(@Valid OrderCallbackLogsPageReqVO pageReqVO) {
+        PageResult<OrderCallbackLogsDO> pageResult = orderCallbackLogsService.getOrderCallbackLogsPage(pageReqVO);
+        return success(BeanUtils.toBean(pageResult, OrderCallbackLogsRespVO.class));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出第三方回调日志 Excel")
+    @PreAuthorize("@ss.hasPermission('trade:order-callback-logs:export')")
+    @OperateLog(type = EXPORT)
+    public void exportOrderCallbackLogsExcel(@Valid OrderCallbackLogsPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<OrderCallbackLogsDO> list = orderCallbackLogsService.getOrderCallbackLogsPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "第三方回调日志.xls", "数据", OrderCallbackLogsRespVO.class,
+                        BeanUtils.toBean(list, OrderCallbackLogsRespVO.class));
+    }
+
+}

+ 33 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/vo/OrderCallbackLogsPageReqVO.java

@@ -0,0 +1,33 @@
+package cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo;
+
+import lombok.*;
+import io.swagger.v3.oas.annotations.media.Schema;
+import cn.newfeifan.mall.framework.common.pojo.PageParam;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.time.LocalDateTime;
+
+import static cn.newfeifan.mall.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 第三方回调日志分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class OrderCallbackLogsPageReqVO extends PageParam {
+
+    @Schema(description = "订单ID", example = "27271")
+    private String orderId;
+
+    @Schema(description = "回调推送参数体")
+    private String requestParam;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+    @Schema(description = "回调响应体")
+    private String responseBody;
+
+    @Schema(description = "回调状态,失败是0,成功是1", example = "1")
+    private Boolean status;
+
+}

+ 37 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/vo/OrderCallbackLogsRespVO.java

@@ -0,0 +1,37 @@
+package cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.time.LocalDateTime;
+import com.alibaba.excel.annotation.*;
+
+@Schema(description = "管理后台 - 第三方回调日志 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class OrderCallbackLogsRespVO {
+
+    @Schema(description = "订单ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "27271")
+    @ExcelProperty("订单ID")
+    private String orderId;
+
+    @Schema(description = "回调推送参数体", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("回调推送参数体")
+    private String requestParam;
+
+    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+    @Schema(description = "回调编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20993")
+    @ExcelProperty("回调编号")
+    private Long id;
+
+    @Schema(description = "回调响应体")
+    @ExcelProperty("回调响应体")
+    private String responseBody;
+
+    @Schema(description = "回调状态,失败是0,成功是1", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    @ExcelProperty("回调状态,失败是0,成功是1")
+    private Boolean status;
+
+}

+ 29 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/ordercallbacklogs/vo/OrderCallbackLogsSaveReqVO.java

@@ -0,0 +1,29 @@
+package cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import javax.validation.constraints.*;
+
+@Schema(description = "管理后台 - 第三方回调日志新增/修改 Request VO")
+@Data
+public class OrderCallbackLogsSaveReqVO {
+
+    @Schema(description = "订单ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "27271")
+    @NotEmpty(message = "订单ID不能为空")
+    private String orderId;
+
+    @Schema(description = "回调推送参数体", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotEmpty(message = "回调推送参数体不能为空")
+    private String requestParam;
+
+    @Schema(description = "回调编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20993")
+    private Long id;
+
+    @Schema(description = "回调响应体")
+    private String responseBody;
+
+    @Schema(description = "回调状态,失败是0,成功是1", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    @NotNull(message = "回调状态,失败是0,成功是1不能为空")
+    private Boolean status;
+
+}

+ 44 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/dataobject/ordercallbacklogs/OrderCallbackLogsDO.java

@@ -0,0 +1,44 @@
+package cn.newfeifan.mall.module.trade.dal.dataobject.ordercallbacklogs;
+
+import lombok.*;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.newfeifan.mall.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 第三方回调日志 DO
+ *
+ * @author 非繁人
+ */
+@TableName("trade_order_callback_logs")
+@KeySequence("trade_order_callback_logs_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class OrderCallbackLogsDO extends BaseDO {
+
+    /**
+     * 订单ID
+     */
+    private String orderId;
+    /**
+     * 回调推送参数体
+     */
+    private String requestParam;
+    /**
+     * 回调编号
+     */
+    @TableId
+    private Long id;
+    /**
+     * 回调响应体
+     */
+    private String responseBody;
+    /**
+     * 回调状态,失败是0,成功是1
+     */
+    private Boolean status;
+
+}

+ 29 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/mysql/ordercallbacklogs/OrderCallbackLogsMapper.java

@@ -0,0 +1,29 @@
+package cn.newfeifan.mall.module.trade.dal.mysql.ordercallbacklogs;
+
+
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
+import cn.newfeifan.mall.module.trade.dal.dataobject.ordercallbacklogs.OrderCallbackLogsDO;
+import org.apache.ibatis.annotations.Mapper;
+import cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo.*;
+
+/**
+ * 第三方回调日志 Mapper
+ *
+ * @author 非繁人
+ */
+@Mapper
+public interface OrderCallbackLogsMapper extends BaseMapperX<OrderCallbackLogsDO> {
+
+    default PageResult<OrderCallbackLogsDO> selectPage(OrderCallbackLogsPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<OrderCallbackLogsDO>()
+                .eqIfPresent(OrderCallbackLogsDO::getOrderId, reqVO.getOrderId())
+                .eqIfPresent(OrderCallbackLogsDO::getRequestParam, reqVO.getRequestParam())
+                .betweenIfPresent(OrderCallbackLogsDO::getCreateTime, reqVO.getCreateTime())
+                .eqIfPresent(OrderCallbackLogsDO::getResponseBody, reqVO.getResponseBody())
+                .eqIfPresent(OrderCallbackLogsDO::getStatus, reqVO.getStatus())
+                .orderByDesc(OrderCallbackLogsDO::getId));
+    }
+
+}

+ 6 - 6
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderUpdateServiceImpl.java

@@ -371,7 +371,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
 
         try {
             //发送订单订阅
-            testSubscribe(order);
+            subscribe(order);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -400,13 +400,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
      * @param order 交易订单对象,包含物流信息和接收人手机号
      * @throws Exception 抛出异常,可能由于外部服务调用失败等原因
      */
-    private void testSubscribe(TradeOrderDO order) throws Exception {
+    private void subscribe(TradeOrderDO order) throws Exception {
         // 根据物流ID获取配送信息
         DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(order.getLogisticsId());
 
         // 设置订阅参数,包括回调URL和手机号
         SubscribeParameters subscribeParameters = new SubscribeParameters();
-        subscribeParameters.setCallbackurl("https://47.107.28.221:8001/admin-api/trade/order/callBackUrl?orderId=" + order.getId());
+        subscribeParameters.setCallbackurl("http://47.107.28.221:8002/admin-api/trade/order/callBackUrl?orderId="+order.getId());
         subscribeParameters.setPhone(order.getReceiverMobile());
         //添加盐
         subscribeParameters.setSalt(order.getLogisticsNo());
@@ -433,13 +433,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
         String returnCode = jsonObject.get("returnCode").getAsString();
 
         if (result && returnCode.equals("200")) {
-            log.info("订单号:{}:订阅成功", order.getLogisticsNo());
+            log.info("订单号:{}:订阅成功",order.getLogisticsNo());
 
             order.setSubscriptionLogisticsInfo(TradeOrderSubscribeStatusEnum.SUBSCRIBE.getStatus());
-        } else if (returnCode.equals("600") || returnCode.equals("601")) {
+        } else if(returnCode.equals("600") || returnCode.equals("601")) {
             throw exception(NOT_SUFFICIENT_FUNDS);
         } else {
-            log.info("订单号:{}:订阅失败", order.getLogisticsNo());
+            log.info("订单号:{}:订阅失败",order.getLogisticsNo());
 
             order.setSubscriptionLogisticsInfo(TradeOrderSubscribeStatusEnum.abnormal.getStatus());
         }

+ 63 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/ordercallbacklogs/OrderCallbackLogsService.java

@@ -0,0 +1,63 @@
+package cn.newfeifan.mall.module.trade.service.ordercallbacklogs;
+
+import javax.validation.*;
+import cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo.*;
+import cn.newfeifan.mall.module.trade.dal.dataobject.ordercallbacklogs.OrderCallbackLogsDO;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+
+/**
+ * 第三方回调日志 Service 接口
+ *
+ * @author 非繁人
+ */
+public interface OrderCallbackLogsService {
+
+    /**
+     * 创建第三方回调日志
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createOrderCallbackLogs(@Valid OrderCallbackLogsSaveReqVO createReqVO);
+
+    /**
+     * 更新第三方回调日志
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateOrderCallbackLogs(@Valid OrderCallbackLogsSaveReqVO updateReqVO);
+
+    /**
+     * 删除第三方回调日志
+     *
+     * @param id 编号
+     */
+    void deleteOrderCallbackLogs(Long id);
+
+    /**
+     * 获得第三方回调日志
+     *
+     * @param id 编号
+     * @return 第三方回调日志
+     */
+    OrderCallbackLogsDO getOrderCallbackLogs(Long id);
+
+    /**
+     * 获得第三方回调日志分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 第三方回调日志分页
+     */
+    PageResult<OrderCallbackLogsDO> getOrderCallbackLogsPage(OrderCallbackLogsPageReqVO pageReqVO);
+
+    /**
+     * 创建第三方回调日志
+     *
+     * @param orderId 订单编号
+     * @param param 推送参数
+     * @param responseBody 响应体
+     * @param status 状态
+     */
+    void create(String orderId,String param,String responseBody,String status);
+
+}

+ 77 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/ordercallbacklogs/OrderCallbackLogsServiceImpl.java

@@ -0,0 +1,77 @@
+package cn.newfeifan.mall.module.trade.service.ordercallbacklogs;
+
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo.*;
+import cn.newfeifan.mall.module.trade.dal.dataobject.ordercallbacklogs.OrderCallbackLogsDO;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+
+import cn.newfeifan.mall.module.trade.dal.mysql.ordercallbacklogs.OrderCallbackLogsMapper;
+
+import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
+
+/**
+ * 第三方回调日志 Service 实现类
+ *
+ * @author 非繁人
+ */
+@Service
+@Validated
+public class OrderCallbackLogsServiceImpl implements OrderCallbackLogsService {
+
+    @Resource
+    private OrderCallbackLogsMapper orderCallbackLogsMapper;
+
+    @Override
+    public Long createOrderCallbackLogs(OrderCallbackLogsSaveReqVO createReqVO) {
+        // 插入
+        OrderCallbackLogsDO orderCallbackLogs = BeanUtils.toBean(createReqVO, OrderCallbackLogsDO.class);
+        orderCallbackLogsMapper.insert(orderCallbackLogs);
+        // 返回
+        return orderCallbackLogs.getId();
+    }
+
+    @Override
+    public void updateOrderCallbackLogs(OrderCallbackLogsSaveReqVO updateReqVO) {
+        // 校验存在
+        validateOrderCallbackLogsExists(updateReqVO.getId());
+        // 更新
+        OrderCallbackLogsDO updateObj = BeanUtils.toBean(updateReqVO, OrderCallbackLogsDO.class);
+        orderCallbackLogsMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deleteOrderCallbackLogs(Long id) {
+        // 校验存在
+        validateOrderCallbackLogsExists(id);
+        // 删除
+        orderCallbackLogsMapper.deleteById(id);
+    }
+
+    private void validateOrderCallbackLogsExists(Long id) {
+        if (orderCallbackLogsMapper.selectById(id) == null) {
+            throw exception(ORDER_CALLBACK_LOGS_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public OrderCallbackLogsDO getOrderCallbackLogs(Long id) {
+        return orderCallbackLogsMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<OrderCallbackLogsDO> getOrderCallbackLogsPage(OrderCallbackLogsPageReqVO pageReqVO) {
+        return orderCallbackLogsMapper.selectPage(pageReqVO);
+    }
+
+    @Override
+    public void create(String orderId, String param, String responseBody, String status) {
+        boolean flag = status.equals("200");
+        OrderCallbackLogsDO build = OrderCallbackLogsDO.builder().orderId(orderId).requestParam(param).responseBody(responseBody).status(flag).build();
+        orderCallbackLogsMapper.insert(build);
+    }
+
+}

+ 12 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/ordercallbacklogs/OrderCallbackLogsMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.newfeifan.mall.module.trade.dal.mysql.ordercallbacklogs.OrderCallbackLogsMapper">
+
+    <!--
+        一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
+        无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
+        代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
+        文档可见:https://www.zhongxing.cn/MyBatis/x-plugins/
+     -->
+
+</mapper>

+ 139 - 0
feifan-module-mall/feifan-module-trade-biz/src/test/java/cn/newfeifan/mall/module/trade/service/ordercallbacklogs/OrderCallbackLogsServiceImplTest.java

@@ -0,0 +1,139 @@
+package cn.newfeifan.mall.module.trade.service.ordercallbacklogs;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import javax.annotation.Resource;
+
+import cn.newfeifan.mall.framework.test.core.ut.BaseDbUnitTest;
+
+import cn.newfeifan.mall.module.trade.controller.admin.ordercallbacklogs.vo.*;
+import cn.newfeifan.mall.module.trade.dal.dataobject.ordercallbacklogs.OrderCallbackLogsDO;
+import cn.newfeifan.mall.module.trade.dal.mysql.ordercallbacklogs.OrderCallbackLogsMapper;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+
+import org.springframework.context.annotation.Import;
+
+import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
+import static cn.newfeifan.mall.framework.test.core.util.AssertUtils.*;
+import static cn.newfeifan.mall.framework.test.core.util.RandomUtils.*;
+import static cn.newfeifan.mall.framework.common.util.date.LocalDateTimeUtils.*;
+import static cn.newfeifan.mall.framework.common.util.object.ObjectUtils.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * {@link OrderCallbackLogsServiceImpl} 的单元测试类
+ *
+ * @author 非繁人
+ */
+@Import(OrderCallbackLogsServiceImpl.class)
+public class OrderCallbackLogsServiceImplTest extends BaseDbUnitTest {
+
+    @Resource
+    private OrderCallbackLogsServiceImpl orderCallbackLogsService;
+
+    @Resource
+    private OrderCallbackLogsMapper orderCallbackLogsMapper;
+
+    @Test
+    public void testCreateOrderCallbackLogs_success() {
+        // 准备参数
+        OrderCallbackLogsSaveReqVO createReqVO = randomPojo(OrderCallbackLogsSaveReqVO.class).setId(null);
+
+        // 调用
+        Long orderCallbackLogsId = orderCallbackLogsService.createOrderCallbackLogs(createReqVO);
+        // 断言
+        assertNotNull(orderCallbackLogsId);
+        // 校验记录的属性是否正确
+        OrderCallbackLogsDO orderCallbackLogs = orderCallbackLogsMapper.selectById(orderCallbackLogsId);
+        assertPojoEquals(createReqVO, orderCallbackLogs, "id");
+    }
+
+    @Test
+    public void testUpdateOrderCallbackLogs_success() {
+        // mock 数据
+        OrderCallbackLogsDO dbOrderCallbackLogs = randomPojo(OrderCallbackLogsDO.class);
+        orderCallbackLogsMapper.insert(dbOrderCallbackLogs);// @Sql: 先插入出一条存在的数据
+        // 准备参数
+        OrderCallbackLogsSaveReqVO updateReqVO = randomPojo(OrderCallbackLogsSaveReqVO.class, o -> {
+            o.setId(dbOrderCallbackLogs.getId()); // 设置更新的 ID
+        });
+
+        // 调用
+        orderCallbackLogsService.updateOrderCallbackLogs(updateReqVO);
+        // 校验是否更新正确
+        OrderCallbackLogsDO orderCallbackLogs = orderCallbackLogsMapper.selectById(updateReqVO.getId()); // 获取最新的
+        assertPojoEquals(updateReqVO, orderCallbackLogs);
+    }
+
+    @Test
+    public void testUpdateOrderCallbackLogs_notExists() {
+        // 准备参数
+        OrderCallbackLogsSaveReqVO updateReqVO = randomPojo(OrderCallbackLogsSaveReqVO.class);
+
+        // 调用, 并断言异常
+        assertServiceException(() -> orderCallbackLogsService.updateOrderCallbackLogs(updateReqVO), ORDER_CALLBACK_LOGS_NOT_EXISTS);
+    }
+
+    @Test
+    public void testDeleteOrderCallbackLogs_success() {
+        // mock 数据
+        OrderCallbackLogsDO dbOrderCallbackLogs = randomPojo(OrderCallbackLogsDO.class);
+        orderCallbackLogsMapper.insert(dbOrderCallbackLogs);// @Sql: 先插入出一条存在的数据
+        // 准备参数
+        Long id = dbOrderCallbackLogs.getId();
+
+        // 调用
+        orderCallbackLogsService.deleteOrderCallbackLogs(id);
+       // 校验数据不存在了
+       assertNull(orderCallbackLogsMapper.selectById(id));
+    }
+
+    @Test
+    public void testDeleteOrderCallbackLogs_notExists() {
+        // 准备参数
+        Long id = randomLongId();
+
+        // 调用, 并断言异常
+        assertServiceException(() -> orderCallbackLogsService.deleteOrderCallbackLogs(id), ORDER_CALLBACK_LOGS_NOT_EXISTS);
+    }
+
+    @Test
+    @Disabled  // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
+    public void testGetOrderCallbackLogsPage() {
+       // mock 数据
+       OrderCallbackLogsDO dbOrderCallbackLogs = randomPojo(OrderCallbackLogsDO.class, o -> { // 等会查询到
+           o.setOrderId(null);
+           o.setRequestParam(null);
+           o.setCreateTime(null);
+           o.setResponseBody(null);
+           o.setStatus(null);
+       });
+       orderCallbackLogsMapper.insert(dbOrderCallbackLogs);
+       // 测试 orderId 不匹配
+       orderCallbackLogsMapper.insert(cloneIgnoreId(dbOrderCallbackLogs, o -> o.setOrderId(null)));
+       // 测试 requestParam 不匹配
+       orderCallbackLogsMapper.insert(cloneIgnoreId(dbOrderCallbackLogs, o -> o.setRequestParam(null)));
+       // 测试 createTime 不匹配
+       orderCallbackLogsMapper.insert(cloneIgnoreId(dbOrderCallbackLogs, o -> o.setCreateTime(null)));
+       // 测试 responseBody 不匹配
+       orderCallbackLogsMapper.insert(cloneIgnoreId(dbOrderCallbackLogs, o -> o.setResponseBody(null)));
+       // 测试 status 不匹配
+       orderCallbackLogsMapper.insert(cloneIgnoreId(dbOrderCallbackLogs, o -> o.setStatus(null)));
+       // 准备参数
+       OrderCallbackLogsPageReqVO reqVO = new OrderCallbackLogsPageReqVO();
+       reqVO.setOrderId(null);
+       reqVO.setRequestParam(null);
+       reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
+       reqVO.setResponseBody(null);
+       reqVO.setStatus(null);
+
+       // 调用
+       PageResult<OrderCallbackLogsDO> pageResult = orderCallbackLogsService.getOrderCallbackLogsPage(reqVO);
+       // 断言
+       assertEquals(1, pageResult.getTotal());
+       assertEquals(1, pageResult.getList().size());
+       assertPojoEquals(dbOrderCallbackLogs, pageResult.getList().get(0));
+    }
+
+}