|
|
|
@ -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<SupCompanyEntity> supCompanyList = JSONUtil.toList(jsonObject.getJSONArray(SupCompanyEntity.class.getSimpleName()), SupCompanyEntity.class);
|
|
|
|
|
List<SupManufacturerEntity> supManufacturerList = JSONUtil.toList(jsonObject.getJSONArray(SupManufacturerEntity.class.getSimpleName()), SupManufacturerEntity.class);
|
|
|
|
|
List<SupProductEntity> supProductList = JSONUtil.toList(jsonObject.getJSONArray(SupProductEntity.class.getSimpleName()), SupProductEntity.class);
|
|
|
|
|
|
|
|
|
|
List<String> 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<List<UdiRelevanceEntity>> splits = CustomUtil.splitList(udiRelevanceList, 200);
|
|
|
|
|
splits.forEach(items -> {
|
|
|
|
|
udiRelevanceDao.replaceBatch(items);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(productsList)) {
|
|
|
|
|
//过来500 条 数据 过滤掉uuid一样的 100个产品
|
|
|
|
|
List<BasicProductsEntity> uniqueUuidProducts = productsList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(BasicProductsEntity::getUuid))
|
|
|
|
|
.values()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(list -> list.get(0))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
for (BasicProductsEntity basicProductsEntity : uniqueUuidProducts){
|
|
|
|
|
List<BasicProductsEntity> basicProductsEntities = basicProductsDao.selectList(new LambdaQueryWrapper<BasicProductsEntity>().eq(BasicProductsEntity::getUuid, basicProductsEntity.getUuid()));
|
|
|
|
|
if (CollectionUtil.isNotEmpty(basicProductsEntities)){
|
|
|
|
|
for (BasicProductsEntity basicProductsEntity1 : basicProductsEntities){
|
|
|
|
|
if (basicProductsEntity1.getNameCode() == null){
|
|
|
|
|
basicProductsDao.deleteById(basicProductsEntity1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
Stream.<Runnable>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();
|
|
|
|
|
}
|
|
|
|
|
// 异步处理文件下载
|
|
|
|
|
processSyncFilesAsync(syncFiles);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
List<List<BasicProductsEntity>> splits = CustomUtil.splitList(productsList, 200);
|
|
|
|
|
splits.forEach(items -> {
|
|
|
|
|
basicProductsDao.replaceBatch(items);
|
|
|
|
|
});
|
|
|
|
|
// basicProductsDao.replaceBatchs(productsList, 1000);
|
|
|
|
|
|
|
|
|
|
// 各处理逻辑封装为独立方法
|
|
|
|
|
private void processHospType(List<BasicHospTypeEntity> list) {
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) return;
|
|
|
|
|
basicHospTypeDao.replaceBatch(list);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(relevanceList)) {
|
|
|
|
|
relevanceDao.replaceBatch(relevanceList);
|
|
|
|
|
|
|
|
|
|
private void processUdiRelevance(List<UdiRelevanceEntity> list) {
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) return;
|
|
|
|
|
CustomUtil.splitList(list, 200).forEach(udiRelevanceDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(corpList)) {
|
|
|
|
|
corpDao.replaceBatch(corpList);
|
|
|
|
|
|
|
|
|
|
private void processProducts(List<BasicProductsEntity> productsList) {
|
|
|
|
|
if (CollectionUtil.isEmpty(productsList)) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 去重逻辑优化
|
|
|
|
|
Map<String, BasicProductsEntity> uuidToProductMap = productsList.stream()
|
|
|
|
|
.collect(Collectors.toMap(BasicProductsEntity::getUuid, product -> product, (existing, replacement) -> existing));
|
|
|
|
|
List<BasicProductsEntity> uniqueUuidProducts = new ArrayList<>(uuidToProductMap.values());
|
|
|
|
|
|
|
|
|
|
// 批量查询数据库中已存在的产品
|
|
|
|
|
List<String> uuids = uniqueUuidProducts.stream().map(BasicProductsEntity::getUuid).collect(Collectors.toList());
|
|
|
|
|
List<BasicProductsEntity> existingProducts = basicProductsDao.selectBatchIds(uuids);
|
|
|
|
|
|
|
|
|
|
// 批量删除符合条件的记录
|
|
|
|
|
List<String> uuidsToDelete = existingProducts.stream()
|
|
|
|
|
.filter(p -> p.getNameCode() == null)
|
|
|
|
|
.map(BasicProductsEntity::getUuid)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (!uuidsToDelete.isEmpty()) {
|
|
|
|
|
basicProductsDao.deleteBatchIds(uuidsToDelete);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(supCertList)) {
|
|
|
|
|
supCertDao.replaceBatch(supCertList);
|
|
|
|
|
|
|
|
|
|
// 分批处理
|
|
|
|
|
CustomUtil.splitList(productsList, 500).forEach(basicProductsDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(supCertSetList)) {
|
|
|
|
|
supCertSetDao.replaceBatch(supCertSetList);
|
|
|
|
|
|
|
|
|
|
private void processRelevance(List<CompanyProductRelevanceEntity> list) {
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) return;
|
|
|
|
|
CustomUtil.splitList(list, 200).forEach(relevanceDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(supCompanyList)) {
|
|
|
|
|
supCompanyDao.replaceBatch(supCompanyList);
|
|
|
|
|
|
|
|
|
|
private void processCorp(List<BasicCorpEntity> list) {
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) return;
|
|
|
|
|
CustomUtil.splitList(list, 200).forEach(corpDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(supManufacturerList)) {
|
|
|
|
|
supManufacturerDao.replaceBatch(supManufacturerList);
|
|
|
|
|
|
|
|
|
|
// 合并证书相关处理
|
|
|
|
|
private void processSupCerts(List<SupCertEntity> certList, List<SupCertSetEntity> certSetList) {
|
|
|
|
|
if (CollectionUtil.isNotEmpty(certList)) {
|
|
|
|
|
CustomUtil.splitList(certList, 200).forEach(supCertDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(supProductList)) {
|
|
|
|
|
List<List<SupProductEntity>> splits = CustomUtil.splitList(supProductList, 100);
|
|
|
|
|
if (CollUtil.isNotEmpty(splits)) {
|
|
|
|
|
for (List<SupProductEntity> items : splits) {
|
|
|
|
|
supProductDao.insertOrUpdateBatch(items);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(certSetList)) {
|
|
|
|
|
CustomUtil.splitList(certSetList, 200).forEach(supCertSetDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void processSupCompanies(List<SupCompanyEntity> list) {
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) return;
|
|
|
|
|
CustomUtil.splitList(list, 200).forEach(supCompanyDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(syncFiles)) {
|
|
|
|
|
// fileService.download(syncFiles);
|
|
|
|
|
idcService.batchDownloadFile(spGetHttp.getIpUrl(), syncFiles.toArray(new String[syncFiles.size()]));
|
|
|
|
|
|
|
|
|
|
private void processSupManufacturers(List<SupManufacturerEntity> list) {
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) return;
|
|
|
|
|
CustomUtil.splitList(list, 200).forEach(supManufacturerDao::replaceBatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void processSupProducts(List<SupProductEntity> list) {
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) return;
|
|
|
|
|
CustomUtil.splitList(list, 100).forEach(supProductDao::insertOrUpdateBatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 异步文件处理
|
|
|
|
|
private void processSyncFilesAsync(List<String> 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;
|
|
|
|
|