|
@@ -0,0 +1,90 @@
|
|
|
+package com.sd.wln.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+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;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class WlnOutboundOrderServiceImpl implements WlnOutboundOrderService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutboundOrderService outboundOrderService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncOutboundOrder() {
|
|
|
+ List<JSONObject> wlnOutboundOrder = getWlnOutboundOrder();
|
|
|
+ if (ObjectUtil.isEmpty(wlnOutboundOrder)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OutboundOrder> outboundOrderList = new ArrayList<>();
|
|
|
+ for (JSONObject item : wlnOutboundOrder) {
|
|
|
+ // 非指定事业部订单不同步
|
|
|
+ if (ObjectUtil.notEqual(WlnOrderServiceImpl.WAREHOUSE_CODE, item.getString("storage_code"))) {
|
|
|
+ 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.setStorageCode(item.getString("storage_code"));
|
|
|
+ outboundOrder.setSkuSpecCode(itemDetails.getString("sku_no"));
|
|
|
+ outboundOrder.setQuantity(itemDetails.getBigDecimal("nums"));
|
|
|
+ outboundOrder.setOutboundTime(item.getDate("modify_time"));
|
|
|
+ outboundOrder.setOutboundTimestamp(item.getLong("modify_time"));
|
|
|
+ outboundOrder.setExpress(item.getString("express"));
|
|
|
+ outboundOrderList.add(outboundOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ outboundOrderService.saveBatch(outboundOrderList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询近万里牛出库单
|
|
|
+ */
|
|
|
+ private List<JSONObject> getWlnOutboundOrder() {
|
|
|
+ OutboundOrder outboundOrder = outboundOrderService.getOne(q -> q.orderByDesc(OutboundOrder::getOutboundTimestamp));
|
|
|
+
|
|
|
+ long startTime;
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ if (outboundOrder == null) {
|
|
|
+ startTime = endTime - 1000 * 60 * 60 * 24 * 7;
|
|
|
+ } else {
|
|
|
+ startTime = outboundOrder.getOutboundTimestamp() + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|