Procházet zdrojové kódy

JST 采购单+商品入库

zhaoxian před 6 měsíci
rodič
revize
0ad13930de

+ 3 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/constants/KuaiShouConstants.java

@@ -6,5 +6,8 @@ public class KuaiShouConstants {
     public static final String APP_SECRET = "3qAsvwcUYuHFVpxJ_OTSFg";
     public static final String SIGN_SECRET = "8e21f5bc03b6d2dc63e6256225dac00b";
 
+    //聚水潭连接(https://openweb.jushuitan.com/dev-doc?docType=2&docId=14)
+    public static final String JST_URL = "https://openapi.jushuitan.com";
+
 
 }

+ 44 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaiJSTController.java

@@ -2,22 +2,66 @@ package com.ruixuan.isc.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.ruixuan.isc.service.IKwaiJSTService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
 @RestController
+@Api(tags = "聚水潭")
 @RequestMapping("/kwaixiaodian/jst")
 public class KwaiJSTController {
     @Autowired
     private IKwaiJSTService kwaiJSTService;
 
+    static ExecutorService dateService = Executors.newFixedThreadPool(6);
+
     @GetMapping(value = "/refreshToken")
+    @ApiOperation(value = "refreshToken")
     public JSONObject refreshToken() {
         return kwaiJSTService.refreshToken();
+    }
 
+    /**
+     * https://openweb.jushuitan.com/dev-doc?docType=2&docId=14
+     * 普通商品资料查询(按sku查询) + 组合装商品查询
+     * 对应数据表:ruixuan.kwaixiaodian_jst
+     */
+    @GetMapping(value = "/queryAndInsertSku")
+    @ApiOperation(value = "普通商品资料查询(按sku查询)+组合装商品查询")
+    public void queryAndInsertSku(@ApiParam("时间") @RequestParam(value = "date", required = false) String date) {
+//        List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes("2024-01-01", "2024-11-25");
+//        allDatesOfTwoTimes.forEach(dates -> dateService.submit(() -> {
+        try {
+//            Thread.sleep(5000L);
+            kwaiJSTService.queryAndInsertSku(date);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+//        }));
+    }
 
+    /**
+     * https://openweb.jushuitan.com/dev-doc?docType=6&docId=26
+     * 采购单查询
+     * 对应数据表:ruixuan.kwaixiaodian_jst_purchase、kwaixiaodian_jst_purchase_item
+     */
+    @GetMapping(value = "/queryAndInsertPurchase")
+    @ApiOperation(value = "采购单查询")
+    public void queryAndInsertPurchase(@ApiParam("时间") @RequestParam(value = "date", required = false) String date) {
+        try {
+            kwaiJSTService.queryAndInsertPurchase(date);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
+
 }

+ 202 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianJst.java

@@ -0,0 +1,202 @@
+package com.ruixuan.isc.entity;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 商品信息-聚水潭对象 kwaixiaodian_jst
+ */
+@Data
+public class KwaixiaodianJst {
+
+    /**
+     * 商品编码
+     */
+    private String skuId;
+
+    /**
+     * 1-普通商品,2-组合商品
+     */
+    private String dataType;
+
+    /**
+     * 款式编码
+     */
+    private String iId;
+
+    /**
+     * 商品名称
+     */
+    private String name;
+
+    /**
+     * 商品简称
+     */
+    private String shortName;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 销售价
+     */
+    private BigDecimal salePrice;
+
+    /**
+     * 成本价
+     */
+    private BigDecimal costPrice;
+
+    /**
+     * 颜色规格
+     */
+    private String propertiesValue;
+
+    /**
+     * 颜色
+     */
+    private String color;
+
+    /**
+     * 类目id
+     */
+    private Long cId;
+
+    /**
+     * 分类
+     */
+    private Long category;
+
+    /**
+     * 大图地址
+     */
+    private String picBig;
+
+    /**
+     * 图片地址
+     */
+    private String pic;
+
+    /**
+     * 是否启用,0:备用,1:启用,-1:禁用
+     */
+    private Long enabled;
+
+    /**
+     * 重量
+     */
+    private BigDecimal weight;
+
+    /**
+     * 市场价
+     */
+    private BigDecimal marketPrice;
+
+    /**
+     * 品牌
+     */
+    private String brand;
+
+    /**
+     * 供应商编号;对应页面:供应商信息-供应商内部编码
+     */
+    private String supplierId;
+
+    /**
+     * 供应商名称
+     */
+    private String supplierName;
+
+    /**
+     * 国标码
+     */
+    private String skuCode;
+
+    /**
+     * 供应商商品编码
+     */
+    private String supplierSkuId;
+
+    /**
+     * 供应商商品款号
+     */
+    private String supplierIId;
+
+    /**
+     * 虚拟分类
+     */
+    private String vcName;
+
+    /**
+     * 商品类型
+     */
+    private String skuType;
+
+    /**
+     * 创建者
+     */
+    private String creator;
+
+    /**
+     * 创建时间
+     */
+    private String created;
+
+    /**
+     * 修改时间
+     */
+    private String modified;
+
+    /**
+     * 商品属性,成品,半成品,原材料,包材
+     */
+    private String itemType;
+
+    /**
+     * 是否禁止同步,0=启用同步,1=禁用同步,2=部分禁用
+     */
+    private Long stockDisabled;
+
+    /**
+     * 单位
+     */
+    private String unit;
+
+    /**
+     * 保质期
+     */
+    private Long shelfLife;
+
+    /**
+     * 商品标签,多个标签时以逗号分隔
+     */
+    private String labels;
+
+    /**
+     * 生产许可证
+     */
+    private String productionLicence;
+
+    /**
+     * 长
+     */
+    private Long l;
+
+    /**
+     * 宽
+     */
+    private Long w;
+
+    /**
+     * 高
+     */
+    private Long h;
+
+    /**
+     * 是否开启序列号
+     */
+    private String isSeriesNumber;
+}

+ 43 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianJstItems.java

@@ -0,0 +1,43 @@
+package com.ruixuan.isc.entity;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 聚水潭-组合装子商品列表 kwaixiaodian_jst_items
+ */
+@Data
+public class KwaixiaodianJstItems {
+
+
+    /**
+     * 组合装商品编码
+     */
+    private String skuId;
+
+    /**
+     * 子商品编码
+     */
+    private String srcSkuId;
+
+    /**
+     * 子商品数量
+     */
+    private Long qty;
+
+    /**
+     * 应占售价
+     */
+    private BigDecimal salePrice;
+
+    /**
+     * 修改时间
+     */
+    private String modified;
+
+    /**
+     * 组合装商品编码
+     */
+    private String combineSkuId;
+}

+ 117 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianJstPurchase.java

@@ -0,0 +1,117 @@
+package com.ruixuan.isc.entity;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 聚水潭-采购信息对象 kwaixiaodian_jst_purchase
+ */
+@Data
+public class KwaixiaodianJstPurchase {
+
+
+    /**
+     * 采购单号
+     */
+    private Long poId;
+
+    /**
+     * 外部单号;对应采购单管理页面外部单号(且对应采购单上传的external_id)
+     */
+    private Long soId;
+
+    /**
+     * 采购日期
+     */
+    private String poDate;
+
+    /**
+     * 状态:Creating:草拟,WaitConfirm:待审核,Confirmed:已确认,Finished:完成,Cancelled:作废,Delete:删除
+     */
+    private String status;
+
+    /**
+     * 收货状态:Timeout:预计收货超时,Received:全部入库,Part_Received:部分入库,Not_Received:未入库
+     */
+    private String receiveStatus;
+
+    /**
+     * 供应商编码
+     */
+    private Long supplierId;
+
+    /**
+     * 供应商名称
+     */
+    private String seller;
+
+    /**
+     * 税率
+     */
+    private Long taxRate;
+
+    /**
+     * 采购员
+     */
+    private String purchaserName;
+
+    /**
+     * 送货地址
+     */
+    private String sendAddress;
+
+    /**
+     * 合同条款
+     */
+    private String term;
+
+    /**
+     * 商品类型
+     */
+    private String itemType;
+
+    /**
+     * 多标签
+     */
+    private String labels;
+
+    /**
+     * 审核生效日期
+     */
+    private String confirmDate;
+
+    /**
+     * 完成日期
+     */
+    private String finishTime;
+
+    /**
+     * 修改时间
+     */
+    private String modified;
+
+    /**
+     * 仓库编号
+     */
+    private Long wmsCoId;
+
+    /**
+     * 溢装比
+     */
+    private BigDecimal moreRate;
+
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 运费
+     */
+    private BigDecimal freight;
+
+    /**
+     * 汇总采购单号
+     */
+    private String mergePoId;
+}

+ 91 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianJstPurchaseItems.java

@@ -0,0 +1,91 @@
+package com.ruixuan.isc.entity;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 聚水潭-采购单明细对象 kwaixiaodian_jst_purchase_item
+ */
+@Data
+public class KwaixiaodianJstPurchaseItems {
+
+    /**
+     * 采购单明细编号
+     */
+    private Long poiId;
+
+    /**
+     * 采购单号
+     */
+    private Long poId;
+
+    /**
+     * 商家sku
+     */
+    private String skuId;
+
+    /**
+     * 商品名称
+     */
+    private String name;
+
+    /**
+     * 数量,非实际入库数量,如需获取实际入库数量请调用采购入库查询接口,对应采购入库单(已入库状态)的商品明细数量
+     */
+    private Long qty;
+
+    /**
+     * 单价
+     */
+    private BigDecimal price;
+
+    /**
+     * 款号
+     */
+    private String iId;
+
+    /**
+     * 预计到货日期
+     */
+    private String deliveryDate;
+
+    /**
+     * 税率
+     */
+    private BigDecimal taxRate;
+
+    /**
+     * 质检数
+     */
+    private Long qcQty;
+
+    /**
+     * 质检正品数
+     */
+    private Long qcQualityQty;
+
+    /**
+     * 质检次品数
+     */
+    private Long qcDefectiveQty;
+
+    /**
+     * 已入库数
+     */
+    private Long inQty;
+
+    /**
+     * 退货数
+     */
+    private Long returnQty;
+
+    /**
+     * 是否上架:2全部上架 1部分上架 0未上架
+     */
+    private Long isDelivery;
+    /**
+     * 备注
+     */
+    private String remark;
+}

+ 12 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/KwaiJSTMapper.java

@@ -1,6 +1,10 @@
 package com.ruixuan.isc.mapper;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ruixuan.isc.entity.KwaixiaodianJst;
+import com.ruixuan.isc.entity.KwaixiaodianJstItems;
+import com.ruixuan.isc.entity.KwaixiaodianJstPurchase;
+import com.ruixuan.isc.entity.KwaixiaodianJstPurchaseItems;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -9,4 +13,12 @@ public interface KwaiJSTMapper {
     List<JSONObject> getList();
 
     void updateToken(@Param("id") Long id, @Param("accessToken") String accessToken, @Param("refreshToken") String refreshToken);
+
+    void replaceKwaixiaodianJst(@Param("list") List<KwaixiaodianJst> jstList);
+
+    void replaceKwaixiaodianJstItems(@Param("list") List<KwaixiaodianJstItems> itemList);
+
+    void replacekwaixiaodianJstPurchase(@Param("list") List<KwaixiaodianJstPurchase> jstList);
+
+    void replaceKwaixiaodianJstPurchaseItems(@Param("list") List<KwaixiaodianJstPurchaseItems> itemList);
 }

+ 4 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/IKwaiJSTService.java

@@ -4,4 +4,8 @@ import com.alibaba.fastjson.JSONObject;
 
 public interface IKwaiJSTService {
     JSONObject refreshToken();
+
+    void queryAndInsertSku(String date);
+
+    void queryAndInsertPurchase(String dates);
 }

+ 224 - 6
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaiJSTServiceImpl.java

@@ -1,18 +1,27 @@
 package com.ruixuan.isc.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.http.HttpUtil;
+import com.ruixuan.isc.constants.KuaiShouConstants;
+import com.ruixuan.isc.entity.KwaixiaodianJst;
+import com.ruixuan.isc.entity.KwaixiaodianJstItems;
+import com.ruixuan.isc.entity.KwaixiaodianJstPurchase;
+import com.ruixuan.isc.entity.KwaixiaodianJstPurchaseItems;
 import com.ruixuan.isc.mapper.KwaiJSTMapper;
 import com.ruixuan.isc.service.IKwaiJSTService;
 import com.ruixuan.isc.utils.JSTSignUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+@Slf4j
 @Service
 public class KwaiJSTServiceImpl implements IKwaiJSTService {
     @Autowired
@@ -21,7 +30,6 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
 
     @Override
     public JSONObject refreshToken() {
-
         JSONObject returnJson = new JSONObject();
         try {
             List<JSONObject> list = kwaiJSTMapper.getList();
@@ -41,7 +49,7 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
                 requestMap.put("charset", "utf-8");
                 long timestamp = System.currentTimeMillis() / 1000;
                 requestMap.put("timestamp", String.valueOf(timestamp));
-          //      requestMap.put("code", JSTSignUtils.generateSoleName());
+                //      requestMap.put("code", JSTSignUtils.generateSoleName());
 
                 requestMap.put("refresh_token", refreshToken);
                 requestMap.put("scope", "all");
@@ -50,14 +58,14 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
 
                 String s = HttpUtil.httpPostFormRequest(accessTokenUrl, requestMap, null);
                 JSONObject info = JSONObject.parseObject(s);
-                if(!Check.isNull(info)){
+                if (!Check.isNull(info)) {
                     Integer code = info.getInteger("code");
-                    if(code == 0){
+                    if (code == 0) {
                         JSONObject data = info.getJSONObject("data");
-                        if(!Check.isNull(data)){
+                        if (!Check.isNull(data)) {
                             String accessToken1 = data.getString("access_token");
                             String refreshToken1 = data.getString("refresh_token");
-                            kwaiJSTMapper.updateToken(id,accessToken1,refreshToken1);
+                            kwaiJSTMapper.updateToken(id, accessToken1, refreshToken1);
                         }
                     }
                 }
@@ -73,4 +81,214 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
         }
         return returnJson;
     }
+
+    @Override
+    public void queryAndInsertSku(String date) {
+        try {
+            List<JSONObject> list = kwaiJSTMapper.getList();
+            if (Check.isNull(list)) {
+                throw new Exception("token信息为空");
+            }
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject obj = list.get(i);
+                Map<String, Object> params = new HashMap<>();
+                params.put("app_key", obj.getString("appKey"));
+                params.put("access_token", obj.getString("accessToken"));
+                params.put("charset", "utf-8");
+                params.put("version", "2");
+                params.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
+                //普通商品
+                addSku(params, obj.getString("appSecret"), date, 1);
+                //组合装
+                addCombineSku(params, obj.getString("appSecret"), date, 1);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        log.info("{} 完毕", date);
+    }
+
+
+    private void addSku(Map<String, Object> params, String secret, String date, int pageIndex) throws InterruptedException {
+        boolean hasNext = false;
+        JSONObject biz = new JSONObject();
+        biz.put("page_index", pageIndex);
+        biz.put("page_size", 50);
+        biz.put("modified_begin", date + " 00:00:00");
+        biz.put("modified_end", date + " 23:59:59");
+        params.put("biz", biz);
+        String sign = JSTSignUtils.getSign(secret, params);
+        params.put("sign", sign);
+        Thread.sleep(500l);
+        String request = HttpUtil.httpPostFormRequest(KuaiShouConstants.JST_URL + "/open/sku/query", params, null);
+        JSONObject info = JSONObject.parseObject(request);
+        if (!Check.isNull(info)) {
+            Integer code = info.getInteger("code");
+            if (code == 0) {
+                JSONObject data = info.getJSONObject("data");
+                if (!Check.isNull(data)) {
+                    if (data.getBoolean("has_next")) {
+                        hasNext = true;
+                    }
+                    List<KwaixiaodianJst> jstList = new ArrayList<>();
+                    JSONArray datas = data.getJSONArray("datas");
+                    for (int i = 0; i < datas.size(); i++) {
+                        JSONObject skuInfo = datas.getJSONObject(i);
+                        KwaixiaodianJst jst = JSONObject.parseObject(skuInfo.toJSONString(), KwaixiaodianJst.class);
+                        jst.setDataType("1");
+                        jstList.add(jst);
+                    }
+                    if (jstList.size() > 0) {
+                        kwaiJSTMapper.replaceKwaixiaodianJst(jstList);
+                    }
+                }
+            } else {
+                log.error("获取JST普通商品失败,原因:\n{}", info);
+            }
+        }
+        if (hasNext) {
+            addSku(params, secret, date, pageIndex + 1);
+        }
+    }
+
+    private void addCombineSku(Map<String, Object> params, String secret, String date, int pageIndex) throws InterruptedException {
+        boolean hasNext = false;
+        JSONObject biz = new JSONObject();
+        biz.put("page_index", pageIndex);
+        biz.put("page_size", 50);
+        biz.put("modified_begin", date + " 00:00:00");
+        biz.put("modified_end", date + " 23:59:59");
+        params.put("biz", biz);
+        String sign = JSTSignUtils.getSign(secret, params);
+        params.put("sign", sign);
+        Thread.sleep(500l);
+        String request = HttpUtil.httpPostFormRequest(KuaiShouConstants.JST_URL + "/open/combine/sku/query", params, null);
+        JSONObject info = JSONObject.parseObject(request);
+        if (!Check.isNull(info)) {
+            Integer code = info.getInteger("code");
+            if (code == 0) {
+                JSONObject data = info.getJSONObject("data");
+                if (!Check.isNull(data)) {
+                    if (data.getBoolean("has_next")) {
+                        hasNext = true;
+                    }
+                    List<KwaixiaodianJst> jstList = new ArrayList<>();
+                    JSONArray datas = data.getJSONArray("datas");
+                    for (int i = 0; i < datas.size(); i++) {
+                        JSONObject skuInfo = datas.getJSONObject(i);
+                        KwaixiaodianJst jst = JSONObject.parseObject(skuInfo.toJSONString(), KwaixiaodianJst.class);
+                        jst.setDataType("2");
+                        jstList.add(jst);
+                        if (!Check.isNull(skuInfo.getJSONArray("items"))) {
+                            addCombineSkuItems(jst.getSkuId(), skuInfo.getJSONArray("items"));
+                        }
+                    }
+                    if (jstList.size() > 0) {
+                        kwaiJSTMapper.replaceKwaixiaodianJst(jstList);
+                    }
+                }
+            } else {
+                log.error("获取JST组合装商品失败,原因:\n{}", info);
+            }
+        }
+        if (hasNext) {
+            addCombineSku(params, secret, date, pageIndex + 1);
+        }
+    }
+
+    private void addCombineSkuItems(String skuId, JSONArray items) {
+        List<KwaixiaodianJstItems> itemList = new ArrayList<>();
+        for (int i = 0; i < items.size(); i++) {
+            JSONObject it = items.getJSONObject(i);
+            KwaixiaodianJstItems item = JSONObject.parseObject(it.toJSONString(), KwaixiaodianJstItems.class);
+            item.setSkuId(skuId);
+            itemList.add(item);
+        }
+        if (itemList.size() > 0) {
+            kwaiJSTMapper.replaceKwaixiaodianJstItems(itemList);
+        }
+    }
+
+    @Override
+    public void queryAndInsertPurchase(String date) {
+        try {
+            List<JSONObject> list = kwaiJSTMapper.getList();
+            if (Check.isNull(list)) {
+                throw new Exception("token信息为空");
+            }
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject obj = list.get(i);
+                Map<String, Object> params = new HashMap<>();
+                params.put("app_key", obj.getString("appKey"));
+                params.put("access_token", obj.getString("accessToken"));
+                params.put("charset", "utf-8");
+                params.put("version", "2");
+                params.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
+                //采购单查询
+                addPurchase(params, obj.getString("appSecret"), date, 1);
+
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        log.info("{} 完毕", date);
+    }
+
+    private void addPurchase(Map<String, Object> params, String secret, String date, int pageIndex) throws InterruptedException {
+        boolean hasNext = false;
+        JSONObject biz = new JSONObject();
+        biz.put("page_index", pageIndex);
+        biz.put("page_size", 50);
+        biz.put("modified_begin", date + " 00:00:00");
+        biz.put("modified_end", date + " 23:59:59");
+        params.put("biz", biz);
+        String sign = JSTSignUtils.getSign(secret, params);
+        params.put("sign", sign);
+        Thread.sleep(500l);
+        String request = HttpUtil.httpPostFormRequest(KuaiShouConstants.JST_URL + "/open/purchase/query", params, null);
+        JSONObject info = JSONObject.parseObject(request);
+        if (!Check.isNull(info)) {
+            Integer code = info.getInteger("code");
+            if (code == 0) {
+                JSONObject data = info.getJSONObject("data");
+                if (!Check.isNull(data)) {
+                    if (data.getBoolean("has_next")) {
+                        hasNext = true;
+                    }
+                    List<KwaixiaodianJstPurchase> jstList = new ArrayList<>();
+                    JSONArray datas = data.getJSONArray("datas");
+                    if (!Check.isNull(datas)) {
+                        for (int i = 0; i < datas.size(); i++) {
+                            JSONObject skuInfo = datas.getJSONObject(i);
+                            KwaixiaodianJstPurchase jst = JSONObject.parseObject(skuInfo.toJSONString(), KwaixiaodianJstPurchase.class);
+                            jstList.add(jst);
+                            if (!Check.isNull(skuInfo.getJSONArray("items"))) {
+                                addPurchaseItems(skuInfo.getJSONArray("items"));
+                            }
+                        }
+                    }
+                    if (jstList.size() > 0) {
+                        kwaiJSTMapper.replacekwaixiaodianJstPurchase(jstList);
+                    }
+                }
+            } else {
+                log.error("查询JST采购单失败,原因:\n{}", info);
+            }
+        }
+        if (hasNext) {
+            addPurchase(params, secret, date, pageIndex + 1);
+        }
+    }
+
+    private void addPurchaseItems(JSONArray items) {
+        List<KwaixiaodianJstPurchaseItems> itemList = new ArrayList<>();
+        for (int i = 0; i < items.size(); i++) {
+            JSONObject it = items.getJSONObject(i);
+            KwaixiaodianJstPurchaseItems item = JSONObject.parseObject(it.toJSONString(), KwaixiaodianJstPurchaseItems.class);
+            itemList.add(item);
+        }
+        if (itemList.size() > 0) {
+            kwaiJSTMapper.replaceKwaixiaodianJstPurchaseItems(itemList);
+        }
+    }
 }

+ 203 - 0
ruixuan-live/src/main/resources/mapper/isc/KwaiJSTMapper.xml

@@ -16,4 +16,207 @@
 
         FROM kwaixiaodian_jst_token
     </select>
+
+
+    <insert id="replaceKwaixiaodianJst">
+        replace into `ruixuan`.kwaixiaodian_jst(
+        sku_id,
+        data_type,
+        i_id,
+        `name`,
+        short_name,
+        sale_price,
+        cost_price,
+        properties_value,
+        color,
+        c_id,
+        category,
+        pic_big,
+        pic,
+        enabled,
+        weight,
+        market_price,
+        brand,
+        supplier_id,
+        supplier_name,
+        sku_code,
+        supplier_sku_id,
+        supplier_i_id,
+        vc_name,
+        sku_type,
+        creator,
+        created,
+        modified,
+        remark,
+        item_type,
+        stock_disabled,
+        unit,
+        shelf_life,
+        labels,
+        production_licence,
+        l,
+        w,
+        h,
+        is_series_number
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.skuId},
+            #{li.dataType},
+            #{li.iId},
+            #{li.name},
+            #{li.shortName},
+            #{li.salePrice},
+            #{li.costPrice},
+            #{li.propertiesValue},
+            #{li.color},
+            #{li.cId},
+            #{li.category},
+            #{li.picBig},
+            #{li.pic},
+            #{li.enabled},
+            #{li.weight},
+            #{li.marketPrice},
+            #{li.brand},
+            #{li.supplierId},
+            #{li.supplierName},
+            #{li.skuCode},
+            #{li.supplierSkuId},
+            #{li.supplierIId},
+            #{li.vcName},
+            #{li.skuType},
+            #{li.creator},
+            #{li.created},
+            #{li.modified},
+            #{li.remark},
+            #{li.itemType},
+            #{li.stockDisabled},
+            #{li.unit},
+            #{li.shelfLife},
+            #{li.labels},
+            #{li.productionLicence},
+            #{li.l},
+            #{li.w},
+            #{li.h},
+            #{li.isSeriesNumber}
+            )
+        </foreach>
+    </insert>
+
+    <insert id="replaceKwaixiaodianJstItems">
+        replace into `ruixuan`.kwaixiaodian_jst_items(
+        sku_id,
+        src_sku_id,
+        qty,
+        sale_price,
+        modified,
+        combine_sku_id
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.skuId},
+            #{li.srcSkuId},
+            #{li.qty},
+            #{li.salePrice},
+            #{li.modified},
+            #{li.combineSkuId}
+            )
+        </foreach>
+    </insert>
+
+    <insert id="replacekwaixiaodianJstPurchase">
+        replace into `ruixuan`.kwaixiaodian_jst_purchase(
+        po_id,
+        so_id,
+        po_date,
+        remark,
+        status,
+        receive_status,
+        supplier_id,
+        seller,
+        tax_rate,
+        purchaser_name,
+        send_address,
+        term,
+        item_type,
+        labels,
+        confirm_date,
+        finish_time,
+        modified,
+        wms_co_id,
+        more_rate,
+        freight,
+        merge_po_id
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.poId},
+            #{li.soId},
+            #{li.poDate},
+            #{li.remark},
+            #{li.status},
+            #{li.receiveStatus},
+            #{li.supplierId},
+            #{li.seller},
+            #{li.taxRate},
+            #{li.purchaserName},
+            #{li.sendAddress},
+            #{li.term},
+            #{li.itemType},
+            #{li.labels},
+            #{li.confirmDate},
+            #{li.finishTime},
+            #{li.modified},
+            #{li.wmsCoId},
+            #{li.moreRate},
+            #{li.freight},
+            #{li.mergePoId}
+            )
+        </foreach>
+    </insert>
+
+    <insert id="replaceKwaixiaodianJstPurchaseItems">
+        replace into `ruixuan`.kwaixiaodian_jst_purchase_items(
+        poi_id,
+        po_id,
+        sku_id,
+        name,
+        qty,
+        price,
+        i_id,
+        delivery_date,
+        remark,
+        tax_rate,
+        qc_qty,
+        qc_quality_qty,
+        qc_defective_qty,
+        in_qty,
+        return_qty,
+        is_delivery
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.poiId},
+            #{li.poId},
+            #{li.skuId},
+            #{li.name},
+            #{li.qty},
+            #{li.price},
+            #{li.iId},
+            #{li.deliveryDate},
+            #{li.remark},
+            #{li.taxRate},
+            #{li.qcQty},
+            #{li.qcQualityQty},
+            #{li.qcDefectiveQty},
+            #{li.inQty},
+            #{li.returnQty},
+            #{li.isDelivery}
+            )
+        </foreach>
+    </insert>
 </mapper>