|
@@ -83,28 +83,23 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
// 循环万里牛订单
|
|
|
for (JSONObject wlnOrder : wlnOrderList) {
|
|
|
|
|
|
- // 订单uid
|
|
|
- String wlnUid = wlnOrder.getString("uid");
|
|
|
-
|
|
|
- OrderInfo orderInfo = existOrderMap.get(wlnUid);
|
|
|
+ // 数据库中是否存在订单
|
|
|
+ OrderInfo orderInfo = existOrderMap.get(wlnOrder.getString("uid"));
|
|
|
|
|
|
+ // 不存在新增
|
|
|
if (orderInfo == null) {
|
|
|
// 创建订单
|
|
|
orderInfo = createOrder(context, wlnOrder);
|
|
|
- } else {
|
|
|
- // 修改订单
|
|
|
+ // 添加订单到上下文
|
|
|
+ addOrder(context, wlnOrder, orderInfo);
|
|
|
+ }
|
|
|
+ // 存在修改
|
|
|
+ else {
|
|
|
updateOrder(context, wlnOrder, orderInfo);
|
|
|
- continue;
|
|
|
}
|
|
|
|
|
|
- // 添加订单到上下文
|
|
|
- addOrder(context, wlnOrder, orderInfo);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- // 计算订单价格
|
|
|
- setOrderPrice(context);
|
|
|
-
|
|
|
// 保存或更新数据
|
|
|
saveOrUpdateOrder(context);
|
|
|
|
|
@@ -124,7 +119,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderInfo.setTag("0");
|
|
|
orderInfo.setSettlementStatus(1);
|
|
|
|
|
|
- orderInfo.setWlnStorageCode(context.getWarehouseCode());
|
|
|
+ orderInfo.setWlnStorageCode(wlnOrder.getString("storage_code"));
|
|
|
orderInfo.setWlnUid(wlnOrder.getString("uid"));
|
|
|
orderInfo.setCode(wlnOrder.getString("tp_tid"));
|
|
|
orderInfo.setWlnCode(wlnOrder.getString("trade_no"));
|
|
@@ -144,6 +139,14 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderInfo.setDeliveryTime(DateUtil.offsetDay(orderInfo.getWlnCreateTime(), 1));
|
|
|
orderInfo.setRemark(wlnOrder.getString("remark"));
|
|
|
|
|
|
+ orderInfo.setTotalAmount(BigDecimal.ZERO);
|
|
|
+ orderInfo.setProductTotalAmount(BigDecimal.ZERO);
|
|
|
+ orderInfo.setCustomProcessingFee(BigDecimal.ZERO);
|
|
|
+ orderInfo.setLssueFee(BigDecimal.ZERO);
|
|
|
+ orderInfo.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
+ orderInfo.setPackingLabor(BigDecimal.ZERO);
|
|
|
+ orderInfo.setPackagingMaterialCost(BigDecimal.ZERO);
|
|
|
+
|
|
|
// 赋值订单异常类型
|
|
|
orderInfo.setExceptionType(OrderExceptionTypeEnum.NORMAL.getKey().toString());
|
|
|
if (orderInfo.getWlnStatus() == 10) {
|
|
@@ -174,14 +177,15 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
return orderInfo;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 修改订单
|
|
|
*/
|
|
|
private void updateOrder(OrderContext context, JSONObject wlnOrder, OrderInfo orderInfo) {
|
|
|
+ Department department = context.getDepartment();
|
|
|
+ Map<Long, List<OrderSku>> existOrderSkuMap = context.getExistOrderSkuMap();
|
|
|
List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
|
|
|
- orderInfo.setWlnStorageCode(context.getWarehouseCode());
|
|
|
+ orderInfo.setWlnStorageCode(wlnOrder.getString("storage_code"));
|
|
|
orderInfo.setWlnUid(wlnOrder.getString("uid"));
|
|
|
orderInfo.setCode(wlnOrder.getString("tp_tid"));
|
|
|
orderInfo.setWlnCode(wlnOrder.getString("trade_no"));
|
|
@@ -212,35 +216,32 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
addExceptionType(orderInfo, OrderExceptionTypeEnum.ORDER_EXCEPTION_HANDLING);
|
|
|
}
|
|
|
|
|
|
- // 事业部id
|
|
|
- Department department = context.getDepartment();
|
|
|
+ // 事业部
|
|
|
if (department == null) {
|
|
|
addExceptionType(orderInfo, OrderExceptionTypeEnum.UNKNOWN_WAREHOUSE);
|
|
|
} else {
|
|
|
orderInfo.setDepartmentId(department.getId());
|
|
|
}
|
|
|
|
|
|
- Long orderInfoId = orderInfo.getId();
|
|
|
-
|
|
|
- List<OrderSku> list = orderSkuService.list(q -> q.eq(OrderSku::getOrderId, orderInfoId));
|
|
|
+ List<OrderSku> orderSkuList = new ArrayList<>(existOrderSkuMap.getOrDefault(orderInfo.getId(), Collections.emptyList()));
|
|
|
List<JSONObject> wlnOrderSkuList = wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class);
|
|
|
|
|
|
- if (list.size() != wlnOrderSkuList.size()) {
|
|
|
+ if (orderSkuList.size() != wlnOrderSkuList.size()) {
|
|
|
addExceptionType(orderInfo, OrderExceptionTypeEnum.SKU_UPDATE);
|
|
|
} else {
|
|
|
for (JSONObject wlnOrderSku : wlnOrderSkuList) {
|
|
|
- for (OrderSku orderSku : list) {
|
|
|
+ for (OrderSku orderSku : orderSkuList) {
|
|
|
if (Objects.equals(wlnOrderSku.getString("sys_goods_uid"), orderSku.getWlnSkuId())
|
|
|
&& Objects.equals(wlnOrderSku.getString("sys_spec_uid"), orderSku.getWlnSkuSpecId())
|
|
|
&& Objects.equals(wlnOrderSku.getString("oln_sku_name"), orderSku.getWlnSkuName())
|
|
|
&& Objects.equals(wlnOrderSku.getBigDecimal("size"), orderSku.getQuantity())) {
|
|
|
- list.remove(orderSku);
|
|
|
+ orderSkuList.remove(orderSku);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (list.size() != 0) {
|
|
|
+ if (orderSkuList.size() != 0) {
|
|
|
addExceptionType(orderInfo, OrderExceptionTypeEnum.SKU_UPDATE);
|
|
|
}
|
|
|
}
|
|
@@ -251,30 +252,28 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
/**
|
|
|
* 创建订单包材
|
|
|
*/
|
|
|
- private List<OrderSkuBom> createOrderSkuBoom(OrderContext context, List<OrderSku> orderSkuList) {
|
|
|
+ private List<OrderSkuBom> createOrderSkuBoom(OrderContext context, OrderSku orderSku) {
|
|
|
Map<Long, Map<Integer, List<SkuSpecLink>>> linkBomSpecMap = context.getSkuSpecLinkBomSpecMap();
|
|
|
Map<Long, BomSpecBo> bomBoMap = context.getBomSpecBoMap();
|
|
|
|
|
|
- return orderSkuList.stream().flatMap(orderSku -> {
|
|
|
- Map<Integer, List<SkuSpecLink>> map = linkBomSpecMap.getOrDefault(orderSku.getSkuSpecId(), Collections.emptyMap());
|
|
|
- List<SkuSpecLink> skuSpecLinkList = map.getOrDefault(1, 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());
|
|
|
- BomSpecBo bomSpecBo = bomBoMap.get(item.getBomSpecId());
|
|
|
- if (bomSpecBo == null) {
|
|
|
- orderSkuBom.setUnitPrice(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- orderSkuBom.setUnitPrice(bomSpecBo.getInternalSellingPrice());
|
|
|
- }
|
|
|
- return orderSkuBom;
|
|
|
- });
|
|
|
-
|
|
|
+ Map<Integer, List<SkuSpecLink>> map = linkBomSpecMap.getOrDefault(orderSku.getSkuSpecId(), Collections.emptyMap());
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = map.getOrDefault(1, 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());
|
|
|
+ BomSpecBo bomSpecBo = bomBoMap.get(orderSkuBom.getBomSpecId());
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ orderSkuBom.setUnitPrice(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ orderSkuBom.setUnitPrice(bomSpecBo.getInternalSellingPrice());
|
|
|
+ orderSku.setPackagingMaterialCost(bomSpecBo.getInternalSellingPrice().multiply(item.getQuantity()));
|
|
|
+ }
|
|
|
+ return orderSkuBom;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
}
|
|
@@ -327,38 +326,44 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
Map<String, SkuSpec> skuSpecMap = context.getSkuSpecMap();
|
|
|
|
|
|
List<OrderSku> orderSkuList = new ArrayList<>();
|
|
|
+ List<OrderSkuBom> orderSkuBomList = new ArrayList<>();
|
|
|
|
|
|
// 创建订单sku
|
|
|
for (JSONObject wlnOrderSku : wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class)) {
|
|
|
- // sku规格信息
|
|
|
+
|
|
|
+ // 通过万里牛sku规格uid找到sku规格
|
|
|
SkuSpec skuSpec = skuSpecMap.get(wlnOrderSku.getString("sys_spec_uid"));
|
|
|
if (skuSpec == null) {
|
|
|
addExceptionType(orderInfo, OrderExceptionTypeEnum.UNKNOWN_SKU_SPEC);
|
|
|
} else if (skuSpec.getBomSpecId() == null) {
|
|
|
addExceptionType(orderInfo, OrderExceptionTypeEnum.UNKNOWN_BOM_SPEC);
|
|
|
}
|
|
|
+
|
|
|
// 创建订单sku
|
|
|
- OrderSku orderSku = createOrderSku(wlnOrderSku, orderInfo, skuSpec);
|
|
|
+ OrderSku orderSku = createOrderSku(context, wlnOrderSku, orderInfo, skuSpec);
|
|
|
+
|
|
|
+ // 获取订单sku包材
|
|
|
+ List<OrderSkuBom> tempOrderSkuBomList = createOrderSkuBoom(context, orderSku);
|
|
|
+
|
|
|
+ // 添加订单金额
|
|
|
+ addOrderInfoPrice(orderInfo, orderSku);
|
|
|
+
|
|
|
orderSkuList.add(orderSku);
|
|
|
+ orderSkuBomList.addAll(tempOrderSkuBomList);
|
|
|
}
|
|
|
|
|
|
- // 获取订单sku包材
|
|
|
- List<OrderSkuBom> orderSkuBomList = createOrderSkuBoom(context, orderSkuList);
|
|
|
-
|
|
|
- // 获取订单sku快递包装
|
|
|
List<OrderPackageBom> orderPackageBomList = createOrderPackageBomList(context, orderSkuList);
|
|
|
|
|
|
context.getSaveOrderList().add(orderInfo);
|
|
|
context.getSaveOrderSkuList().addAll(orderSkuList);
|
|
|
context.getSaveOrderSkuBomList().addAll(orderSkuBomList);
|
|
|
context.getOrderPackageBomList().addAll(orderPackageBomList);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建订单sku
|
|
|
*/
|
|
|
- private OrderSku createOrderSku(JSONObject wlnOrderSku, OrderInfo orderInfo, SkuSpec skuSpec) {
|
|
|
+ private OrderSku createOrderSku(OrderContext context, JSONObject wlnOrderSku, OrderInfo orderInfo, SkuSpec skuSpec) {
|
|
|
OrderSku orderSku = new OrderSku();
|
|
|
orderSku.setId(IdWorker.getId());
|
|
|
orderSku.setWlnSkuId(wlnOrderSku.getString("sys_goods_uid"));
|
|
@@ -369,121 +374,50 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderSku.setPrintType(1);
|
|
|
orderSku.setStockPreparationStatus(StatusConstant.NO);
|
|
|
|
|
|
+ orderSku.setUnitPrice(BigDecimal.ZERO);
|
|
|
+ orderSku.setCustomProcessingFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setLssueFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setPackingLabor(BigDecimal.ZERO);
|
|
|
+ orderSku.setPackagingMaterialCost(BigDecimal.ZERO);
|
|
|
+
|
|
|
if (skuSpec != null) {
|
|
|
orderSku.setSkuId(skuSpec.getSkuId());
|
|
|
orderSku.setSkuSpecId(skuSpec.getId());
|
|
|
orderSku.setBomSpecId(skuSpec.getBomSpecId());
|
|
|
+ assignedOrderSkuPrice(context, orderSku, skuSpec);
|
|
|
}
|
|
|
return orderSku;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 赋值订单价格
|
|
|
+ * 赋值订单sku价格
|
|
|
*/
|
|
|
- private void setOrderPrice(OrderContext context) {
|
|
|
-
|
|
|
- List<OrderInfo> saveOrderList = context.getSaveOrderList();
|
|
|
- List<OrderSku> saveOrderSkuList = context.getSaveOrderSkuList();
|
|
|
- List<OrderSkuBom> saveOrderSkuBomList = context.getSaveOrderSkuBomList();
|
|
|
- Map<String, SkuSpec> skuSpecMap = context.getSkuSpecMap();
|
|
|
+ private void assignedOrderSkuPrice(OrderContext context, OrderSku orderSku, SkuSpec skuSpec) {
|
|
|
+ BomSpecBo bomSpecBo = context.getBomSpecBoMap().get(skuSpec.getBomSpecId());
|
|
|
List<PriceBillingStandardDetail> priceBillingStandardDetailList = context.getPriceBillingStandardList();
|
|
|
- Map<Long, BomSpecBo> bomBoMap = context.getBomSpecBoMap();
|
|
|
|
|
|
- if (saveOrderList.size() == 0) {
|
|
|
+ // 订单明细sku没绑定bom,不赋值价格
|
|
|
+ if (bomSpecBo == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 订单明细
|
|
|
- Map<Long, List<OrderSku>> orderSkuGroup = saveOrderSkuList.stream().collect(Collectors.groupingBy(OrderSku::getOrderId));
|
|
|
-
|
|
|
- for (OrderInfo orderInfo : saveOrderList) {
|
|
|
-
|
|
|
- orderInfo.setTotalAmount(BigDecimal.ZERO);
|
|
|
- orderInfo.setProductTotalAmount(BigDecimal.ZERO);
|
|
|
- orderInfo.setCustomProcessingFee(BigDecimal.ZERO);
|
|
|
- orderInfo.setLssueFee(BigDecimal.ZERO);
|
|
|
- orderInfo.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
- orderInfo.setPackingLabor(BigDecimal.ZERO);
|
|
|
- orderInfo.setPackagingMaterialCost(BigDecimal.ZERO);
|
|
|
-
|
|
|
- // 订单明细
|
|
|
- List<OrderSku> itemOrderSkuList = orderSkuGroup.get(orderInfo.getId());
|
|
|
-
|
|
|
- for (OrderSku orderSku : itemOrderSkuList) {
|
|
|
-
|
|
|
- // 赋值单价
|
|
|
- assignedUnitPrice(orderSku, bomBoMap);
|
|
|
+ // 设置单价
|
|
|
+ orderSku.setUnitPrice(bomSpecBo.getInternalSellingPrice());
|
|
|
|
|
|
- // 赋值包材费
|
|
|
- assignedPackagingMaterialCost(orderSku, saveOrderSkuBomList);
|
|
|
-
|
|
|
- // 赋值其他价格
|
|
|
- assignedOtherPrice(orderSku, bomBoMap, priceBillingStandardDetailList, skuSpecMap);
|
|
|
-
|
|
|
- // 添加订单金额
|
|
|
- addOrderInfoPrice(orderInfo, orderSku);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 赋值单价
|
|
|
- */
|
|
|
- private void assignedUnitPrice(OrderSku orderSku, Map<Long, BomSpecBo> bomBoMap) {
|
|
|
- BomSpecBo bomSpecBo = bomBoMap.get(orderSku.getBomSpecId());
|
|
|
- if (bomSpecBo != null) {
|
|
|
- orderSku.setUnitPrice(ObjectUtil.defaultIfNull(bomSpecBo.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
- } else {
|
|
|
- orderSku.setUnitPrice(BigDecimal.ZERO);
|
|
|
+ // 如果bom规格不为主材,不赋值价格
|
|
|
+ if (ObjectUtil.notEqual(bomSpecBo.getClassifyParentId(), 1L)) {
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 赋值包材费
|
|
|
- */
|
|
|
- private void assignedPackagingMaterialCost(OrderSku orderSku, List<OrderSkuBom> saveOrderSkuBomList) {
|
|
|
- BigDecimal packagingMaterialCost = saveOrderSkuBomList.stream()
|
|
|
- .filter(item -> Objects.equals(item.getOrderSkuId(), orderSku.getId()))
|
|
|
- .map(item -> item.getUnitPrice().multiply(item.getQuantity()))
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
- orderSku.setPackagingMaterialCost(packagingMaterialCost);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 赋值其他价格
|
|
|
- */
|
|
|
- private void assignedOtherPrice(OrderSku orderSku, Map<Long, BomSpecBo> bomBoMap,
|
|
|
- List<PriceBillingStandardDetail> priceBillingStandardDetailList,
|
|
|
- Map<String, SkuSpec> skuSpecMap) {
|
|
|
-
|
|
|
- orderSku.setCustomProcessingFee(BigDecimal.ZERO);
|
|
|
- orderSku.setLssueFee(BigDecimal.ZERO);
|
|
|
- orderSku.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
- orderSku.setPackingLabor(BigDecimal.ZERO);
|
|
|
|
|
|
// 报价规则列表
|
|
|
if (ObjectUtil.isEmpty(priceBillingStandardDetailList)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 没绑定bom规格,不赋值价格
|
|
|
- BomSpecBo bomSpecBo = bomBoMap.get(orderSku.getBomSpecId());
|
|
|
- if (bomSpecBo == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 如果bom规格不为主材,不赋值价格
|
|
|
- if (ObjectUtil.notEqual(bomSpecBo.getClassifyParentId(), 1L)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
for (PriceBillingStandardDetail priceBillingStandardDetail : priceBillingStandardDetailList) {
|
|
|
-
|
|
|
String chargeItem = priceBillingStandardDetail.getChargeItem();
|
|
|
- BigDecimal chargePrice = ObjectUtil.defaultIfNull(priceBillingStandardDetail.getChargePrice(), BigDecimal.ZERO);
|
|
|
+ BigDecimal chargePrice = priceBillingStandardDetail.getChargePrice();
|
|
|
|
|
|
switch (chargeItem) {
|
|
|
case "40":
|
|
@@ -496,9 +430,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderSku.setDeliveryMaterialsFee(chargePrice);
|
|
|
break;
|
|
|
default:
|
|
|
- SkuSpec skuSpec = skuSpecMap.get(orderSku.getWlnSkuSpecId());
|
|
|
- if (skuSpec != null
|
|
|
- && Objects.equals(chargeItem, skuSpec.getMachinedPanel())
|
|
|
+ if (Objects.equals(chargeItem, skuSpec.getMachinedPanel())
|
|
|
&& orderSku.getQuantity().compareTo(priceBillingStandardDetail.getSectionMin()) >= 0
|
|
|
&& orderSku.getQuantity().compareTo(priceBillingStandardDetail.getSectionMax()) < 0) {
|
|
|
orderSku.setCustomProcessingType(chargeItem);
|