|
@@ -25,11 +25,15 @@ import zs.payment.service.imseweishopgoodsspec.ImsEweiShopGoodsSpecService;
|
|
|
import zs.payment.service.imseweishopgoodsspecitem.ImsEweiShopGoodsSpecItemService;
|
|
import zs.payment.service.imseweishopgoodsspecitem.ImsEweiShopGoodsSpecItemService;
|
|
|
import zs.payment.service.supply.paysupply.PaySupplyService;
|
|
import zs.payment.service.supply.paysupply.PaySupplyService;
|
|
|
import zs.payment.service.supply.product.ProductSupplyService;
|
|
import zs.payment.service.supply.product.ProductSupplyService;
|
|
|
|
|
+import zs.payment.service.supply.token.SupplyTokenService;
|
|
|
import zs.payment.utils.RedisUtils;
|
|
import zs.payment.utils.RedisUtils;
|
|
|
import zs.payment.utils.TimeUtils;
|
|
import zs.payment.utils.TimeUtils;
|
|
|
|
|
+import zs.payment.dao.supply.StorageSyncFailLogDao;
|
|
|
|
|
+import zs.payment.entity.mongodb.supply.StorageSyncFailLog;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -41,6 +45,8 @@ public class KafkaConsumer {
|
|
|
private PaySupplyService paySupplyService;
|
|
private PaySupplyService paySupplyService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ProductSupplyService productSupplyService;
|
|
private ProductSupplyService productSupplyService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SupplyTokenService supplyTokenService;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisUtils redisUtils;
|
|
private RedisUtils redisUtils;
|
|
@@ -58,7 +64,8 @@ public class KafkaConsumer {
|
|
|
private ImsEweiShopGoodsSpecItemService imsEweiShopGoodsSpecItemService;
|
|
private ImsEweiShopGoodsSpecItemService imsEweiShopGoodsSpecItemService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ImsEweiShopGoodsOptionService imsEweiShopGoodsOptionService;
|
|
private ImsEweiShopGoodsOptionService imsEweiShopGoodsOptionService;
|
|
|
-
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private StorageSyncFailLogDao storageSyncFailLogDao;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 商品下架
|
|
* 商品下架
|
|
@@ -427,4 +434,80 @@ public class KafkaConsumer {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 选品库同步剩余分页并发处理
|
|
|
|
|
+ * 消息格式:{"total":100000, "pageSize":50}
|
|
|
|
|
+ */
|
|
|
|
|
+ @KafkaListener(
|
|
|
|
|
+ topics = "sync.qiyun.remain",
|
|
|
|
|
+ groupId = "pay2-group"
|
|
|
|
|
+ )
|
|
|
|
|
+ public void syncQiyunRemain(String message) {
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(message);
|
|
|
|
|
+ int total = jsonObject.getIntValue("total");
|
|
|
|
|
+ int pageSize = jsonObject.getIntValue("pageSize");
|
|
|
|
|
+ int totalPages = (total + pageSize - 1) / pageSize;
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = supplyTokenService.buildAuthHeaders();
|
|
|
|
|
+ if (headers == null) {
|
|
|
|
|
+ log.error("syncQiyunRemain: 获取token失败,无法处理剩余分页");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 线程池并发查询剩余分页(从第2页开始)
|
|
|
|
|
+ int threadCount = Math.min(20, totalPages - 1);
|
|
|
|
|
+ ExecutorService executor = Executors.newFixedThreadPool(Math.max(1, threadCount));
|
|
|
|
|
+ List<Future<?>> futures = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (int page = 2; page <= totalPages; page++) {
|
|
|
|
|
+ final int p = page;
|
|
|
|
|
+ futures.add(executor.submit(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject pageData = productSupplyService.fetchStoragePage(p, pageSize, headers);
|
|
|
|
|
+ if (pageData == null) {
|
|
|
|
|
+ log.error("syncQiyunRemain: 查询第{}页失败,返回null", p);
|
|
|
|
|
+ saveSyncFailLog(p, pageSize, total, "查询第" + p + "页返回null");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONArray array = pageData.getJSONArray("list");
|
|
|
|
|
+ if (array != null && !array.isEmpty()) {
|
|
|
|
|
+ productSupplyService.sendKafkaMessageWithRetry(array.toString());
|
|
|
|
|
+ log.info("syncQiyunRemain: 成功发送第{}页数据,共{}条", p, array.size());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("syncQiyunRemain: 查询第{}页异常", p, e);
|
|
|
|
|
+ saveSyncFailLog(p, pageSize, total, e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 等待所有任务完成
|
|
|
|
|
+ for (Future<?> future : futures) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ future.get();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("syncQiyunRemain: 等待分页任务完成异常", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ executor.shutdown();
|
|
|
|
|
+ log.info("syncQiyunRemain: 所有分页处理完成,总页数={}", totalPages);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存同步异常日志到 MongoDB
|
|
|
|
|
+ */
|
|
|
|
|
+ private void saveSyncFailLog(int page, int pageSize, int total, String errorMsg) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ StorageSyncFailLog logEntity = new StorageSyncFailLog();
|
|
|
|
|
+ logEntity.setPage(page);
|
|
|
|
|
+ logEntity.setPageSize(pageSize);
|
|
|
|
|
+ logEntity.setTotal(total);
|
|
|
|
|
+ logEntity.setErrorMsg(errorMsg);
|
|
|
|
|
+ logEntity.setCreateTime(System.currentTimeMillis());
|
|
|
|
|
+ storageSyncFailLogDao.save(logEntity);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("saveSyncFailLog: 保存异常日志到MongoDB失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|