|
@@ -0,0 +1,118 @@
|
|
|
+package com.sd.wln.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictCommonData;
|
|
|
+import com.fjhx.tenant.service.dict.DictCommonDataService;
|
|
|
+import com.sd.business.entity.outbound.po.OutboundOrder;
|
|
|
+import com.sd.business.service.outbound.OutboundOrderService;
|
|
|
+import com.sd.wln.service.WlnOutboundOrderService;
|
|
|
+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.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class WlnOutboundOrderServiceImpl implements WlnOutboundOrderService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DictCommonDataService dictCommonDataService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutboundOrderService outboundOrderService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncOutboundOrder() {
|
|
|
+
|
|
|
+ List<String> storageCodeList = getStorageCodeList();
|
|
|
+ if (ObjectUtil.isEmpty(storageCodeList)) {
|
|
|
+ log.error("出库单同步失败,仓库字典:warehouse_code 为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<JSONObject> wlnOutboundOrder = getWlnOutboundOrder();
|
|
|
+ if (ObjectUtil.isEmpty(wlnOutboundOrder)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OutboundOrder> outboundOrderList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (JSONObject item : wlnOutboundOrder) {
|
|
|
+
|
|
|
+
|
|
|
+ String storageCode = item.getString("storage_code");
|
|
|
+ if (!storageCodeList.contains(storageCode)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<JSONObject> detailsList = item.getJSONArray("details").toJavaList(JSONObject.class);
|
|
|
+ for (JSONObject itemDetails : detailsList) {
|
|
|
+ OutboundOrder outboundOrder = new OutboundOrder();
|
|
|
+ outboundOrder.setCode(item.getString("inv_no"));
|
|
|
+ outboundOrder.setOrderCode(item.getString("tp_tid"));
|
|
|
+ outboundOrder.setOrderWlnCode(item.getString("from_trade_no"));
|
|
|
+ outboundOrder.setSkuSpecCode(itemDetails.getString("sku_no"));
|
|
|
+ outboundOrder.setStorageCode(storageCode);
|
|
|
+ outboundOrder.setQuantity(itemDetails.getBigDecimal("nums"));
|
|
|
+ outboundOrder.setOutboundTime(item.getDate("modify_time"));
|
|
|
+ outboundOrder.setOutboundTimestamp(item.getLong("modify_time"));
|
|
|
+ outboundOrderList.add(outboundOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ outboundOrderService.saveBatch(outboundOrderList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getStorageCodeList() {
|
|
|
+ List<DictCommonData> warehouseCodeList = dictCommonDataService.list(
|
|
|
+ q -> q.eq(DictCommonData::getDictCode, "warehouse_code"));
|
|
|
+ if (warehouseCodeList.size() == 0) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return warehouseCodeList.stream().map(DictCommonData::getDictValue).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询近万里牛出库单
|
|
|
+ */
|
|
|
+ private List<JSONObject> getWlnOutboundOrder() {
|
|
|
+ OutboundOrder outboundOrder = outboundOrderService.getOne(
|
|
|
+ q -> q.orderByDesc(OutboundOrder::getOutboundTimestamp).last("limit 1"));
|
|
|
+
|
|
|
+ long startTime;
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ if (outboundOrder != null) {
|
|
|
+ startTime = outboundOrder.getOutboundTimestamp();
|
|
|
+ } else {
|
|
|
+ startTime = endTime - 1000 * 60 * 60 * 24 * 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<JSONObject> list = new ArrayList<>();
|
|
|
+
|
|
|
+ int page = 1;
|
|
|
+ int size;
|
|
|
+ do {
|
|
|
+ try {
|
|
|
+ List<JSONObject> itemList = WlnUtil.getOutboundOrder(page, 200, startTime, endTime);
|
|
|
+ page++;
|
|
|
+ size = itemList.size();
|
|
|
+ list.addAll(itemList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("出库单同步失败", e);
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ } while (size >= 200);
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|