Browse Source

出库单

24282 1 year ago
parent
commit
edff158450

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/order/po/OrderInfo.java

@@ -74,6 +74,11 @@ public class OrderInfo extends BasePo {
     private Date wlnPrintTime;
     private Date wlnPrintTime;
 
 
     /**
     /**
+     * 万里牛仓库编码
+     */
+    private String wlnStorageCode;
+
+    /**
      * 交期
      * 交期
      */
      */
     @NotNull(message = "交货时间不能为空")
     @NotNull(message = "交货时间不能为空")

+ 4 - 2
sd-wln/src/main/java/com/sd/wln/entity/Signature.java

@@ -2,14 +2,16 @@ package com.sd.wln.entity;
 
 
 import com.ruoyi.common.utils.sign.Md5Utils;
 import com.ruoyi.common.utils.sign.Md5Utils;
 import com.sd.wln.constants.WlnConstant;
 import com.sd.wln.constants.WlnConstant;
-import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
 
 
 /**
 /**
  * 签名参数实体类
  * 签名参数实体类
  */
  */
-@Data
+@Getter
+@Setter
 public class Signature implements Serializable {
 public class Signature implements Serializable {
 
 
     private static final long serialVersionUID = 1L;
     private static final long serialVersionUID = 1L;

+ 56 - 0
sd-wln/src/main/java/com/sd/wln/entity/StockParam.java

@@ -0,0 +1,56 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package com.sd.wln.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 查询订单参数实体类
+ */
+@Getter
+@Setter
+public class StockParam extends Signature {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 单据编码
+     */
+    private String bill_code;
+
+    /**
+     * 单据编码
+     */
+    private String trade_code;
+
+    /**
+     * 单据修改时间,仅支持近3个月的日期查询
+     */
+    private Long modify_time;
+
+    /**
+     * 单据修改结束时间,仅支持近3个月的日期查询
+     */
+    private Long modify_end_time;
+
+    /**
+     * 是否拆分组合商品
+     */
+    private Boolean is_split;
+
+}

+ 16 - 4
sd-wln/src/main/java/com/sd/wln/scheduled/WlnSyncTask.java

@@ -1,16 +1,16 @@
 package com.sd.wln.scheduled;
 package com.sd.wln.scheduled;
 
 
 import com.sd.wln.service.WlnOrderService;
 import com.sd.wln.service.WlnOrderService;
+import com.sd.wln.service.WlnOutboundOrderService;
 import com.sd.wln.service.WlnSkuService;
 import com.sd.wln.service.WlnSkuService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Profile;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
 /**
 /**
  * 同步万里牛数据(本地环境不执行同步逻辑)
  * 同步万里牛数据(本地环境不执行同步逻辑)
  */
  */
-@Profile({"test", "prod"})
+// @Profile({"test", "prod"})
 @Component
 @Component
 public class WlnSyncTask {
 public class WlnSyncTask {
 
 
@@ -20,10 +20,13 @@ public class WlnSyncTask {
     @Autowired
     @Autowired
     private WlnOrderService wlnOrderService;
     private WlnOrderService wlnOrderService;
 
 
+    @Autowired
+    private WlnOutboundOrderService wlnOutboundOrderService;
+
     /**
     /**
      * 每天凌晨1点同步一次sku信息
      * 每天凌晨1点同步一次sku信息
      */
      */
-    @Scheduled(cron = "0 0 1 * * ?")
+    // @Scheduled(cron = "0 0 1 * * ?")
     // @Scheduled(fixedDelay = 60 * 1000)
     // @Scheduled(fixedDelay = 60 * 1000)
     public void syncSku() {
     public void syncSku() {
         for (int i = 0; i < 3; i++) {
         for (int i = 0; i < 3; i++) {
@@ -44,9 +47,18 @@ public class WlnSyncTask {
     /**
     /**
      * 每分钟同步一次订单数据
      * 每分钟同步一次订单数据
      */
      */
-    @Scheduled(fixedDelay = 60 * 1000)
+    // @Scheduled(fixedDelay = 60 * 1000)
     private void syncOrder() {
     private void syncOrder() {
         wlnOrderService.syncOrder();
         wlnOrderService.syncOrder();
     }
     }
 
 
+    /**
+     * 每5分钟同步一次出库单数据
+     */
+    @Scheduled(fixedDelay = 5 * 60 * 1000)
+    private void syncOutboundOrder() {
+        wlnOutboundOrderService.syncOutboundOrder();
+        System.out.println();
+    }
+
 }
 }

+ 7 - 0
sd-wln/src/main/java/com/sd/wln/service/WlnOutboundOrderService.java

@@ -0,0 +1,7 @@
+package com.sd.wln.service;
+
+public interface WlnOutboundOrderService {
+
+    void syncOutboundOrder();
+
+}

+ 1 - 0
sd-wln/src/main/java/com/sd/wln/service/impl/WlnOrderServiceImpl.java

@@ -276,6 +276,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
         orderInfo.setWlnCreateTime(wlnOrder.getDate("create_time"));
         orderInfo.setWlnCreateTime(wlnOrder.getDate("create_time"));
         orderInfo.setWlnApproveTime(wlnOrder.getDate("approve_time"));
         orderInfo.setWlnApproveTime(wlnOrder.getDate("approve_time"));
         orderInfo.setWlnPrintTime(wlnOrder.getDate("print_time"));
         orderInfo.setWlnPrintTime(wlnOrder.getDate("print_time"));
+        orderInfo.setWlnStorageCode(wlnOrder.getString("storage_code"));
         orderInfo.setDeliveryTime(DateUtil.offsetDay(orderInfo.getWlnCreateTime(), 1));
         orderInfo.setDeliveryTime(DateUtil.offsetDay(orderInfo.getWlnCreateTime(), 1));
         orderInfo.setProvince(wlnOrder.getString("province"));
         orderInfo.setProvince(wlnOrder.getString("province"));
         orderInfo.setCity(wlnOrder.getString("city"));
         orderInfo.setCity(wlnOrder.getString("city"));

+ 118 - 0
sd-wln/src/main/java/com/sd/wln/service/impl/WlnOutboundOrderServiceImpl.java

@@ -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;
+    }
+
+}

+ 43 - 13
sd-wln/src/main/java/com/sd/wln/util/WlnUtil.java

@@ -8,6 +8,7 @@ import com.ruoyi.common.utils.MapUtil;
 import com.sd.wln.constants.WlnConstant;
 import com.sd.wln.constants.WlnConstant;
 import com.sd.wln.entity.GoodsSpecParam;
 import com.sd.wln.entity.GoodsSpecParam;
 import com.sd.wln.entity.SkuClassifyParam;
 import com.sd.wln.entity.SkuClassifyParam;
+import com.sd.wln.entity.StockParam;
 import com.sd.wln.entity.TradesParam;
 import com.sd.wln.entity.TradesParam;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -68,10 +69,10 @@ public class WlnUtil {
      */
      */
     public static List<JSONObject> getOrderList(Integer page, Integer limit, Long startTime, Long endTime, String warehouseCode) throws Exception {
     public static List<JSONObject> getOrderList(Integer page, Integer limit, Long startTime, Long endTime, String warehouseCode) throws Exception {
         TradesParam param = new TradesParam();
         TradesParam param = new TradesParam();
-        param.setApprove_time(startTime);
-        param.setEnd_time(endTime);
         param.setPage(page);
         param.setPage(page);
         param.setLimit(limit);
         param.setLimit(limit);
+        param.setApprove_time(startTime);
+        param.setEnd_time(endTime);
         param.setStorage_code(warehouseCode);
         param.setStorage_code(warehouseCode);
         param.setIs_split(true);
         param.setIs_split(true);
         param.setManualImport(false);
         param.setManualImport(false);
@@ -80,6 +81,7 @@ public class WlnUtil {
         //     param.setTrade_status("2");
         //     param.setTrade_status("2");
         // }
         // }
         param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
         param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
+
         String result = send(PREFIX + "erp/opentrade/list/trades", MapUtil.beanToMap(param));
         String result = send(PREFIX + "erp/opentrade/list/trades", MapUtil.beanToMap(param));
         JSONObject json = JSONObject.parseObject(result);
         JSONObject json = JSONObject.parseObject(result);
         Integer code = json.getInteger("code");
         Integer code = json.getInteger("code");
@@ -89,17 +91,45 @@ public class WlnUtil {
         return json.getJSONArray("data").toJavaList(JSONObject.class);
         return json.getJSONArray("data").toJavaList(JSONObject.class);
     }
     }
 
 
-    // public static void main(String[] args) throws Exception {
-    //     List<JSONObject> skuList = getSkuList(1, 200);
-    //
-    //     List<JSONObject> skuClassifyList = getSkuClassifyList();
-    //
-    //     long endTime = System.currentTimeMillis();
-    //     long startTime = endTime - 1000 * 60 * 60 * 24;
-    //     List<JSONObject> orderList = getOrderList(1, 50, startTime, endTime, "B012");
-    //
-    //     System.out.println();
-    // }
+    /**
+     * 获取出库单
+     */
+    public static List<JSONObject> getOutboundOrder(Integer page, Integer limit, Long startTime, Long endTime) throws IOException {
+        StockParam param = new StockParam();
+        param.setPage(page);
+        param.setLimit(limit);
+        param.setModify_time(startTime);
+        param.setModify_end_time(endTime);
+        param.setIs_split(true);
+        param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
+
+        String result = send(PREFIX + "erp/sale/stock/out/query", MapUtil.beanToMap(param));
+        JSONObject json = JSONObject.parseObject(result);
+        Integer code = json.getInteger("code");
+        if (code != 0) {
+            throw new ServiceException(result);
+        }
+        return json.getJSONArray("data").toJavaList(JSONObject.class);
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        // List<JSONObject> skuList = getSkuList(1, 200);
+        //
+        // List<JSONObject> skuClassifyList = getSkuClassifyList();
+        //
+        // long endTime = System.currentTimeMillis();
+        // long startTime = endTime - 1000 * 60 * 60 * 24;
+        // List<JSONObject> orderList = getOrderList(1, 50, startTime, endTime, "B012");
+
+        long endTime = System.currentTimeMillis();
+        long startTime = endTime - 1000 * 60 * 60 * 24 * 7;
+
+        List<JSONObject> outboundOrder = getOutboundOrder(0, 200, 1690367461000L, 1690367461000L);
+
+        String s = JSONObject.toJSONString(outboundOrder);
+        System.out.println();
+    }
 
 
 
 
     /**
     /**