|
@@ -2,15 +2,12 @@ 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.framework.mybatis.holder.LogicHolder;
|
|
|
import com.sd.business.entity.bom.bo.BomBo;
|
|
|
+import com.sd.business.entity.bom.po.BomSpec;
|
|
|
import com.sd.business.entity.department.po.Department;
|
|
|
import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
import com.sd.business.entity.order.po.OrderInfo;
|
|
@@ -20,16 +17,15 @@ import com.sd.business.entity.order.po.OrderSkuBom;
|
|
|
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.service.department.DepartmentService;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.business.service.order.OrderPackageBomService;
|
|
|
import com.sd.business.service.order.OrderService;
|
|
|
import com.sd.business.service.order.OrderSkuBomService;
|
|
|
import com.sd.business.service.order.OrderSkuService;
|
|
|
-import com.sd.business.service.price.PriceBillingStandardDetailService;
|
|
|
import com.sd.business.service.sku.SkuSpecLinkService;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
+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;
|
|
@@ -52,12 +48,6 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
private TransactionDefinition transactionDefinition;
|
|
|
|
|
|
@Autowired
|
|
|
- private DictCommonDataService dictCommonDataService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private DepartmentService departmentService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private OrderService orderService;
|
|
|
|
|
|
@Autowired
|
|
@@ -73,186 +63,64 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
private SkuSpecService skuSpecService;
|
|
|
|
|
|
@Autowired
|
|
|
- private PriceBillingStandardDetailService priceBillingStandardDetailService;
|
|
|
+ private SkuSpecLinkService skuSpecLinkService;
|
|
|
|
|
|
@Autowired
|
|
|
- private SkuSpecLinkService skuSpecLinkService;
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
|
|
|
@Override
|
|
|
public void syncOrder() {
|
|
|
|
|
|
-
|
|
|
- Date endDate = new Date();
|
|
|
-
|
|
|
- List<OrderInfo> saveOrderList = new ArrayList<>();
|
|
|
-
|
|
|
- List<OrderInfo> updateOrderList = new ArrayList<>();
|
|
|
-
|
|
|
- List<OrderSku> saveOrderSkuList = new ArrayList<>();
|
|
|
-
|
|
|
- List<OrderSkuBom> saveOrderSkuBomList = new ArrayList<>();
|
|
|
-
|
|
|
- List<OrderPackageBom> orderPackageBomList = new ArrayList<>();
|
|
|
-
|
|
|
-
|
|
|
- List<JSONObject> wlnOrderList = getWlnOrderList(endDate);
|
|
|
- if (wlnOrderList == null || wlnOrderList.size() == 0) {
|
|
|
+ OrderContext context = new OrderContext();
|
|
|
+
|
|
|
+
|
|
|
+ List<JSONObject> wlnOrderList = context.getWlnOrderList();
|
|
|
+ if (ObjectUtil.isEmpty(wlnOrderList)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- Map<String, OrderInfo> orderMap = getOrderMap(endDate);
|
|
|
-
|
|
|
-
|
|
|
- Map<String, Department> departmentMap = getDepartmentMap();
|
|
|
-
|
|
|
-
|
|
|
- Map<String, SkuSpec> skuSpecMap = getSkuSpecMap(wlnOrderList);
|
|
|
-
|
|
|
|
|
|
for (JSONObject wlnOrder : wlnOrderList) {
|
|
|
|
|
|
-
|
|
|
- String storageCode = wlnOrder.getString("storage_code");
|
|
|
- Department department = departmentMap.get(storageCode);
|
|
|
- if (department == null) {
|
|
|
- log.error("未知仓库code:{}", storageCode);
|
|
|
+
|
|
|
+ OrderInfo orderInfo = createOrder(context, wlnOrder);
|
|
|
+
|
|
|
+
|
|
|
+ if (orderInfo == null) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- OrderInfo orderInfo = createOrder(wlnOrder, department);
|
|
|
-
|
|
|
|
|
|
- boolean existOrder = existOrder(orderMap, orderInfo, updateOrderList);
|
|
|
+ boolean existOrder = existOrder(context, orderInfo);
|
|
|
|
|
|
|
|
|
if (existOrder) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- List<OrderSku> tempOrderSkuList = new ArrayList<>();
|
|
|
- List<OrderSkuBom> tempOrderSkuBomList = new ArrayList<>();
|
|
|
-
|
|
|
- boolean isSave = true;
|
|
|
-
|
|
|
-
|
|
|
- for (JSONObject wlnOrderSku : wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class)) {
|
|
|
-
|
|
|
-
|
|
|
- String sysSpecUid = wlnOrderSku.getString("sys_spec_uid");
|
|
|
- SkuSpec skuSpec = skuSpecMap.get(sysSpecUid);
|
|
|
- if (skuSpec == null) {
|
|
|
- isSave = false;
|
|
|
- log.error("没有通过万里牛sys_spec_uid: {} 找到sku规格", sysSpecUid);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- OrderSku orderSku = createOrderSku(wlnOrderSku, orderInfo, skuSpec);
|
|
|
- tempOrderSkuList.add(orderSku);
|
|
|
-
|
|
|
-
|
|
|
- List<OrderSkuBom> orderSkuBomList = createOrderSkuBoom(orderInfo, orderSku);
|
|
|
- tempOrderSkuBomList.addAll(orderSkuBomList);
|
|
|
- }
|
|
|
-
|
|
|
- if (isSave) {
|
|
|
- saveOrderList.add(orderInfo);
|
|
|
- saveOrderSkuList.addAll(tempOrderSkuList);
|
|
|
- saveOrderSkuBomList.addAll(tempOrderSkuBomList);
|
|
|
- orderPackageBomList.addAll(createOrderPackageBomList(tempOrderSkuList, department.getId()));
|
|
|
- }
|
|
|
+
|
|
|
+ addOrder(context, wlnOrder, orderInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- setOrderPrice(departmentMap, saveOrderList, saveOrderSkuList, saveOrderSkuBomList, skuSpecMap);
|
|
|
+
|
|
|
+ setOrderPrice(context);
|
|
|
|
|
|
-
|
|
|
- TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
- try {
|
|
|
- if (saveOrderList.size() > 0) {
|
|
|
- orderService.saveBatch(saveOrderList);
|
|
|
- }
|
|
|
- if (updateOrderList.size() > 0) {
|
|
|
- orderService.updateBatchById(updateOrderList);
|
|
|
- }
|
|
|
- if (saveOrderSkuList.size() > 0) {
|
|
|
- orderSkuService.saveBatch(saveOrderSkuList);
|
|
|
- }
|
|
|
- if (saveOrderSkuBomList.size() > 0) {
|
|
|
- orderSkuBomService.saveBatch(saveOrderSkuBomList);
|
|
|
- }
|
|
|
- if (orderPackageBomList.size() > 0) {
|
|
|
- orderPackageBomService.saveBatch(orderPackageBomList);
|
|
|
- }
|
|
|
-
|
|
|
- platformTransactionManager.commit(transactionStatus);
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- platformTransactionManager.rollback(transactionStatus);
|
|
|
- log.error("同步订单失败", e);
|
|
|
- }
|
|
|
+
|
|
|
+ saveOrUpdateOrder(context);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 查询1天内万里牛订单
|
|
|
- */
|
|
|
- private List<JSONObject> getWlnOrderList(Date endDate) {
|
|
|
- List<DictCommonData> warehouseCodeList = dictCommonDataService.list(q -> q.eq(DictCommonData::getDictCode, "warehouse_code"));
|
|
|
- if (warehouseCodeList.size() == 0) {
|
|
|
- log.error("订单同步失败,仓库字典:warehouse_code 为空");
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- List<JSONObject> list = new ArrayList<>();
|
|
|
-
|
|
|
- long endTime = endDate.getTime();
|
|
|
- long startTime = endTime - 1000 * 60 * 60 * 24;
|
|
|
-
|
|
|
- for (DictCommonData dictCommonData : warehouseCodeList) {
|
|
|
- int page = 1;
|
|
|
- int size;
|
|
|
- do {
|
|
|
- try {
|
|
|
- List<JSONObject> itemList = WlnUtil.getOrderList(page, 200, startTime, endTime, dictCommonData.getDictValue());
|
|
|
- page++;
|
|
|
- size = itemList.size();
|
|
|
- list.addAll(itemList);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("订单同步失败", e);
|
|
|
- return null;
|
|
|
- }
|
|
|
- } while (size >= 200);
|
|
|
- }
|
|
|
-
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 查询近3天已存在数据库中的订单
|
|
|
- */
|
|
|
- private Map<String, OrderInfo> getOrderMap(Date endDate) {
|
|
|
- LogicHolder.setLogicHolder(new LogicHolder());
|
|
|
-
|
|
|
- Map<String, OrderInfo> orderMap = orderService.mapKEntity(
|
|
|
- OrderInfo::getWlnUid,
|
|
|
- q -> q.between(OrderInfo::getWlnApproveTime, DateUtil.offsetDay(endDate, -3), endDate)
|
|
|
- );
|
|
|
-
|
|
|
- LogicHolder.clear();
|
|
|
- return orderMap;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
* 订单是否存在,若订单存在且订单信息被修改,则添加到更新订单数组
|
|
|
*/
|
|
|
- private boolean existOrder(Map<String, OrderInfo> orderMap, OrderInfo orderInfo, List<OrderInfo> updateOrderList) {
|
|
|
+ private boolean existOrder(OrderContext context, OrderInfo orderInfo) {
|
|
|
+ Map<String, OrderInfo> orderMap = context.getOrderMap();
|
|
|
+ List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
|
|
|
|
|
|
OrderInfo oldOrderInfo = orderMap.get(orderInfo.getWlnUid());
|
|
|
+
|
|
|
if (oldOrderInfo != null) {
|
|
|
if (ObjectUtil.notEqual(oldOrderInfo.getWlnStatus(), orderInfo.getWlnStatus())
|
|
|
|| ObjectUtil.notEqual(oldOrderInfo.getWlnModifyTimestamp(), orderInfo.getWlnModifyTimestamp())
|
|
@@ -260,6 +128,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
|| ObjectUtil.notEqual(DateUtil.formatDateTime(oldOrderInfo.getWlnPrintTime()), DateUtil.formatDateTime(orderInfo.getWlnPrintTime()))
|
|
|
|| ObjectUtil.notEqual(oldOrderInfo.getWlnStorageCode(), orderInfo.getWlnStorageCode())
|
|
|
|| ObjectUtil.notEqual(oldOrderInfo.getDepartmentId(), orderInfo.getDepartmentId())) {
|
|
|
+
|
|
|
OrderInfo updateOrder = new OrderInfo();
|
|
|
updateOrder.setId(oldOrderInfo.getId());
|
|
|
updateOrder.setWlnStatus(orderInfo.getWlnStatus());
|
|
@@ -270,6 +139,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
updateOrder.setWlnStorageCode(orderInfo.getWlnStorageCode());
|
|
|
updateOrder.setDepartmentId(orderInfo.getDepartmentId());
|
|
|
updateOrderList.add(updateOrder);
|
|
|
+
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -278,41 +148,22 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 查询事业部
|
|
|
+ * 创建订单
|
|
|
*/
|
|
|
- private Map<String, Department> getDepartmentMap() {
|
|
|
- List<Department> departmentList = departmentService.list();
|
|
|
- Map<String, Department> departmentMap = new HashMap<>();
|
|
|
+ private OrderInfo createOrder(OrderContext context, JSONObject wlnOrder) {
|
|
|
|
|
|
- for (Department department : departmentList) {
|
|
|
- String warehouseCode = department.getWlnWarehouseCode();
|
|
|
- if (StrUtil.isBlank(warehouseCode)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (String item : warehouseCode.split(",")) {
|
|
|
- departmentMap.put(item, department);
|
|
|
- }
|
|
|
- }
|
|
|
- return departmentMap;
|
|
|
- }
|
|
|
+
|
|
|
+ String storageCode = wlnOrder.getString("storage_code");
|
|
|
|
|
|
-
|
|
|
- * 获取sku规格
|
|
|
- */
|
|
|
- private Map<String, SkuSpec> getSkuSpecMap(List<JSONObject> wlnOrderList) {
|
|
|
- List<String> wlnUidList = wlnOrderList.stream()
|
|
|
- .flatMap(item -> item.getJSONArray("orders").toJavaList(JSONObject.class).stream())
|
|
|
- .map(item -> item.getString("sys_spec_uid"))
|
|
|
- .filter(ObjectUtil::isNotNull)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- return skuSpecService.mapKEntity(SkuSpec::getWlnUid, q -> q.in(SkuSpec::getWlnUid, wlnUidList));
|
|
|
- }
|
|
|
+
|
|
|
+ Department department = context.getDepartmentMap().get(storageCode);
|
|
|
+
|
|
|
+
|
|
|
+ if (department == null) {
|
|
|
+ log.error("未知仓库code:{}", storageCode);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- * 创建订单
|
|
|
- */
|
|
|
- private OrderInfo createOrder(JSONObject wlnOrder, Department department) {
|
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
|
orderInfo.setId(IdWorker.getId());
|
|
|
orderInfo.setSource(2);
|
|
@@ -345,11 +196,11 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
}
|
|
|
|
|
|
if (wlnOrder.containsKey("shop_name")) {
|
|
|
- builder.append("_");
|
|
|
- builder.append(wlnOrder.getString("shop_name"));
|
|
|
+ builder.append("_").append(wlnOrder.getString("shop_name"));
|
|
|
}
|
|
|
orderInfo.setCommercePlatform(builder.toString());
|
|
|
|
|
|
+
|
|
|
if (orderInfo.getWlnStatus() == 10 || orderInfo.getWlnStatus() == 11 || orderInfo.getWlnStatus() == 12) {
|
|
|
orderInfo.setStatus(OrderStatusEnum.EXCEPTION.getKey());
|
|
|
} else if (Objects.equals(department.getOrderMode(), "2")) {
|
|
@@ -367,14 +218,15 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
private OrderSku createOrderSku(JSONObject wlnOrderSku, OrderInfo orderInfo, SkuSpec skuSpec) {
|
|
|
OrderSku orderSku = new OrderSku();
|
|
|
orderSku.setId(IdWorker.getId());
|
|
|
- orderSku.setOrderId(orderInfo.getId());
|
|
|
- orderSku.setQuantity(wlnOrderSku.getBigDecimal("size"));
|
|
|
- orderSku.setPrintType(1);
|
|
|
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.setSkuId(skuSpec.getSkuId());
|
|
|
orderSku.setSkuSpecId(skuSpec.getId());
|
|
|
+ orderSku.setBomSpecId(skuSpec.getBomSpecId());
|
|
|
+ orderSku.setQuantity(wlnOrderSku.getBigDecimal("size"));
|
|
|
+ orderSku.setPrintType(1);
|
|
|
orderSku.setStockPreparationStatus(StatusConstant.NO);
|
|
|
return orderSku;
|
|
|
}
|
|
@@ -382,55 +234,55 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
|
|
|
* 创建订单包材
|
|
|
*/
|
|
|
- private List<OrderSkuBom> createOrderSkuBoom(OrderInfo orderInfo, OrderSku orderSku) {
|
|
|
-
|
|
|
- List<SkuSpecLink> list = skuSpecLinkService.list(q -> q
|
|
|
- .eq(SkuSpecLink::getSkuSpecId, orderSku.getSkuSpecId())
|
|
|
- .eq(SkuSpecLink::getType, 1)
|
|
|
- .eq(SkuSpecLink::getDepartmentId, orderInfo.getDepartmentId())
|
|
|
- );
|
|
|
+ private List<OrderSkuBom> createOrderSkuBoom(List<OrderSku> orderSkuList, List<SkuSpecLink> list) {
|
|
|
|
|
|
- if (list.size() == 0) {
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
+ Map<Long, List<SkuSpecLink>> skuSpecLinkMap = list.stream().collect(Collectors.groupingBy(SkuSpecLink::getSkuSpecId));
|
|
|
+
|
|
|
|
|
|
- List<Long> skuSpecIdList = list.stream().map(SkuSpecLink::getSkuSpecId).collect(Collectors.toList());
|
|
|
- Map<Long, BomBo> bomBoMap = skuSpecService.getBomBySkuSpecIdList(skuSpecIdList);
|
|
|
-
|
|
|
- return list.stream().map(item -> {
|
|
|
- OrderSkuBom orderSkuBom = new OrderSkuBom();
|
|
|
- orderSkuBom.setId(IdWorker.getId());
|
|
|
- orderSkuBom.setOrderId(orderInfo.getId());
|
|
|
- orderSkuBom.setOrderSkuId(orderSku.getId());
|
|
|
- orderSkuBom.setBomSpecId(item.getBomSpecId());
|
|
|
- orderSkuBom.setQuantity(item.getQuantity());
|
|
|
-
|
|
|
- BomBo bomBo = bomBoMap.get(item.getBomSpecId());
|
|
|
- if (bomBo == null) {
|
|
|
- orderSkuBom.setUnitPrice(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- orderSkuBom.setUnitPrice(ObjectUtil.defaultIfNull(bomBo.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
- }
|
|
|
+ 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());
|
|
|
+ if (bomSpec == null) {
|
|
|
+ orderSkuBom.setUnitPrice(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ orderSkuBom.setUnitPrice(ObjectUtil.defaultIfNull(bomSpec.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderSkuBom;
|
|
|
+ });
|
|
|
|
|
|
- return orderSkuBom;
|
|
|
}).collect(Collectors.toList());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
* 创建订单包装
|
|
|
*/
|
|
|
- private List<OrderPackageBom> createOrderPackageBomList(List<OrderSku> orderSkuList, Long departmentId) {
|
|
|
+ private List<OrderPackageBom> createOrderPackageBomList(List<OrderSku> orderSkuList, List<SkuSpecLink> list) {
|
|
|
|
|
|
-
|
|
|
- List<Long> skuSpecIdList = orderSkuList.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList());
|
|
|
- List<SkuSpecLink> list = skuSpecLinkService.list(q -> q
|
|
|
- .in(SkuSpecLink::getSkuSpecId, skuSpecIdList)
|
|
|
- .eq(SkuSpecLink::getType, 2)
|
|
|
- .eq(SkuSpecLink::getDepartmentId, departmentId)
|
|
|
- );
|
|
|
- Map<Long, List<SkuSpecLink>> skuSpecLinkMap = list.stream().collect(Collectors.groupingBy(SkuSpecLink::getSkuSpecId));
|
|
|
+ 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<>();
|
|
|
|
|
@@ -445,6 +297,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
for (SkuSpecLink skuSpecLink : skuSpecLinkList) {
|
|
|
|
|
|
Long bomSpecId = skuSpecLink.getBomSpecId();
|
|
|
+
|
|
|
OrderPackageBom orderPackageBom = orderPackageBomMap.computeIfAbsent(bomSpecId, item -> {
|
|
|
OrderPackageBom tempOrderPackageBom = new OrderPackageBom();
|
|
|
tempOrderPackageBom.setOrderId(orderSku.getOrderId());
|
|
@@ -462,39 +315,86 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 赋值订单价格
|
|
|
+ * 添加订单到上下文
|
|
|
*/
|
|
|
- private void setOrderPrice(Map<String, Department> departmentMap,
|
|
|
- List<OrderInfo> orderList,
|
|
|
- List<OrderSku> orderSkuList,
|
|
|
- List<OrderSkuBom> saveOrderSkuBomList,
|
|
|
- Map<String, SkuSpec> skuSpecMap) {
|
|
|
+ private void addOrder(OrderContext context, JSONObject wlnOrder, OrderInfo orderInfo) {
|
|
|
+ Map<String, SkuSpec> skuSpecMap = context.getSkuSpecMap();
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ boolean isAdd = true;
|
|
|
+
|
|
|
+
|
|
|
+ for (JSONObject wlnOrderSku : wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class)) {
|
|
|
+
|
|
|
+
|
|
|
+ String sysSpecUid = wlnOrderSku.getString("sys_spec_uid");
|
|
|
+
|
|
|
+
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(sysSpecUid);
|
|
|
+
|
|
|
+ if (skuSpec == null) {
|
|
|
+ isAdd = false;
|
|
|
+ log.error("没有通过万里牛sys_spec_uid: {} 找到sku规格", sysSpecUid);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ OrderSku orderSku = createOrderSku(wlnOrderSku, orderInfo, skuSpec);
|
|
|
+ orderSkuList.add(orderSku);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- if (orderList.size() == 0 || orderSkuList.size() == 0) {
|
|
|
+ if (!isAdd) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- Map<Long, Long> departmentIdPriceBillingStandardIdMap = departmentMap.values()
|
|
|
- .stream()
|
|
|
- .filter(ObjectUtil::isNotNull)
|
|
|
- .filter(item -> ObjectUtil.isNotNull(item.getPriceBillingStandardId()))
|
|
|
- .collect(Collectors.toMap(BaseIdPo::getId, Department::getPriceBillingStandardId, (t1, t2) -> t1));
|
|
|
+
|
|
|
+ List<Long> skuSpecIdList = orderSkuList.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList());
|
|
|
+ List<SkuSpecLink> list = skuSpecLinkService.list(q -> q
|
|
|
+ .in(SkuSpecLink::getSkuSpecId, skuSpecIdList)
|
|
|
+ .eq(SkuSpecLink::getDepartmentId, orderInfo.getDepartmentId()));
|
|
|
+
|
|
|
+
|
|
|
+ Map<Integer, List<SkuSpecLink>> map = list.stream().collect(Collectors.groupingBy(SkuSpecLink::getType));
|
|
|
+
|
|
|
+
|
|
|
+ List<OrderSkuBom> orderSkuBomList = createOrderSkuBoom(orderSkuList, map.get(1));
|
|
|
+
|
|
|
+
|
|
|
+ List<OrderPackageBom> orderPackageBomList = createOrderPackageBomList(orderSkuList, map.get(2));
|
|
|
+
|
|
|
+ context.getSaveOrderList().add(orderInfo);
|
|
|
+ context.getSaveOrderSkuList().addAll(orderSkuList);
|
|
|
+ context.getSaveOrderSkuBomList().addAll(orderSkuBomList);
|
|
|
+ context.getOrderPackageBomList().addAll(orderPackageBomList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 赋值订单价格
|
|
|
+ */
|
|
|
+ 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();
|
|
|
+ Map<Long, List<PriceBillingStandardDetail>> priceBillingStandardMap = context.getPriceBillingStandardMap();
|
|
|
|
|
|
-
|
|
|
- Map<Long, List<PriceBillingStandardDetail>> priceBillingStandardMap = priceBillingStandardDetailService.list()
|
|
|
- .stream()
|
|
|
- .filter(item -> ObjectUtil.isNotNull(item.getPriceBillingStandardId()))
|
|
|
- .collect(Collectors.groupingBy(PriceBillingStandardDetail::getPriceBillingStandardId));
|
|
|
+ if (saveOrderList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
Map<Long, BomBo> bomBoMap = skuSpecService.getBomBySkuSpecIdList(
|
|
|
- orderSkuList.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList()));
|
|
|
+ saveOrderSkuList.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList()));
|
|
|
|
|
|
|
|
|
- Map<Long, List<OrderSku>> orderSkuGroup = orderSkuList.stream().collect(Collectors.groupingBy(OrderSku::getOrderId));
|
|
|
+ Map<Long, List<OrderSku>> orderSkuGroup = saveOrderSkuList.stream().collect(Collectors.groupingBy(OrderSku::getOrderId));
|
|
|
|
|
|
- for (OrderInfo orderInfo : orderList) {
|
|
|
+ for (OrderInfo orderInfo : saveOrderList) {
|
|
|
|
|
|
orderInfo.setTotalAmount(BigDecimal.ZERO);
|
|
|
orderInfo.setProductTotalAmount(BigDecimal.ZERO);
|
|
@@ -504,10 +404,12 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderInfo.setPackingLabor(BigDecimal.ZERO);
|
|
|
orderInfo.setPackagingMaterialCost(BigDecimal.ZERO);
|
|
|
|
|
|
+
|
|
|
+ Long departmentId = orderInfo.getDepartmentId();
|
|
|
+ List<PriceBillingStandardDetail> priceBillingStandardDetailList = priceBillingStandardMap.get(departmentId);
|
|
|
+
|
|
|
+
|
|
|
List<OrderSku> itemOrderSkuList = orderSkuGroup.get(orderInfo.getId());
|
|
|
- if (ObjectUtil.isEmpty(itemOrderSkuList)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
|
|
|
for (OrderSku orderSku : itemOrderSkuList) {
|
|
|
|
|
@@ -518,11 +420,11 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
assignedPackagingMaterialCost(orderSku, saveOrderSkuBomList);
|
|
|
|
|
|
|
|
|
- assignedOtherPrice(orderSku, orderInfo.getDepartmentId(), bomBoMap,
|
|
|
- departmentIdPriceBillingStandardIdMap, priceBillingStandardMap, skuSpecMap);
|
|
|
+ assignedOtherPrice(orderSku, bomBoMap, priceBillingStandardDetailList, skuSpecMap);
|
|
|
|
|
|
|
|
|
addOrderInfoPrice(orderInfo, orderSku);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -534,7 +436,6 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
private void assignedUnitPrice(OrderSku orderSku, Map<Long, BomBo> bomBoMap) {
|
|
|
BomBo bomBo = bomBoMap.get(orderSku.getSkuSpecId());
|
|
|
if (bomBo != null) {
|
|
|
- orderSku.setBomSpecId(bomBo.getBomSpecId());
|
|
|
orderSku.setUnitPrice(ObjectUtil.defaultIfNull(bomBo.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
} else {
|
|
|
orderSku.setUnitPrice(BigDecimal.ZERO);
|
|
@@ -556,11 +457,8 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
|
|
|
* 赋值其他价格
|
|
|
*/
|
|
|
- private void assignedOtherPrice(OrderSku orderSku,
|
|
|
- Long departmentId,
|
|
|
- Map<Long, BomBo> bomBoMap,
|
|
|
- Map<Long, Long> departmentIdPriceBillingStandardIdMap,
|
|
|
- Map<Long, List<PriceBillingStandardDetail>> priceBillingStandardMap,
|
|
|
+ private void assignedOtherPrice(OrderSku orderSku, Map<Long, BomBo> bomBoMap,
|
|
|
+ List<PriceBillingStandardDetail> priceBillingStandardDetailList,
|
|
|
Map<String, SkuSpec> skuSpecMap) {
|
|
|
|
|
|
orderSku.setCustomProcessingFee(BigDecimal.ZERO);
|
|
@@ -568,6 +466,11 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderSku.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
orderSku.setPackingLabor(BigDecimal.ZERO);
|
|
|
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(priceBillingStandardDetailList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
BomBo bomBo = bomBoMap.get(orderSku.getSkuSpecId());
|
|
|
if (bomBo == null) {
|
|
@@ -579,18 +482,6 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- Long priceBillingStandardId = departmentIdPriceBillingStandardIdMap.get(departmentId);
|
|
|
- if (priceBillingStandardId == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- List<PriceBillingStandardDetail> priceBillingStandardDetailList = priceBillingStandardMap.get(priceBillingStandardId);
|
|
|
- if (ObjectUtil.isEmpty(priceBillingStandardDetailList)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
for (PriceBillingStandardDetail priceBillingStandardDetail : priceBillingStandardDetailList) {
|
|
|
|
|
|
String chargeItem = priceBillingStandardDetail.getChargeItem();
|
|
@@ -647,4 +538,49 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderInfo.setTotalAmount(orderInfo.getTotalAmount().add(totalAmount));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 保存或更新数据
|
|
|
+ */
|
|
|
+ private void saveOrUpdateOrder(OrderContext context) {
|
|
|
+
|
|
|
+ List<OrderInfo> saveOrderList = context.getSaveOrderList();
|
|
|
+ List<OrderInfo> updateOrderList = context.getUpdateOrderList();
|
|
|
+ List<OrderSku> saveOrderSkuList = context.getSaveOrderSkuList();
|
|
|
+ List<OrderSkuBom> saveOrderSkuBomList = context.getSaveOrderSkuBomList();
|
|
|
+ List<OrderPackageBom> orderPackageBomList = context.getOrderPackageBomList();
|
|
|
+
|
|
|
+
|
|
|
+ TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (saveOrderList.size() > 0) {
|
|
|
+ orderService.saveBatch(saveOrderList);
|
|
|
+ }
|
|
|
+ if (updateOrderList.size() > 0) {
|
|
|
+ orderService.updateBatchById(updateOrderList);
|
|
|
+ }
|
|
|
+ if (saveOrderSkuList.size() > 0) {
|
|
|
+ orderSkuService.saveBatch(saveOrderSkuList);
|
|
|
+ }
|
|
|
+ if (saveOrderSkuBomList.size() > 0) {
|
|
|
+ orderSkuBomService.saveBatch(saveOrderSkuBomList);
|
|
|
+ }
|
|
|
+ if (orderPackageBomList.size() > 0) {
|
|
|
+ orderPackageBomService.saveBatch(orderPackageBomList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ platformTransactionManager.commit(transactionStatus);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ log.error("同步订单失败", e);
|
|
|
+
|
|
|
+
|
|
|
+ platformTransactionManager.rollback(transactionStatus);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|