@ -815,249 +815,255 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
Long waybillId = warehouseWaybillClient . addEnntity ( waybillEntity ) ;
waybillEntity . setId ( waybillId ) ;
List < WarehouseWayBillDetail > details = new ArrayList < > ( ) ;
if ( ! Objects . isNull ( waybillId ) ) {
log . info ( "#################openWaybill: 运单保存成功" ) ;
//保存运单货物明细
List < WaybillDetailDTO > waybillDetailList = openOrderDTO . getWaybillDetailList ( ) ;
for ( WaybillDetailDTO waybillDetailDTO : waybillDetailList ) {
WarehouseWayBillDetail warehouseWayBillDetail = new WarehouseWayBillDetail ( ) ;
warehouseWayBillDetail . setWaybillId ( waybillId ) ;
warehouseWayBillDetail . setWaybillNo ( waybillEntity . getWaybillNo ( ) ) ;
Long goodsId = waybillDetailDTO . getGoodsId ( ) ;
String goodsName = waybillDetailDTO . getGoodsName ( ) ;
// if (Objects.isNull(goodsId)) {
// //如果品名id没有就先通过goodsName查寻,没有就新增
// BasicdataCategoryEntity basicdataCategoryEntity = basicdataCategoryClient.findByName(goodsName);
// if (Objects.isNull(basicdataCategoryEntity)) {
// basicdataCategoryEntity = new BasicdataCategoryEntity();
// basicdataCategoryEntity.setName(goodsName);
// basicdataCategoryEntity.setType(1);
// goodsId = basicdataCategoryClient.addReturnId(basicdataCategoryEntity);
// } else {
// goodsId = basicdataCategoryEntity.getId();
try {
List < WarehouseWayBillDetail > details = new ArrayList < > ( ) ;
if ( ! Objects . isNull ( waybillId ) ) {
log . info ( "#################openWaybill: 运单保存成功" ) ;
//保存运单货物明细
List < WaybillDetailDTO > waybillDetailList = openOrderDTO . getWaybillDetailList ( ) ;
for ( WaybillDetailDTO waybillDetailDTO : waybillDetailList ) {
WarehouseWayBillDetail warehouseWayBillDetail = new WarehouseWayBillDetail ( ) ;
warehouseWayBillDetail . setWaybillId ( waybillId ) ;
warehouseWayBillDetail . setWaybillNo ( waybillEntity . getWaybillNo ( ) ) ;
Long goodsId = waybillDetailDTO . getGoodsId ( ) ;
String goodsName = waybillDetailDTO . getGoodsName ( ) ;
// if (Objects.isNull(goodsId)) {
// //如果品名id没有就先通过goodsName查寻,没有就新增
// BasicdataCategoryEntity basicdataCategoryEntity = basicdataCategoryClient.findByName(goodsName);
// if (Objects.isNull(basicdataCategoryEntity)) {
// basicdataCategoryEntity = new BasicdataCategoryEntity();
// basicdataCategoryEntity.setName(goodsName);
// basicdataCategoryEntity.setType(1);
// goodsId = basicdataCategoryClient.addReturnId(basicdataCategoryEntity);
// } else {
// goodsId = basicdataCategoryEntity.getId();
// }
// }
// }
warehouseWayBillDetail . setCreateUser ( AuthUtil . getUserId ( ) ) ;
warehouseWayBillDetail . setUpdateUser ( AuthUtil . getUserId ( ) ) ;
Date date = new Date ( ) ;
warehouseWayBillDetail . setCreateTime ( date ) ;
warehouseWayBillDetail . setUpdateTime ( date ) ;
warehouseWayBillDetail . setStatus ( 1 ) ;
warehouseWayBillDetail . setIsDeleted ( 0 ) ;
warehouseWayBillDetail . setProductId ( goodsId ) ;
warehouseWayBillDetail . setProductName ( goodsName ) ;
Integer num = waybillDetailDTO . getNum ( ) ;
BigDecimal volume = waybillDetailDTO . getVolume ( ) ;
BigDecimal weight = waybillDetailDTO . getWeight ( ) ;
warehouseWayBillDetail . setNum ( num ) ;
warehouseWayBillDetail . setVolume ( volume ) ;
warehouseWayBillDetail . setWeight ( weight ) ;
BigDecimal price = waybillDetailDTO . getPrice ( ) ;
Integer chargeType = waybillDetailDTO . getChargeType ( ) ;
BigDecimal subtotalFreight = waybillDetailDTO . getSubtotalFreight ( ) ;
if ( price . compareTo ( BigDecimal . ZERO ) = = 0 ) {
warehouseWayBillDetail . setCreateUser ( AuthUtil . getUserId ( ) ) ;
warehouseWayBillDetail . setUpdateUser ( AuthUtil . getUserId ( ) ) ;
Date date = new Date ( ) ;
warehouseWayBillDetail . setCreateTime ( date ) ;
warehouseWayBillDetail . setUpdateTime ( date ) ;
warehouseWayBillDetail . setStatus ( 1 ) ;
warehouseWayBillDetail . setIsDeleted ( 0 ) ;
warehouseWayBillDetail . setProductId ( goodsId ) ;
warehouseWayBillDetail . setProductName ( goodsName ) ;
Integer num = waybillDetailDTO . getNum ( ) ;
BigDecimal volume = waybillDetailDTO . getVolume ( ) ;
BigDecimal weight = waybillDetailDTO . getWeight ( ) ;
warehouseWayBillDetail . setNum ( num ) ;
warehouseWayBillDetail . setVolume ( volume ) ;
warehouseWayBillDetail . setWeight ( weight ) ;
BigDecimal price = waybillDetailDTO . getPrice ( ) ;
Integer chargeType = waybillDetailDTO . getChargeType ( ) ;
BigDecimal subtotalFreight = waybillDetailDTO . getSubtotalFreight ( ) ;
if ( price . compareTo ( BigDecimal . ZERO ) = = 0 ) {
if ( chargeType . equals ( 1 ) ) {
price = subtotalFreight . divide ( new BigDecimal ( num ) , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 2 ) ) {
price = subtotalFreight . divide ( volume , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 3 ) ) {
price = subtotalFreight . divide ( weight , 6 , RoundingMode . HALF_UP ) ;
}
if ( chargeType . equals ( 1 ) ) {
price = subtotalFreight . divide ( new BigDecimal ( num ) , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 2 ) ) {
price = subtotalFreight . divide ( volume , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 3 ) ) {
price = subtotalFreight . divide ( weight , 6 , RoundingMode . HALF_UP ) ;
}
warehouseWayBillDetail . setPrice ( price ) ;
warehouseWayBillDetail . setSubtotalFreight ( subtotalFreight ) ;
warehouseWayBillDetail . setChargeType ( chargeType ) ;
warehouseWayBillDetail . setDeliveryPrice ( waybillDetailDTO . getDeliveryPrice ( ) ) ;
warehouseWayBillDetail . setSubtotalDeliveryFee ( waybillDetailDTO . getSubtotalDeliveryFee ( ) ) ;
warehouseWayBillDetail . setPickupPrice ( waybillDetailDTO . getPickupPrice ( ) ) ;
warehouseWayBillDetail . setFreightPrice ( waybillDetailDTO . getFreightPrice ( ) ) ;
warehouseWayBillDetail . setSystemChargeType ( waybillDetailDTO . getSystemChargeType ( ) ) ;
warehouseWayBillDetail . setSystemDeliveryChargeType ( waybillDetailDTO . getSystemDeliveryChargeType ( ) ) ;
warehouseWayBillDetail . setSystemPickupChargeType ( waybillDetailDTO . getSystemPickupChargeType ( ) ) ;
warehouseWayBillDetail . setSystemWarehouseChargeType ( waybillDetailDTO . getSystemWarehouseChargeType ( ) ) ;
details . add ( warehouseWayBillDetail ) ;
}
warehouseWayBillDetail . setPrice ( price ) ;
warehouseWayBillDetail . setSubtotalFreight ( subtotalFreight ) ;
warehouseWayBillDetail . setChargeType ( chargeType ) ;
warehouseWayBillDetail . setDeliveryPrice ( waybillDetailDTO . getDeliveryPrice ( ) ) ;
warehouseWayBillDetail . setSubtotalDeliveryFee ( waybillDetailDTO . getSubtotalDeliveryFee ( ) ) ;
warehouseWayBillDetail . setPickupPrice ( waybillDetailDTO . getPickupPrice ( ) ) ;
warehouseWayBillDetail . setFreightPrice ( waybillDetailDTO . getFreightPrice ( ) ) ;
warehouseWayBillDetail . setSystemChargeType ( waybillDetailDTO . getSystemChargeType ( ) ) ;
warehouseWayBillDetail . setSystemDeliveryChargeType ( waybillDetailDTO . getSystemDeliveryChargeType ( ) ) ;
warehouseWayBillDetail . setSystemPickupChargeType ( waybillDetailDTO . getSystemPickupChargeType ( ) ) ;
warehouseWayBillDetail . setSystemWarehouseChargeType ( waybillDetailDTO . getSystemWarehouseChargeType ( ) ) ;
details . add ( warehouseWayBillDetail ) ;
warehouseWaybillDetailClient . addList ( details ) ;
} else {
log . info ( "#################openWaybill: 运单保存失败" ) ;
throw new CustomerException ( 405 , "运单保存失败" ) ;
}
warehouseWaybillDetailClient . addList ( details ) ;
} else {
log . info ( "#################openWaybill: 运单保存失败" ) ;
throw new CustomerException ( 405 , "运单保存失败" ) ;
}
//绑定订单和运单的关系
List < TrunklineAdvanceEntity > advanceEntityList = advanceService . findListByIds ( advanceIds ) ;
List < TrunklineWaybillOrderEntity > waybillOrderEntities = new ArrayList < > ( ) ;
List < TrunklineAdvanceEntity > updateAdvanceEntityList = new ArrayList < > ( ) ;
Set < String > orderCodeSet = new HashSet < > ( ) ;
for ( TrunklineAdvanceEntity advanceEntity : advanceEntityList ) {
orderCodeSet . add ( advanceEntity . getOrderCode ( ) ) ;
Long advanceId = advanceEntity . getId ( ) ;
String waybillStatus = advanceEntity . getWaybillStatus ( ) ;
if ( "1" . equals ( waybillStatus ) ) {
log . error ( "###############openWaybill: 已存在已开单的暂存单" ) ;
throw new CustomerException ( 405 , "已存在已开单的暂存单" ) ;
//绑定订单和运单的关系
List < TrunklineAdvanceEntity > advanceEntityList = advanceService . findListByIds ( advanceIds ) ;
List < TrunklineWaybillOrderEntity > waybillOrderEntities = new ArrayList < > ( ) ;
List < TrunklineAdvanceEntity > updateAdvanceEntityList = new ArrayList < > ( ) ;
Set < String > orderCodeSet = new HashSet < > ( ) ;
for ( TrunklineAdvanceEntity advanceEntity : advanceEntityList ) {
orderCodeSet . add ( advanceEntity . getOrderCode ( ) ) ;
Long advanceId = advanceEntity . getId ( ) ;
String waybillStatus = advanceEntity . getWaybillStatus ( ) ;
if ( "1" . equals ( waybillStatus ) ) {
log . error ( "###############openWaybill: 已存在已开单的暂存单" ) ;
throw new CustomerException ( 405 , "已存在已开单的暂存单" ) ;
}
TrunklineWaybillOrderEntity waybillOrderEntity = new TrunklineWaybillOrderEntity ( ) ;
waybillOrderEntity . setWarehouseId ( warehouseId ) ;
waybillOrderEntity . setWarehouseName ( basicdataWarehouseEntity . getName ( ) ) ;
waybillOrderEntity . setWaybillId ( waybillId ) ;
waybillOrderEntity . setWaybillNo ( waybillNo ) ;
waybillOrderEntity . setAdvanceId ( advanceId ) ;
waybillOrderEntity . setOrderCode ( advanceEntity . getOrderCode ( ) ) ;
waybillOrderEntity . setTotalNumber ( advanceEntity . getTotalNum ( ) ) ;
Integer incomingNum = advanceDetailService . getIncomingNum ( advanceId ) ;
waybillOrderEntity . setHandleNumber ( incomingNum ) ;
waybillOrderEntities . add ( waybillOrderEntity ) ;
// orderCodes.add(advanceEntity.getOrderCode());
TrunklineAdvanceEntity updateAdvanceEntity = new TrunklineAdvanceEntity ( ) ;
updateAdvanceEntity . setId ( advanceId ) ;
updateAdvanceEntity . setWaybillStatus ( "1" ) ;
updateAdvanceEntity . setWaybillNo ( waybillNo ) ;
updateAdvanceEntityList . add ( updateAdvanceEntity ) ;
}
TrunklineWaybillOrderEntity waybillOrderEntity = new TrunklineWaybillOrderEntity ( ) ;
waybillOrderEntity . setWarehouseId ( warehouseId ) ;
waybillOrderEntity . setWarehouseName ( basicdataWarehouseEntity . getName ( ) ) ;
waybillOrderEntity . setWaybillId ( waybillId ) ;
waybillOrderEntity . setWaybillNo ( waybillNo ) ;
waybillOrderEntity . setAdvanceId ( advanceId ) ;
waybillOrderEntity . setOrderCode ( advanceEntity . getOrderCode ( ) ) ;
waybillOrderEntity . setTotalNumber ( advanceEntity . getTotalNum ( ) ) ;
Integer incomingNum = advanceDetailService . getIncomingNum ( advanceId ) ;
waybillOrderEntity . setHandleNumber ( incomingNum ) ;
waybillOrderEntities . add ( waybillOrderEntity ) ;
trunklineWaybillOrderService . saveBatch ( waybillOrderEntities ) ;
//修改暂存单的状态为已开单
advanceService . updateBatchById ( updateAdvanceEntityList ) ;
// orderCodes.add(advanceEntity.getOrderCode());
//更新暂存单包件的运单信息
TrunklineAdvanceEntity updateAdvanceEntity = new TrunklineAdvanceEntity ( ) ;
updateAdvanceEntity . setId ( advanceId ) ;
updateAdvanceEntity . setWaybillStatus ( "1" ) ;
updateAdvanceEntity . setWaybillNo ( waybillNo ) ;
updateAdvanceEntityList . add ( updateAdvanceEntity ) ;
}
trunklineWaybillOrderService . saveBatch ( waybillOrderEntities ) ;
//修改暂存单的状态为已开单
advanceService . updateBatchById ( updateAdvanceEntityList ) ;
//更新暂存单包件的运单信息
List < TrunklineAdvanceDetailVO > list = advanceDetailService . findListByAdvanceIds ( advanceIds ) ;
trunklineWaybillPackageService . saveList ( list , waybillEntity ) ;
List < TrunklineAdvanceDetailVO > list = advanceDetailService . findListByAdvanceIds ( advanceIds ) ;
trunklineWaybillPackageService . saveList ( list , waybillEntity ) ;
List < TrunklineAdvanceDetailEntity > updateAdvanceDetailList = openOrderDTO . getUpdateAdvanceDetailList ( ) ;
List < TrunklineAdvanceDetailEntity > updateAdvanceDetailList = openOrderDTO . getUpdateAdvanceDetailList ( ) ;
//把updateAdvanceDetailList转化成以orderPackageCode为key的Map
Map < String , TrunklineAdvanceDetailEntity > advanceDetailEntityMap = updateAdvanceDetailList . stream ( ) . collect ( Collectors . toMap ( TrunklineAdvanceDetailEntity : : getOrderPackageCode , Function . identity ( ) ) ) ;
//把updateAdvanceDetailList转化成以orderPackageCode为key的Map
Map < String , TrunklineAdvanceDetailEntity > advanceDetailEntityMap = updateAdvanceDetailList . stream ( ) . collect ( Collectors . toMap ( TrunklineAdvanceDetailEntity : : getOrderPackageCode , Function . identity ( ) ) ) ;
List < String > orderPackageCodes = new ArrayList < > ( ) ;
String finalWaybillNo = waybillNo ;
List < String > orderPackageCodes = new ArrayList < > ( ) ;
String finalWaybillNo = waybillNo ;
updateAdvanceDetailList . forEach ( detail - > {
Long id = detail . getId ( ) ;
detail . setWaybillId ( waybillId ) ;
detail . setWaybillNo ( finalWaybillNo ) ;
orderPackageCodes . add ( detail . getOrderPackageCode ( ) ) ;
} ) ;
updateAdvanceDetailList . forEach ( detail - > {
Long id = detail . getId ( ) ;
detail . setWaybillId ( waybillId ) ;
detail . setWaybillNo ( finalWaybillNo ) ;
orderPackageCodes . add ( detail . getOrderPackageCode ( ) ) ;
} ) ;
if ( CollUtil . isNotEmpty ( orderPackageCodes ) ) {
if ( CollUtil . isNotEmpty ( orderPackageCodes ) ) {
//把orderPackageCodes每500条分为一组
List < List < String > > orderPackageCodeList = CollUtil . split ( orderPackageCodes , 500 ) ;
List < DistributionParcelListEntity > parcelListEntities = new ArrayList < > ( ) ;
orderPackageCodeList . forEach ( orderPackageCodeList1 - > {
log . info ( "###############openWaybill: 分组查询订单包裹信息, {}" , orderPackageCodeList1 ) ;
parcelListEntities . addAll ( distributionParcelListClient . findListByOrderPackageCodes ( orderPackageCodeList1 ) ) ;
} ) ;
//把orderPackageCodes每500条分为一组
List < List < String > > orderPackageCodeList = CollUtil . split ( orderPackageCodes , 500 ) ;
List < DistributionParcelListEntity > parcelListEntities = new ArrayList < > ( ) ;
orderPackageCodeList . forEach ( orderPackageCodeList1 - > {
log . info ( "###############openWaybill: 分组查询订单包裹信息, {}" , orderPackageCodeList1 ) ;
parcelListEntities . addAll ( distributionParcelListClient . findListByOrderPackageCodes ( orderPackageCodeList1 ) ) ;
} ) ;
String departureWarehouseName = waybillEntity . getDepartureWarehouseName ( ) ;
String destinationWarehouseName = waybillEntity . getDestinationWarehouseName ( ) ;
Long consigneeId1 = waybillEntity . getConsigneeId ( ) ;
BasicdataClientEntity basicdataClientEntity = basicdataClientClient . findEntityById ( consigneeId1 ) ;
Set < Long > stockArticleIds = new TreeSet < > ( ) ;
parcelListEntities . forEach ( parcelListEntity - > {
TrunklineAdvanceDetailEntity trunklineAdvanceDetailEntity = advanceDetailEntityMap . get ( parcelListEntity . getOrderPackageCode ( ) ) ;
if ( ! Objects . isNull ( trunklineAdvanceDetailEntity ) ) {
parcelListEntity . setWeight ( trunklineAdvanceDetailEntity . getWeight ( ) ) ;
parcelListEntity . setVolume ( trunklineAdvanceDetailEntity . getVolume ( ) ) ;
}
Long packageWarehouseId = parcelListEntity . getWarehouseId ( ) ;
parcelListEntity . setWaybillId ( waybillId ) ;
parcelListEntity . setWaybillNumber ( finalWaybillNo ) ;
parcelListEntity . setSendWarehouseId ( departureWarehouseId ) ;
parcelListEntity . setSendWarehouseName ( departureWarehouseName ) ;
parcelListEntity . setAcceptWarehouseId ( destinationWarehouseId ) ;
parcelListEntity . setAcceptWarehouseName ( destinationWarehouseName ) ;
if ( departureWarehouseId . equals ( destinationWarehouseId ) ) {
parcelListEntity . setIsTransfer ( 0 ) ;
} else {
if ( destinationWarehouseId . equals ( packageWarehouseId ) ) {
String departureWarehouseName = waybillEntity . getDepartureWarehouseName ( ) ;
String destinationWarehouseName = waybillEntity . getDestinationWarehouseName ( ) ;
Long consigneeId1 = waybillEntity . getConsigneeId ( ) ;
BasicdataClientEntity basicdataClientEntity = basicdataClientClient . findEntityById ( consigneeId1 ) ;
Set < Long > stockArticleIds = new TreeSet < > ( ) ;
parcelListEntities . forEach ( parcelListEntity - > {
TrunklineAdvanceDetailEntity trunklineAdvanceDetailEntity = advanceDetailEntityMap . get ( parcelListEntity . getOrderPackageCode ( ) ) ;
if ( ! Objects . isNull ( trunklineAdvanceDetailEntity ) ) {
parcelListEntity . setWeight ( trunklineAdvanceDetailEntity . getWeight ( ) ) ;
parcelListEntity . setVolume ( trunklineAdvanceDetailEntity . getVolume ( ) ) ;
}
Long packageWarehouseId = parcelListEntity . getWarehouseId ( ) ;
parcelListEntity . setWaybillId ( waybillId ) ;
parcelListEntity . setWaybillNumber ( finalWaybillNo ) ;
parcelListEntity . setSendWarehouseId ( departureWarehouseId ) ;
parcelListEntity . setSendWarehouseName ( departureWarehouseName ) ;
parcelListEntity . setAcceptWarehouseId ( destinationWarehouseId ) ;
parcelListEntity . setAcceptWarehouseName ( destinationWarehouseName ) ;
if ( departureWarehouseId . equals ( destinationWarehouseId ) ) {
parcelListEntity . setIsTransfer ( 0 ) ;
} else {
parcelListEntity . setIsTransfer ( 1 ) ;
}
}
stockArticleIds . add ( parcelListEntity . getStockArticleId ( ) ) ;
} ) ;
distributionParcelListClient . updateList ( parcelListEntities ) ;
//根据订单id获取每个订单的运单拼接数据
if ( ! stockArticleIds . isEmpty ( ) ) {
List < Long > newList = new ArrayList < > ( stockArticleIds ) ;
List < DistributionStockArticleEntity > stockArticleEntities = distributionStockArticleClient . findStockListByIds ( newList ) ;
// List<DistributionStockArticleEntity> stockArticleEntities = distributionStockArticleClient.findWaybillNoByOrderIds(stockArticleIds);
List < DistributionStockArticleEntity > updateStockArticleList = new ArrayList < > ( ) ;
stockArticleEntities . forEach ( stockArticleEntity - > {
String waybillNumber = stockArticleEntity . getWaybillNumber ( ) ;
DistributionStockArticleEntity updateEntity = new DistributionStockArticleEntity ( ) ;
updateEntity . setId ( stockArticleEntity . getId ( ) ) ;
if ( StringUtil . isBlank ( waybillNumber ) ) {
updateEntity . setWaybillNumber ( finalWaybillNo ) ;
} else {
if ( ! waybillNumber . contains ( finalWaybillNo ) ) {
waybillNumber = waybillNumber + "," + finalWaybillNo ;
updateEntity . setWaybillNumber ( waybillNumber ) ;
if ( destinationWarehouseId . equals ( packageWarehouseId ) ) {
parcelListEntity . setIsTransfer ( 0 ) ;
} else {
parcelListEntity . setIsTransfer ( 1 ) ;
}
}
stockArticleIds . add ( parcelListEntity . getStockArticleId ( ) ) ;
} ) ;
updateEntity . setMallId ( consigneeId1 ) ;
updateEntity . setMallCode ( basicdataClientEntity . getClientCode ( ) ) ;
updateEntity . setMallName ( basicdataClientEntity . getClientName ( ) ) ;
updateEntity . setTypeService ( basicdataClientEntity . getTypeService ( ) + "" ) ;
updateEntity . setConsigneePerson ( waybillEntity . getConsigneeName ( ) ) ;
updateEntity . setConsigneeMobile ( waybillEntity . getConsigneeMobile ( ) ) ;
updateEntity . setConsigneeAddress ( waybillEntity . getConsigneeAddress ( ) ) ;
updateEntity . setConsigneeUnit ( basicdataClientEntity . getClientName ( ) ) ;
updateStockArticleList . add ( updateEntity ) ;
distributionParcelListClient . updateList ( parcelListEntities ) ;
//根据订单id获取每个订单的运单拼接数据
if ( ! stockArticleIds . isEmpty ( ) ) {
List < Long > newList = new ArrayList < > ( stockArticleIds ) ;
List < DistributionStockArticleEntity > stockArticleEntities = distributionStockArticleClient . findStockListByIds ( newList ) ;
// List<DistributionStockArticleEntity> stockArticleEntities = distributionStockArticleClient.findWaybillNoByOrderIds(stockArticleIds);
List < DistributionStockArticleEntity > updateStockArticleList = new ArrayList < > ( ) ;
stockArticleEntities . forEach ( stockArticleEntity - > {
String waybillNumber = stockArticleEntity . getWaybillNumber ( ) ;
DistributionStockArticleEntity updateEntity = new DistributionStockArticleEntity ( ) ;
updateEntity . setId ( stockArticleEntity . getId ( ) ) ;
if ( StringUtil . isBlank ( waybillNumber ) ) {
updateEntity . setWaybillNumber ( finalWaybillNo ) ;
} else {
if ( ! waybillNumber . contains ( finalWaybillNo ) ) {
waybillNumber = waybillNumber + "," + finalWaybillNo ;
updateEntity . setWaybillNumber ( waybillNumber ) ;
}
}
} ) ;
if ( CollUtil . isNotEmpty ( updateStockArticleList ) ) {
distributionStockArticleClient . updateByBatchId ( updateStockArticleList ) ;
updateEntity . setMallId ( consigneeId1 ) ;
updateEntity . setMallCode ( basicdataClientEntity . getClientCode ( ) ) ;
updateEntity . setMallName ( basicdataClientEntity . getClientName ( ) ) ;
updateEntity . setTypeService ( basicdataClientEntity . getTypeService ( ) + "" ) ;
updateEntity . setConsigneePerson ( waybillEntity . getConsigneeName ( ) ) ;
updateEntity . setConsigneeMobile ( waybillEntity . getConsigneeMobile ( ) ) ;
updateEntity . setConsigneeAddress ( waybillEntity . getConsigneeAddress ( ) ) ;
updateEntity . setConsigneeUnit ( basicdataClientEntity . getClientName ( ) ) ;
updateStockArticleList . add ( updateEntity ) ;
} ) ;
if ( CollUtil . isNotEmpty ( updateStockArticleList ) ) {
distributionStockArticleClient . updateByBatchId ( updateStockArticleList ) ;
}
}
}
}
//修改暂存单明细的结算品类
//把updateAdvanceDetailList分成每300条一组
List < List < TrunklineAdvanceDetailEntity > > updateAdvanceDetailListList = CollUtil . split ( updateAdvanceDetailList , 300 ) ;
updateAdvanceDetailListList . forEach ( updateAdvanceDetailList1 - > {
advanceDetailService . updateBatchById ( updateAdvanceDetailList1 ) ;
} ) ;
}
//修改暂存单明细的结算品类
//把updateAdvanceDetailList分成每300条一组
List < List < TrunklineAdvanceDetailEntity > > updateAdvanceDetailListList = CollUtil . split ( updateAdvanceDetailList , 300 ) ;
updateAdvanceDetailListList . forEach ( updateAdvanceDetailList1 - > {
advanceDetailService . updateBatchById ( updateAdvanceDetailList1 ) ;
} ) ;
trunklineWaybillPackageService . updateWaybillStatus ( waybillEntity ) ;
trunklineWaybillPackageService . updateWaybillStatus ( waybillEntity ) ;
//计算扫码入库的包件是否需要把运单和提货单挂上
openOrderAsyncService . dealwithBillladingInfo ( advanceIds , warehouseId , warehouseName , waybillId , waybillNo ) ;
//计算扫码入库的包件是否需要把运单和提货单挂上
openOrderAsyncService . dealwithBillladingInfo ( advanceIds , warehouseId , warehouseName , waybillId , waybillNo ) ;
//异步存入日志
String nickName = AuthUtil . getNickName ( ) ;
Long userId = AuthUtil . getUserId ( ) ;
//异步存入日志
String nickName = AuthUtil . getNickName ( ) ;
Long userId = AuthUtil . getUserId ( ) ;
String createOperationRemark = "创建运单" + waybillNo + ",时间:" + CommonUtil . dateToStringGeneral ( new Date ( ) ) ;
openOrderAsyncService . saveLog ( waybillId , waybillNo , "10" , "创建运单" , createOperationRemark , nickName , userId , warehouseId , warehouseName ) ;
String createOperationRemark = "创建运单" + waybillNo + ",时间:" + CommonUtil . dateToStringGeneral ( new Date ( ) ) ;
openOrderAsyncService . saveLog ( waybillId , waybillNo , "10" , "创建运单" , createOperationRemark , nickName , userId , warehouseId , warehouseName ) ;
openOrderAsyncService . syncUnloadScanWaybillInfo ( advanceIds , waybillEntity ) ;
openOrderAsyncService . syncUnloadScanWaybillInfo ( advanceIds , waybillEntity ) ;
//队列处理包件补数据
carsLoadService . sendRabbitMessageOpenOrder ( advanceIds , waybillId ) ;
//队列处理包件补数据
carsLoadService . sendRabbitMessageOpenOrder ( advanceIds , waybillId ) ;
//发布开单广播
// openOrderAsyncService.sendOpenWaybillFanout(waybillEntity, details, advanceIds);
//发布开单广播
// openOrderAsyncService.sendOpenWaybillFanout(waybillEntity, details, advanceIds);
advanceDetailService . sendReportAdvanceOpenData ( AuthUtil . getNickName ( ) , AuthUtil . getUserId ( ) , warehouseId , warehouseName , updateAdvanceDetailList , waybillEntity ) ;
advanceDetailService . sendReportAdvanceOpenData ( AuthUtil . getNickName ( ) , AuthUtil . getUserId ( ) , warehouseId , warehouseName , updateAdvanceDetailList , waybillEntity ) ;
advanceIds . forEach ( advanceId - > {
bladeRedis . del ( openAdvanceIds + advanceId ) ;
} ) ;
advanceIds . forEach ( advanceId - > {
bladeRedis . del ( openAdvanceIds + advanceId ) ;
} ) ;
} catch ( Exception e ) {
log . error ( "#####openWaybill:开单失败" , e ) ;
warehouseWaybillClient . deleteAllByWaybillId ( waybillId ) ;
throw new CustomerException ( 405 , "开单失败" ) ;
}
return R . data ( waybillId ) ;
}
@ -1221,125 +1227,132 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
Long waybillId = warehouseWaybillClient . addEnntity ( waybillEntity ) ;
waybillEntity . setId ( waybillId ) ;
List < WarehouseWayBillDetail > details = new ArrayList < > ( ) ;
if ( ! Objects . isNull ( waybillId ) ) {
log . info ( "#################openZeroWaybill: 运单保存成功" ) ;
//保存运单货物明细
List < WaybillDetailDTO > waybillDetailList = openOrderDTO . getAddList ( ) ;
for ( WaybillDetailDTO waybillDetailDTO : waybillDetailList ) {
WarehouseWayBillDetail warehouseWayBillDetail = new WarehouseWayBillDetail ( ) ;
warehouseWayBillDetail . setCreateUser ( AuthUtil . getUserId ( ) ) ;
warehouseWayBillDetail . setUpdateUser ( AuthUtil . getUserId ( ) ) ;
Date date = new Date ( ) ;
warehouseWayBillDetail . setCreateTime ( date ) ;
warehouseWayBillDetail . setUpdateTime ( date ) ;
warehouseWayBillDetail . setStatus ( 1 ) ;
warehouseWayBillDetail . setIsDeleted ( 0 ) ;
warehouseWayBillDetail . setWaybillId ( waybillId ) ;
warehouseWayBillDetail . setWaybillNo ( waybillEntity . getWaybillNo ( ) ) ;
Long goodsId = waybillDetailDTO . getGoodsId ( ) ;
String goodsName = waybillDetailDTO . getGoodsName ( ) ;
if ( Objects . isNull ( goodsId ) ) {
//如果品名id没有就先通过goodsName查寻,没有就新增
if ( StringUtil . isNotBlank ( goodsName ) ) {
BasicdataCategoryEntity basicdataCategoryEntity = basicdataCategoryClient . findByName ( goodsName . trim ( ) ) ;
if ( Objects . isNull ( basicdataCategoryEntity ) ) {
basicdataCategoryEntity = new BasicdataCategoryEntity ( ) ;
basicdataCategoryEntity . setName ( goodsName ) ;
basicdataCategoryEntity . setType ( "1" ) ;
goodsId = basicdataCategoryClient . addReturnId ( basicdataCategoryEntity ) ;
} else {
goodsId = basicdataCategoryEntity . getId ( ) ;
try {
List < WarehouseWayBillDetail > details = new ArrayList < > ( ) ;
if ( ! Objects . isNull ( waybillId ) ) {
log . info ( "#################openZeroWaybill: 运单保存成功" ) ;
//保存运单货物明细
List < WaybillDetailDTO > waybillDetailList = openOrderDTO . getAddList ( ) ;
for ( WaybillDetailDTO waybillDetailDTO : waybillDetailList ) {
WarehouseWayBillDetail warehouseWayBillDetail = new WarehouseWayBillDetail ( ) ;
warehouseWayBillDetail . setCreateUser ( AuthUtil . getUserId ( ) ) ;
warehouseWayBillDetail . setUpdateUser ( AuthUtil . getUserId ( ) ) ;
Date date = new Date ( ) ;
warehouseWayBillDetail . setCreateTime ( date ) ;
warehouseWayBillDetail . setUpdateTime ( date ) ;
warehouseWayBillDetail . setStatus ( 1 ) ;
warehouseWayBillDetail . setIsDeleted ( 0 ) ;
warehouseWayBillDetail . setWaybillId ( waybillId ) ;
warehouseWayBillDetail . setWaybillNo ( waybillEntity . getWaybillNo ( ) ) ;
Long goodsId = waybillDetailDTO . getGoodsId ( ) ;
String goodsName = waybillDetailDTO . getGoodsName ( ) ;
if ( Objects . isNull ( goodsId ) ) {
//如果品名id没有就先通过goodsName查寻,没有就新增
if ( StringUtil . isNotBlank ( goodsName ) ) {
BasicdataCategoryEntity basicdataCategoryEntity = basicdataCategoryClient . findByName ( goodsName . trim ( ) ) ;
if ( Objects . isNull ( basicdataCategoryEntity ) ) {
basicdataCategoryEntity = new BasicdataCategoryEntity ( ) ;
basicdataCategoryEntity . setName ( goodsName ) ;
basicdataCategoryEntity . setType ( "1" ) ;
goodsId = basicdataCategoryClient . addReturnId ( basicdataCategoryEntity ) ;
} else {
goodsId = basicdataCategoryEntity . getId ( ) ;
}
}
}
}
warehouseWayBillDetail . setProductId ( goodsId ) ;
warehouseWayBillDetail . setProductName ( goodsName ) ;
Integer num = waybillDetailDTO . getNum ( ) ;
BigDecimal volume = waybillDetailDTO . getVolume ( ) ;
BigDecimal weight = waybillDetailDTO . getWeight ( ) ;
warehouseWayBillDetail . setNum ( num ) ;
warehouseWayBillDetail . setVolume ( volume ) ;
warehouseWayBillDetail . setWeight ( weight ) ;
BigDecimal price = waybillDetailDTO . getPrice ( ) ;
Integer chargeType = waybillDetailDTO . getChargeType ( ) ;
BigDecimal subtotalFreight = waybillDetailDTO . getSubtotalFreight ( ) ;
if ( price . compareTo ( BigDecimal . ZERO ) = = 0 ) {
warehouseWayBillDetail . setProductId ( goodsId ) ;
warehouseWayBillDetail . setProductName ( goodsName ) ;
Integer num = waybillDetailDTO . getNum ( ) ;
BigDecimal volume = waybillDetailDTO . getVolume ( ) ;
BigDecimal weight = waybillDetailDTO . getWeight ( ) ;
warehouseWayBillDetail . setNum ( num ) ;
warehouseWayBillDetail . setVolume ( volume ) ;
warehouseWayBillDetail . setWeight ( weight ) ;
BigDecimal price = waybillDetailDTO . getPrice ( ) ;
Integer chargeType = waybillDetailDTO . getChargeType ( ) ;
BigDecimal subtotalFreight = waybillDetailDTO . getSubtotalFreight ( ) ;
if ( price . compareTo ( BigDecimal . ZERO ) = = 0 ) {
if ( chargeType . equals ( 1 ) ) {
price = subtotalFreight . divide ( new BigDecimal ( num ) , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 2 ) ) {
price = subtotalFreight . divide ( volume , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 3 ) ) {
price = subtotalFreight . divide ( weight , 6 , RoundingMode . HALF_UP ) ;
}
if ( chargeType . equals ( 1 ) ) {
price = subtotalFreight . divide ( new BigDecimal ( num ) , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 2 ) ) {
price = subtotalFreight . divide ( volume , 6 , RoundingMode . HALF_UP ) ;
} else if ( chargeType . equals ( 3 ) ) {
price = subtotalFreight . divide ( weight , 6 , RoundingMode . HALF_UP ) ;
}
warehouseWayBillDetail . setPrice ( price ) ;
warehouseWayBillDetail . setSubtotalFreight ( subtotalFreight ) ;
warehouseWayBillDetail . setChargeType ( chargeType ) ;
warehouseWayBillDetail . setDeliveryPrice ( waybillDetailDTO . getDeliveryPrice ( ) ) ;
warehouseWayBillDetail . setSubtotalDeliveryFee ( waybillDetailDTO . getSubtotalDeliveryFee ( ) ) ;
warehouseWayBillDetail . setPickupPrice ( waybillDetailDTO . getPickupPrice ( ) ) ;
warehouseWayBillDetail . setFreightPrice ( waybillDetailDTO . getFreightPrice ( ) ) ;
warehouseWayBillDetail . setSystemChargeType ( waybillDetailDTO . getChargeType ( ) ) ;
warehouseWayBillDetail . setSystemDeliveryChargeType ( waybillDetailDTO . getSystemDeliveryChargeType ( ) ) ;
warehouseWayBillDetail . setSystemPickupChargeType ( waybillDetailDTO . getSystemPickupChargeType ( ) ) ;
warehouseWayBillDetail . setSystemWarehouseChargeType ( waybillDetailDTO . getSystemWarehouseChargeType ( ) ) ;
details . add ( warehouseWayBillDetail ) ;
}
warehouseWaybillDetailClient . addList ( details ) ;
} else {
log . info ( "#################openZeroWaybill: 运单保存失败" ) ;
return R . fail ( 405 , "运单保存失败" ) ;
}
if ( advanceIds ! = null & & advanceIds . size ( ) > 0 ) {
List < TrunklineAdvanceEntity > advanceEntityList = advanceService . findListByIds ( advanceIds ) ;
for ( TrunklineAdvanceEntity advanceEntity : advanceEntityList ) {
advanceEntity . setWaybillNo ( waybillNo ) ;
advanceEntity . setWaybillStatus ( "1" ) ;
}
warehouseWayBillDetail . setPrice ( price ) ;
warehouseWayBillDetail . setSubtotalFreight ( subtotalFreight ) ;
warehouseWayBillDetail . setChargeType ( chargeType ) ;
warehouseWayBillDetail . setDeliveryPrice ( waybillDetailDTO . getDeliveryPrice ( ) ) ;
warehouseWayBillDetail . setSubtotalDeliveryFee ( waybillDetailDTO . getSubtotalDeliveryFee ( ) ) ;
warehouseWayBillDetail . setPickupPrice ( waybillDetailDTO . getPickupPrice ( ) ) ;
warehouseWayBillDetail . setFreightPrice ( waybillDetailDTO . getFreightPrice ( ) ) ;
warehouseWayBillDetail . setSystemChargeType ( waybillDetailDTO . getChargeType ( ) ) ;
warehouseWayBillDetail . setSystemDeliveryChargeType ( waybillDetailDTO . getSystemDeliveryChargeType ( ) ) ;
warehouseWayBillDetail . setSystemPickupChargeType ( waybillDetailDTO . getSystemPickupChargeType ( ) ) ;
warehouseWayBillDetail . setSystemWarehouseChargeType ( waybillDetailDTO . getSystemWarehouseChargeType ( ) ) ;
details . add ( warehouseWayBillDetail ) ;
advanceService . updateBatchById ( advanceEntityList ) ;
}
warehouseWaybillDetailClient . addList ( details ) ;
} else {
log . info ( "#################openZeroWaybill: 运单保存失败" ) ;
return R . fail ( 405 , "运单保存失败" ) ;
}
//异步存入日志
Date date = new Date ( ) ;
String nickName = AuthUtil . getNickName ( ) ;
Long userId = AuthUtil . getUserId ( ) ;
String createOperationRemark = "创建运单" + waybillNo + ",时间:" + CommonUtil . dateToStringGeneral ( date ) ;
openOrderAsyncService . saveLog ( waybillId , waybillNo , "10" , "创建运单" , createOperationRemark , nickName , userId , warehouseId , warehouseName ) ;
if ( advanceIds ! = null & & advanceIds . size ( ) > 0 ) {
List < TrunklineAdvanceEntity > advanceEntityList = advanceService . findListByIds ( advanceIds ) ;
for ( TrunklineAdvanceEntity advanceEntity : advanceEntityList ) {
advanceEntity . setWaybillNo ( waybillNo ) ;
advanceEntity . setWaybillStatus ( "1" ) ;
Integer totalCount = waybillEntity . getTotalCount ( ) ;
Integer stockCount = waybillEntity . getStockCount ( ) ;
if ( totalCount . equals ( stockCount ) ) {
createOperationRemark = "运单入库:" + stockCount + "/" + totalCount + ",入库类型:【零担开单及入库】,入库时间:" + CommonUtil . dateToStringGeneral ( date ) ;
openOrderAsyncService . saveLog ( waybillId , waybillNo , "20" , "已入库" , createOperationRemark , nickName , userId , warehouseId , warehouseName ) ;
}
advanceService . updateBatchById ( advanceEntityList ) ;
}
//异步存入日志
Date date = new Date ( ) ;
String nickName = AuthUtil . getNickName ( ) ;
Long userId = AuthUtil . getUserId ( ) ;
String createOperationRemark = "创建运单" + waybillNo + ",时间:" + CommonUtil . dateToStringGeneral ( date ) ;
openOrderAsyncService . saveLog ( waybillId , waybillNo , "10" , "创建运单" , createOperationRemark , nickName , userId , warehouseId , warehouseName ) ;
Integer totalCount = waybillEntity . getTotalCount ( ) ;
Integer stockCount = waybillEntity . getStockCount ( ) ;
if ( totalCount . equals ( stockCount ) ) {
createOperationRemark = "运单入库:" + stockCount + "/" + totalCount + ",入库类型:【零担开单及入库】,入库时间:" + CommonUtil . dateToStringGeneral ( date ) ;
openOrderAsyncService . saveLog ( waybillId , waybillNo , "20" , "已入库" , createOperationRemark , nickName , userId , warehouseId , warehouseName ) ;
//创建零担订单
createStockArticle ( waybillEntity ) ;
//存入运单与订单关联信息
TrunklineWaybillOrderEntity trunklineWaybillOrderEntity = new TrunklineWaybillOrderEntity ( ) ;
trunklineWaybillOrderEntity . setWarehouseId ( warehouseId ) ;
trunklineWaybillOrderEntity . setWarehouseName ( basicdataWarehouseEntity . getName ( ) ) ;
trunklineWaybillOrderEntity . setWaybillId ( waybillId ) ;
trunklineWaybillOrderEntity . setWaybillNo ( waybillNo ) ;
trunklineWaybillOrderEntity . setOrderCode ( waybillNo ) ;
trunklineWaybillOrderEntity . setTotalNumber ( waybillEntity . getTotalCount ( ) ) ;
trunklineWaybillOrderEntity . setHandleNumber ( waybillEntity . getTotalCount ( ) ) ;
trunklineWaybillOrderService . save ( trunklineWaybillOrderEntity ) ;
//发布开单广播
openOrderAsyncService . sendOpenWaybillFanout ( waybillEntity , details , null ) ;
//发送零担开单广播
sendOpenZeroWaybillFanout ( AuthUtil . getUserId ( ) , AuthUtil . getNickName ( ) , warehouseId , warehouseName , waybillEntity , details ) ;
} catch ( Exception e ) {
log . error ( "#####openWaybill:开单失败" , e ) ;
warehouseWaybillClient . deleteAllByWaybillId ( waybillId ) ;
throw new CustomerException ( 405 , "开单失败" ) ;
}
//创建零担订单
createStockArticle ( waybillEntity ) ;
//存入运单与订单关联信息
TrunklineWaybillOrderEntity trunklineWaybillOrderEntity = new TrunklineWaybillOrderEntity ( ) ;
trunklineWaybillOrderEntity . setWarehouseId ( warehouseId ) ;
trunklineWaybillOrderEntity . setWarehouseName ( basicdataWarehouseEntity . getName ( ) ) ;
trunklineWaybillOrderEntity . setWaybillId ( waybillId ) ;
trunklineWaybillOrderEntity . setWaybillNo ( waybillNo ) ;
trunklineWaybillOrderEntity . setOrderCode ( waybillNo ) ;
trunklineWaybillOrderEntity . setTotalNumber ( waybillEntity . getTotalCount ( ) ) ;
trunklineWaybillOrderEntity . setHandleNumber ( waybillEntity . getTotalCount ( ) ) ;
trunklineWaybillOrderService . save ( trunklineWaybillOrderEntity ) ;
//发布开单广播
openOrderAsyncService . sendOpenWaybillFanout ( waybillEntity , details , null ) ;
//发送零担开单广播
sendOpenZeroWaybillFanout ( AuthUtil . getUserId ( ) , AuthUtil . getNickName ( ) , warehouseId , warehouseName , waybillEntity , details ) ;
Map < String , Object > map = new HashMap < > ( ) ;
map . put ( "waybillId" , waybillId ) ;
map . put ( "waybillNo" , waybillNo ) ;
@ -4632,7 +4645,7 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
}
//TODO 还需要加上 生成了预存单的无法进行作废
//生成了预存单的无法进行作废
Integer status = orderInfoClient . findCreateRencilitionOrderStatus ( waybillId ) ;
if ( status = = 1 ) {
log . warn ( "##########abolishWaybill: 运单已有预存单确认 waybillId={}" , waybillId ) ;
@ -4802,6 +4815,14 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
public R findAdvanceDetailListByAdvanceIds ( AdvanceDTO advanceDTO ) {
List < Long > advanceIds = advanceDTO . getAdvanceIds ( ) ;
Long clientId = advanceDTO . getClientId ( ) ;
if ( ! Objects . isNull ( clientId ) ) {
BasicdataClientEntity clientEntity = basicdataClientClient . findEntityById ( clientId ) ;
if ( ! Objects . isNull ( clientEntity ) ) {
advanceDTO . setMainId ( clientEntity . getMainId ( ) ) ;
}
}
List < AdvanceDetailVO > advanceDetailVOList = advanceDetailService . findAdvanceDetailListByAdvanceIds ( advanceDTO ) ;
return R . data ( advanceDetailVOList ) ;
@ -5596,9 +5617,9 @@ public class OpenOrderServiceImpl implements IOpenOrderService {
Long newDestinationWarehouseId = openOrderDTO . getDestinationWarehouseId ( ) ;
String newDestinationWarehouseName = openOrderDTO . getDestinationWarehouseName ( ) ;
Long destinationWarehouseId = waybillEntity . getDestinationWarehouseId ( ) ;
String departure WarehouseName = waybillEntity . getDeparture WarehouseName ( ) ;
String destination WarehouseName = waybillEntity . getDestination WarehouseName ( ) ;
if ( ! ObjectUtil . equals ( destinationWarehouseId , newDestinationWarehouseId ) ) {
stringBuilder . append ( "目的仓:" ) . append ( departure WarehouseName ) . append ( "-->" ) . append ( newDestinationWarehouseName ) . append ( ";" ) ;
stringBuilder . append ( "目的仓:" ) . append ( destination WarehouseName ) . append ( "-->" ) . append ( newDestinationWarehouseName ) . append ( ";" ) ;
waybillEntity . setDestinationWarehouseId ( newDestinationWarehouseId ) ;
waybillEntity . setDestinationWarehouseName ( newDestinationWarehouseName ) ;
//查询所有该运单的包件