From 86b2b0cc421405eb0432b44357ad37eb0dfae50d Mon Sep 17 00:00:00 2001 From: zhenghaoyu Date: Thu, 9 May 2024 18:03:27 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=B9=B2=E7=BA=BF=E5=AF=BC=E5=85=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basicdata/feign/IBasicdataCodeClient.java | 6 + .../dto/ImportOrderNoPackageExcelDTO.java | 46 +- .../basicdata/feign/BasicdataCodeClient.java | 8 +- .../service/IBasicdataCodeService.java | 3 + .../impl/BasicdataCodeServiceImpl.java | 59 +- .../config/InterceptorAdapterConfig.java | 11 +- .../controller/OpenOrderController.java | 4 +- .../mapper/TrunklineAdvanceMapper.java | 4 +- .../trunkline/service/IAsyncService.java | 2 + .../trunkline/service/IOpenOrderService.java | 4 +- .../service/ITrunklineAdvanceService.java | 3 +- .../service/impl/AsyncServiceImpl.java | 13 + .../service/impl/OpenOrderServiceImpl.java | 985 ++++++++++++------ .../impl/TrunklineAdvanceServiceImpl.java | 2 +- 14 files changed, 783 insertions(+), 367 deletions(-) diff --git a/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/feign/IBasicdataCodeClient.java b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/feign/IBasicdataCodeClient.java index 4d28599c8..9648f2bb6 100644 --- a/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/feign/IBasicdataCodeClient.java +++ b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/feign/IBasicdataCodeClient.java @@ -5,6 +5,8 @@ import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; +import java.util.List; + @FeignClient( value = ModuleNameConstant.APPLICATION_BASICDATA_NAME ) @@ -15,4 +17,8 @@ public interface IBasicdataCodeClient { @GetMapping(API_PREFIX+"/getCodeByType") String getCodeByType(@RequestParam Integer type,@RequestParam String warehouseCode,@RequestParam String orderCode); + + @GetMapping(API_PREFIX+"/getBatchPackageCodeByType") + List getBatchPackageCodeByType(@RequestParam String warehouseCode, @RequestParam String orderCode,@RequestParam Integer num); + } diff --git a/blade-service-api/logpm-trunkline-api/src/main/java/com/logpm/trunkline/dto/ImportOrderNoPackageExcelDTO.java b/blade-service-api/logpm-trunkline-api/src/main/java/com/logpm/trunkline/dto/ImportOrderNoPackageExcelDTO.java index d65165262..c4e7980a2 100644 --- a/blade-service-api/logpm-trunkline-api/src/main/java/com/logpm/trunkline/dto/ImportOrderNoPackageExcelDTO.java +++ b/blade-service-api/logpm-trunkline-api/src/main/java/com/logpm/trunkline/dto/ImportOrderNoPackageExcelDTO.java @@ -8,35 +8,57 @@ import java.io.Serializable; @Data public class ImportOrderNoPackageExcelDTO implements Serializable { - @ExcelProperty(value = "下单日期") - private String orderTime; - @ExcelProperty(value = "商场名称") - private String dealerName; + @ExcelProperty(value = "服务号") + private String serviceNum ; @ExcelProperty(value = "订单自编号") private String orderCode; + @ExcelProperty(value = "品牌") + private String brand ; + @ExcelProperty(value = "一级品类") + private String firsts; + @ExcelProperty(value = "二级品类") + private String seconds; + @ExcelProperty(value = "三级品类") + private String thirds; + @ExcelProperty(value = "物料名称") + private String materialName; + @ExcelProperty(value = "物料编码") + private String materialCode; + @ExcelProperty(value = "单位") + private String unit; @ExcelProperty(value = "销售数量") private String num; + @ExcelProperty(value = "合计件数") + private String count; + @ExcelProperty(value = "体积") + private String volume; + @ExcelProperty(value = "重量") + private String weight; + @ExcelProperty(value = "车次号") + private String trainNumber ; + @ExcelProperty(value = "商场编码") + private String dealerCode; + @ExcelProperty(value = "商场名称") + private String dealerName; @ExcelProperty(value = "商场收货人") private String consigneePerson; @ExcelProperty(value = "商场收货人电话") private String consigneeMobile; @ExcelProperty(value = "商场收货地址") private String consigneeAddress; + @ExcelProperty(value = "发货人") + private String shipperPerson; + @ExcelProperty(value = "发货人电话") + private String shipperMobile; + @ExcelProperty(value = "发货人地址") + private String shipperAddress; @ExcelProperty(value = "收货人") private String customerName ; @ExcelProperty(value = "联系电话") private String customerPhone ; @ExcelProperty(value = "地址") private String customerAddress ; - @ExcelProperty(value = "车次") - private String trainNumber ; - @ExcelProperty(value = "发货日期") - private String sendDateStr ; - @ExcelProperty(value = "品牌") - private String brand ; @ExcelProperty(value = "配送区域") private String area ; - @ExcelProperty(value = "服务号") - private String serviceNum ; } diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/feign/BasicdataCodeClient.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/feign/BasicdataCodeClient.java index 11156019c..4d1f5ab0e 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/feign/BasicdataCodeClient.java +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/feign/BasicdataCodeClient.java @@ -1,11 +1,12 @@ package com.logpm.basicdata.feign; -import com.logpm.basicdata.entity.BasicdataClientEntity; import com.logpm.basicdata.service.IBasicdataCodeService; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; +import java.util.List; + @ApiIgnore() @RestController @AllArgsConstructor @@ -18,4 +19,9 @@ public class BasicdataCodeClient implements IBasicdataCodeClient { return basicdataCodeService.getCodeByType(type,warehouseCode,orderCode); } + @Override + public List getBatchPackageCodeByType(String warehouseCode, String orderCode, Integer num) { + return basicdataCodeService.getBatchPackageCodeByType(warehouseCode,orderCode,num); + } + } diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/IBasicdataCodeService.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/IBasicdataCodeService.java index 5c71c2826..e9637e558 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/IBasicdataCodeService.java +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/IBasicdataCodeService.java @@ -1,7 +1,10 @@ package com.logpm.basicdata.service; +import java.util.List; + public interface IBasicdataCodeService { String getCodeByType(Integer type,String warehouseCode,String orderCode); + List getBatchPackageCodeByType(String warehouseCode, String orderCode, Integer num); } diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java index 6dcb25201..06ec890c2 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java @@ -18,9 +18,7 @@ import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; -import java.util.Calendar; -import java.util.Date; -import java.util.Objects; +import java.util.*; @Service @AllArgsConstructor @@ -93,6 +91,61 @@ public class BasicdataCodeServiceImpl implements IBasicdataCodeService { return code; } + @Override + public List getBatchPackageCodeByType(String warehouseCode, String orderCode, Integer num) { + if(!StringUtil.hasLength(warehouseCode)){ + log.warn("############getBatchPackageCodeByType: 仓库编码为空warehouseCode={}",warehouseCode); + return null; + } + if(!StringUtil.hasLength(orderCode)){ + log.warn("############getBatchPackageCodeByType: 订单号为空orderCode={}",orderCode); + return null; + } + + //包条 HT+仓库拼音/超管/职能+年月日时分秒+订单索引+包条个数索引 + String haxCodeByLong = CommonUtil.getHaxCodeByLong(orderCode, 8); + + BasicdataWarehouseEntity basicdataWarehouseEntity = basicdataWarehouseService.getWarehouseEntityByWarehouseCode(warehouseCode); + if(Objects.isNull(basicdataWarehouseEntity)){ + log.warn("############getWayBillNo: 仓库信息不存在 warehouseCode={}",warehouseCode); + return null; + } + + Calendar calendar = Calendar.getInstance(); + //获取年份 + Integer year = calendar.get(Calendar.YEAR); + + // 获取月份(注意月份从0开始计数) + Integer month = calendar.get(Calendar.MONTH) + 1; + + + BasicdataCodeRecordEntity basicdataCodeRecordEntity = basicdataCodeRecordService.findEntityByCodeTypeAndWarehouseCodeAndYearAndMonth(CodeNumConstant.PACKAGE,warehouseCode,year+"",month+""); + + if(Objects.isNull(basicdataCodeRecordEntity)){ + basicdataCodeRecordEntity = new BasicdataCodeRecordEntity(); + basicdataCodeRecordEntity.setCodeType(CodeNumConstant.PACKAGE); + basicdataCodeRecordEntity.setWarehouseId(basicdataWarehouseEntity.getId()); + basicdataCodeRecordEntity.setWarehouseName(basicdataWarehouseEntity.getName()); + basicdataCodeRecordEntity.setWarehouseCode(warehouseCode); + basicdataCodeRecordEntity.setYear(year+""); + basicdataCodeRecordEntity.setMonth(month+""); + basicdataCodeRecordEntity.setNum(0); + basicdataCodeRecordService.save(basicdataCodeRecordEntity); + } + + Integer oldNum = basicdataCodeRecordEntity.getNum(); + List packageCodes = new ArrayList<>(); + for (int i = 0; i < num; i++) { + oldNum = oldNum + 1; + String packageCode = "HT" + warehouseCode + year + CommonUtil.geFourNumber(month.longValue(),2) + haxCodeByLong + CommonUtil.geFourNumber(oldNum.longValue(),6); + packageCodes.add(packageCode); + } + basicdataCodeRecordEntity.setNum(oldNum); + basicdataCodeRecordService.updateById(basicdataCodeRecordEntity); + + return packageCodes; + } + private String generateTrunklineLoadSignCode(Integer type, String warehouseCode, String orderCode) { if(!StringUtil.hasLength(warehouseCode)){ diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java index b29922165..bc294dfcb 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java @@ -7,7 +7,6 @@ import com.logpm.factory.interceptor.ZbFactoryAccountsInterceptor; import com.logpm.factory.props.ZbFactoryProperties; import lombok.AllArgsConstructor; import org.springblade.core.redis.cache.BladeRedis; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.web.servlet.config.annotation.InterceptorRegistration; @@ -22,6 +21,8 @@ public class InterceptorAdapterConfig implements WebMvcConfigurer { private final BladeRedis redis; + private final ZbFactoryProperties zbFactoryProperties; + private final Environment environment; @@ -32,8 +33,12 @@ public class InterceptorAdapterConfig implements WebMvcConfigurer { excludePathPatterns("/factory/auth/token"). excludePathPatterns("/factory/oupai/**"). excludePathPatterns("/factory/zb/**") - .excludePathPatterns("/factory/common/**"); - registry=interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis,environment)); + .excludePathPatterns("/factory/common/**").order(1); + InterceptorRegistration registryZbFactory = interceptorRegistry.addInterceptor(new ZbFactoryAccountsInterceptor(zbFactoryProperties)); + registryZbFactory.addPathPatterns("/factory/zb/**").order(2); + + + registry=interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis,environment)).addPathPatterns("/**").order(3); } } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/controller/OpenOrderController.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/controller/OpenOrderController.java index e2d95ba27..9bf3452bd 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/controller/OpenOrderController.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/controller/OpenOrderController.java @@ -1060,7 +1060,7 @@ public class OpenOrderController { return R.fail(403,"仓库信息为空"); } - return openOrderService.batchOpenLabel(myCurrentWarehouse.getId(),myCurrentWarehouse.getName(),file); + return openOrderService.batchOpenLabel(myCurrentWarehouse.getId(),myCurrentWarehouse.getName(),myCurrentWarehouse.getWarehouseCode(),file); }catch (CustomerException e){ log.error(e.message,e); return R.fail(e.code,e.message); @@ -1119,7 +1119,7 @@ public class OpenOrderController { return R.fail(403,"仓库信息为空"); } - R> listR = openOrderService.importOrderNoPackage(myCurrentWarehouse.getId(),myCurrentWarehouse.getName(),file); + R> listR = openOrderService.importOrderNoPackage(myCurrentWarehouse.getId(),myCurrentWarehouse.getName(),myCurrentWarehouse.getWarehouseCode(),file); // List data = listR.getData(); // if(!CollUtil.isEmpty(data)){ // for (TrunklineAdvanceEntity datum : data) { diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceMapper.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceMapper.java index 184f734b8..5d1b355df 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceMapper.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceMapper.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.logpm.trunkline.dto.AdvanceDTO; import com.logpm.trunkline.dto.InComingDTO; -import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; import com.logpm.trunkline.entity.TrunklineAdvanceEntity; import com.logpm.trunkline.vo.CustomerInfoVO; import com.logpm.trunkline.vo.OpenOrderVO; @@ -13,7 +12,6 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; -import java.util.Set; @Mapper public interface TrunklineAdvanceMapper extends BaseMapper { @@ -40,5 +38,5 @@ public interface TrunklineAdvanceMapper extends BaseMapper findListByExistsAndOrderCodeSet(@Param("orderCodeSet") Set orderCodeSet); + List findListByExistsAndOrderCodeSet(@Param("orderCodeSet") List orderCodeSet); } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IAsyncService.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IAsyncService.java index fb342ef09..6e07875d5 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IAsyncService.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IAsyncService.java @@ -1,6 +1,7 @@ package com.logpm.trunkline.service; import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; +import com.logpm.trunkline.entity.TrunklineAdvanceEntity; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -9,4 +10,5 @@ public interface IAsyncService { CompletableFuture getResponseFromCp(List list, int queryType); + CompletableFuture saveAdvanceEntity(List list, int queryType); } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderService.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderService.java index 71779d5fd..ec6946060 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderService.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderService.java @@ -58,11 +58,11 @@ public interface IOpenOrderService { R findBrandList(OpenOrderDTO openOrderDTO); - R batchOpenLabel(Long warehouseId, String warehouseName, MultipartFile file) throws IOException; + R batchOpenLabel(Long warehouseId, String warehouseName, String warehouseCode, MultipartFile file) throws IOException; R findPayWayByClientId(Long clientId); - R> importOrderNoPackage(Long warehouseId, String warehouseName, MultipartFile file) throws IOException; + R> importOrderNoPackage(Long warehouseId, String warehouseName, String warehouseCode, MultipartFile file) throws IOException; R checkWaybill(OpenOrderDTO openOrderDTO); diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java index 944b07f96..2fcfa17b1 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java @@ -11,7 +11,6 @@ import com.logpm.trunkline.vo.TrunklineAdvanceVO; import org.springblade.core.mp.base.BaseService; import java.util.List; -import java.util.Set; public interface ITrunklineAdvanceService extends BaseService { @@ -39,5 +38,5 @@ public interface ITrunklineAdvanceService extends BaseService incomingPackageBatch(Long advanceId, Long warehouseId, List detailList, Long userId, Long deptId, String tenantId); - List findListByExistsAndOrderCodeSet(Set orderCodeSet); + List findListByExistsAndOrderCodeSet(List orderCodeSet); } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/AsyncServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/AsyncServiceImpl.java index 2065c168e..a2db2bd8a 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/AsyncServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/AsyncServiceImpl.java @@ -1,8 +1,10 @@ package com.logpm.trunkline.service.impl; import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; +import com.logpm.trunkline.entity.TrunklineAdvanceEntity; import com.logpm.trunkline.service.IAsyncService; import com.logpm.trunkline.service.ITrunklineAdvanceDetailService; +import com.logpm.trunkline.service.ITrunklineAdvanceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -13,6 +15,8 @@ import java.util.concurrent.CompletableFuture; @Service public class AsyncServiceImpl implements IAsyncService { + @Autowired + private ITrunklineAdvanceService advanceService; @Autowired private ITrunklineAdvanceDetailService advanceDetailService; @@ -25,4 +29,13 @@ public class AsyncServiceImpl implements IAsyncService { ); } + @Async("asyncExecutor") + @Override + public CompletableFuture saveAdvanceEntity(List list, int queryType) { + return CompletableFuture + .completedFuture( + advanceService.saveBatch(list) + ); + } + } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java index a9525d33e..c309cdfca 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java @@ -992,7 +992,7 @@ public class OpenOrderServiceImpl implements IOpenOrderService { advanceDetailModel.setOrderCode(openLabelDTO.getOrderCode()); advanceDetailModel.setBrand(openLabelDTO.getBrand()); advanceDetailModel.setSystemType("线上"); - advanceDetailModel.setOrderPackageCode(basicdataCodeClient.getCodeByType(CodeNumConstant.PACKAGE, warehouseCode, orderCode)); +// advanceDetailModel.setOrderPackageCode(basicdataCodeClient.getCodeByType(CodeNumConstant.PACKAGE, warehouseCode, orderCode)); advanceDetailModel.setFirstPackName(firsts); String sencods = openLabelDTO.getSencods(); @@ -1014,12 +1014,20 @@ public class OpenOrderServiceImpl implements IOpenOrderService { advanceDetailModel.setVolume(openLabelDTO.getVolume()); List detailEntities = new ArrayList<>(); - for (int i = 0; i < totalNumber; i++) { - TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); - BeanUtil.copy(advanceDetailModel, advanceDetailEntity); - advanceDetailEntity.setOrderPackageCode(basicdataCodeClient.getCodeByType(CodeNumConstant.PACKAGE, warehouseCode, orderCode)); - detailEntities.add(advanceDetailEntity); - } + + List batchPackageCodeByType = basicdataCodeClient.getBatchPackageCodeByType(warehouseCode, orderCode, totalNumber); + batchPackageCodeByType.forEach(item -> { + advanceDetailModel.setOrderPackageCode(item); + detailEntities.add(advanceDetailModel); + }); + + +// for (int i = 0; i < totalNumber; i++) { +// TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); +// BeanUtil.copy(advanceDetailModel, advanceDetailEntity); +// advanceDetailEntity.setOrderPackageCode(basicdataCodeClient.getCodeByType(CodeNumConstant.PACKAGE, warehouseCode, orderCode)); +// detailEntities.add(advanceDetailEntity); +// } advanceDetailService.saveBatch(detailEntities); return R.success("保存成功"); } @@ -1040,25 +1048,31 @@ public class OpenOrderServiceImpl implements IOpenOrderService { listMap.remove("null&null"); //把pacakgeDetailExcelDTOS中的orderCode存入一个set集合 - Set orderCodeSet = pacakgeDetailExcelDTOS.parallelStream().map(PacakgeDetailExcelDTO::getOrderCode).collect(Collectors.toSet()); - + Set orderCodes = pacakgeDetailExcelDTOS.parallelStream().map(PacakgeDetailExcelDTO::getOrderCode).collect(Collectors.toSet()); - Set set = listMap.keySet(); List advanceDetailEntities = new ArrayList<>(); List advanceEntityList = new ArrayList<>(); Map advanceEntityMap = new HashMap<>(); - List advanceIds = new ArrayList<>(); List detailEntities = new ArrayList<>(); - //把orderCodeSet分成每2000个元素为一组 - List> orderCodeSets = orderCodeSet.parallelStream().collect(Collectors.groupingBy(a -> a.hashCode() % 2000)).values().stream().map(a -> new HashSet<>(a)).collect(Collectors.toList()); - for (int i = 0; i < orderCodeSets.size(); i++) { - Set set1 = orderCodeSets.get(i); - List entities = advanceService.findListByExistsAndOrderCodeSet(orderCodeSet); + //把orderCodes转成List + List orderCodeList = new ArrayList<>(orderCodes); + //把orderCodeList分成每2000个元素一组 + int batchSize = 2000; + List> orderedGroups = new ArrayList<>(); + + for (int i = 0; i < orderCodeList.size(); i += batchSize) { + int endIndex = Math.min(i + batchSize, orderCodeList.size()); + orderedGroups.add(orderCodeList.subList(i, endIndex)); + } + + for (int i = 0; i < orderedGroups.size(); i++) { + List set1 = orderedGroups.get(i); + List entities = advanceService.findListByExistsAndOrderCodeSet(set1); detailEntities.addAll(entities); } @@ -1066,22 +1080,15 @@ public class OpenOrderServiceImpl implements IOpenOrderService { detailEntities.forEach(advanceEntity -> { String orderCode = advanceEntity.getOrderCode(); String trainNumber = advanceEntity.getTrainNumber(); - String key = orderCode + "&" + trainNumber; + String key = orderCode + "&" + (StringUtil.isBlank(trainNumber)?"null":trainNumber); advanceEntityMap.put(key,advanceEntity); }); - -// Map> advanceMap = detailEntities.parallelStream().collect(Collectors.groupingBy(a -> a.getOrderCode() + "&" + a.getTrainNumber())); - listMap.keySet().forEach(str -> { - String[] split = str.split("&"); - String orderCode = split[0]; - String trainNumber = split[1]; - if("null".equals(trainNumber)){ - trainNumber = null; - } List excelDTOS = listMap.get(str); PacakgeDetailExcelDTO pacakgeDetailExcelDTO = excelDTOS.get(0); + String trainNumber = pacakgeDetailExcelDTO.getTrainNumber(); + String orderCode = pacakgeDetailExcelDTO.getOrderCode(); TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(str); if (Objects.isNull(advanceEntity)) { advanceEntity = new TrunklineAdvanceEntity(); @@ -1130,19 +1137,32 @@ public class OpenOrderServiceImpl implements IOpenOrderService { advanceEntity.setWaybillStatus("0"); advanceEntity.setFreezeStatus("0"); advanceEntity.setLegacyStatus("0"); + advanceEntity.setHasPackage(1); advanceEntity.setCreateUserName(AuthUtil.getNickName()); advanceEntityList.add(advanceEntity); } else { advanceIds.add(advanceEntity.getId()); - advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+advanceEntity.getTrainNumber(),advanceEntity); + advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+(StringUtil.isBlank(trainNumber)?"null":trainNumber),advanceEntity); } }); - advanceService.saveBatch(advanceEntityList); + if (!advanceEntityList.isEmpty()) { + //把advanceDetailEntities分成相等数量的10个集合 + List> advanceEntitiesList = advanceEntityList.stream().collect(Collectors.groupingBy(item -> advanceDetailEntities.indexOf(item) / 1000)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); + List comlist = new ArrayList<>(); + for (int i = 0; i < advanceEntitiesList.size(); i++) { + List list = advanceEntitiesList.get(i); + CompletableFuture fromCpFirstReq = asyncService.saveAdvanceEntity(list, i+1); + comlist.add(fromCpFirstReq); + } + CompletableFuture.allOf(comlist.toArray(new CompletableFuture[0])).join(); + + } advanceEntityList.forEach(advanceEntity -> { advanceIds.add(advanceEntity.getId()); - advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+advanceEntity.getTrainNumber(),advanceEntity); + String trainNumber = advanceEntity.getTrainNumber(); + advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+(StringUtil.isBlank(trainNumber)?"null":trainNumber),advanceEntity); }); //通过advanceIds查询所有advanceDetail @@ -1157,12 +1177,10 @@ public class OpenOrderServiceImpl implements IOpenOrderService { listMap.keySet().forEach(str -> { List pacakgeDetailExcelList = listMap.get(str); - - String[] split = str.split("&"); - String orderCode = split[0]; TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(str); if(!Objects.isNull(advanceEntity)){ Long advanceId = advanceEntity.getId(); + String orderCode = advanceEntity.getOrderCode(); List orderPackageCodes = map.get(advanceId); pacakgeDetailExcelList.forEach(pacakgeDetailExcelDTO -> { String orderPackageCode = pacakgeDetailExcelDTO.getOrderPackageCode(); @@ -1175,6 +1193,7 @@ public class OpenOrderServiceImpl implements IOpenOrderService { advanceDetailModel.setOrderPackageCode(orderPackageCode); advanceDetailModel.setBrand(pacakgeDetailExcelDTO.getBrand()); advanceDetailModel.setSystemType("线上"); + advanceDetailModel.setTrainNumber(advanceEntity.getTrainNumber()); String firsts = pacakgeDetailExcelDTO.getFirsts(); advanceDetailModel.setFirstPackName(firsts); String sencods = pacakgeDetailExcelDTO.getSencods(); @@ -1275,7 +1294,7 @@ public class OpenOrderServiceImpl implements IOpenOrderService { @Override public R> importCustomizedOuPai(Long warehouseId, String warehouseName, MultipartFile file) throws IOException { if (Objects.isNull(file)) { - log.warn("##################openLabelHasPacakage: 文件不存在"); + log.warn("##################importCustomizedOuPai: 文件不存在"); return R.fail(405, "文件不存在"); } InputStream inputStream = file.getInputStream(); @@ -1288,99 +1307,194 @@ public class OpenOrderServiceImpl implements IOpenOrderService { listMap.remove("null&null"); - Set set = listMap.keySet(); + //把pacakgeDetailExcelDTOS中的orderCode存入一个set集合 + Set orderCodes = importCustomizedOuPaiDTOS.parallelStream() + .map(ImportCustomizedOuPaiDTO::getOrderCode) + .collect(Collectors.toSet()); + //把orderCodes转成List + List orderCodeList = new ArrayList<>(orderCodes); + //把orderCodeList分成每2000个元素一组 + int batchSize = 2000; + List> orderedGroups = new ArrayList<>(); + + for (int i = 0; i < orderCodeList.size(); i += batchSize) { + int endIndex = Math.min(i + batchSize, orderCodeList.size()); + orderedGroups.add(orderCodeList.subList(i, endIndex)); + } - List advanceEntityList = new ArrayList<>(); List advanceDetailEntities = new ArrayList<>(); - for (String str : set) { - List paiDTOList = listMap.get(str); - ImportCustomizedOuPaiDTO importCustomizedOuPaiDTO = paiDTOList.get(0); - String[] split = str.split("&"); - String orderCode = split[0]; - String trainNumber = split[1]; - List orderPackageCodes = new ArrayList<>(); - TrunklineAdvanceEntity trunklineAdvanceEntity = advanceService.findEntityByOrderCodeAndTrainNumber(orderCode, trainNumber); - if (Objects.isNull(trunklineAdvanceEntity)) { - trunklineAdvanceEntity = new TrunklineAdvanceVO(); - trunklineAdvanceEntity.setWarehouseId(warehouseId); - trunklineAdvanceEntity.setWarehouseName(warehouseName); - trunklineAdvanceEntity.setOrderCode(orderCode); - trunklineAdvanceEntity.setSiteName(importCustomizedOuPaiDTO.getSiteName()); - trunklineAdvanceEntity.setOrderType(importCustomizedOuPaiDTO.getOrderType()); - trunklineAdvanceEntity.setBrand("欧派"); - trunklineAdvanceEntity.setTotalNum(paiDTOList.size()); - trunklineAdvanceEntity.setPackName(importCustomizedOuPaiDTO.getFirstsName()); - trunklineAdvanceEntity.setDealerCode(importCustomizedOuPaiDTO.getDealerCode()); - trunklineAdvanceEntity.setDealerName(importCustomizedOuPaiDTO.getDealerName()); - trunklineAdvanceEntity.setCarrierName(importCustomizedOuPaiDTO.getCarrierName()); - trunklineAdvanceEntity.setCustomerName(importCustomizedOuPaiDTO.getCustomerName()); - trunklineAdvanceEntity.setCustomerPhone(importCustomizedOuPaiDTO.getCustomerPhone()); - trunklineAdvanceEntity.setCustomerAddress(importCustomizedOuPaiDTO.getCustomerAddress()); - trunklineAdvanceEntity.setSystemType("线上"); - trunklineAdvanceEntity.setServiceNum(importCustomizedOuPaiDTO.getServiceNum()); - trunklineAdvanceEntity.setMatingType("1"); - trunklineAdvanceEntity.setWaybillStatus("0"); - trunklineAdvanceEntity.setTrainNumber(importCustomizedOuPaiDTO.getTrainNumber()); - trunklineAdvanceEntity.setFreezeStatus("0"); - trunklineAdvanceEntity.setLegacyStatus("0"); + + List advanceEntityList = new ArrayList<>(); + + Map advanceEntityMap = new HashMap<>(); + + List advanceIds = new ArrayList<>(); + + List detailEntities = new ArrayList<>(); + + + for (int i = 0; i < orderedGroups.size(); i++) { + List set1 = orderedGroups.get(i); + List entities = advanceService.findListByExistsAndOrderCodeSet(set1); + detailEntities.addAll(entities); + } + + //把detailEntities转化成以orderCode和trainNumber为key的map + detailEntities.forEach(advanceEntity -> { + String orderCode = advanceEntity.getOrderCode(); + String trainNumber = advanceEntity.getTrainNumber(); + String key = orderCode + "&" + (StringUtil.isBlank(trainNumber)?"null":trainNumber); + advanceEntityMap.put(key,advanceEntity); + }); + + listMap.keySet().forEach(str -> { + List excelDTOS = listMap.get(str); + ImportCustomizedOuPaiDTO importCustomizedOuPaiDTO = excelDTOS.get(0); + TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(str); + if (Objects.isNull(advanceEntity)) { + String orderCode = importCustomizedOuPaiDTO.getOrderCode(); + advanceEntity = new TrunklineAdvanceVO(); + advanceEntity.setWarehouseId(warehouseId); + advanceEntity.setWarehouseName(warehouseName); + advanceEntity.setOrderCode(orderCode); + advanceEntity.setCarrierName(importCustomizedOuPaiDTO.getCarrierName()); + advanceEntity.setTrainNumber(importCustomizedOuPaiDTO.getTrainNumber()); + advanceEntity.setSiteName(importCustomizedOuPaiDTO.getSiteName()); + advanceEntity.setOrderType(importCustomizedOuPaiDTO.getOrderType()); + advanceEntity.setBrand("欧派"); + advanceEntity.setTotalNum(excelDTOS.size()); + advanceEntity.setPackName(importCustomizedOuPaiDTO.getFirstsName()); + advanceEntity.setDealerCode(importCustomizedOuPaiDTO.getDealerCode()); + String dealerName = importCustomizedOuPaiDTO.getDealerName(); + if(StringUtil.isBlank(dealerName)){ + int firstDigitIndex = findFirstDigitIndex(orderCode); + if(firstDigitIndex != -1){ + dealerName = orderCode.substring(0,firstDigitIndex); + } + } + advanceEntity.setDealerName(dealerName); + advanceEntity.setCarrierName(importCustomizedOuPaiDTO.getCarrierName()); + advanceEntity.setCustomerName(importCustomizedOuPaiDTO.getCustomerName()); + advanceEntity.setCustomerPhone(importCustomizedOuPaiDTO.getCustomerPhone()); + advanceEntity.setCustomerAddress(importCustomizedOuPaiDTO.getCustomerAddress()); + advanceEntity.setSystemType("线上"); + advanceEntity.setServiceNum(importCustomizedOuPaiDTO.getServiceNum()); + advanceEntity.setMatingType("1"); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setTrainNumber(importCustomizedOuPaiDTO.getTrainNumber()); + advanceEntity.setFreezeStatus("0"); + advanceEntity.setLegacyStatus("0"); + advanceEntity.setIsGcp(0); + String isOupai = importCustomizedOuPaiDTO.getIsOupai(); + if("是".equals(isOupai)){ + advanceEntity.setIsGcp(1); + } if (orderCode.contains("遗")) { - trunklineAdvanceEntity.setLegacyStatus("1"); + advanceEntity.setLegacyStatus("1"); } - trunklineAdvanceEntity.setDeliveryDate(CommonUtil.StringToDate(importCustomizedOuPaiDTO.getDueDateStr())); - trunklineAdvanceEntity.setCreateUserName(AuthUtil.getNickName()); - advanceService.save(trunklineAdvanceEntity); - advanceEntityList.add(trunklineAdvanceEntity); + advanceEntity.setDeliveryDate(CommonUtil.StringToDate(importCustomizedOuPaiDTO.getDueDateStr())); + advanceEntity.setCreateUserName(AuthUtil.getNickName()); + advanceEntity.setHasPackage(1); + advanceEntityList.add(advanceEntity); } else { - Long advanceId = trunklineAdvanceEntity.getId(); - orderPackageCodes = advanceDetailService.findOrderPackageCodesByAdvanceId(advanceId); + advanceIds.add(advanceEntity.getId()); + String trainNumber = advanceEntity.getTrainNumber(); + advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+(StringUtil.isBlank(trainNumber)?"null":trainNumber),advanceEntity); } + }); - for (ImportCustomizedOuPaiDTO customizedOuPaiDTO : paiDTOList) { - String orderPackageCode = customizedOuPaiDTO.getOrderPackageCode(); - if (orderPackageCodes.contains(orderPackageCode)) { - continue; - } - TrunklineAdvanceDetailEntity advanceDetailModel = new TrunklineAdvanceDetailEntity(); - advanceDetailModel.setWarehouseId(warehouseId); - advanceDetailModel.setWarehouseName(warehouseName); - advanceDetailModel.setAdvanceId(trunklineAdvanceEntity.getId()); - advanceDetailModel.setOrderPackageCode(orderPackageCode); - advanceDetailModel.setTrainNumber(customizedOuPaiDTO.getTrainNumber()); - advanceDetailModel.setOrderCode(orderCode); - advanceDetailModel.setBrand("欧派"); - advanceDetailModel.setSystemType("线上"); - String firsts = customizedOuPaiDTO.getFirstsName(); - advanceDetailModel.setFirstPackName(firsts); - String sencods = customizedOuPaiDTO.getSencodsName(); - if (StringUtil.isBlank(sencods)) { - advanceDetailModel.setSecondPackName(firsts); - } else { - advanceDetailModel.setSecondPackName(sencods); - } - String thirds = customizedOuPaiDTO.getThirdsName(); - if (StringUtil.isBlank(thirds)) { - advanceDetailModel.setThirdPackName(firsts); - } else { - advanceDetailModel.setThirdPackName(thirds); - } - advanceDetailModel.setQuantity(1); - advanceDetailModel.setServiceNum(customizedOuPaiDTO.getServiceNum()); - advanceDetailModel.setPackageStatus("0"); - advanceDetailModel.setSupple(customizedOuPaiDTO.getSupple()); - advanceDetailModel.setManifest(customizedOuPaiDTO.getManifest()); - advanceDetailModel.setReturnNum(customizedOuPaiDTO.getReturnNum()); - advanceDetailModel.setSendDateStr(customizedOuPaiDTO.getSendDateStr()); - advanceDetailModel.setCarNumber(customizedOuPaiDTO.getCarNumber()); - advanceDetailModel.setGoodsMan(customizedOuPaiDTO.getGoodsMan()); - advanceDetailEntities.add(advanceDetailModel); + if (!advanceEntityList.isEmpty()) { + //把advanceDetailEntities分成相等数量的10个集合 + List> advanceEntitiesList = advanceEntityList.stream().collect(Collectors.groupingBy(item -> advanceDetailEntities.indexOf(item) / 1000)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); + List comlist = new ArrayList<>(); + for (int i = 0; i < advanceEntitiesList.size(); i++) { + List list = advanceEntitiesList.get(i); + CompletableFuture fromCpFirstReq = asyncService.saveAdvanceEntity(list, i+1); + comlist.add(fromCpFirstReq); } + CompletableFuture.allOf(comlist.toArray(new CompletableFuture[0])).join(); + + } + + advanceEntityList.forEach(advanceEntity -> { + advanceIds.add(advanceEntity.getId()); + String trainNumber = advanceEntity.getTrainNumber(); + advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+(StringUtil.isBlank(trainNumber)?"null":trainNumber),advanceEntity); + }); + + //通过advanceIds查询所有advanceDetail + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("advance_id",advanceIds) + .eq("is_deleted",0); + List advanceDetailEntityList = advanceDetailService.list(queryWrapper); + //把advanceDetailEntityList通过advanceId分组并且把集合转化为orderPackageCode的集合 + Map> map = advanceDetailEntityList.parallelStream().collect(Collectors.groupingBy(TrunklineAdvanceDetailEntity::getAdvanceId, Collectors.mapping(TrunklineAdvanceDetailEntity::getOrderPackageCode, Collectors.toList()))); + Map materialMap = new HashMap<>(); + + + listMap.keySet().forEach(str -> { + List importCustomizedOuPaiDTOList = listMap.get(str); + + TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(str); + if(!Objects.isNull(advanceEntity)){ + Long advanceId = advanceEntity.getId(); + String orderCode = advanceEntity.getOrderCode(); + List orderPackageCodes = map.get(advanceId); + importCustomizedOuPaiDTOList.forEach(importCustomizedOuPaiDTO -> { + String orderPackageCode = importCustomizedOuPaiDTO.getOrderPackageCode(); + if(Objects.isNull(orderPackageCodes) || !orderPackageCodes.contains(orderPackageCode)){ + TrunklineAdvanceDetailEntity advanceDetailModel = new TrunklineAdvanceDetailEntity(); + advanceDetailModel.setWarehouseId(warehouseId); + advanceDetailModel.setWarehouseName(warehouseName); + advanceDetailModel.setAdvanceId(advanceId); + advanceDetailModel.setOrderCode(orderCode); + advanceDetailModel.setOrderPackageCode(orderPackageCode); + advanceDetailModel.setBrand(advanceEntity.getBrand()); + advanceDetailModel.setSystemType("线上"); + advanceDetailModel.setSiteName(importCustomizedOuPaiDTO.getSiteName()); + advanceDetailModel.setSupple(importCustomizedOuPaiDTO.getSupple()); + advanceDetailModel.setManifest(importCustomizedOuPaiDTO.getManifest()); + advanceDetailModel.setReturnNum(importCustomizedOuPaiDTO.getReturnNum()); + advanceDetailModel.setSendDateStr(importCustomizedOuPaiDTO.getSendDateStr()); + advanceDetailModel.setCarNumber(importCustomizedOuPaiDTO.getCarNumber()); + advanceDetailModel.setGoodsMan(importCustomizedOuPaiDTO.getGoodsMan()); + advanceDetailModel.setTrainNumber(advanceEntity.getTrainNumber()); + String firsts = importCustomizedOuPaiDTO.getFirstsName(); + advanceDetailModel.setFirstPackName(firsts); + String sencods = importCustomizedOuPaiDTO.getSencodsName(); + if (StringUtil.isBlank(sencods)) { + advanceDetailModel.setSecondPackName(firsts); + } else { + advanceDetailModel.setSecondPackName(sencods); + } + String thirds = importCustomizedOuPaiDTO.getThirdsName(); + if (StringUtil.isBlank(thirds)) { + advanceDetailModel.setThirdPackName(firsts); + } else { + advanceDetailModel.setThirdPackName(thirds); + } + advanceDetailModel.setQuantity(1); + advanceDetailModel.setServiceNum(advanceEntity.getServiceNum()); + advanceDetailModel.setPackageStatus("0"); + advanceDetailEntities.add(advanceDetailModel); + } + + }); + } + }); + + if (!advanceDetailEntities.isEmpty()) { + //把advanceDetailEntities分成相等数量的10个集合 + List> advanceDetailEntitiesList = advanceDetailEntities.stream().collect(Collectors.groupingBy(item -> advanceDetailEntities.indexOf(item) / 1000)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); + List comlist = new ArrayList<>(); + for (int i = 0; i < advanceDetailEntitiesList.size(); i++) { + List list = advanceDetailEntitiesList.get(i); + CompletableFuture fromCpFirstReq = asyncService.getResponseFromCp(list, i+1); + comlist.add(fromCpFirstReq); + } + CompletableFuture.allOf(comlist.toArray(new CompletableFuture[0])).join(); -// int all = orderPackageCodes.size() + advanceDetailEntities.size(); -// if(all != trunklineAdvanceEntity.getTotalNum()){ -// advanceService.updateTotalNumById(trunklineAdvanceEntity.getId(),all); -// } } - advanceDetailService.saveBatch(advanceDetailEntities); long end = new Date().getTime(); @@ -1404,148 +1518,228 @@ public class OpenOrderServiceImpl implements IOpenOrderService { listMap.remove("null&null"); - Set set = listMap.keySet(); + //把pacakgeDetailExcelDTOS中的orderCode存入一个set集合 + Set orderCodes = importStandardOuPaiDTOS.parallelStream().map(ImportStandardOuPaiDTO::getOrderCode).collect(Collectors.toSet()); - List advanceEntityList = new ArrayList<>(); List advanceDetailEntities = new ArrayList<>(); - for (String str : set) { - List paiDTOList = listMap.get(str); - ImportStandardOuPaiDTO importStandardOuPaiDTO = paiDTOList.get(0); - String[] split = str.split("&"); - String orderCode = split[0]; - String trainNumber = split[1]; - List orderPackageCodes = new ArrayList<>(); - TrunklineAdvanceEntity trunklineAdvanceEntity = advanceService.findEntityByOrderCodeAndTrainNumber(orderCode, trainNumber); - if (Objects.isNull(trunklineAdvanceEntity)) { - trunklineAdvanceEntity = new TrunklineAdvanceVO(); - trunklineAdvanceEntity.setWarehouseId(warehouseId); - trunklineAdvanceEntity.setWarehouseName(warehouseName); - trunklineAdvanceEntity.setOrderCode(orderCode); - trunklineAdvanceEntity.setSiteName(importStandardOuPaiDTO.getSiteName()); - trunklineAdvanceEntity.setBrand("欧派"); - trunklineAdvanceEntity.setTotalNum(paiDTOList.size()); - trunklineAdvanceEntity.setPackName(importStandardOuPaiDTO.getFirstsName()); - trunklineAdvanceEntity.setDealerCode(importStandardOuPaiDTO.getDealerCode()); - trunklineAdvanceEntity.setDealerName(importStandardOuPaiDTO.getDealerName()); - trunklineAdvanceEntity.setCarrierName(importStandardOuPaiDTO.getCarrierName()); - trunklineAdvanceEntity.setCustomerName(importStandardOuPaiDTO.getCustomerName()); - trunklineAdvanceEntity.setCustomerPhone(importStandardOuPaiDTO.getCustomerPhone()); - trunklineAdvanceEntity.setCustomerAddress(importStandardOuPaiDTO.getCustomerAddress()); - trunklineAdvanceEntity.setSystemType("线上"); - trunklineAdvanceEntity.setMatingType("1"); - trunklineAdvanceEntity.setWaybillStatus("0"); - trunklineAdvanceEntity.setTrainNumber(importStandardOuPaiDTO.getTrainNumber()); - trunklineAdvanceEntity.setFreezeStatus("0"); - trunklineAdvanceEntity.setLegacyStatus("0"); + + List advanceEntityList = new ArrayList<>(); + + Map advanceEntityMap = new HashMap<>(); + + List advanceIds = new ArrayList<>(); + + List detailEntities = new ArrayList<>(); + //把orderCodes转成List + List orderCodeList = new ArrayList<>(orderCodes); + //把orderCodeList分成每2000个元素一组 + int batchSize = 2000; + List> orderedGroups = new ArrayList<>(); + + for (int i = 0; i < orderCodeList.size(); i += batchSize) { + int endIndex = Math.min(i + batchSize, orderCodeList.size()); + orderedGroups.add(orderCodeList.subList(i, endIndex)); + } + for (int i = 0; i < orderedGroups.size(); i++) { + List set1 = orderedGroups.get(i); + List entities = advanceService.findListByExistsAndOrderCodeSet(set1); + detailEntities.addAll(entities); + } + + //把detailEntities转化成以orderCode和trainNumber为key的map + detailEntities.forEach(advanceEntity -> { + String orderCode = advanceEntity.getOrderCode(); + String trainNumber = advanceEntity.getTrainNumber(); + String key = orderCode + "&" + (StringUtil.isBlank(trainNumber)?"null":trainNumber); + advanceEntityMap.put(key,advanceEntity); + }); + + listMap.keySet().forEach(str -> { + List excelDTOS = listMap.get(str); + ImportStandardOuPaiDTO importStandardOuPaiDTO = excelDTOS.get(0); + TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(str); + if (Objects.isNull(advanceEntity)) { + String orderCode = importStandardOuPaiDTO.getOrderCode(); + advanceEntity = new TrunklineAdvanceVO(); + advanceEntity.setWarehouseId(warehouseId); + advanceEntity.setWarehouseName(warehouseName); + advanceEntity.setOrderCode(orderCode); + advanceEntity.setCarrierName(importStandardOuPaiDTO.getCarrierName()); + advanceEntity.setTrainNumber(importStandardOuPaiDTO.getTrainNumber()); + advanceEntity.setSiteName(importStandardOuPaiDTO.getSiteName()); +// advanceEntity.setOrderType(importStandardOuPaiDTO.getOrderType()); + advanceEntity.setBrand("欧派"); + advanceEntity.setTotalNum(excelDTOS.size()); + advanceEntity.setPackName(importStandardOuPaiDTO.getFirstsName()); + advanceEntity.setDealerCode(importStandardOuPaiDTO.getDealerCode()); + String dealerName = importStandardOuPaiDTO.getDealerName(); + if(StringUtil.isBlank(dealerName)){ + int firstDigitIndex = findFirstDigitIndex(orderCode); + if(firstDigitIndex != -1){ + dealerName = orderCode.substring(0,firstDigitIndex); + } + } + advanceEntity.setDealerName(dealerName); + advanceEntity.setCustomerName(importStandardOuPaiDTO.getCustomerName()); + advanceEntity.setCustomerPhone(importStandardOuPaiDTO.getCustomerPhone()); + advanceEntity.setCustomerAddress(importStandardOuPaiDTO.getCustomerAddress()); + advanceEntity.setSenderFactory(importStandardOuPaiDTO.getSendFactory()); + advanceEntity.setSystemType("线上"); + advanceEntity.setMatingType("1"); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setTrainNumber(importStandardOuPaiDTO.getTrainNumber()); + advanceEntity.setFreezeStatus("0"); + advanceEntity.setLegacyStatus("0"); + advanceEntity.setIsGcp(0); + String isOupai = importStandardOuPaiDTO.getIsOupai(); + if("是".equals(isOupai)){ + advanceEntity.setIsGcp(1); + } if (orderCode.contains("遗")) { - trunklineAdvanceEntity.setLegacyStatus("1"); + advanceEntity.setLegacyStatus("1"); } - trunklineAdvanceEntity.setDeliveryDate(CommonUtil.StringToDate(importStandardOuPaiDTO.getDueDateStr())); - trunklineAdvanceEntity.setCreateUserName(AuthUtil.getNickName()); - advanceService.save(trunklineAdvanceEntity); - advanceEntityList.add(trunklineAdvanceEntity); + advanceEntity.setDeliveryDate(CommonUtil.StringToDate(importStandardOuPaiDTO.getDueDateStr())); + advanceEntity.setCreateUserName(AuthUtil.getNickName()); + advanceEntity.setHasPackage(1); + advanceEntityList.add(advanceEntity); } else { - Long advanceId = trunklineAdvanceEntity.getId(); - orderPackageCodes = advanceDetailService.findOrderPackageCodesByAdvanceId(advanceId); + advanceIds.add(advanceEntity.getId()); + String trainNumber = advanceEntity.getTrainNumber(); + advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+(StringUtil.isBlank(trainNumber)?"null":trainNumber),advanceEntity); } + }); + if (!advanceEntityList.isEmpty()) { + //把advanceDetailEntities分成相等数量的10个集合 + List> advanceEntitiesList = advanceEntityList.stream().collect(Collectors.groupingBy(item -> advanceDetailEntities.indexOf(item) / 1000)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); + List comlist = new ArrayList<>(); + for (int i = 0; i < advanceEntitiesList.size(); i++) { + List list = advanceEntitiesList.get(i); + CompletableFuture fromCpFirstReq = asyncService.saveAdvanceEntity(list, i+1); + comlist.add(fromCpFirstReq); + } + CompletableFuture.allOf(comlist.toArray(new CompletableFuture[0])).join(); + } - for (ImportStandardOuPaiDTO standardOuPaiDTO : paiDTOList) { - String orderPackageCode = standardOuPaiDTO.getOrderPackageCode(); - if (orderPackageCodes.contains(orderPackageCode)) { - - TrunklineAdvanceDetailEntity advanceDetailEntity = advanceDetailService.findEntityByOrderPackageCode(orderPackageCode); - String materialCode = standardOuPaiDTO.getMaterialCode(); - String materialName = standardOuPaiDTO.getMaterialName(); - String num = standardOuPaiDTO.getNum(); - - if (StringUtil.isNotBlank(materialCode) && StringUtil.isNotBlank(materialName)) { - BasicMaterialEntity basicMaterialEntity = basicMaterialClient.findEntityByCodeAndName(materialCode, materialName); - if (Objects.isNull(basicMaterialEntity)) { - basicMaterialEntity = new BasicMaterialEntity(); - basicMaterialEntity.setProductCode(materialCode); - basicMaterialEntity.setName(materialName); - basicMaterialEntity.setBrandId("1713382405517201409"); - basicMaterialEntity.setProperty("家配"); - basicMaterialEntity.setSpecification("件"); - basicMaterialEntity.setPackingSpecification(num + "件/箱"); - basicMaterialEntity.setLogpmUnit("箱"); - basicMaterialEntity.setSku(materialCode); - basicMaterialEntity.setPackageNum(num); - basicMaterialEntity.setHide(1); - Long aLong = basicMaterialClient.addMaterial(basicMaterialEntity); - basicMaterialEntity.setId(aLong); + advanceEntityList.forEach(advanceEntity -> { + advanceIds.add(advanceEntity.getId()); + String trainNumber = advanceEntity.getTrainNumber(); + advanceEntityMap.put(advanceEntity.getOrderCode()+"&"+(StringUtil.isBlank(trainNumber)?"null":trainNumber),advanceEntity); + }); + + //通过advanceIds查询所有advanceDetail + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("advance_id",advanceIds) + .eq("is_deleted",0); + List advanceDetailEntityList = advanceDetailService.list(queryWrapper); + //把advanceDetailEntityList通过advanceId分组并且把集合转化为orderPackageCode的集合 + Map> map = advanceDetailEntityList.parallelStream().collect(Collectors.groupingBy(TrunklineAdvanceDetailEntity::getAdvanceId, Collectors.mapping(TrunklineAdvanceDetailEntity::getOrderPackageCode, Collectors.toList()))); + Map materialMap = new HashMap<>(); + + listMap.keySet().forEach(str -> { + List importStandardOuPaiDTOList = listMap.get(str); + + TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(str); + if(!Objects.isNull(advanceEntity)){ + Long advanceId = advanceEntity.getId(); + String orderCode = advanceEntity.getOrderCode(); + String brand = advanceEntity.getBrand(); + List orderPackageCodes = map.get(advanceId); + importStandardOuPaiDTOList.forEach(importStandardOuPaiDTO -> { + String orderPackageCode = importStandardOuPaiDTO.getOrderPackageCode(); + if(Objects.isNull(orderPackageCodes) || !orderPackageCodes.contains(orderPackageCode)){ + TrunklineAdvanceDetailEntity advanceDetailModel = new TrunklineAdvanceDetailEntity(); + advanceDetailModel.setWarehouseId(warehouseId); + advanceDetailModel.setWarehouseName(warehouseName); + advanceDetailModel.setAdvanceId(advanceId); + advanceDetailModel.setOrderCode(orderCode); + advanceDetailModel.setOrderPackageCode(orderPackageCode); + advanceDetailModel.setBrand(brand); + advanceDetailModel.setSystemType("线上"); + advanceDetailModel.setSiteName(importStandardOuPaiDTO.getSiteName()); + advanceDetailModel.setReturnNum(importStandardOuPaiDTO.getReturnNum()); + advanceDetailModel.setSendDateStr(importStandardOuPaiDTO.getSendDateStr()); + advanceDetailModel.setCarNumber(importStandardOuPaiDTO.getCarNumber()); + advanceDetailModel.setVolume(new BigDecimal(importStandardOuPaiDTO.getVolume())); + advanceDetailModel.setTrainNumber(advanceEntity.getTrainNumber()); + String firsts = importStandardOuPaiDTO.getFirstsName(); + advanceDetailModel.setFirstPackName(firsts); + String sencods = importStandardOuPaiDTO.getSencodsName(); + if (StringUtil.isBlank(sencods)) { + advanceDetailModel.setSecondPackName(firsts); + } else { + advanceDetailModel.setSecondPackName(sencods); } - advanceDetailEntity.setMaterialId(basicMaterialEntity.getId()); - advanceDetailEntity.setMaterialCode(basicMaterialEntity.getProductCode()); - advanceDetailEntity.setMaterialName(basicMaterialEntity.getName()); - } - advanceDetailService.updateById(advanceDetailEntity); - continue; - } - TrunklineAdvanceDetailEntity advanceDetailModel = new TrunklineAdvanceDetailEntity(); - advanceDetailModel.setWarehouseId(warehouseId); - advanceDetailModel.setWarehouseName(warehouseName); - advanceDetailModel.setAdvanceId(trunklineAdvanceEntity.getId()); - advanceDetailModel.setOrderPackageCode(orderPackageCode); - advanceDetailModel.setTrainNumber(importStandardOuPaiDTO.getTrainNumber()); - advanceDetailModel.setOrderCode(orderCode); - advanceDetailModel.setBrand("欧派"); - advanceDetailModel.setSystemType("线上"); - String firsts = standardOuPaiDTO.getFirstsName(); - advanceDetailModel.setFirstPackName(firsts); - String sencods = standardOuPaiDTO.getSencodsName(); - if (StringUtil.isBlank(sencods)) { - advanceDetailModel.setSecondPackName(firsts); - } else { - advanceDetailModel.setSecondPackName(sencods); - } - String thirds = standardOuPaiDTO.getThirdsName(); - if (StringUtil.isBlank(thirds)) { - advanceDetailModel.setThirdPackName(firsts); - } else { - advanceDetailModel.setThirdPackName(thirds); - } - advanceDetailModel.setQuantity(1); - advanceDetailModel.setPackageStatus("0"); - advanceDetailModel.setReturnNum(standardOuPaiDTO.getReturnNum()); - advanceDetailModel.setSendDateStr(standardOuPaiDTO.getSendDateStr()); - advanceDetailModel.setCarNumber(standardOuPaiDTO.getCarNumber()); - String materialCode = standardOuPaiDTO.getMaterialCode(); - String materialName = standardOuPaiDTO.getMaterialName(); - String num = standardOuPaiDTO.getNum(); - - if (StringUtil.isNotBlank(materialCode) && StringUtil.isNotBlank(materialName)) { - BasicMaterialEntity basicMaterialEntity = basicMaterialClient.findEntityByCodeAndName(materialCode, materialName); - if (Objects.isNull(basicMaterialEntity)) { - basicMaterialEntity = new BasicMaterialEntity(); - basicMaterialEntity.setProductCode(materialCode); - basicMaterialEntity.setName(materialName); - basicMaterialEntity.setBrandId("1713382405517201409"); - basicMaterialEntity.setProperty("家配"); - basicMaterialEntity.setSpecification("件"); - basicMaterialEntity.setPackingSpecification(num + "件/箱"); - basicMaterialEntity.setLogpmUnit("箱"); - basicMaterialEntity.setSku(materialCode); - basicMaterialEntity.setPackageNum(num); - basicMaterialEntity.setHide(1); - Long aLong = basicMaterialClient.addMaterial(basicMaterialEntity); - basicMaterialEntity.setId(aLong); + String thirds = importStandardOuPaiDTO.getThirdsName(); + if (StringUtil.isBlank(thirds)) { + advanceDetailModel.setThirdPackName(firsts); + } else { + advanceDetailModel.setThirdPackName(thirds); + } + advanceDetailModel.setQuantity(1); + advanceDetailModel.setServiceNum(advanceEntity.getServiceNum()); + advanceDetailModel.setPackageStatus("0"); + String materialName = importStandardOuPaiDTO.getMaterialName(); + String materialCode = importStandardOuPaiDTO.getMaterialCode(); + + if (StringUtil.isNotBlank(materialCode) && StringUtil.isNotBlank(materialName)) { + Long materialId = materialMap.get(materialCode); + if(!Objects.isNull(materialId)){ + advanceDetailModel.setMaterialId(materialId); + advanceDetailModel.setMaterialCode(materialCode); + advanceDetailModel.setMaterialName(materialName); + }else{ + BasicMaterialEntity basicMaterialEntity = basicMaterialClient.findEntityByCodeAndName(materialCode, materialName); + if (Objects.isNull(basicMaterialEntity)) { + basicMaterialEntity = new BasicMaterialEntity(); + basicMaterialEntity.setProductCode(materialCode); + basicMaterialEntity.setName(materialName); + BasicdataBrandEntity basicdataBrandEntity = basicdataBrandClient.findEntityByName(brand); + if(Objects.isNull(basicdataBrandEntity)){ + basicMaterialEntity.setBrandId("1713382405517201409"); + }else{ + basicMaterialEntity.setBrandId(basicdataBrandEntity.getId()+""); + } + basicMaterialEntity.setProperty("家配"); + basicMaterialEntity.setSpecification("件"); + basicMaterialEntity.setPackingSpecification("1件/箱"); + basicMaterialEntity.setLogpmUnit("箱"); + basicMaterialEntity.setSku(materialCode); + basicMaterialEntity.setPackageNum("1"); + basicMaterialEntity.setHide(1); + Long aLong = basicMaterialClient.addMaterial(basicMaterialEntity); + basicMaterialEntity.setId(aLong); + materialMap.put(materialCode,aLong); + advanceDetailModel.setMaterialId(aLong); + advanceDetailModel.setMaterialCode(materialCode); + advanceDetailModel.setMaterialName(materialName); + }else{ + materialMap.put(materialCode,basicMaterialEntity.getId()); + advanceDetailModel.setMaterialId(basicMaterialEntity.getId()); + advanceDetailModel.setMaterialCode(basicMaterialEntity.getProductCode()); + advanceDetailModel.setMaterialName(basicMaterialEntity.getName()); + } + } + } + advanceDetailEntities.add(advanceDetailModel); } - advanceDetailModel.setMaterialId(basicMaterialEntity.getId()); - advanceDetailModel.setMaterialCode(basicMaterialEntity.getProductCode()); - advanceDetailModel.setMaterialName(basicMaterialEntity.getName()); - } - advanceDetailEntities.add(advanceDetailModel); + + }); } + }); -// int all = orderPackageCodes.size() + advanceDetailEntities.size(); -// if(all != trunklineAdvanceEntity.getTotalNum()){ -// advanceService.updateTotalNumById(trunklineAdvanceEntity.getId(),all); -// } + if (!advanceDetailEntities.isEmpty()) { + //把advanceDetailEntities分成相等数量的10个集合 + List> advanceDetailEntitiesList = advanceDetailEntities.stream().collect(Collectors.groupingBy(item -> advanceDetailEntities.indexOf(item) / 1000)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); + List comlist = new ArrayList<>(); + for (int i = 0; i < advanceDetailEntitiesList.size(); i++) { + List list = advanceDetailEntitiesList.get(i); + CompletableFuture fromCpFirstReq = asyncService.getResponseFromCp(list, i+1); + comlist.add(fromCpFirstReq); + } + CompletableFuture.allOf(comlist.toArray(new CompletableFuture[0])).join(); } - advanceDetailService.saveBatch(advanceDetailEntities); return R.data(advanceEntityList); } @@ -1650,81 +1844,152 @@ public class OpenOrderServiceImpl implements IOpenOrderService { return R.data(ls); } + @Transactional(rollbackFor = Exception.class) @Override - public R batchOpenLabel(Long warehouseId, String warehouseName, MultipartFile file) throws IOException { + public R batchOpenLabel(Long warehouseId, String warehouseName, String warehouseCode, MultipartFile file) throws IOException { if (Objects.isNull(file)) { - log.warn("##################openLabelHasPacakage: 文件不存在"); + log.warn("##################batchOpenLabel: 文件不存在"); return R.fail(405, "文件不存在"); } InputStream inputStream = file.getInputStream(); - List orderNoPackageExcelDTOS = EasyExcel.read(inputStream).head(OrderNoPackageExcelDTO.class).sheet(0).headRowNumber(2).doReadSync(); + List importOrderNoPackageExcelDTOS = EasyExcel.read(inputStream).head(ImportOrderNoPackageExcelDTO.class).sheet(0).headRowNumber(2).doReadSync(); - BasicdataWarehouseEntity basicdataWarehouseEntity = basicdataWarehouseClient.getEntityWarehouseId(warehouseId); + //把importOrderNoPackageExcelDTOS中的orderCode存入一个set集合 + Set orderCodes = importOrderNoPackageExcelDTOS.parallelStream().map(ImportOrderNoPackageExcelDTO::getOrderCode).collect(Collectors.toSet()); - for (OrderNoPackageExcelDTO orderNoPackageExcelDTO : orderNoPackageExcelDTOS) { - TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); - advanceEntity.setWarehouseId(warehouseId); - advanceEntity.setWarehouseName(warehouseName); - String orderCode = orderNoPackageExcelDTO.getOrderCode(); - advanceEntity.setOrderCode(orderCode); - advanceEntity.setArea(orderNoPackageExcelDTO.getArea()); - advanceEntity.setOrderType("Label"); - advanceEntity.setBrand(orderNoPackageExcelDTO.getBrand()); - Integer totalNumber = Integer.parseInt(orderNoPackageExcelDTO.getNum()); - advanceEntity.setTotalNum(totalNumber); - String firsts = orderNoPackageExcelDTO.getFirsts(); - advanceEntity.setPackName(firsts); - advanceEntity.setDealerName(orderNoPackageExcelDTO.getDealerName()); - advanceEntity.setConsigneePerson(orderNoPackageExcelDTO.getConsigneePerson()); - advanceEntity.setConsigneeMobile(orderNoPackageExcelDTO.getConsigneeMobile()); - advanceEntity.setConsigneeAddress(orderNoPackageExcelDTO.getConsigneeAddress()); - advanceEntity.setCustomerName(orderNoPackageExcelDTO.getCustomerName()); - advanceEntity.setCustomerPhone(orderNoPackageExcelDTO.getCustomerPhone()); - advanceEntity.setCustomerAddress(orderNoPackageExcelDTO.getCustomerAddress()); - advanceEntity.setSystemType("线上"); - advanceEntity.setServiceNum(orderNoPackageExcelDTO.getServiceNum()); - advanceEntity.setMatingType("1"); - advanceEntity.setWaybillStatus("0"); - advanceEntity.setFreezeStatus("0"); - advanceEntity.setLegacyStatus("0"); - advanceService.save(advanceEntity); - Long advanceId = advanceEntity.getId(); + //把importOrderNoPackageExcelDTOS的每个元素提取成一个key为orderCode和trainNumber的拼接,value为元素本身的map + Map importOrderNoPackageExcelDTOMap = importOrderNoPackageExcelDTOS.parallelStream().collect(Collectors.toMap(a -> a.getOrderCode() + "&" + a.getTrainNumber(), a -> a)); - TrunklineAdvanceDetailEntity advanceDetailModel = new TrunklineAdvanceDetailEntity(); - advanceDetailModel.setWarehouseId(warehouseId); - advanceDetailModel.setWarehouseName(warehouseName); - advanceDetailModel.setAdvanceId(advanceId); - advanceDetailModel.setOrderCode(orderCode); - advanceDetailModel.setBrand(orderNoPackageExcelDTO.getBrand()); - advanceDetailModel.setSystemType("线上"); - - advanceDetailModel.setFirstPackName(firsts); - String sencods = orderNoPackageExcelDTO.getSencods(); - if (StringUtil.isBlank(sencods)) { - advanceDetailModel.setSecondPackName(firsts); - } else { - advanceDetailModel.setSecondPackName(sencods); + importOrderNoPackageExcelDTOMap.remove("null&null"); + + List detailEntities = new ArrayList<>(); + + //把orderCodes转成List + List orderCodeList = new ArrayList<>(orderCodes); + //把orderCodeList分成每2000个元素一组 + int batchSize = 2000; + List> orderedGroups = new ArrayList<>(); + + for (int i = 0; i < orderCodeList.size(); i += batchSize) { + int endIndex = Math.min(i + batchSize, orderCodeList.size()); + orderedGroups.add(orderCodeList.subList(i, endIndex)); + } + for (int i = 0; i < orderedGroups.size(); i++) { + List set1 = orderedGroups.get(i); + List entities = advanceService.findListByExistsAndOrderCodeSet(set1); + detailEntities.addAll(entities); + } + + Map advanceEntityMap = new HashMap<>(); + + //把detailEntities转化成以orderCode和trainNumber为key的map + detailEntities.forEach(advanceEntity -> { + String orderCode = advanceEntity.getOrderCode(); + String trainNumber = advanceEntity.getTrainNumber(); + String key = orderCode + "&" + (StringUtil.isBlank(trainNumber)?"null":trainNumber); + advanceEntityMap.put(key,advanceEntity); + }); + + List list = new ArrayList<>(); + importOrderNoPackageExcelDTOMap.keySet().forEach(key -> { + ImportOrderNoPackageExcelDTO importOrderNoPackageExcelDTO = importOrderNoPackageExcelDTOMap.get(key); + TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(key); + if(Objects.isNull(advanceEntity)){ + String orderCode = importOrderNoPackageExcelDTO.getOrderCode(); + advanceEntity = new TrunklineAdvanceVO(); + advanceEntity.setWarehouseId(warehouseId); + advanceEntity.setWarehouseName(warehouseName); + advanceEntity.setServiceNum(importOrderNoPackageExcelDTO.getServiceNum()); + advanceEntity.setOrderCode(orderCode); + advanceEntity.setArea(importOrderNoPackageExcelDTO.getArea()); + advanceEntity.setBrand(importOrderNoPackageExcelDTO.getBrand()); + advanceEntity.setTotalNum(Integer.parseInt(importOrderNoPackageExcelDTO.getCount())); + advanceEntity.setPackName(importOrderNoPackageExcelDTO.getFirsts()); + advanceEntity.setDealerCode(importOrderNoPackageExcelDTO.getDealerCode()); + advanceEntity.setDealerName(importOrderNoPackageExcelDTO.getDealerName()); + advanceEntity.setCustomerName(importOrderNoPackageExcelDTO.getCustomerName()); + advanceEntity.setCustomerPhone(importOrderNoPackageExcelDTO.getCustomerPhone()); + advanceEntity.setCustomerAddress(importOrderNoPackageExcelDTO.getCustomerAddress()); + advanceEntity.setConsigneePerson(importOrderNoPackageExcelDTO.getConsigneePerson()); + advanceEntity.setConsigneeMobile(importOrderNoPackageExcelDTO.getConsigneeMobile()); + advanceEntity.setConsigneeAddress(importOrderNoPackageExcelDTO.getConsigneeAddress()); + advanceEntity.setSenderName(importOrderNoPackageExcelDTO.getShipperPerson()); + advanceEntity.setSenderPhone(importOrderNoPackageExcelDTO.getShipperMobile()); + advanceEntity.setSenderAddress(importOrderNoPackageExcelDTO.getShipperAddress()); + advanceEntity.setTrainNumber(importOrderNoPackageExcelDTO.getTrainNumber()); + advanceEntity.setSystemType("线上"); + advanceEntity.setMatingType("1"); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setFreezeStatus("0"); + advanceEntity.setLegacyStatus("0"); + if (orderCode.contains("遗")) { + advanceEntity.setLegacyStatus("1"); + } + advanceEntity.setHasPackage(1); + advanceEntity.setCreateUserName(AuthUtil.getUserName()); + list.add(advanceEntity); } - String thirds = orderNoPackageExcelDTO.getThirds(); - if (StringUtil.isBlank(thirds)) { - advanceDetailModel.setThirdPackName(firsts); - } else { - advanceDetailModel.setThirdPackName(thirds); + }); + advanceService.saveBatch(list); + + List advanceDetailEntities = new ArrayList<>(); + for (TrunklineAdvanceEntity advanceEntity : list) { + String orderCode = advanceEntity.getOrderCode(); + String trainNumber = advanceEntity.getTrainNumber(); + ImportOrderNoPackageExcelDTO importOrderNoPackageExcelDTO = importOrderNoPackageExcelDTOMap.get(orderCode + "&" + (StringUtil.isBlank(trainNumber) ? "null" : trainNumber)); + if(Objects.isNull(importOrderNoPackageExcelDTO)){ + String firsts = importOrderNoPackageExcelDTO.getFirsts(); + Integer totalNum = advanceEntity.getTotalNum(); + TrunklineAdvanceDetailEntity advanceDetailModel = new TrunklineAdvanceDetailEntity(); + advanceDetailModel.setWarehouseId(warehouseId); + advanceDetailModel.setWarehouseName(warehouseName); + advanceDetailModel.setAdvanceId(advanceEntity.getId()); + advanceDetailModel.setOrderCode(advanceEntity.getOrderCode()); + advanceDetailModel.setBrand(advanceEntity.getBrand()); + advanceDetailModel.setSystemType("线上"); + + advanceDetailModel.setFirstPackName(firsts); + String sencods = importOrderNoPackageExcelDTO.getSeconds(); + if (StringUtil.isBlank(sencods)) { + advanceDetailModel.setSecondPackName(firsts); + } else { + advanceDetailModel.setSecondPackName(sencods); + } + String thirds = importOrderNoPackageExcelDTO.getThirds(); + if (StringUtil.isBlank(thirds)) { + advanceDetailModel.setThirdPackName(firsts); + } else { + advanceDetailModel.setThirdPackName(thirds); + } + advanceDetailModel.setQuantity(1); + advanceDetailModel.setServiceNum(advanceEntity.getServiceNum()); + advanceDetailModel.setMaterialCode(importOrderNoPackageExcelDTO.getMaterialCode()); + advanceDetailModel.setMaterialName(importOrderNoPackageExcelDTO.getMaterialName()); + advanceDetailModel.setVolume(new BigDecimal(importOrderNoPackageExcelDTO.getVolume())); + advanceDetailModel.setWeight(new BigDecimal(importOrderNoPackageExcelDTO.getWeight())); + advanceDetailModel.setPackageStatus("0"); + + List orderPackageCodes = basicdataCodeClient.getBatchPackageCodeByType(warehouseCode, orderCode, totalNum); + orderPackageCodes.forEach(orderPackageCode -> { + advanceDetailModel.setOrderPackageCode(orderPackageCode); + advanceDetailEntities.add(advanceDetailModel); + }); } - advanceDetailModel.setQuantity(1); - advanceDetailModel.setServiceNum(orderNoPackageExcelDTO.getServiceNum()); - advanceDetailModel.setPackageStatus("0"); - - List detailEntities = new ArrayList<>(); - for (int i = 0; i < totalNumber; i++) { - TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); - BeanUtil.copy(advanceDetailModel, advanceDetailEntity); - advanceDetailEntity.setOrderPackageCode(basicdataCodeClient.getCodeByType(CodeNumConstant.PACKAGE, basicdataWarehouseEntity.getWarehouseCode(), orderCode)); - detailEntities.add(advanceDetailEntity); + } + + if (!advanceDetailEntities.isEmpty()) { + //把advanceDetailEntities分成相等数量的10个集合 + List> advanceDetailEntitiesList = advanceDetailEntities.stream().collect(Collectors.groupingBy(item -> advanceDetailEntities.indexOf(item) / 1000)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); + List comlist = new ArrayList<>(); + for (int i = 0; i < advanceDetailEntitiesList.size(); i++) { + List ls = advanceDetailEntitiesList.get(i); + CompletableFuture fromCpFirstReq = asyncService.getResponseFromCp(ls, i+1); + comlist.add(fromCpFirstReq); } - advanceDetailService.saveBatch(detailEntities); + CompletableFuture.allOf(comlist.toArray(new CompletableFuture[0])).join(); } + return R.success("添加成功"); } @@ -1757,49 +2022,93 @@ public class OpenOrderServiceImpl implements IOpenOrderService { return R.data(map); } + @Transactional(rollbackFor = Exception.class) @Override - public R> importOrderNoPackage(Long warehouseId, String warehouseName, MultipartFile file) throws IOException { + public R> importOrderNoPackage(Long warehouseId, String warehouseName, String warehouseCode, MultipartFile file) throws IOException { if (Objects.isNull(file)) { log.warn("##################importOrderNoPackage: 文件不存在"); return R.fail(405, "文件不存在"); } InputStream inputStream = file.getInputStream(); - List importOrderNoPackageExcelDTOS = EasyExcel.read(inputStream).head(ImportOrderNoPackageExcelDTO.class).sheet(0).headRowNumber(1).doReadSync(); + List importOrderNoPackageExcelDTOS = EasyExcel.read(inputStream).head(ImportOrderNoPackageExcelDTO.class).sheet(0).headRowNumber(2).doReadSync(); + + //把importOrderNoPackageExcelDTOS中的orderCode存入一个set集合 + Set orderCodes = importOrderNoPackageExcelDTOS.parallelStream().map(ImportOrderNoPackageExcelDTO::getOrderCode).collect(Collectors.toSet()); + + //把importOrderNoPackageExcelDTOS的每个元素提取成一个key为orderCode和trainNumber的拼接,value为元素本身的map + Map importOrderNoPackageExcelDTOMap = importOrderNoPackageExcelDTOS.parallelStream().collect(Collectors.toMap(a -> a.getOrderCode() + "&" + a.getTrainNumber(), a -> a)); + + importOrderNoPackageExcelDTOMap.remove("null&null"); + + List detailEntities = new ArrayList<>(); + + //把orderCodes转成List + List orderCodeList = new ArrayList<>(orderCodes); + //把orderCodeList分成每2000个元素一组 + int batchSize = 2000; + List> orderedGroups = new ArrayList<>(); + + for (int i = 0; i < orderCodeList.size(); i += batchSize) { + int endIndex = Math.min(i + batchSize, orderCodeList.size()); + orderedGroups.add(orderCodeList.subList(i, endIndex)); + } + for (int i = 0; i < orderedGroups.size(); i++) { + List set1 = orderedGroups.get(i); + List entities = advanceService.findListByExistsAndOrderCodeSet(set1); + detailEntities.addAll(entities); + } + + Map advanceEntityMap = new HashMap<>(); + + //把detailEntities转化成以orderCode和trainNumber为key的map + detailEntities.forEach(advanceEntity -> { + String orderCode = advanceEntity.getOrderCode(); + String trainNumber = advanceEntity.getTrainNumber(); + String key = orderCode + "&" + (StringUtil.isBlank(trainNumber)?"null":trainNumber); + advanceEntityMap.put(key,advanceEntity); + }); + List list = new ArrayList<>(); - for (ImportOrderNoPackageExcelDTO importOrderNoPackageExcelDTO : importOrderNoPackageExcelDTOS) { - String orderCode = importOrderNoPackageExcelDTO.getOrderCode(); - String trainNumber = importOrderNoPackageExcelDTO.getTrainNumber(); - TrunklineAdvanceEntity trunklineAdvanceEntity = advanceService.findEntityByOrderCodeAndTrainNumber(orderCode, trainNumber); - if (Objects.isNull(trunklineAdvanceEntity)) { - trunklineAdvanceEntity = new TrunklineAdvanceVO(); - trunklineAdvanceEntity.setWarehouseId(warehouseId); - trunklineAdvanceEntity.setWarehouseName(warehouseName); - trunklineAdvanceEntity.setOrderCode(orderCode); - trunklineAdvanceEntity.setBrand(importOrderNoPackageExcelDTO.getBrand()); - trunklineAdvanceEntity.setTotalNum(Integer.parseInt(importOrderNoPackageExcelDTO.getNum())); - trunklineAdvanceEntity.setDealerName(importOrderNoPackageExcelDTO.getDealerName()); - trunklineAdvanceEntity.setCustomerName(importOrderNoPackageExcelDTO.getCustomerName()); - trunklineAdvanceEntity.setCustomerPhone(importOrderNoPackageExcelDTO.getCustomerPhone()); - trunklineAdvanceEntity.setCustomerAddress(importOrderNoPackageExcelDTO.getCustomerAddress()); - trunklineAdvanceEntity.setConsigneePerson(importOrderNoPackageExcelDTO.getConsigneePerson()); - trunklineAdvanceEntity.setConsigneeMobile(importOrderNoPackageExcelDTO.getConsigneeMobile()); - trunklineAdvanceEntity.setConsigneeAddress(importOrderNoPackageExcelDTO.getConsigneeAddress()); - trunklineAdvanceEntity.setServiceNum(importOrderNoPackageExcelDTO.getServiceNum()); - trunklineAdvanceEntity.setSystemType("线上"); - trunklineAdvanceEntity.setMatingType("1"); - trunklineAdvanceEntity.setWaybillStatus("0"); - trunklineAdvanceEntity.setTrainNumber(importOrderNoPackageExcelDTO.getTrainNumber()); - trunklineAdvanceEntity.setFreezeStatus("0"); - trunklineAdvanceEntity.setLegacyStatus("0"); + importOrderNoPackageExcelDTOMap.keySet().forEach(key -> { + ImportOrderNoPackageExcelDTO importOrderNoPackageExcelDTO = importOrderNoPackageExcelDTOMap.get(key); + TrunklineAdvanceEntity advanceEntity = advanceEntityMap.get(key); + if(Objects.isNull(advanceEntity)){ + String orderCode = importOrderNoPackageExcelDTO.getOrderCode(); + advanceEntity = new TrunklineAdvanceVO(); + advanceEntity.setWarehouseId(warehouseId); + advanceEntity.setWarehouseName(warehouseName); + advanceEntity.setServiceNum(importOrderNoPackageExcelDTO.getServiceNum()); + advanceEntity.setOrderCode(orderCode); + advanceEntity.setArea(importOrderNoPackageExcelDTO.getArea()); + advanceEntity.setBrand(importOrderNoPackageExcelDTO.getBrand()); + advanceEntity.setTotalNum(Integer.parseInt(importOrderNoPackageExcelDTO.getCount())); + advanceEntity.setPackName(importOrderNoPackageExcelDTO.getFirsts()); + advanceEntity.setDealerCode(importOrderNoPackageExcelDTO.getDealerCode()); + advanceEntity.setDealerName(importOrderNoPackageExcelDTO.getDealerName()); + advanceEntity.setCustomerName(importOrderNoPackageExcelDTO.getCustomerName()); + advanceEntity.setCustomerPhone(importOrderNoPackageExcelDTO.getCustomerPhone()); + advanceEntity.setCustomerAddress(importOrderNoPackageExcelDTO.getCustomerAddress()); + advanceEntity.setConsigneePerson(importOrderNoPackageExcelDTO.getConsigneePerson()); + advanceEntity.setConsigneeMobile(importOrderNoPackageExcelDTO.getConsigneeMobile()); + advanceEntity.setConsigneeAddress(importOrderNoPackageExcelDTO.getConsigneeAddress()); + advanceEntity.setSenderName(importOrderNoPackageExcelDTO.getShipperPerson()); + advanceEntity.setSenderPhone(importOrderNoPackageExcelDTO.getShipperMobile()); + advanceEntity.setSenderAddress(importOrderNoPackageExcelDTO.getShipperAddress()); + advanceEntity.setTrainNumber(importOrderNoPackageExcelDTO.getTrainNumber()); + advanceEntity.setSystemType("线上"); + advanceEntity.setMatingType("1"); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setFreezeStatus("0"); + advanceEntity.setLegacyStatus("0"); if (orderCode.contains("遗")) { - trunklineAdvanceEntity.setLegacyStatus("1"); + advanceEntity.setLegacyStatus("1"); } - trunklineAdvanceEntity.setHasPackage(0); - trunklineAdvanceEntity.setCreateUserName(AuthUtil.getUserName()); - list.add(trunklineAdvanceEntity); + advanceEntity.setHasPackage(0); + advanceEntity.setCreateUserName(AuthUtil.getUserName()); + list.add(advanceEntity); } - } + }); advanceService.saveBatch(list); return R.data(list); diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceServiceImpl.java index 717a07dfd..bbbc7f08a 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceServiceImpl.java @@ -631,7 +631,7 @@ public class TrunklineAdvanceServiceImpl extends BaseServiceImpl findListByExistsAndOrderCodeSet(Set orderCodeSet) { + public List findListByExistsAndOrderCodeSet(List orderCodeSet) { return baseMapper.findListByExistsAndOrderCodeSet(orderCodeSet); }