|
|
|
@ -4517,76 +4517,81 @@ public class TrunklineCarsLoadServiceImpl extends BaseServiceImpl<TrunklineCarsL
|
|
|
|
|
List<TrunklineCarsOrderEntity> carsOrderEntityList = trunklineCarsOrderService.listByIds(carsOrderIdList); |
|
|
|
|
//移除carsOrderEntityList中signNum不为0的元素
|
|
|
|
|
carsOrderEntityList.removeIf(e -> e.getSignNum() != 0); |
|
|
|
|
//把carsOrderEntityList通过signOrderId进行分组
|
|
|
|
|
Map<Long, List<TrunklineCarsOrderEntity>> collect = carsOrderEntityList.stream().collect(Collectors.groupingBy(TrunklineCarsOrderEntity::getSignOrderId)); |
|
|
|
|
Set<Long> signOrderIds = collect.keySet(); |
|
|
|
|
List<TrunklineLoadSignOrderEntity> signOrderEntityList = trunklineLoadSignOrderService.listByIds(signOrderIds); |
|
|
|
|
//把signOrderEntityList转化成id为key的Map
|
|
|
|
|
Map<Long, TrunklineLoadSignOrderEntity> signOrderEntityMap = signOrderEntityList.stream().collect(Collectors.toMap(TrunklineLoadSignOrderEntity::getId, Function.identity())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<TrunklineCarsOrderEntity> updateCarsOrderList = new ArrayList<>(); |
|
|
|
|
List<TrunklineLoadSignOrderEntity> updateSignOrderList = new ArrayList<>(); |
|
|
|
|
List<Long> delSignOrderList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
Long finalLoadId1 = loadId; |
|
|
|
|
collect.keySet().forEach(signOrderId -> { |
|
|
|
|
List<TrunklineCarsOrderEntity> list = collect.get(signOrderId); |
|
|
|
|
TrunklineLoadSignOrderEntity trunklineLoadSignOrderEntity = signOrderEntityMap.get(signOrderId); |
|
|
|
|
//把list中所有元素的realNum求和
|
|
|
|
|
int sumLoading = list.stream().mapToInt(TrunklineCarsOrderEntity::getRealNum).sum(); |
|
|
|
|
int sumPlan = list.stream().mapToInt(TrunklineCarsOrderEntity::getPlanNum).sum(); |
|
|
|
|
Integer planNum = trunklineLoadSignOrderEntity.getPlanNum(); |
|
|
|
|
Integer loadingNum = trunklineLoadSignOrderEntity.getLoadingNum(); |
|
|
|
|
Integer signNum = trunklineLoadSignOrderEntity.getSignNum(); |
|
|
|
|
if(sumPlan < planNum){ |
|
|
|
|
//只是更新不删除
|
|
|
|
|
TrunklineLoadSignOrderEntity updateSignOrderEntity = new TrunklineLoadSignOrderEntity(); |
|
|
|
|
updateSignOrderEntity.setId(trunklineLoadSignOrderEntity.getId()); |
|
|
|
|
int diff = planNum - sumPlan; |
|
|
|
|
updateSignOrderEntity.setPlanNum(diff); |
|
|
|
|
updateSignOrderEntity.setLoadingNum(loadingNum-sumLoading); |
|
|
|
|
if(signNum >= diff){ |
|
|
|
|
updateSignOrderEntity.setSignStatus("20"); |
|
|
|
|
}else if(signNum == 0){ |
|
|
|
|
updateSignOrderEntity.setSignStatus("0"); |
|
|
|
|
if(CollUtil.isNotEmpty(carsOrderEntityList)){ |
|
|
|
|
//把carsOrderEntityList通过signOrderId进行分组
|
|
|
|
|
Map<Long, List<TrunklineCarsOrderEntity>> collect = carsOrderEntityList.stream().collect(Collectors.groupingBy(TrunklineCarsOrderEntity::getSignOrderId)); |
|
|
|
|
Set<Long> signOrderIds = collect.keySet(); |
|
|
|
|
List<TrunklineLoadSignOrderEntity> signOrderEntityList = trunklineLoadSignOrderService.listByIds(signOrderIds); |
|
|
|
|
//把signOrderEntityList转化成id为key的Map
|
|
|
|
|
Map<Long, TrunklineLoadSignOrderEntity> signOrderEntityMap = signOrderEntityList.stream().collect(Collectors.toMap(TrunklineLoadSignOrderEntity::getId, Function.identity())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<TrunklineCarsOrderEntity> updateCarsOrderList = new ArrayList<>(); |
|
|
|
|
List<TrunklineLoadSignOrderEntity> updateSignOrderList = new ArrayList<>(); |
|
|
|
|
List<Long> delSignOrderList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
Long finalLoadId1 = loadId; |
|
|
|
|
collect.keySet().forEach(signOrderId -> { |
|
|
|
|
List<TrunklineCarsOrderEntity> list = collect.get(signOrderId); |
|
|
|
|
TrunklineLoadSignOrderEntity trunklineLoadSignOrderEntity = signOrderEntityMap.get(signOrderId); |
|
|
|
|
//把list中所有元素的realNum求和
|
|
|
|
|
int sumLoading = list.stream().mapToInt(TrunklineCarsOrderEntity::getRealNum).sum(); |
|
|
|
|
int sumPlan = list.stream().mapToInt(TrunklineCarsOrderEntity::getPlanNum).sum(); |
|
|
|
|
Integer planNum = trunklineLoadSignOrderEntity.getPlanNum(); |
|
|
|
|
Integer loadingNum = trunklineLoadSignOrderEntity.getLoadingNum(); |
|
|
|
|
Integer signNum = trunklineLoadSignOrderEntity.getSignNum(); |
|
|
|
|
if(sumPlan < planNum){ |
|
|
|
|
//只是更新不删除
|
|
|
|
|
TrunklineLoadSignOrderEntity updateSignOrderEntity = new TrunklineLoadSignOrderEntity(); |
|
|
|
|
updateSignOrderEntity.setId(trunklineLoadSignOrderEntity.getId()); |
|
|
|
|
int diff = planNum - sumPlan; |
|
|
|
|
updateSignOrderEntity.setPlanNum(diff); |
|
|
|
|
updateSignOrderEntity.setLoadingNum(loadingNum-sumLoading); |
|
|
|
|
if(signNum >= diff){ |
|
|
|
|
updateSignOrderEntity.setSignStatus("20"); |
|
|
|
|
}else if(signNum == 0){ |
|
|
|
|
updateSignOrderEntity.setSignStatus("0"); |
|
|
|
|
}else{ |
|
|
|
|
updateSignOrderEntity.setSignStatus("10"); |
|
|
|
|
} |
|
|
|
|
updateSignOrderList.add(updateSignOrderEntity); |
|
|
|
|
}else{ |
|
|
|
|
updateSignOrderEntity.setSignStatus("10"); |
|
|
|
|
//删除
|
|
|
|
|
delSignOrderList.add(signOrderId); |
|
|
|
|
} |
|
|
|
|
updateSignOrderList.add(updateSignOrderEntity); |
|
|
|
|
}else{ |
|
|
|
|
//删除
|
|
|
|
|
delSignOrderList.add(signOrderId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
list.forEach(e -> { |
|
|
|
|
TrunklineCarsOrderEntity carsOrderEntity = new TrunklineCarsOrderEntity(); |
|
|
|
|
carsOrderEntity.setId(e.getId()); |
|
|
|
|
carsOrderEntity.setOrderCode(e.getOrderCode()); |
|
|
|
|
carsOrderEntity.setWaybillNo(e.getWaybillNo()); |
|
|
|
|
carsOrderEntity.setLoadId(finalLoadId1); |
|
|
|
|
carsOrderEntity.setNodeId(e.getNodeId()); |
|
|
|
|
updateCarsOrderList.add(carsOrderEntity); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
list.forEach(e -> { |
|
|
|
|
TrunklineCarsOrderEntity carsOrderEntity = new TrunklineCarsOrderEntity(); |
|
|
|
|
carsOrderEntity.setId(e.getId()); |
|
|
|
|
carsOrderEntity.setOrderCode(e.getOrderCode()); |
|
|
|
|
carsOrderEntity.setWaybillNo(e.getWaybillNo()); |
|
|
|
|
carsOrderEntity.setLoadId(finalLoadId1); |
|
|
|
|
carsOrderEntity.setNodeId(e.getNodeId()); |
|
|
|
|
updateCarsOrderList.add(carsOrderEntity); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if(CollUtil.isNotEmpty(updateSignOrderList)){ |
|
|
|
|
trunklineLoadSignOrderService.updateBatchById(updateSignOrderList); |
|
|
|
|
} |
|
|
|
|
if(CollUtil.isNotEmpty(delSignOrderList)){ |
|
|
|
|
trunklineLoadSignOrderService.deleteListBySignOrderIds(delSignOrderList); |
|
|
|
|
} |
|
|
|
|
if(CollUtil.isNotEmpty(updateCarsOrderList)){ |
|
|
|
|
//把updateCarsOrderIdList所有的id放入一个List
|
|
|
|
|
List<Long> updateCarsOrderIdList = updateCarsOrderList.stream().map(TrunklineCarsOrderEntity::getId).collect(Collectors.toList()); |
|
|
|
|
trunklineCarsOrderService.updateNoCustomer(updateCarsOrderIdList); |
|
|
|
|
updateCarsOrderList.forEach(e -> { |
|
|
|
|
Long nodeId = e.getNodeId(); |
|
|
|
|
String orderCode = e.getOrderCode(); |
|
|
|
|
String waybillNo = e.getWaybillNo(); |
|
|
|
|
trunklineCarsLoadScanService.clearSignOrderIdByLoadIdAndWarehouseIdAndOrderCodeAndWaybillNo(finalLoadId1,nodeId,orderCode,waybillNo); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if(CollUtil.isNotEmpty(updateSignOrderList)){ |
|
|
|
|
trunklineLoadSignOrderService.updateBatchById(updateSignOrderList); |
|
|
|
|
} |
|
|
|
|
if(CollUtil.isNotEmpty(delSignOrderList)){ |
|
|
|
|
trunklineLoadSignOrderService.deleteListBySignOrderIds(delSignOrderList); |
|
|
|
|
} |
|
|
|
|
if(CollUtil.isNotEmpty(updateCarsOrderList)){ |
|
|
|
|
//把updateCarsOrderIdList所有的id放入一个List
|
|
|
|
|
List<Long> updateCarsOrderIdList = updateCarsOrderList.stream().map(TrunklineCarsOrderEntity::getId).collect(Collectors.toList()); |
|
|
|
|
trunklineCarsOrderService.updateNoCustomer(updateCarsOrderIdList); |
|
|
|
|
updateCarsOrderList.forEach(e -> { |
|
|
|
|
Long nodeId = e.getNodeId(); |
|
|
|
|
String orderCode = e.getOrderCode(); |
|
|
|
|
String waybillNo = e.getWaybillNo(); |
|
|
|
|
trunklineCarsLoadScanService.clearSignOrderIdByLoadIdAndWarehouseIdAndOrderCodeAndWaybillNo(finalLoadId1,nodeId,orderCode,waybillNo); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
log.warn("###############updateWaybillOrderIsCustemer: 订单已有签收数据不能移除"); |
|
|
|
|
return R.fail(405,"订单已有签收数据,不能移除"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|