|
@@ -234,80 +234,69 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
/**
|
|
|
* 创建订单包材
|
|
|
*/
|
|
|
- private List<OrderSkuBom> createOrderSkuBoom(List<OrderSku> orderSkuList, List<SkuSpecLink> list) {
|
|
|
-
|
|
|
+ private List<OrderSkuBom> createOrderSkuBoom(List<OrderSku> orderSkuList, Map<Long, BomSpec> bomSpecMap, List<SkuSpecLink> list) {
|
|
|
if (ObjectUtil.isEmpty(list)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
Map<Long, List<SkuSpecLink>> skuSpecLinkMap = list.stream().collect(Collectors.groupingBy(SkuSpecLink::getSkuSpecId));
|
|
|
|
|
|
- // 根据sku规格id获取bomId和bom规格id
|
|
|
- List<Long> bomSpecIdList = list.stream().map(SkuSpecLink::getBomSpecId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
- Map<Long, BomSpec> map = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIdList));
|
|
|
-
|
|
|
return orderSkuList.stream().flatMap(orderSku -> {
|
|
|
-
|
|
|
List<SkuSpecLink> skuSpecLinkList = skuSpecLinkMap.getOrDefault(orderSku.getSkuSpecId(), Collections.emptyList());
|
|
|
-
|
|
|
return skuSpecLinkList.stream().map(item -> {
|
|
|
-
|
|
|
OrderSkuBom orderSkuBom = new OrderSkuBom();
|
|
|
orderSkuBom.setId(IdWorker.getId());
|
|
|
orderSkuBom.setOrderId(orderSku.getOrderId());
|
|
|
orderSkuBom.setOrderSkuId(orderSku.getId());
|
|
|
orderSkuBom.setBomSpecId(item.getBomSpecId());
|
|
|
orderSkuBom.setQuantity(item.getQuantity());
|
|
|
-
|
|
|
- BomSpec bomSpec = map.get(item.getBomSpecId());
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(item.getBomSpecId());
|
|
|
if (bomSpec == null) {
|
|
|
orderSkuBom.setUnitPrice(BigDecimal.ZERO);
|
|
|
} else {
|
|
|
orderSkuBom.setUnitPrice(ObjectUtil.defaultIfNull(bomSpec.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
}
|
|
|
-
|
|
|
return orderSkuBom;
|
|
|
});
|
|
|
-
|
|
|
}).collect(Collectors.toList());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建订单包装
|
|
|
*/
|
|
|
- private List<OrderPackageBom> createOrderPackageBomList(List<OrderSku> orderSkuList, List<SkuSpecLink> list) {
|
|
|
-
|
|
|
+ private List<OrderPackageBom> createOrderPackageBomList(List<OrderSku> orderSkuList, Map<Long, BomSpec> bomSpecMap, List<SkuSpecLink> list) {
|
|
|
if (ObjectUtil.isEmpty(list)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
Map<Long, List<SkuSpecLink>> skuSpecLinkMap = list.stream().collect(Collectors.groupingBy(SkuSpecLink::getSkuSpecId));
|
|
|
-
|
|
|
Map<Long, OrderPackageBom> orderPackageBomMap = new HashMap<>();
|
|
|
|
|
|
// 循环订单sku规格
|
|
|
for (OrderSku orderSku : orderSkuList) {
|
|
|
-
|
|
|
List<SkuSpecLink> skuSpecLinkList = skuSpecLinkMap.get(orderSku.getSkuSpecId());
|
|
|
if (ObjectUtil.isEmpty(skuSpecLinkList)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
for (SkuSpecLink skuSpecLink : skuSpecLinkList) {
|
|
|
-
|
|
|
Long bomSpecId = skuSpecLink.getBomSpecId();
|
|
|
-
|
|
|
OrderPackageBom orderPackageBom = orderPackageBomMap.computeIfAbsent(bomSpecId, item -> {
|
|
|
OrderPackageBom tempOrderPackageBom = new OrderPackageBom();
|
|
|
tempOrderPackageBom.setOrderId(orderSku.getOrderId());
|
|
|
tempOrderPackageBom.setBomSpecId(bomSpecId);
|
|
|
tempOrderPackageBom.setQuantity(BigDecimal.ZERO);
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(bomSpecId);
|
|
|
+ if (bomSpec == null) {
|
|
|
+ tempOrderPackageBom.setCostPrice(BigDecimal.ZERO);
|
|
|
+ tempOrderPackageBom.setInternalSellingPrice(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ tempOrderPackageBom.setCostPrice(ObjectUtil.defaultIfNull(bomSpec.getCostPrice(), BigDecimal.ZERO));
|
|
|
+ tempOrderPackageBom.setInternalSellingPrice(ObjectUtil.defaultIfNull(bomSpec.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
+ }
|
|
|
return tempOrderPackageBom;
|
|
|
});
|
|
|
-
|
|
|
orderPackageBom.setQuantity(orderPackageBom.getQuantity().add(orderSku.getQuantity().multiply(skuSpecLink.getQuantity())));
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -359,11 +348,20 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
// 跳过type区分包材和快递包装
|
|
|
Map<Integer, List<SkuSpecLink>> map = list.stream().collect(Collectors.groupingBy(SkuSpecLink::getType));
|
|
|
|
|
|
+ // 根据sku规格id获取bomId和bom规格id
|
|
|
+ List<Long> bomSpecIdList = list.stream().map(SkuSpecLink::getBomSpecId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpec> bomSpecMap;
|
|
|
+ if (bomSpecIdList.size() == 0) {
|
|
|
+ bomSpecMap = Collections.emptyMap();
|
|
|
+ } else {
|
|
|
+ bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIdList));
|
|
|
+ }
|
|
|
+
|
|
|
// 获取订单sku包材
|
|
|
- List<OrderSkuBom> orderSkuBomList = createOrderSkuBoom(orderSkuList, map.get(1));
|
|
|
+ List<OrderSkuBom> orderSkuBomList = createOrderSkuBoom(orderSkuList, bomSpecMap, map.get(1));
|
|
|
|
|
|
// 获取订单sku快递包装
|
|
|
- List<OrderPackageBom> orderPackageBomList = createOrderPackageBomList(orderSkuList, map.get(2));
|
|
|
+ List<OrderPackageBom> orderPackageBomList = createOrderPackageBomList(orderSkuList, bomSpecMap, map.get(2));
|
|
|
|
|
|
context.getSaveOrderList().add(orderInfo);
|
|
|
context.getSaveOrderSkuList().addAll(orderSkuList);
|