|
|
|
@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -3111,75 +3112,60 @@ public class WarehouseUpdownTypeServiceImpl extends BaseServiceImpl<WarehouseUpd
|
|
|
|
|
QueryWrapper<WarehouseUpdownGoodsEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("updown_type_id", updownTypeId); |
|
|
|
|
List<WarehouseUpdownGoodsEntity> list = warehouseUpdownGoodsService.list(queryWrapper); |
|
|
|
|
Set<String> set = new TreeSet<>(); |
|
|
|
|
Integer totalNum = 0; |
|
|
|
|
Integer orderTotalNum = 0; |
|
|
|
|
Integer stockNum = 0; |
|
|
|
|
Integer stockTotalNum = 0; |
|
|
|
|
for (WarehouseUpdownGoodsEntity updownGoodsEntity : list) { |
|
|
|
|
String associationType = updownGoodsEntity.getAssociationType(); |
|
|
|
|
Long associationId = updownGoodsEntity.getAssociationId(); |
|
|
|
|
String associationValue = updownGoodsEntity.getAssociationValue(); |
|
|
|
|
Long marketId = updownGoodsEntity.getMarketId(); |
|
|
|
|
Integer num = updownGoodsEntity.getNum(); |
|
|
|
|
String incomingBatch = updownGoodsEntity.getIncomingBatch(); |
|
|
|
|
if ("1".equals(associationType)) { |
|
|
|
|
//零担订单数据
|
|
|
|
|
String orderCode = associationValue; |
|
|
|
|
DistributionStockArticleEntity stockArticleEntity = distributionStockArticleClient.findStockArticleByOrderCodeAndWarehouseId(orderCode, warehouseId); |
|
|
|
|
Integer totalNumber = stockArticleEntity.getTotalNumber(); |
|
|
|
|
if (!set.contains(associationValue)) { |
|
|
|
|
set.add(orderCode); |
|
|
|
|
orderTotalNum = orderTotalNum + totalNumber; |
|
|
|
|
} |
|
|
|
|
totalNum = totalNum + num; |
|
|
|
|
|
|
|
|
|
} else if ("3".equals(associationType)) { |
|
|
|
|
DistributionParcelListEntity parcelListEntity = distributionParcelListClient.findByPacketBarCodeAndWarehouseId(associationValue, warehouseId); |
|
|
|
|
String orderCode = parcelListEntity.getOrderCode(); |
|
|
|
|
DistributionStockArticleEntity stockArticleEntity = distributionStockArticleClient.findStockArticleByOrderCodeAndWarehouseId(orderCode, warehouseId); |
|
|
|
|
Integer totalNumber = stockArticleEntity.getTotalNumber(); |
|
|
|
|
if (!set.contains(orderCode)) { |
|
|
|
|
set.add(orderCode); |
|
|
|
|
orderTotalNum = orderTotalNum + totalNumber; |
|
|
|
|
} |
|
|
|
|
totalNum = totalNum + num; |
|
|
|
|
} else if ("4".equals(associationType)) { |
|
|
|
|
DistributionStockListEntity stockListEntity = distributionStockListClient.getEntityByMarketIdAndMaterialCodeAndIncomingBatch(marketId, associationValue, incomingBatch, warehouseId); |
|
|
|
|
Integer quantityStock = stockListEntity.getQuantityStock(); |
|
|
|
|
stockNum = stockNum + num; |
|
|
|
|
stockTotalNum = stockTotalNum + quantityStock; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
baseMapper.updateNumByUpdownTypeId(orderTotalNum, totalNum, stockNum, stockTotalNum, updownTypeId); |
|
|
|
|
AtomicReference<Integer> totalNum = new AtomicReference<>(0); |
|
|
|
|
AtomicReference<Integer> orderTotalNum = new AtomicReference<>(0); |
|
|
|
|
AtomicReference<Integer> stockNum = new AtomicReference<>(0); |
|
|
|
|
AtomicReference<Integer> stockTotalNum = new AtomicReference<>(0); |
|
|
|
|
|
|
|
|
|
// DistributionStockArticleEntity stockArticleEntity = distributionStockArticleClient.findStockArticleByOrderCode(orderCode);
|
|
|
|
|
// if(Objects.isNull(stockArticleEntity)){
|
|
|
|
|
// log.warn("##############updateUpdownTypeNumPackage: 订单信息不存在 orderCode={}",orderCode);
|
|
|
|
|
// throw new CustomerException(403,"订单信息不存在");
|
|
|
|
|
// }
|
|
|
|
|
// Integer orderTotalNumber = stockArticleEntity.getTotalNumber();
|
|
|
|
|
// //查询该订单在该上架方式下的包件还有几条数据
|
|
|
|
|
// List<WarehouseUpdownGoodsEntity> ls = warehouseUpdownGoodsService.findListByUpdownTypeIdAndOrderCode(updownTypeId,orderCode);
|
|
|
|
|
// int size = ls.size();
|
|
|
|
|
// if("1".equals(addStatus)){
|
|
|
|
|
// if(size==0){
|
|
|
|
|
// baseMapper.updateOrderTotalNumAndTotalNum(updownTypeId,orderTotalNumber,quantity);
|
|
|
|
|
// }else{
|
|
|
|
|
// baseMapper.updateTotalNum(updownTypeId,quantity);
|
|
|
|
|
// }
|
|
|
|
|
// }else if("2".equals(addStatus)){
|
|
|
|
|
// if(size==0){
|
|
|
|
|
// log.warn("##############updateUpdownTypeNumPackage: 数据格式问题 updownTypeId={} orderCode={}",updownTypeId,orderCode);
|
|
|
|
|
// throw new CustomerException(403,"数据格式问题");
|
|
|
|
|
// }else if(size > 1){
|
|
|
|
|
// //如果库中有至少2条数据,那么去掉一条也不会影响改订单的总数变化,所以只减去包件的数量
|
|
|
|
|
// baseMapper.updateTotalNum(updownTypeId,-quantity);
|
|
|
|
|
// }else{
|
|
|
|
|
// //如果库中有至少2条数据,那么去掉一条也不会影响改订单的总数变化,所以只减去包件的数量
|
|
|
|
|
// baseMapper.updateOrderTotalNumAndTotalNum(updownTypeId,-orderTotalNumber,-quantity);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// 使用Java Stream对list按associationType字段进行分组
|
|
|
|
|
Map<String, List<WarehouseUpdownGoodsEntity>> groupedByAssociationType = list.stream() |
|
|
|
|
.collect(Collectors.groupingBy(WarehouseUpdownGoodsEntity::getAssociationType)); |
|
|
|
|
|
|
|
|
|
groupedByAssociationType.keySet().forEach(associationType -> { |
|
|
|
|
List<WarehouseUpdownGoodsEntity> updownGoodsEntities = groupedByAssociationType.get(associationType); |
|
|
|
|
|
|
|
|
|
//统计updownGoodsEntities中所有元素的num之和
|
|
|
|
|
Integer total = updownGoodsEntities.stream() |
|
|
|
|
.mapToInt(WarehouseUpdownGoodsEntity::getNum) |
|
|
|
|
.sum(); |
|
|
|
|
//把updownGoodsEntities中所有元素的associationValue放入一个List<String>中
|
|
|
|
|
List<String> associationValues = updownGoodsEntities.stream() |
|
|
|
|
.map(WarehouseUpdownGoodsEntity::getAssociationValue) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
if ("1".equals(associationType)) { |
|
|
|
|
//零担
|
|
|
|
|
//获取所有
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.put("orderCodes",associationValues); |
|
|
|
|
jsonObject.put("warehouseId",warehouseId); |
|
|
|
|
Integer orderTotal = distributionStockArticleClient.findOrderTotalNumByOrderCodes(jsonObject); |
|
|
|
|
|
|
|
|
|
totalNum.set(totalNum.get()+total); |
|
|
|
|
orderTotalNum.set(orderTotalNum.get()+orderTotal); |
|
|
|
|
|
|
|
|
|
}else if ("3".equals(associationType)){ |
|
|
|
|
//订制品
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.put("orderPackageCodes",associationValues); |
|
|
|
|
jsonObject.put("warehouseId",warehouseId); |
|
|
|
|
Integer orderTotal = distributionStockArticleClient.findOrderTotalNumByOrderPackageCodes(jsonObject); |
|
|
|
|
|
|
|
|
|
totalNum.set(totalNum.get()+total); |
|
|
|
|
orderTotalNum.set(orderTotalNum.get()+orderTotal); |
|
|
|
|
|
|
|
|
|
}else if ("4".equals(associationType)){ |
|
|
|
|
//无数据库存品
|
|
|
|
|
updownGoodsEntities.forEach(updownGoodsEntity -> { |
|
|
|
|
DistributionStockListEntity stockListEntity = distributionStockListClient.getEntityByMarketIdAndMaterialCodeAndIncomingBatch(updownGoodsEntity.getMarketId(), updownGoodsEntity.getAssociationValue(), updownGoodsEntity.getIncomingBatch(), warehouseId); |
|
|
|
|
Integer quantityStock = stockListEntity.getQuantityStock(); |
|
|
|
|
stockTotalNum.set(stockTotalNum.get() + quantityStock); |
|
|
|
|
}); |
|
|
|
|
stockNum.set(stockNum.get() + total); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
baseMapper.updateNumByUpdownTypeId(orderTotalNum.get(), totalNum.get(), stockNum.get(), stockTotalNum.get(), updownTypeId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|