|
|
@@ -70,10 +70,10 @@ import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.math.MathContext;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -226,11 +226,17 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
//从缓存中获得库存
|
|
|
// redisClient.basicData("all");
|
|
|
List<StockGoods> stockGoodsList = stockGoodsClient.selectStockGoodsAll();
|
|
|
-
|
|
|
+ List<DeliveryItems> reducelList = collect.stream().filter(distinctByKey(DeliveryItems::getItemId)).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
List<DeliveryItems> deliveryItemsList1 = new ArrayList<>();
|
|
|
List<StockGoods> stockGoodsList1 = new ArrayList<>();
|
|
|
- for (DeliveryItems deliveryItems : collect) {
|
|
|
+ for (DeliveryItems deliveryItems : reducelList) {
|
|
|
+ BigDecimal oldOrderQuantity = deliveryItems.getActualQuantity();
|
|
|
+ // 原单据的订货数量
|
|
|
+ BigDecimal orderQuantity = collect.stream().filter(i -> i.getItemId().equals(deliveryItems.getItemId()))
|
|
|
+ .collect(Collectors.toList()).stream().map(DeliveryItems::getActualQuantity)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ deliveryItems.setActualQuantity(orderQuantity);
|
|
|
if (deliveryItems.getItemId() == null) {
|
|
|
throw new RuntimeException("发货明细中商品id不能为空");
|
|
|
}
|
|
|
@@ -303,18 +309,6 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // todo 更新订单明细中发货数量 采购和销售可能需要调不同接口
|
|
|
- R actualQuantity = orderItemsClient.updateActualQuantity(deliveryItems.getSrcId(), deliveryItems.getArrivalQuantity(), delivery.getDeliveryType());
|
|
|
- if (!actualQuantity.isSuccess()) {
|
|
|
- throw new RuntimeException(actualQuantity.getMsg());
|
|
|
- }
|
|
|
- // todo 出口贸易确认发货修改发票重量
|
|
|
- if (delivery.getTradeType().equals(OrderTypeEnum.IMPORT.getType())) {
|
|
|
- R actualWeight = orderItemsClient.updateActualWeight(deliveryItems.getSrcId(), deliveryItems.getInvoiceWeight(), delivery.getDeliveryType());
|
|
|
- if (!actualWeight.isSuccess()) {
|
|
|
- throw new RuntimeException("更新订单发票重量出错");
|
|
|
- }
|
|
|
- }
|
|
|
//更新发货明细库存字段
|
|
|
if ("681169".equals(AuthUtil.getTenantId())) {
|
|
|
if (goods != null) {
|
|
|
@@ -349,9 +343,24 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
if (ObjectUtils.isNotNull(stock)) {
|
|
|
stockGoodsList1.add(stock);
|
|
|
}
|
|
|
+ deliveryItems.setActualQuantity(oldOrderQuantity);
|
|
|
deliveryItemsList1.add(deliveryItems);
|
|
|
// baseMapper.updateById(deliveryItems);
|
|
|
}
|
|
|
+ for (DeliveryItems deliveryItems : reducelList) {
|
|
|
+ // todo 更新订单明细中发货数量 采购和销售可能需要调不同接口
|
|
|
+ R actualQuantity = orderItemsClient.updateActualQuantity(deliveryItems.getSrcId(), deliveryItems.getArrivalQuantity(), delivery.getDeliveryType());
|
|
|
+ if (!actualQuantity.isSuccess()) {
|
|
|
+ throw new RuntimeException(actualQuantity.getMsg());
|
|
|
+ }
|
|
|
+ // todo 出口贸易确认发货修改发票重量
|
|
|
+ if (delivery.getTradeType().equals(OrderTypeEnum.IMPORT.getType())) {
|
|
|
+ R actualWeight = orderItemsClient.updateActualWeight(deliveryItems.getSrcId(), deliveryItems.getInvoiceWeight(), delivery.getDeliveryType());
|
|
|
+ if (!actualWeight.isSuccess()) {
|
|
|
+ throw new RuntimeException("更新订单发票重量出错");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (stockGoodsList1.size() > 0) {
|
|
|
R res = stockGoodsClient.saveOrUpdateBatchList(stockGoodsList1);
|
|
|
if (!res.isSuccess()) {
|
|
|
@@ -360,6 +369,7 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
}
|
|
|
this.saveOrUpdateBatch(deliveryItemsList1);
|
|
|
}
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(itemsList)) {
|
|
|
itemsList.forEach(item -> {
|
|
|
// 父级ID
|
|
|
@@ -388,6 +398,11 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
return deliveryItemsList;
|
|
|
}
|
|
|
|
|
|
+ private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
|
|
+ Set<Object> seen = ConcurrentHashMap.newKeySet();
|
|
|
+ return t -> seen.add(keyExtractor.apply(t));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 提交收货信息
|
|
|
*
|