@ -52,6 +52,7 @@ import java.io.IOException;
import java.io.InputStream ;
import java.math.BigDecimal ;
import java.util.* ;
import java.util.concurrent.CompletableFuture ;
import java.util.stream.Collectors ;
@Slf4j
@ -89,6 +90,7 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
private final IBasicdataOpenIncomingClient basicdataOpenIncomingClient ;
private final ITrunklineCarsLoadService carsLoadService ;
private final IBasicdataStoreContactClient basicdataStoreContactClient ;
private final IAsyncService asyncService ;
@Override
public IPage < TrunklineAdvanceVO > advancePageList ( AdvanceDTO advanceDTO ) {
@ -1027,27 +1029,50 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
listMap . remove ( "null&null" ) ;
//把pacakgeDetailExcelDTOS中的orderCode存入一个set集合
Set < String > orderCodeSet = pacakgeDetailExcelDTOS . parallelStream ( ) . map ( PacakgeDetailExcelDTO : : getOrderCode ) . collect ( Collectors . toSet ( ) ) ;
Set < String > set = listMap . keySet ( ) ;
List < TrunklineAdvanceDetailEntity > advanceDetailEntities = new ArrayList < > ( ) ;
List < TrunklineAdvanceEntity > advanceEntityList = new ArrayList < > ( ) ;
for ( String str : set ) {
List < PacakgeDetailExcelDTO > detailExcelDTOS = listMap . get ( str ) ;
PacakgeDetailExcelDTO pacakgeDetailExcelDTO = detailExcelDTOS . get ( 0 ) ;
Map < String , TrunklineAdvanceEntity > advanceEntityMap = new HashMap < > ( ) ;
List < Long > advanceIds = new ArrayList < > ( ) ;
List < TrunklineAdvanceEntity > detailEntities = advanceService . findListByExistsAndOrderCodeSet ( orderCodeSet ) ;
//把detailEntities转化成以orderCode和trainNumber为key的map
detailEntities . forEach ( advanceEntity - > {
String orderCode = advanceEntity . getOrderCode ( ) ;
String trainNumber = advanceEntity . getTrainNumber ( ) ;
String key = orderCode + "&" + trainNumber ;
advanceEntityMap . put ( key , advanceEntity ) ;
} ) ;
Map < String , List < TrunklineAdvanceEntity > > 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 ] ;
List < String > orderPackageCodes = new ArrayList < > ( ) ;
TrunklineAdvanceEntity advanceEntity = advanceService . findEntityByOrderCodeAndTrainNumber ( orderCode , trainNumber ) ;
if ( "null" . equals ( trainNumber ) ) {
trainNumber = null ;
}
List < PacakgeDetailExcelDTO > excelDTOS = listMap . get ( str ) ;
PacakgeDetailExcelDTO pacakgeDetailExcelDTO = excelDTOS . get ( 0 ) ;
TrunklineAdvanceEntity advanceEntity = advanceEntityMap . get ( str ) ;
if ( Objects . isNull ( advanceEntity ) ) {
advanceEntity = new TrunklineAdvanceEntity ( ) ;
advanceEntity . setWarehouseId ( warehouseId ) ;
advanceEntity . setWarehouseName ( warehouseName ) ;
advanceEntity . setOrderCode ( orderCode ) ;
advanceEntity . setArea ( pacakgeDetailExcelDTO . getArea ( ) ) ;
advanceEntity . setOrderType ( "Label" ) ;
advanceEntity . setBrand ( pacakgeDetailExcelDTO . getBrand ( ) ) ;
advanceEntity . setTotalNum ( detailExcelDTOS . size ( ) ) ;
advanceEntity . setTotalNum ( excelDTOS . size ( ) ) ;
String firsts = pacakgeDetailExcelDTO . getFirsts ( ) ;
advanceEntity . setPackName ( firsts ) ;
advanceEntity . setDealerCode ( pacakgeDetailExcelDTO . getDealerCode ( ) ) ;
@ -1076,81 +1101,132 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
advanceEntity . setFreezeStatus ( "0" ) ;
advanceEntity . setLegacyStatus ( "0" ) ;
advanceEntity . setCreateUserName ( AuthUtil . getNickName ( ) ) ;
advanceService . save ( advanceEntity ) ;
advanceEntityList . add ( advanceEntity ) ;
} else {
Long advanceId = advanceEntity . getId ( ) ;
orderPackageCodes = advanceDetailService . findOrderPackageCodesByAdvanceId ( advanceId ) ;
advanceIds . add ( advanceEntity . getId ( ) ) ;
advanceEntityMap . put ( advanceEntity . getOrderCode ( ) + "&" + advanceEntity . getTrainNumber ( ) , advanceEntity ) ;
}
} ) ;
for ( PacakgeDetailExcelDTO detailExcelDTO : detailExcelDTOS ) {
String orderPackageCode = detailExcelDTO . getOrderPackageCode ( ) ;
if ( orderPackageCodes . contains ( orderPackageCode ) ) {
continue ;
}
TrunklineAdvanceDetailEntity advanceDetailModel = new TrunklineAdvanceDetailEntity ( ) ;
advanceDetailModel = new TrunklineAdvanceDetailEntity ( ) ;
advanceDetailModel . setWarehouseId ( warehouseId ) ;
advanceDetailModel . setWarehouseName ( warehouseName ) ;
advanceDetailModel . setAdvanceId ( advanceEntity . getId ( ) ) ;
advanceDetailModel . setOrderCode ( orderCode ) ;
advanceDetailModel . setOrderPackageCode ( orderPackageCode ) ;
advanceDetailModel . setBrand ( detailExcelDTO . getBrand ( ) ) ;
advanceDetailModel . setSystemType ( "线上" ) ;
String firsts = detailExcelDTO . getFirsts ( ) ;
advanceDetailModel . setFirstPackName ( firsts ) ;
String sencods = detailExcelDTO . getSencods ( ) ;
if ( StringUtil . isBlank ( sencods ) ) {
advanceDetailModel . setSecondPackName ( firsts ) ;
} else {
advanceDetailModel . setSecondPackName ( sencods ) ;
}
String thirds = detailExcelDTO . getThirds ( ) ;
if ( StringUtil . isBlank ( thirds ) ) {
advanceDetailModel . setThirdPackName ( firsts ) ;
} else {
advanceDetailModel . setThirdPackName ( thirds ) ;
}
advanceDetailModel . setQuantity ( 1 ) ;
advanceDetailModel . setServiceNum ( detailExcelDTO . getServiceNum ( ) ) ;
advanceDetailModel . setPackageStatus ( "0" ) ;
if ( ! Objects . isNull ( detailExcelDTO . getVolume ( ) ) ) {
advanceDetailModel . setVolume ( new BigDecimal ( detailExcelDTO . getVolume ( ) ) ) ;
}
advanceService . saveBatch ( advanceEntityList ) ;
String materialName = detailExcelDTO . getMaterialName ( ) ;
String materialCode = detailExcelDTO . getMaterialCode ( ) ;
advanceEntityList . forEach ( advanceEntity - > {
advanceIds . add ( advanceEntity . getId ( ) ) ;
advanceEntityMap . put ( advanceEntity . getOrderCode ( ) + "&" + advanceEntity . getTrainNumber ( ) , advanceEntity ) ;
} ) ;
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 ( "1件/箱" ) ;
basicMaterialEntity . setLogpmUnit ( "箱" ) ;
basicMaterialEntity . setSku ( materialCode ) ;
basicMaterialEntity . setPackageNum ( "1" ) ;
basicMaterialEntity . setHide ( 1 ) ;
Long aLong = basicMaterialClient . addMaterial ( basicMaterialEntity ) ;
basicMaterialEntity . setId ( aLong ) ;
//通过advanceIds查询所有advanceDetail
QueryWrapper < TrunklineAdvanceDetailEntity > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . in ( "advance_id" , advanceIds )
. eq ( "is_deleted" , 0 ) ;
List < TrunklineAdvanceDetailEntity > advanceDetailEntityList = advanceDetailService . list ( queryWrapper ) ;
//把advanceDetailEntityList通过advanceId分组并且把集合转化为orderPackageCode的集合
Map < Long , List < String > > map = advanceDetailEntityList . parallelStream ( ) . collect ( Collectors . groupingBy ( TrunklineAdvanceDetailEntity : : getAdvanceId , Collectors . mapping ( TrunklineAdvanceDetailEntity : : getOrderPackageCode , Collectors . toList ( ) ) ) ) ;
Map < String , Long > materialMap = new HashMap < > ( ) ;
listMap . keySet ( ) . forEach ( str - > {
List < PacakgeDetailExcelDTO > 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 ( ) ;
List < String > orderPackageCodes = map . get ( advanceId ) ;
pacakgeDetailExcelList . forEach ( pacakgeDetailExcelDTO - > {
String orderPackageCode = pacakgeDetailExcelDTO . 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 ( pacakgeDetailExcelDTO . getBrand ( ) ) ;
advanceDetailModel . setSystemType ( "线上" ) ;
String firsts = pacakgeDetailExcelDTO . getFirsts ( ) ;
advanceDetailModel . setFirstPackName ( firsts ) ;
String sencods = pacakgeDetailExcelDTO . getSencods ( ) ;
if ( StringUtil . isBlank ( sencods ) ) {
advanceDetailModel . setSecondPackName ( firsts ) ;
} else {
advanceDetailModel . setSecondPackName ( sencods ) ;
}
String thirds = pacakgeDetailExcelDTO . getThirds ( ) ;
if ( StringUtil . isBlank ( thirds ) ) {
advanceDetailModel . setThirdPackName ( firsts ) ;
} else {
advanceDetailModel . setThirdPackName ( thirds ) ;
}
advanceDetailModel . setQuantity ( 1 ) ;
advanceDetailModel . setServiceNum ( pacakgeDetailExcelDTO . getServiceNum ( ) ) ;
advanceDetailModel . setPackageStatus ( "0" ) ;
if ( ! Objects . isNull ( pacakgeDetailExcelDTO . getVolume ( ) ) ) {
advanceDetailModel . setVolume ( new BigDecimal ( pacakgeDetailExcelDTO . getVolume ( ) ) ) ;
}
String materialName = pacakgeDetailExcelDTO . getMaterialName ( ) ;
String materialCode = pacakgeDetailExcelDTO . 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 ( pacakgeDetailExcelDTO . getBrand ( ) ) ;
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 ) ;
} ) ;
}
} ) ;
if ( ! advanceDetailEntities . isEmpty ( ) ) {
//把advanceDetailEntities分成相等数量的10个集合
List < List < TrunklineAdvanceDetailEntity > > advanceDetailEntitiesList = advanceDetailEntities . stream ( ) . collect ( Collectors . groupingBy ( item - > advanceDetailEntities . indexOf ( item ) / 1000 ) ) . entrySet ( ) . stream ( ) . map ( Map . Entry : : getValue ) . collect ( Collectors . toList ( ) ) ;
List < CompletableFuture > comlist = new ArrayList < > ( ) ;
for ( int i = 0 ; i < advanceDetailEntitiesList . size ( ) ; i + + ) {
List < TrunklineAdvanceDetailEntity > list = advanceDetailEntitiesList . get ( i ) ;
CompletableFuture < Boolean > 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 != advanceEntity.getTotalNum()){
// advanceService.updateTotalNumById(advanceEntity.getId(),all);
// }
}
advanceDetailService . saveBatch ( advanceDetailEntities ) ;
return R . data ( advanceEntityList ) ;
}