diff --git a/src/main/java/com/glxp/api/service/collect/DownloadFactory.java b/src/main/java/com/glxp/api/service/collect/DownloadFactory.java index 655928910..346ce7050 100644 --- a/src/main/java/com/glxp/api/service/collect/DownloadFactory.java +++ b/src/main/java/com/glxp/api/service/collect/DownloadFactory.java @@ -188,6 +188,8 @@ public class DownloadFactory { ioCollectOrder.setUpdateTime(new Date()); ioCollectOrder.setSplitStatus(0); ioCollectOrder.setTagStatus(0); + ioCollectOrder.setBackupOrderRemark1(thrOrder.getBackupOrderRemark1()); + List bizList = new ArrayList<>(); for (IoCollectOrderBiz entity : thrOrder.getBizList()) { IoCollectOrderBiz collectOrderBiz = new IoCollectOrderBiz(); diff --git a/src/main/java/com/glxp/api/service/sync/HeartService.java b/src/main/java/com/glxp/api/service/sync/HeartService.java index aec15fc0e..2cdcac1a9 100644 --- a/src/main/java/com/glxp/api/service/sync/HeartService.java +++ b/src/main/java/com/glxp/api/service/sync/HeartService.java @@ -76,8 +76,13 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ForkJoinPool; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.glxp.api.constant.BasicProcessStatus.NEW_ALL_ORDER; import static com.glxp.api.constant.BasicProcessStatus.NEW_ALL_UDIS; @@ -1625,74 +1630,113 @@ public class HeartService { List supCompanyList = JSONUtil.toList(jsonObject.getJSONArray(SupCompanyEntity.class.getSimpleName()), SupCompanyEntity.class); List supManufacturerList = JSONUtil.toList(jsonObject.getJSONArray(SupManufacturerEntity.class.getSimpleName()), SupManufacturerEntity.class); List supProductList = JSONUtil.toList(jsonObject.getJSONArray(SupProductEntity.class.getSimpleName()), SupProductEntity.class); - List syncFiles = JSONUtil.toList(jsonObject.getJSONArray("syncFiles"), String.class); + // 使用 ExecutorService 管理并行任务 + ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - if (CollectionUtil.isNotEmpty(hospTypeList)) { - basicHospTypeDao.replaceBatch(hospTypeList); - } - if (CollectionUtil.isNotEmpty(udiRelevanceList)) { - List> splits = CustomUtil.splitList(udiRelevanceList, 200); - splits.forEach(items -> { - udiRelevanceDao.replaceBatch(items); - }); - } - if (CollectionUtil.isNotEmpty(productsList)) { - //过来500 条 数据 过滤掉uuid一样的 100个产品 - List uniqueUuidProducts = productsList.stream() - .collect(Collectors.groupingBy(BasicProductsEntity::getUuid)) - .values() - .stream() - .map(list -> list.get(0)) - .collect(Collectors.toList()); - for (BasicProductsEntity basicProductsEntity : uniqueUuidProducts){ - List basicProductsEntities = basicProductsDao.selectList(new LambdaQueryWrapper().eq(BasicProductsEntity::getUuid, basicProductsEntity.getUuid())); - if (CollectionUtil.isNotEmpty(basicProductsEntities)){ - for (BasicProductsEntity basicProductsEntity1 : basicProductsEntities){ - if (basicProductsEntity1.getNameCode() == null){ - basicProductsDao.deleteById(basicProductsEntity1); - } - } - } - } - List> splits = CustomUtil.splitList(productsList, 200); - splits.forEach(items -> { - basicProductsDao.replaceBatch(items); - }); -// basicProductsDao.replaceBatchs(productsList, 1000); - } - if (CollectionUtil.isNotEmpty(relevanceList)) { - relevanceDao.replaceBatch(relevanceList); - } - if (CollectionUtil.isNotEmpty(corpList)) { - corpDao.replaceBatch(corpList); - } - if (CollectionUtil.isNotEmpty(supCertList)) { - supCertDao.replaceBatch(supCertList); - } - if (CollectionUtil.isNotEmpty(supCertSetList)) { - supCertSetDao.replaceBatch(supCertSetList); - } - if (CollectionUtil.isNotEmpty(supCompanyList)) { - supCompanyDao.replaceBatch(supCompanyList); + try { + Stream.of( + () -> processHospType(hospTypeList), + () -> processUdiRelevance(udiRelevanceList), + () -> processProducts(productsList), + () -> processRelevance(relevanceList), + () -> processCorp(corpList), + () -> processSupCerts(supCertList, supCertSetList), + () -> processSupCompanies(supCompanyList), + () -> processSupManufacturers(supManufacturerList), + () -> processSupProducts(supProductList) + ).forEach(task -> executorService.submit(task)); + } finally { + executorService.shutdown(); } - if (CollectionUtil.isNotEmpty(supManufacturerList)) { - supManufacturerDao.replaceBatch(supManufacturerList); + // 异步处理文件下载 + processSyncFilesAsync(syncFiles); + + } + + // 各处理逻辑封装为独立方法 + private void processHospType(List list) { + if (CollectionUtil.isEmpty(list)) return; + basicHospTypeDao.replaceBatch(list); + } + + private void processUdiRelevance(List list) { + if (CollectionUtil.isEmpty(list)) return; + CustomUtil.splitList(list, 200).forEach(udiRelevanceDao::replaceBatch); + } + + private void processProducts(List productsList) { + if (CollectionUtil.isEmpty(productsList)) return; + + + // 去重逻辑优化 + Map uuidToProductMap = productsList.stream() + .collect(Collectors.toMap(BasicProductsEntity::getUuid, product -> product, (existing, replacement) -> existing)); + List uniqueUuidProducts = new ArrayList<>(uuidToProductMap.values()); + + // 批量查询数据库中已存在的产品 + List uuids = uniqueUuidProducts.stream().map(BasicProductsEntity::getUuid).collect(Collectors.toList()); + List existingProducts = basicProductsDao.selectBatchIds(uuids); + + // 批量删除符合条件的记录 + List uuidsToDelete = existingProducts.stream() + .filter(p -> p.getNameCode() == null) + .map(BasicProductsEntity::getUuid) + .collect(Collectors.toList()); + if (!uuidsToDelete.isEmpty()) { + basicProductsDao.deleteBatchIds(uuidsToDelete); } - if (CollectionUtil.isNotEmpty(supProductList)) { - List> splits = CustomUtil.splitList(supProductList, 100); - if (CollUtil.isNotEmpty(splits)) { - for (List items : splits) { - supProductDao.insertOrUpdateBatch(items); - } - } + + // 分批处理 + CustomUtil.splitList(productsList, 500).forEach(basicProductsDao::replaceBatch); + } + + private void processRelevance(List list) { + if (CollectionUtil.isEmpty(list)) return; + CustomUtil.splitList(list, 200).forEach(relevanceDao::replaceBatch); + } + + private void processCorp(List list) { + if (CollectionUtil.isEmpty(list)) return; + CustomUtil.splitList(list, 200).forEach(corpDao::replaceBatch); + } + + // 合并证书相关处理 + private void processSupCerts(List certList, List certSetList) { + if (CollectionUtil.isNotEmpty(certList)) { + CustomUtil.splitList(certList, 200).forEach(supCertDao::replaceBatch); } - if (CollUtil.isNotEmpty(syncFiles)) { -// fileService.download(syncFiles); - idcService.batchDownloadFile(spGetHttp.getIpUrl(), syncFiles.toArray(new String[syncFiles.size()])); + if (CollectionUtil.isNotEmpty(certSetList)) { + CustomUtil.splitList(certSetList, 200).forEach(supCertSetDao::replaceBatch); } } + private void processSupCompanies(List list) { + if (CollectionUtil.isEmpty(list)) return; + CustomUtil.splitList(list, 200).forEach(supCompanyDao::replaceBatch); + } + + private void processSupManufacturers(List list) { + if (CollectionUtil.isEmpty(list)) return; + CustomUtil.splitList(list, 200).forEach(supManufacturerDao::replaceBatch); + } + + private void processSupProducts(List list) { + if (CollectionUtil.isEmpty(list)) return; + CustomUtil.splitList(list, 100).forEach(supProductDao::insertOrUpdateBatch); + } + + // 异步文件处理 + private void processSyncFilesAsync(List syncFiles) { + if (CollectionUtil.isEmpty(syncFiles)) return; + + CompletableFuture.runAsync(() -> { + idcService.batchDownloadFile( + spGetHttp.getIpUrl(), + syncFiles.toArray(new String[0]) + ); + }, ForkJoinPool.commonPool()); + } private final IdcService idcService; private final IoCodeLostMapper ioCodeLostMapper;