|
@@ -0,0 +1,854 @@
|
|
|
+package com.sd.wln.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictCommonData;
|
|
|
+import com.fjhx.tenant.service.dict.DictCommonDataService;
|
|
|
+import com.ruoyi.common.constant.StatusConstant;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.framework.mybatis.holder.LogicHolder;
|
|
|
+import com.sd.business.entity.artwork.po.ArtworkLibrary;
|
|
|
+import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
+import com.sd.business.entity.department.po.Department;
|
|
|
+import com.sd.business.entity.order.enums.OrderClassifyEnum;
|
|
|
+import com.sd.business.entity.order.enums.OrderExceptionTypeEnum;
|
|
|
+import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
+import com.sd.business.entity.order.po.OrderInfo;
|
|
|
+import com.sd.business.entity.order.po.OrderPackageBom;
|
|
|
+import com.sd.business.entity.order.po.OrderSku;
|
|
|
+import com.sd.business.entity.order.po.OrderSkuBom;
|
|
|
+import com.sd.business.entity.order.po.OrderSkuProductionCost;
|
|
|
+import com.sd.business.entity.price.po.PriceBillingStandardDetail;
|
|
|
+import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
+import com.sd.business.entity.sku.po.SkuSpecLink;
|
|
|
+import com.sd.business.entity.statement.dto.StatementOfAccountDto;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.inventory.InventoryFinishedService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
+import com.sd.business.service.order.OrderInfoService;
|
|
|
+import com.sd.business.service.order.OrderPackageBomService;
|
|
|
+import com.sd.business.service.order.OrderSkuBomService;
|
|
|
+import com.sd.business.service.order.OrderSkuProductionCostService;
|
|
|
+import com.sd.business.service.order.OrderSkuService;
|
|
|
+import com.sd.business.service.statement.StatementOfAccountService;
|
|
|
+import com.sd.framework.util.TransactionUtil;
|
|
|
+import com.sd.wln.context.OrderContext;
|
|
|
+import com.sd.wln.service.WlnOrderService;
|
|
|
+import com.sd.wln.util.WlnUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DictCommonDataService dictCommonDataService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderInfoService orderInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuService orderSkuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuBomService orderSkuBomService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderPackageBomService orderPackageBomService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StatementOfAccountService statementOfAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuProductionCostService orderSkuProductionCostService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryFinishedService inventoryFinishedService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncOrder() {
|
|
|
+
|
|
|
+ List<DictCommonData> warehouseCodeList = dictCommonDataService.list(q -> q.eq(DictCommonData::getDictCode, "warehouse_code"));
|
|
|
+
|
|
|
+ for (DictCommonData dictCommonData : warehouseCodeList) {
|
|
|
+
|
|
|
+ // 获取事业部编号
|
|
|
+ String warehouseCode = dictCommonData.getDictValue();
|
|
|
+
|
|
|
+ // 查询事业部万里牛订单
|
|
|
+ List<JSONObject> wlnOrderList = getWlnOrderList(warehouseCode);
|
|
|
+
|
|
|
+ // 万里牛订单数量若为0,结束同步任务
|
|
|
+ if (ObjectUtil.isEmpty(wlnOrderList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化订单上下文
|
|
|
+ OrderContext context = new OrderContext(warehouseCode, wlnOrderList);
|
|
|
+
|
|
|
+ // 获取已存在订单
|
|
|
+ Map<String, OrderInfo> existOrderMap = context.getExistOrderMap();
|
|
|
+
|
|
|
+ // 循环万里牛订单
|
|
|
+ for (JSONObject wlnOrder : wlnOrderList) {
|
|
|
+
|
|
|
+ // 数据库中是否存在订单
|
|
|
+ OrderInfo orderInfo = existOrderMap.get(wlnOrder.getString("uid"));
|
|
|
+
|
|
|
+ // 不存在新增
|
|
|
+ if (orderInfo == null) {
|
|
|
+
|
|
|
+ // 9月1号之前的订单不同步
|
|
|
+ Date printTime = wlnOrder.getDate("print_time");
|
|
|
+ if (printTime != null && printTime.before(DateUtil.parse("2023-09-01 00:00:00"))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 审核通过之前或预售状态的订单不同步
|
|
|
+ Integer processStatus = wlnOrder.getInteger("process_status");
|
|
|
+ if (processStatus < 1 || processStatus == 14) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建订单
|
|
|
+ orderInfo = createOrder(context, wlnOrder);
|
|
|
+
|
|
|
+ // 添加订单到上下文
|
|
|
+ addOrder(context, wlnOrder, orderInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 存在修改
|
|
|
+ else {
|
|
|
+ updateOrder(context, wlnOrder, orderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存新增、修改的订单
|
|
|
+ try {
|
|
|
+ TransactionUtil.execute(() -> {
|
|
|
+ // 保存或更新数据
|
|
|
+ saveOrUpdateOrder(context);
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步订单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public OrderInfo createOrder(OrderContext context, JSONObject wlnOrder) {
|
|
|
+
|
|
|
+ OrderInfo orderInfo = new OrderInfo();
|
|
|
+ orderInfo.setId(IdWorker.getId());
|
|
|
+ orderInfo.setSource(2);
|
|
|
+ orderInfo.setTaxRate(new BigDecimal("10.00"));
|
|
|
+ orderInfo.setTag("0");
|
|
|
+ orderInfo.setSettlementStatus(1);
|
|
|
+
|
|
|
+ orderInfo.setWlnStorageCode(wlnOrder.getString("storage_code"));
|
|
|
+ orderInfo.setWlnUid(wlnOrder.getString("uid"));
|
|
|
+ orderInfo.setCode(wlnOrder.getString("tp_tid"));
|
|
|
+ orderInfo.setWlnCode(wlnOrder.getString("trade_no"));
|
|
|
+ orderInfo.setWlnStatus(wlnOrder.getInteger("process_status"));
|
|
|
+ orderInfo.setWlnCreateTime(wlnOrder.getDate("create_time"));
|
|
|
+ orderInfo.setWlnModifyTime(wlnOrder.getDate("modify_time"));
|
|
|
+ orderInfo.setWlnModifyTimestamp(wlnOrder.getLong("modify_time"));
|
|
|
+ orderInfo.setWlnApproveTime(wlnOrder.getDate("approve_time"));
|
|
|
+ orderInfo.setWlnPrintTime(wlnOrder.getDate("print_time"));
|
|
|
+ orderInfo.setSourcePlatform(wlnOrder.getString("source_platform"));
|
|
|
+ orderInfo.setShopName(wlnOrder.getString("shop_name"));
|
|
|
+ orderInfo.setProvince(wlnOrder.getString("province"));
|
|
|
+ orderInfo.setCity(wlnOrder.getString("city"));
|
|
|
+ orderInfo.setCounty(wlnOrder.getString("district"));
|
|
|
+ orderInfo.setDetailedAddress(wlnOrder.getString("address"));
|
|
|
+ orderInfo.setPostcode(wlnOrder.getString("zip"));
|
|
|
+ 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.setManagementFee(BigDecimal.ZERO);
|
|
|
+ orderInfo.setPackagingMaterialCost(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 赋值订单异常类型
|
|
|
+ orderInfo.setExceptionType(OrderExceptionTypeEnum.NORMAL.getKey().toString());
|
|
|
+ if (orderInfo.getWlnStatus() == 10) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.ORDER_CLOSURE);
|
|
|
+ }
|
|
|
+ if (orderInfo.getWlnStatus() == 11) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.ORDER_ABORT);
|
|
|
+ }
|
|
|
+ if (orderInfo.getWlnStatus() == 12) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.ORDER_EXCEPTION_HANDLING);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 事业部id
|
|
|
+ Department department = context.getDepartment();
|
|
|
+ if (department == null) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.UNKNOWN_WAREHOUSE);
|
|
|
+ } else {
|
|
|
+ orderInfo.setDepartmentId(department.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单进度
|
|
|
+ if (department != null && Objects.equals(department.getOrderMode(), "2") && orderInfo.getWlnStatus() != 1) {
|
|
|
+ orderInfo.setStatus(OrderStatusEnum.STOCK_PREPARATION.getKey());
|
|
|
+ } else {
|
|
|
+ orderInfo.setStatus(OrderStatusEnum.UNDER_REVIEW.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ orderInfo.setLockStorage(StatusConstant.NO);
|
|
|
+
|
|
|
+ return orderInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改订单
|
|
|
+ */
|
|
|
+ public void updateOrder(OrderContext context, JSONObject wlnOrder, OrderInfo orderInfo) {
|
|
|
+
|
|
|
+ // 已删除、生产中、生产完成、已发货的订单跳过修改
|
|
|
+ if (Objects.equals(orderInfo.getDelFlag(), StatusConstant.DELETED)
|
|
|
+ || Objects.equals(orderInfo.getStatus(), OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
+ || Objects.equals(orderInfo.getStatus(), OrderStatusEnum.COMPLETION_PRODUCTION.getKey())
|
|
|
+ || Objects.equals(orderInfo.getStatus(), OrderStatusEnum.HAVE_BEEN_SHIPPED.getKey())) {
|
|
|
+ // 万里牛状态异常:订单关闭的订单类型修改为无理由并生成对账单
|
|
|
+ if (Objects.equals(orderInfo.getStatus(), OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
+ && wlnOrder.getInteger("process_status") == 10
|
|
|
+ && ObjectUtil.notEqual(orderInfo.getClassify(), OrderClassifyEnum.NO_REASON_ORDER.getKey())) {
|
|
|
+ List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
+ List<OrderInfo> saveStatementOrderList = context.getSaveStatementOrderList();
|
|
|
+ orderInfo.setWlnStatus(wlnOrder.getInteger("process_status"));
|
|
|
+ orderInfo.setWlnModifyTime(wlnOrder.getDate("modify_time"));
|
|
|
+ orderInfo.setWlnModifyTimestamp(wlnOrder.getLong("modify_time"));
|
|
|
+ orderInfo.setStatus(OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
|
|
|
+ orderInfo.setClassify(OrderClassifyEnum.NO_REASON_ORDER.getKey());
|
|
|
+ orderInfo.setShippingTime(new Date());
|
|
|
+
|
|
|
+ // 保存对账单列表
|
|
|
+ saveStatementOrderList.add(orderInfo);
|
|
|
+ updateOrderList.add(orderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打回审核真删订单
|
|
|
+ if (wlnOrder.getInteger("process_status") == 0) {
|
|
|
+ LogicHolder.setLogicHolder(true);
|
|
|
+ orderInfoService.deleteAndStore(orderInfo.getId());
|
|
|
+ LogicHolder.clear();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Department department = context.getDepartment();
|
|
|
+ Map<Long, List<OrderSku>> existOrderSkuMap = context.getExistOrderSkuMap();
|
|
|
+ List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
+
|
|
|
+ orderInfo.setWlnStorageCode(wlnOrder.getString("storage_code"));
|
|
|
+ orderInfo.setWlnUid(wlnOrder.getString("uid"));
|
|
|
+ orderInfo.setCode(wlnOrder.getString("tp_tid"));
|
|
|
+ orderInfo.setWlnCode(wlnOrder.getString("trade_no"));
|
|
|
+ orderInfo.setWlnStatus(wlnOrder.getInteger("process_status"));
|
|
|
+ orderInfo.setWlnCreateTime(wlnOrder.getDate("create_time"));
|
|
|
+ orderInfo.setWlnModifyTime(wlnOrder.getDate("modify_time"));
|
|
|
+ orderInfo.setWlnModifyTimestamp(wlnOrder.getLong("modify_time"));
|
|
|
+ orderInfo.setWlnApproveTime(wlnOrder.getDate("approve_time"));
|
|
|
+ orderInfo.setWlnPrintTime(wlnOrder.getDate("print_time"));
|
|
|
+ orderInfo.setSourcePlatform(wlnOrder.getString("source_platform"));
|
|
|
+ orderInfo.setShopName(wlnOrder.getString("shop_name"));
|
|
|
+ orderInfo.setProvince(wlnOrder.getString("province"));
|
|
|
+ orderInfo.setCity(wlnOrder.getString("city"));
|
|
|
+ orderInfo.setCounty(wlnOrder.getString("district"));
|
|
|
+ orderInfo.setDetailedAddress(wlnOrder.getString("address"));
|
|
|
+ orderInfo.setPostcode(wlnOrder.getString("zip"));
|
|
|
+ orderInfo.setDeliveryTime(DateUtil.offsetDay(orderInfo.getWlnCreateTime(), 1));
|
|
|
+ orderInfo.setRemark(wlnOrder.getString("remark"));
|
|
|
+
|
|
|
+ // 赋值订单异常类型
|
|
|
+ if (orderInfo.getWlnStatus() == 10) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.ORDER_CLOSURE);
|
|
|
+ }
|
|
|
+ if (orderInfo.getWlnStatus() == 11) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.ORDER_ABORT);
|
|
|
+ }
|
|
|
+ if (orderInfo.getWlnStatus() == 12) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.ORDER_EXCEPTION_HANDLING);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 事业部
|
|
|
+ if (department == null) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.UNKNOWN_WAREHOUSE);
|
|
|
+ } else {
|
|
|
+ orderInfo.setDepartmentId(department.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = new ArrayList<>(existOrderSkuMap.getOrDefault(orderInfo.getId(), Collections.emptyList()));
|
|
|
+ List<JSONObject> wlnOrderSkuList = wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class);
|
|
|
+
|
|
|
+ if (orderSkuList.size() != wlnOrderSkuList.size()) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.SKU_UPDATE);
|
|
|
+ } else {
|
|
|
+ for (JSONObject wlnOrderSku : wlnOrderSkuList) {
|
|
|
+ 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())
|
|
|
+ && wlnOrderSku.getBigDecimal("size").compareTo(orderSku.getQuantity()) == 0) {
|
|
|
+ orderSkuList.remove(orderSku);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!orderSkuList.isEmpty()) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.SKU_UPDATE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 万里牛订单状态不为1时,订单状态修改为备料中
|
|
|
+ if (department != null
|
|
|
+ && Objects.equals(department.getOrderMode(), "2")
|
|
|
+ && orderInfo.getWlnStatus() != 1
|
|
|
+ && Objects.equals(orderInfo.getStatus(), OrderStatusEnum.UNDER_REVIEW.getKey())) {
|
|
|
+ orderInfo.setStatus(OrderStatusEnum.STOCK_PREPARATION.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ updateOrderList.add(orderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单包材
|
|
|
+ */
|
|
|
+ private List<OrderSkuBom> createOrderSkuBoom(OrderContext context, OrderSku orderSku) {
|
|
|
+ Map<Long, Map<Integer, List<SkuSpecLink>>> linkBomSpecMap = context.getSkuSpecLinkBomSpecMap();
|
|
|
+ Map<Long, BomSpecBo> bomBoMap = context.getBomSpecBoMap();
|
|
|
+
|
|
|
+ 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(orderSku.getPackagingMaterialCost()
|
|
|
+ .add(bomSpecBo.getInternalSellingPrice().multiply(item.getQuantity())));
|
|
|
+ }
|
|
|
+ return orderSkuBom;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单产品成本
|
|
|
+ */
|
|
|
+ private OrderSkuProductionCost createOrderSkuProductionCostList(OrderSku orderSku, List<OrderSkuBom> orderSkuBomList) {
|
|
|
+ OrderSkuProductionCost orderSkuProductionCost = new OrderSkuProductionCost();
|
|
|
+ orderSkuProductionCost.setOrderId(orderSku.getOrderId());
|
|
|
+ orderSkuProductionCost.setOrderSkuId(orderSku.getId());
|
|
|
+
|
|
|
+ // 材料成本
|
|
|
+ orderSkuProductionCost.setMaterialCost(orderSku.getUnitPrice().multiply(orderSku.getQuantity()));
|
|
|
+
|
|
|
+ // 辅料成本暂时没有默认为零
|
|
|
+ orderSkuProductionCost.setAuxiliaryMaterialCost(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 产品包材成本
|
|
|
+ if (orderSkuBomList == null) {
|
|
|
+ orderSkuBomList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ BigDecimal productPackagingMaterialCost = orderSkuBomList.stream()
|
|
|
+ .map(orderSkuBom -> orderSkuBom.getQuantity().multiply(orderSkuBom.getUnitPrice()).multiply(orderSku.getQuantity()))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ orderSkuProductionCost.setProductPackagingMaterialCost(productPackagingMaterialCost);
|
|
|
+
|
|
|
+ // 物流包材成本
|
|
|
+ BigDecimal logisticsPackagingMaterialCost = orderSku.getDeliveryMaterialsFee().multiply(orderSku.getQuantity());
|
|
|
+ orderSkuProductionCost.setLogisticsPackagingMaterialCost(logisticsPackagingMaterialCost);
|
|
|
+
|
|
|
+ // 成本总金额
|
|
|
+ orderSkuProductionCost.setTotalAmount(orderSkuProductionCost.getMaterialCost()
|
|
|
+ .add(orderSkuProductionCost.getAuxiliaryMaterialCost())
|
|
|
+ .add(orderSkuProductionCost.getProductPackagingMaterialCost())
|
|
|
+ .add(orderSkuProductionCost.getLogisticsPackagingMaterialCost()));
|
|
|
+
|
|
|
+ return orderSkuProductionCost;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单包装
|
|
|
+ */
|
|
|
+ private List<OrderPackageBom> createOrderPackageBomList(OrderContext context, OrderSku orderSku) {
|
|
|
+ Map<Long, Map<Integer, List<SkuSpecLink>>> linkBomSpecMap = context.getSkuSpecLinkBomSpecMap();
|
|
|
+ Map<Long, BomSpecBo> bomBoMap = context.getBomSpecBoMap();
|
|
|
+
|
|
|
+ List<OrderPackageBom> orderPackageBomList = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<Integer, List<SkuSpecLink>> map = linkBomSpecMap.getOrDefault(orderSku.getSkuSpecId(), Collections.emptyMap());
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = map.getOrDefault(2, Collections.emptyList());
|
|
|
+
|
|
|
+ for (SkuSpecLink skuSpecLink : skuSpecLinkList) {
|
|
|
+ Long bomSpecId = skuSpecLink.getBomSpecId();
|
|
|
+
|
|
|
+ OrderPackageBom orderPackageBom = new OrderPackageBom();
|
|
|
+ orderPackageBom.setOrderId(orderSku.getOrderId());
|
|
|
+ orderPackageBom.setBomSpecId(bomSpecId);
|
|
|
+ BomSpecBo bomSpecBo = bomBoMap.get(bomSpecId);
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ orderPackageBom.setCostPrice(BigDecimal.ZERO);
|
|
|
+ orderPackageBom.setInternalSellingPrice(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ orderPackageBom.setCostPrice(bomSpecBo.getCostPrice());
|
|
|
+ orderPackageBom.setInternalSellingPrice(bomSpecBo.getInternalSellingPrice());
|
|
|
+ }
|
|
|
+ orderPackageBom.setQuantity(orderSku.getQuantity().multiply(skuSpecLink.getQuantity()));
|
|
|
+
|
|
|
+ // 计算订单sku的快递包材费
|
|
|
+ BigDecimal deliveryMaterialsFee = orderPackageBom.getInternalSellingPrice().multiply(skuSpecLink.getQuantity());
|
|
|
+ orderSku.setDeliveryMaterialsFee(orderSku.getDeliveryMaterialsFee().add(deliveryMaterialsFee));
|
|
|
+
|
|
|
+ orderPackageBomList.add(orderPackageBom);
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderPackageBomList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加订单到上下文
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addOrder(OrderContext context, JSONObject wlnOrder, OrderInfo orderInfo) {
|
|
|
+ Map<String, SkuSpec> skuSpecMap = context.getSkuSpecMap();
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = new ArrayList<>();
|
|
|
+ List<OrderSkuProductionCost> orderSkuProductionCostList = new ArrayList<>();
|
|
|
+ List<OrderSkuBom> orderSkuBomList = new ArrayList<>();
|
|
|
+ List<OrderPackageBom> orderPackageBomList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 创建订单sku
|
|
|
+ for (JSONObject wlnOrderSku : wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class)) {
|
|
|
+
|
|
|
+ // 通过万里牛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(context, wlnOrderSku, orderInfo, skuSpec);
|
|
|
+
|
|
|
+ // 获取订单sku包材
|
|
|
+ List<OrderSkuBom> tempOrderSkuBomList = createOrderSkuBoom(context, orderSku);
|
|
|
+
|
|
|
+ // 获取订单sku快递包材
|
|
|
+ List<OrderPackageBom> tempOrderPackageBomList = createOrderPackageBomList(context, orderSku);
|
|
|
+
|
|
|
+ // 获取订单sku成本
|
|
|
+ OrderSkuProductionCost productionCostList = createOrderSkuProductionCostList(orderSku, tempOrderSkuBomList);
|
|
|
+
|
|
|
+ // 添加订单金额
|
|
|
+ addOrderInfoPrice(orderInfo, orderSku);
|
|
|
+
|
|
|
+ orderSkuList.add(orderSku);
|
|
|
+ orderSkuBomList.addAll(tempOrderSkuBomList);
|
|
|
+ orderPackageBomList.addAll(tempOrderPackageBomList);
|
|
|
+
|
|
|
+ orderSkuProductionCostList.add(productionCostList);
|
|
|
+ }
|
|
|
+ // 合并相同快递包材
|
|
|
+ Map<Long, OrderPackageBom> map = orderPackageBomList.stream().collect(Collectors.toMap(
|
|
|
+ OrderPackageBom::getBomSpecId,
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+ ));
|
|
|
+ context.getSaveOrderList().add(orderInfo);
|
|
|
+ context.getSaveOrderSkuList().addAll(orderSkuList);
|
|
|
+ context.getSaveOrderSkuBomList().addAll(orderSkuBomList);
|
|
|
+ context.getSaveOrderSkuProductionCostList().addAll(orderSkuProductionCostList);
|
|
|
+ context.getOrderPackageBomList().addAll(new ArrayList<>(map.values()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单sku
|
|
|
+ */
|
|
|
+ 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"));
|
|
|
+ orderSku.setWlnSkuSpecId(wlnOrderSku.getString("sys_spec_uid"));
|
|
|
+ orderSku.setWlnSkuName(wlnOrderSku.getString("oln_sku_name"));
|
|
|
+ orderSku.setOrderId(orderInfo.getId());
|
|
|
+ orderSku.setQuantity(wlnOrderSku.getBigDecimal("size"));
|
|
|
+ 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.setManagementFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setPackagingMaterialCost(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ if (skuSpec != null) {
|
|
|
+ orderSku.setSkuId(skuSpec.getSkuId());
|
|
|
+ orderSku.setSkuSpecId(skuSpec.getId());
|
|
|
+ orderSku.setBomSpecId(skuSpec.getBomSpecId());
|
|
|
+
|
|
|
+ Long artworkLibraryId = skuSpec.getArtworkLibraryId();
|
|
|
+
|
|
|
+ if (artworkLibraryId != null) {
|
|
|
+ ArtworkLibrary artworkLibrary = context.getArtworkLibraryMap().get(artworkLibraryId);
|
|
|
+ if (artworkLibrary != null) {
|
|
|
+ orderSku.setArtworkLibraryId(artworkLibraryId);
|
|
|
+ orderSku.setBlueprint(artworkLibrary.getImgUrl());
|
|
|
+ orderSku.setProductionDocument(artworkLibrary.getFileUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ assignedOrderSkuPrice(context, orderSku, skuSpec);
|
|
|
+
|
|
|
+ if (OrderStatusEnum.STOCK_PREPARATION.getKey().equals(orderInfo.getStatus())
|
|
|
+ && orderSku.getArtworkLibraryId() == null) {
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.NO_DESIGN_DOCUMENT);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderSku;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赋值订单sku价格
|
|
|
+ */
|
|
|
+ private void assignedOrderSkuPrice(OrderContext context, OrderSku orderSku, SkuSpec skuSpec) {
|
|
|
+
|
|
|
+ BomSpecBo bomSpecBo = context.getBomSpecBoMap().get(skuSpec.getBomSpecId());
|
|
|
+
|
|
|
+ // 订单明细sku没绑定bom,不赋值价格
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置单价
|
|
|
+ orderSku.setUnitPrice(bomSpecBo.getInternalSellingPrice());
|
|
|
+
|
|
|
+ // 如果bom规格不为主材,不赋值价格
|
|
|
+ if (ObjectUtil.notEqual(bomSpecBo.getClassifyParentId(), 1L)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取报价规则列表
|
|
|
+ List<PriceBillingStandardDetail> priceBillingStandardDetailList =
|
|
|
+ context.getPriceBillingStandardMap(bomSpecBo.getBomSpecies());
|
|
|
+
|
|
|
+ // 报价规则列表
|
|
|
+ if (ObjectUtil.isEmpty(priceBillingStandardDetailList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (PriceBillingStandardDetail priceBillingStandardDetail : priceBillingStandardDetailList) {
|
|
|
+ String chargeItem = priceBillingStandardDetail.getChargeItem();
|
|
|
+ BigDecimal chargePrice = priceBillingStandardDetail.getChargePrice();
|
|
|
+
|
|
|
+ switch (chargeItem) {
|
|
|
+ case "40":
|
|
|
+ orderSku.setPackingLabor(chargePrice);
|
|
|
+ break;
|
|
|
+ case "50":
|
|
|
+ orderSku.setLssueFee(chargePrice);
|
|
|
+ break;
|
|
|
+ case "70":
|
|
|
+ orderSku.setManagementFee(chargePrice);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ if (Objects.equals(chargeItem, skuSpec.getMachinedPanel())
|
|
|
+ && orderSku.getQuantity().compareTo(priceBillingStandardDetail.getSectionMin()) >= 0
|
|
|
+ && orderSku.getQuantity().compareTo(priceBillingStandardDetail.getSectionMax()) < 0) {
|
|
|
+ orderSku.setCustomProcessingType(chargeItem);
|
|
|
+ orderSku.setCustomProcessingFee(chargePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加订单价格
|
|
|
+ */
|
|
|
+ private void addOrderInfoPrice(OrderInfo orderInfo, OrderSku orderSku) {
|
|
|
+ BigDecimal quantity = orderSku.getQuantity();
|
|
|
+
|
|
|
+ BigDecimal productTotalAmount = quantity.multiply(orderSku.getUnitPrice());
|
|
|
+ BigDecimal customProcessingFee = quantity.multiply(orderSku.getCustomProcessingFee());
|
|
|
+ BigDecimal lssueFee = quantity.multiply(orderSku.getLssueFee());
|
|
|
+ BigDecimal deliveryMaterialsFee = quantity.multiply(orderSku.getDeliveryMaterialsFee());
|
|
|
+ BigDecimal packingLabor = quantity.multiply(orderSku.getPackingLabor());
|
|
|
+ BigDecimal packagingMaterialCost = quantity.multiply(orderSku.getPackagingMaterialCost());
|
|
|
+ BigDecimal managementFee = quantity.multiply(orderSku.getManagementFee());
|
|
|
+ BigDecimal totalAmount = productTotalAmount
|
|
|
+ .add(customProcessingFee)
|
|
|
+ .add(lssueFee)
|
|
|
+ .add(deliveryMaterialsFee)
|
|
|
+ .add(packingLabor)
|
|
|
+ .add(packagingMaterialCost)
|
|
|
+ .add(managementFee);
|
|
|
+
|
|
|
+ orderInfo.setProductTotalAmount(orderInfo.getProductTotalAmount().add(productTotalAmount));
|
|
|
+ orderInfo.setCustomProcessingFee(orderInfo.getCustomProcessingFee().add(customProcessingFee));
|
|
|
+ orderInfo.setLssueFee(orderInfo.getLssueFee().add(lssueFee));
|
|
|
+ orderInfo.setDeliveryMaterialsFee(orderInfo.getDeliveryMaterialsFee().add(deliveryMaterialsFee));
|
|
|
+ orderInfo.setPackingLabor(orderInfo.getPackingLabor().add(packingLabor));
|
|
|
+ orderInfo.setManagementFee(orderInfo.getManagementFee().add(managementFee));
|
|
|
+ orderInfo.setPackagingMaterialCost(orderInfo.getPackagingMaterialCost().add(packagingMaterialCost));
|
|
|
+ orderInfo.setTotalAmount(orderInfo.getTotalAmount().add(totalAmount));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加订单异常类型
|
|
|
+ */
|
|
|
+ private void addExceptionType(OrderInfo orderInfo, OrderExceptionTypeEnum exceptionTypeEnum) {
|
|
|
+
|
|
|
+ String exceptionType;
|
|
|
+
|
|
|
+ String oldExceptionType = orderInfo.getExceptionType();
|
|
|
+ if (StrUtil.isBlank(oldExceptionType) || oldExceptionType.equals("0")) {
|
|
|
+ exceptionType = exceptionTypeEnum.getKey().toString();
|
|
|
+ } else if (Arrays.asList(oldExceptionType.split(",")).contains(exceptionTypeEnum.getKey().toString())) {
|
|
|
+ exceptionType = oldExceptionType;
|
|
|
+ } else {
|
|
|
+ exceptionType = oldExceptionType + "," + exceptionTypeEnum.getKey();
|
|
|
+ }
|
|
|
+
|
|
|
+ orderInfo.setExceptionType(exceptionType);
|
|
|
+ orderInfo.setExceptionTime(ObjectUtil.defaultIfNull(orderInfo.getExceptionTime(), new Date()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存或更新数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void saveOrUpdateOrder(OrderContext context) {
|
|
|
+
|
|
|
+ // 新增正常订单锁定库存
|
|
|
+ lockStorage(context);
|
|
|
+
|
|
|
+ // 修改正常订单为异常订单解锁库存
|
|
|
+ unlockStorage(context);
|
|
|
+
|
|
|
+ List<OrderInfo> saveOrderList = context.getSaveOrderList();
|
|
|
+ List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
+ List<OrderInfo> saveStatementOrderList = context.getSaveStatementOrderList();
|
|
|
+ List<OrderSku> saveOrderSkuList = context.getSaveOrderSkuList();
|
|
|
+ List<OrderSkuBom> saveOrderSkuBomList = context.getSaveOrderSkuBomList();
|
|
|
+ List<OrderSkuProductionCost> saveOrderSkuProductionCostList = context.getSaveOrderSkuProductionCostList();
|
|
|
+ List<OrderPackageBom> orderPackageBomList = context.getOrderPackageBomList();
|
|
|
+
|
|
|
+ if (!saveOrderList.isEmpty()) {
|
|
|
+ orderInfoService.saveBatch(saveOrderList);
|
|
|
+ }
|
|
|
+ if (!updateOrderList.isEmpty()) {
|
|
|
+ orderInfoService.updateBatchById(updateOrderList);
|
|
|
+ }
|
|
|
+ if (!saveStatementOrderList.isEmpty()) {
|
|
|
+ saveStatementOrderList.forEach(item -> {
|
|
|
+
|
|
|
+ // 生成对账单
|
|
|
+ StatementOfAccountDto statement = new StatementOfAccountDto();
|
|
|
+ statement.setDepartmentId(item.getDepartmentId());
|
|
|
+ statement.setOrderIdList(Collections.singletonList(item.getId()));
|
|
|
+ statementOfAccountService.add(statement);
|
|
|
+
|
|
|
+ // 生产入库
|
|
|
+ inventoryFinishedService.productionWarehousing(Collections.singletonList(item.getId()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!saveOrderSkuList.isEmpty()) {
|
|
|
+ orderSkuService.saveBatch(saveOrderSkuList);
|
|
|
+ }
|
|
|
+ if (!saveOrderSkuBomList.isEmpty()) {
|
|
|
+ orderSkuBomService.saveBatch(saveOrderSkuBomList);
|
|
|
+ }
|
|
|
+ if (!saveOrderSkuProductionCostList.isEmpty()) {
|
|
|
+ orderSkuProductionCostService.saveBatch(saveOrderSkuProductionCostList);
|
|
|
+ }
|
|
|
+ if (!orderPackageBomList.isEmpty()) {
|
|
|
+ orderPackageBomService.saveBatch(orderPackageBomList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void lockStorage(OrderContext context) {
|
|
|
+
|
|
|
+ Department department = context.getDepartment();
|
|
|
+
|
|
|
+ if (department == null || ObjectUtil.notEqual(department.getOrderMode(), "2")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderInfo> saveOrderList = context.getSaveOrderList();
|
|
|
+ List<OrderSku> saveOrderSkuList = context.getSaveOrderSkuList();
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = context.getBomSpecBoMap();
|
|
|
+ List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
+ Map<Long, List<OrderSku>> existOrderSkuMap = context.getExistOrderSkuMap();
|
|
|
+
|
|
|
+ Map<Long, OrderInfo> orderMap = Stream.concat(saveOrderList.stream(), updateOrderList.stream()).collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
|
|
|
+
|
|
|
+ Map<Long, List<OrderSku>> orderSkuMap = Stream.concat(
|
|
|
+ saveOrderSkuList.stream(),
|
|
|
+ updateOrderList.stream().map(item -> existOrderSkuMap.get(item.getId())).flatMap(Collection::stream)
|
|
|
+ )
|
|
|
+ .filter(item -> orderMap.get(item.getOrderId()).getExceptionType().equals(OrderExceptionTypeEnum.NORMAL.getKey().toString()))
|
|
|
+ .filter(item -> Objects.equals(orderMap.get(item.getOrderId()).getStatus(), OrderStatusEnum.STOCK_PREPARATION.getKey()))
|
|
|
+ .filter(item -> Objects.equals(orderMap.get(item.getOrderId()).getLockStorage(), StatusConstant.NO))
|
|
|
+ .filter(item -> bomSpecBoMap.get(item.getBomSpecId()).getClassifyParentId().equals(1L))
|
|
|
+ .collect(Collectors.groupingBy(OrderSku::getOrderId));
|
|
|
+
|
|
|
+ orderSkuMap.forEach((orderId, orderSkuList) -> {
|
|
|
+ OrderInfo orderInfo = orderMap.get(orderId);
|
|
|
+ boolean lockStorageFlag = inventoryService.lockStorage(orderSkuList);
|
|
|
+
|
|
|
+ if (lockStorageFlag) {
|
|
|
+ orderInfo.setLockStorage(StatusConstant.YES);
|
|
|
+ } else {
|
|
|
+ orderInfo.setLockStorage(StatusConstant.NO);
|
|
|
+ addExceptionType(orderInfo, OrderExceptionTypeEnum.UNDERSTOCK);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void unlockStorage(OrderContext context) {
|
|
|
+ List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
+ Map<Long, List<OrderSku>> existOrderSkuMap = context.getExistOrderSkuMap();
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = context.getBomSpecBoMap();
|
|
|
+
|
|
|
+ List<OrderSku> unlockStorageOrderSkuList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (OrderInfo orderInfo : updateOrderList) {
|
|
|
+ if (ObjectUtil.equal(orderInfo.getExceptionType(), OrderExceptionTypeEnum.NORMAL.getKey().toString())
|
|
|
+ || ObjectUtil.equal(orderInfo.getLockStorage(), StatusConstant.NO)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = existOrderSkuMap.get(orderInfo.getId())
|
|
|
+ .stream()
|
|
|
+ .filter(item -> {
|
|
|
+ Long bomSpecId = item.getBomSpecId();
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(bomSpecId);
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ bomSpecBo = bomSpecService.getBomSpecBo(bomSpecId);
|
|
|
+ bomSpecBoMap.put(bomSpecId, bomSpecBo);
|
|
|
+ }
|
|
|
+ return Objects.equals(bomSpecBo.getClassifyParentId(), 1L);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ unlockStorageOrderSkuList.addAll(orderSkuList);
|
|
|
+ orderInfo.setLockStorage(StatusConstant.NO);
|
|
|
+ }
|
|
|
+
|
|
|
+ inventoryService.unlockStorage(unlockStorageOrderSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询万里牛订单列表
|
|
|
+ */
|
|
|
+ private List<JSONObject> getWlnOrderList(String warehouseCode) {
|
|
|
+ long endTime = new Date().getTime();
|
|
|
+ long startTime;
|
|
|
+
|
|
|
+ OrderInfo orderInfo = orderInfoService.getOne(q -> q
|
|
|
+ .eq(OrderInfo::getWlnStorageCode, warehouseCode)
|
|
|
+ .orderByDesc(OrderInfo::getWlnModifyTimestamp));
|
|
|
+
|
|
|
+ List<JSONObject> list = new ArrayList<>();
|
|
|
+
|
|
|
+ if (orderInfo == null) {
|
|
|
+ int day = 7;
|
|
|
+ startTime = endTime - 1000 * 60 * 60 * 24 * day;
|
|
|
+
|
|
|
+ for (int i = 0; i < day - 1; i++) {
|
|
|
+ getOrderList(startTime, startTime + 1000 * 60 * 60 * 24, warehouseCode, list);
|
|
|
+ startTime += 1000 * 60 * 60 * 24;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ startTime = orderInfo.getWlnModifyTimestamp() + 1;
|
|
|
+ if (endTime - startTime > 1000 * 60 * 60 * 24 * 7) {
|
|
|
+ startTime = endTime - 1000 * 60 * 60 * 24 * 7;
|
|
|
+ }
|
|
|
+ getOrderList(startTime, endTime, warehouseCode, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getOrderList(Long startTime, Long endTime, String warehouseCode, List<JSONObject> list) {
|
|
|
+ int page = 1;
|
|
|
+ int size;
|
|
|
+ do {
|
|
|
+ try {
|
|
|
+ List<JSONObject> itemList = WlnUtil.getOrderList(page, 200, startTime, endTime, warehouseCode);
|
|
|
+ page++;
|
|
|
+ size = itemList.size();
|
|
|
+ list.addAll(itemList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("订单同步失败", e);
|
|
|
+ throw new ServiceException("订单同步失败");
|
|
|
+ }
|
|
|
+ } while (size >= 200);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|