|
@@ -7,15 +7,23 @@ 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.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.framework.mybatis.holder.LogicHolder;
|
|
|
+import com.sd.business.entity.bom.bo.BomBo;
|
|
|
import com.sd.business.entity.department.po.Department;
|
|
|
import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
import com.sd.business.entity.order.po.OrderInfo;
|
|
|
import com.sd.business.entity.order.po.OrderSku;
|
|
|
+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.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.service.WlnOrderService;
|
|
|
import com.sd.wln.util.WlnUtil;
|
|
@@ -53,8 +61,17 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
private OrderSkuService orderSkuService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private OrderSkuBomService orderSkuBomService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private SkuSpecService skuSpecService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PriceBillingStandardDetailService priceBillingStandardDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecLinkService skuSpecLinkService;
|
|
|
+
|
|
|
@Override
|
|
|
public boolean syncOrder() {
|
|
|
|
|
@@ -67,6 +84,8 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
List<OrderInfo> updateOrderList = new ArrayList<>();
|
|
|
// 保存订单明细列表
|
|
|
List<OrderSku> saveOrderSkuList = new ArrayList<>();
|
|
|
+ // 保存订单包材
|
|
|
+ List<OrderSkuBom> saveOrderSkuBomList = new ArrayList<>();
|
|
|
|
|
|
// 查询近3天万里牛订单
|
|
|
List<JSONObject> wlnOrderList = getWlnOrderList(endDate);
|
|
@@ -117,13 +136,25 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
|
|
|
// 创建订单sku
|
|
|
for (JSONObject wlnOrderSku : wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class)) {
|
|
|
- SkuSpec skuSpec = skuSpecMap.get(wlnOrderSku.getString("sys_spec_uid"));
|
|
|
+ String sysSpecUid = wlnOrderSku.getString("sys_spec_uid");
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(sysSpecUid);
|
|
|
+ if (skuSpec == null) {
|
|
|
+ log.error("没有通过万里牛sys_spec_uid找到sku规格");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
OrderSku orderSku = createOrderSku(wlnOrderSku, orderInfo, skuSpec);
|
|
|
saveOrderSkuList.add(orderSku);
|
|
|
+
|
|
|
+ List<OrderSkuBom> orderSkuBomList = createOrderSkuBoom(orderInfo, orderSku);
|
|
|
+ saveOrderSkuBomList.addAll(orderSkuBomList);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // 赋值订单价格
|
|
|
+ setOrderPrice(departmentMap, saveOrderList, saveOrderSkuList, saveOrderSkuBomList, skuSpecMap);
|
|
|
+
|
|
|
// 开启事务
|
|
|
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
try {
|
|
@@ -136,6 +167,9 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
if (saveOrderSkuList.size() > 0) {
|
|
|
orderSkuService.saveBatch(saveOrderSkuList);
|
|
|
}
|
|
|
+ if (saveOrderSkuBomList.size() > 0) {
|
|
|
+ orderSkuBomService.saveBatch(saveOrderSkuBomList);
|
|
|
+ }
|
|
|
// 提交事务
|
|
|
platformTransactionManager.commit(transactionStatus);
|
|
|
return true;
|
|
@@ -152,8 +186,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
* 查询近3天万里牛订单
|
|
|
*/
|
|
|
private List<JSONObject> getWlnOrderList(Date endDate) {
|
|
|
- List<DictCommonData> warehouseCodeList = dictCommonDataService.list(q -> q
|
|
|
- .eq(DictCommonData::getDictCode, "warehouse_code"));
|
|
|
+ List<DictCommonData> warehouseCodeList = dictCommonDataService.list(q -> q.eq(DictCommonData::getDictCode, "warehouse_code"));
|
|
|
if (warehouseCodeList.size() == 0) {
|
|
|
log.error("订单同步失败,仓库字典:warehouse_code 为空");
|
|
|
return null;
|
|
@@ -164,25 +197,25 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
long endTime = endDate.getTime();
|
|
|
long startTime = endTime - 1000 * 60 * 60 * 24;
|
|
|
|
|
|
- for (int i = 0; i < 3; i++) {
|
|
|
- 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);
|
|
|
- }
|
|
|
- startTime -= 1000 * 60 * 60 * 24;
|
|
|
- endTime -= 1000 * 60 * 60 * 24;
|
|
|
+ // for (int i = 0; i < 3; i++) {
|
|
|
+ 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);
|
|
|
}
|
|
|
+ // startTime -= 1000 * 60 * 60 * 24;
|
|
|
+ // endTime -= 1000 * 60 * 60 * 24;
|
|
|
+ // }
|
|
|
|
|
|
return list;
|
|
|
}
|
|
@@ -278,11 +311,189 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
orderSku.setWlnSkuId(wlnOrderSku.getString("sys_goods_uid"));
|
|
|
orderSku.setWlnSkuSpecId(wlnOrderSku.getString("sys_spec_uid"));
|
|
|
orderSku.setWlnSkuName(wlnOrderSku.getString("oln_sku_name"));
|
|
|
- if (skuSpec != null) {
|
|
|
- orderSku.setSkuId(skuSpec.getSkuId());
|
|
|
- orderSku.setSkuSpecId(skuSpec.getId());
|
|
|
- }
|
|
|
+ orderSku.setSkuId(skuSpec.getSkuId());
|
|
|
+ orderSku.setSkuSpecId(skuSpec.getId());
|
|
|
return orderSku;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建订单包材
|
|
|
+ */
|
|
|
+ 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())
|
|
|
+ );
|
|
|
+
|
|
|
+ // 根据sku规格id获取bomId和bom规格id
|
|
|
+ Map<Long, BomBo> bomBoMap = skuSpecService.getBomBoByIdList(
|
|
|
+ list.stream().map(SkuSpecLink::getSkuSpecId).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ return list.stream().map(item -> {
|
|
|
+ BomBo bomBo = bomBoMap.get(item.getBomSpecId());
|
|
|
+
|
|
|
+ OrderSkuBom orderSkuBom = new OrderSkuBom();
|
|
|
+ orderSkuBom.setId(IdWorker.getId());
|
|
|
+ orderSkuBom.setOrderId(orderInfo.getId());
|
|
|
+ orderSkuBom.setOrderSkuId(orderSku.getId());
|
|
|
+ orderSkuBom.setBomSpecId(item.getBomSpecId());
|
|
|
+ orderSkuBom.setQuantity(item.getQuantity());
|
|
|
+ orderSkuBom.setUnitPrice(bomBo == null ? BigDecimal.ZERO :
|
|
|
+ ObjectUtil.defaultIfNull(bomBo.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
+ return orderSkuBom;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赋值订单价格
|
|
|
+ */
|
|
|
+ private void setOrderPrice(Map<String, Department> departmentMap,
|
|
|
+ List<OrderInfo> orderList,
|
|
|
+ List<OrderSku> orderSkuList,
|
|
|
+ List<OrderSkuBom> saveOrderSkuBomList,
|
|
|
+ Map<String, SkuSpec> skuSpecMap) {
|
|
|
+
|
|
|
+ if (orderList.size() == 0 || orderSkuList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 部门id、加工计费标准id map
|
|
|
+ Map<Long, Long> departmentIdPriceBillingStandardIdMap = departmentMap.values().stream()
|
|
|
+ .collect(Collectors.toMap(BaseIdPo::getId, Department::getPriceBillingStandardId));
|
|
|
+
|
|
|
+ // 加工计费标准id 报价规则列表 map
|
|
|
+ Map<Long, List<PriceBillingStandardDetail>> priceBillingStandardMap = priceBillingStandardDetailService.list()
|
|
|
+ .stream().collect(Collectors.groupingBy(PriceBillingStandardDetail::getPriceBillingStandardId));
|
|
|
+
|
|
|
+ // 根据sku规格id获取bomId和bom规格id
|
|
|
+ Map<Long, BomBo> bomBoMap = skuSpecService.getBomBoByIdList(
|
|
|
+ orderSkuList.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ // 订单明细
|
|
|
+ Map<Long, List<OrderSku>> orderSkuGroup = orderSkuList.stream().collect(Collectors.groupingBy(OrderSku::getOrderId));
|
|
|
+
|
|
|
+ for (OrderInfo orderInfo : orderList) {
|
|
|
+
|
|
|
+ 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());
|
|
|
+ if (ObjectUtil.isEmpty(itemOrderSkuList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OrderSku orderSku : itemOrderSkuList) {
|
|
|
+
|
|
|
+ // 赋值单价
|
|
|
+ assignedUnitPrice(bomBoMap, orderSku);
|
|
|
+
|
|
|
+ // 赋值其他价格
|
|
|
+ assignedOtherPrice(orderSku, orderInfo.getDepartmentId(),
|
|
|
+ departmentIdPriceBillingStandardIdMap, priceBillingStandardMap, skuSpecMap);
|
|
|
+
|
|
|
+ // 添加订单金额
|
|
|
+ addOrderInfoPrice(orderInfo, orderSku, saveOrderSkuBomList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赋值单价
|
|
|
+ */
|
|
|
+ private void assignedUnitPrice(Map<Long, BomBo> bomBoMap, OrderSku orderSku) {
|
|
|
+ BomBo bomBo = bomBoMap.get(orderSku.getSkuSpecId());
|
|
|
+ if (bomBo != null) {
|
|
|
+ orderSku.setUnitPrice(ObjectUtil.defaultIfNull(bomBo.getInternalSellingPrice(), BigDecimal.ZERO));
|
|
|
+ } else {
|
|
|
+ orderSku.setUnitPrice(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赋值其他价格
|
|
|
+ */
|
|
|
+ private void assignedOtherPrice(OrderSku orderSku,
|
|
|
+ Long departmentId,
|
|
|
+ Map<Long, Long> departmentIdPriceBillingStandardIdMap,
|
|
|
+ Map<Long, List<PriceBillingStandardDetail>> priceBillingStandardMap,
|
|
|
+ Map<String, SkuSpec> skuSpecMap) {
|
|
|
+
|
|
|
+ orderSku.setCustomProcessingFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setLssueFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setPackingLabor(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 获取加工计费标准id
|
|
|
+ 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();
|
|
|
+ BigDecimal chargePrice = priceBillingStandardDetail.getChargePrice();
|
|
|
+
|
|
|
+ switch (chargeItem) {
|
|
|
+ case "3":
|
|
|
+ orderSku.setPackingLabor(chargePrice);
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ orderSku.setLssueFee(chargePrice);
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ orderSku.setDeliveryMaterialsFee(chargePrice);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(orderSku.getWlnSkuSpecId());
|
|
|
+ if (skuSpec != null
|
|
|
+ && Objects.equals(chargeItem, skuSpec.getMachinedPanel())
|
|
|
+ && priceBillingStandardDetail.getSectionMin().compareTo(orderSku.getQuantity()) >= 0
|
|
|
+ && priceBillingStandardDetail.getSectionMax().compareTo(orderSku.getQuantity()) < 0) {
|
|
|
+ orderSku.setCustomProcessingFee(chargePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加订单价格
|
|
|
+ */
|
|
|
+ private void addOrderInfoPrice(OrderInfo orderInfo, OrderSku orderSku, List<OrderSkuBom> saveOrderSkuBomList) {
|
|
|
+ BigDecimal productTotalAmount = orderSku.getQuantity().multiply(orderSku.getUnitPrice());
|
|
|
+ BigDecimal customProcessingFee = orderSku.getQuantity().multiply(orderSku.getCustomProcessingFee());
|
|
|
+ BigDecimal lssueFee = orderSku.getQuantity().multiply(orderSku.getLssueFee());
|
|
|
+ BigDecimal deliveryMaterialsFee = orderSku.getQuantity().multiply(orderSku.getDeliveryMaterialsFee());
|
|
|
+ BigDecimal packingLabor = orderSku.getQuantity().multiply(orderSku.getPackingLabor());
|
|
|
+ BigDecimal totalAmount = productTotalAmount.add(customProcessingFee).add(lssueFee).add(deliveryMaterialsFee).add(packingLabor);
|
|
|
+
|
|
|
+ BigDecimal packagingMaterialCost = saveOrderSkuBomList.stream()
|
|
|
+ .filter(item -> Objects.equals(item.getOrderId(), orderInfo.getId()))
|
|
|
+ .filter(item -> Objects.equals(item.getOrderSkuId(), orderSku.getId()))
|
|
|
+ .map(item -> item.getUnitPrice().multiply(item.getQuantity()))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .multiply(orderSku.getQuantity());
|
|
|
+
|
|
|
+ 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.setPackagingMaterialCost(packagingMaterialCost);
|
|
|
+ orderInfo.setTotalAmount(orderInfo.getTotalAmount().add(totalAmount));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|