Prechádzať zdrojové kódy

feat: 批量修复已支付订单同步支付状态到哈哈平台

- OrderServiceImpl 新增 repairPayStatusSync 方法
- 匹配规则:hahaOrderId > 16位纯数字orderNo(旧覆盖)> 跳过
- repair-goods 接口增加 syncPayStatus 参数复用

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 2 týždňov pred
rodič
commit
9d45a861d5

+ 7 - 1
haha-admin/src/main/java/com/haha/admin/controller/OrderController.java

@@ -231,8 +231,14 @@ public class OrderController {
      */
     @RequirePermission("order:update")
     @PostMapping("/repair-goods")
-    public Result<Map<String, Object>> repairOrdersMissingGoods(@RequestParam(required = false) String activityId) {
+    public Result<Map<String, Object>> repairOrdersMissingGoods(
+            @RequestParam(required = false) String activityId,
+            @RequestParam(required = false, defaultValue = "false") boolean syncPayStatus) {
         com.haha.service.impl.OrderServiceImpl impl = (com.haha.service.impl.OrderServiceImpl) orderService;
+        if (syncPayStatus) {
+            Map<String, Object> data = impl.repairPayStatusSync();
+            return Result.success("同步完成", data);
+        }
         int fixed = impl.repairOrdersMissingGoods(activityId);
         Map<String, Object> data = new HashMap<>();
         data.put("fixed", fixed);

+ 48 - 0
haha-service/src/main/java/com/haha/service/impl/OrderServiceImpl.java

@@ -1105,6 +1105,54 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         return fixed;
     }
 
+    /**
+     * 批量修复已支付订单的支付状态同步到哈哈平台
+     * 匹配规则:优先 hahaOrderId,其次 16 位纯数字 orderNo(曾被哈哈覆盖过的历史数据),否则跳过
+     *
+     * @return { synced: 成功数, skipped: 跳过数, failed: 失败数 }
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public Map<String, Object> repairPayStatusSync() {
+        List<Order> orders = lambdaQuery()
+                .eq(Order::getPayStatus, OrderConstants.PAY_STATUS_PAID)
+                .list();
+
+        int synced = 0, skipped = 0, failed = 0;
+        for (Order order : orders) {
+            String hahaRef = order.getHahaOrderId();
+            if (hahaRef == null || hahaRef.isEmpty()) {
+                // 历史订单可能被哈哈短号覆盖过 orderNo(16位纯数字 = 旧行为)
+                if (order.getOrderNo() != null && order.getOrderNo().matches("^\\d{16}$")) {
+                    hahaRef = order.getOrderNo();
+                }
+            }
+            if (hahaRef == null || hahaRef.isEmpty()) {
+                log.info("跳过同步 - orderNo: {}, 无法确定哈哈订单号", order.getOrderNo());
+                skipped++;
+                continue;
+            }
+
+            try {
+                hahaClient.getOrderApi().setPayStatus(hahaRef);
+                synced++;
+                log.info("支付状态同步成功 - hahaRef: {}, localOrderNo: {}", hahaRef, order.getOrderNo());
+            } catch (Exception e) {
+                failed++;
+                log.error("支付状态同步失败 - hahaRef: {}, localOrderNo: {}, error: {}",
+                        hahaRef, order.getOrderNo(), e.getMessage());
+            }
+        }
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("total", orders.size());
+        result.put("synced", synced);
+        result.put("skipped", skipped);
+        result.put("failed", failed);
+        log.info("批量同步支付状态完成 - total: {}, synced: {}, skipped: {}, failed: {}",
+                orders.size(), synced, skipped, failed);
+        return result;
+    }
+
     /**
      * 标准化图片URL
      */