Bladeren bron

快手小店--成本管理

yumeng 10 maanden geleden
bovenliggende
commit
cb4935c28c

+ 78 - 5
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaiJSTController.java

@@ -1,16 +1,15 @@
 package com.ruixuan.isc.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ruixuan.common.utils.Check;
 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 org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -21,7 +20,8 @@ public class KwaiJSTController {
     @Autowired
     private IKwaiJSTService kwaiJSTService;
 
-    static ExecutorService dateService = Executors.newFixedThreadPool(6);
+    static ExecutorService cleanService = Executors.newFixedThreadPool(2);
+    static ExecutorService cleanCostService = Executors.newFixedThreadPool(2);
 
     @GetMapping(value = "/refreshToken")
     @ApiOperation(value = "refreshToken")
@@ -29,6 +29,79 @@ public class KwaiJSTController {
         return kwaiJSTService.refreshToken();
     }
 
+
+    @PostMapping(value = "/costDetail")
+    public JSONObject costDetail(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+
+
+            if (Check.isNull(requestJson)) {
+                throw new Exception("请输入参数");
+            }
+            String skuNick = requestJson.getString("skuNick");
+            if (Check.isNull(skuNick)) {
+                throw new Exception("请输入sku");
+            }
+            Integer dataType = requestJson.getInteger("dataType");
+            if (Check.isNull(dataType)) {
+                throw new Exception("请输入dataType");
+            }
+
+            cleanService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        kwaiJSTService.costDetail(skuNick, dataType);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", 200);
+            returnJson.put("message", e.getMessage());
+
+        }
+
+
+        return returnJson;
+    }
+
+
+    @PostMapping(value = "/cleanCost")
+    public JSONObject cleanCost(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("请输入参数");
+            }
+            String skuNick = requestJson.getString("skuNick");
+            if (Check.isNull(skuNick)) {
+                throw new Exception("请输入sku");
+            }
+            cleanCostService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        kwaiJSTService.cleanCost(skuNick);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", 200);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
     /**
      * https://openweb.jushuitan.com/dev-doc?docType=2&docId=14
      * 普通商品资料查询(按sku查询) + 组合装商品查询

+ 220 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianCostDetail.java

@@ -0,0 +1,220 @@
+package com.ruixuan.isc.entity;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruixuan.common.annotation.Excel;
+import com.ruixuan.common.core.domain.BaseEntity;
+
+
+/**
+ * 快手小店成本详情对象 kwaixiaodian_cost_detail
+ *
+ * @author ruoyi
+ * @date 2024-11-28
+ */
+public class KwaixiaodianCostDetail extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * $column.columnComment
+     */
+    private Long id;
+    private Long dataLongDate;
+
+    /**
+     * 1-普通商品,2-组合商品
+     */
+    @Excel(name = "1-普通商品,2-组合商品")
+    private Integer dataType;
+
+
+    /**
+     * 公司ID
+     */
+    @Excel(name = "公司ID")
+    private Long companyId;
+
+    /**
+     * 订单ID
+     */
+    @Excel(name = "订单ID")
+    private Long oid;
+
+    /**
+     * 店铺ID
+     */
+    @Excel(name = "店铺ID")
+    private Long shopId;
+
+    /**
+     * itemId
+     */
+    @Excel(name = "itemId")
+    private Long itemId;
+
+    /**
+     * skuId
+     */
+    @Excel(name = "skuId")
+    private String skuId;
+
+    /**
+     * 组合skuId
+     */
+    @Excel(name = "组合skuId")
+    private String combinationSkuId;
+
+
+    /**
+     * 出单日期
+     */
+    @Excel(name = "出单日期")
+    private Long statDate;
+
+    /**
+     * 出单日期时间戳
+     */
+    @Excel(name = "出单日期时间戳")
+    private Long orderTemp;
+
+
+    /**
+     * 数据入库时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "数据入库时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date dataCreateTime;
+
+    /**
+     * 数据修改时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "数据修改时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date dataUpdateTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getDataLongDate() {
+        return dataLongDate;
+    }
+
+    public void setDataLongDate(Long dataLongDate) {
+        this.dataLongDate = dataLongDate;
+    }
+
+    public Integer getDataType() {
+        return dataType;
+    }
+
+    public void setDataType(Integer dataType) {
+        this.dataType = dataType;
+    }
+
+    public Long getCompanyId() {
+        return companyId;
+    }
+
+    public void setCompanyId(Long companyId) {
+        this.companyId = companyId;
+    }
+
+    public Long getOid() {
+        return oid;
+    }
+
+    public void setOid(Long oid) {
+        this.oid = oid;
+    }
+
+    public Long getShopId() {
+        return shopId;
+    }
+
+    public void setShopId(Long shopId) {
+        this.shopId = shopId;
+    }
+
+    public Long getItemId() {
+        return itemId;
+    }
+
+    public void setItemId(Long itemId) {
+        this.itemId = itemId;
+    }
+
+    public String getSkuId() {
+        return skuId;
+    }
+
+    public void setSkuId(String skuId) {
+        this.skuId = skuId;
+    }
+
+    public String getCombinationSkuId() {
+        return combinationSkuId;
+    }
+
+    public void setCombinationSkuId(String combinationSkuId) {
+        this.combinationSkuId = combinationSkuId;
+    }
+
+    public Long getStatDate() {
+        return statDate;
+    }
+
+    public void setStatDate(Long statDate) {
+        this.statDate = statDate;
+    }
+
+    public Long getOrderTemp() {
+        return orderTemp;
+    }
+
+    public void setOrderTemp(Long orderTemp) {
+        this.orderTemp = orderTemp;
+    }
+
+    public Date getDataCreateTime() {
+        return dataCreateTime;
+    }
+
+    public void setDataCreateTime(Date dataCreateTime) {
+        this.dataCreateTime = dataCreateTime;
+    }
+
+    public Date getDataUpdateTime() {
+        return dataUpdateTime;
+    }
+
+    public void setDataUpdateTime(Date dataUpdateTime) {
+        this.dataUpdateTime = dataUpdateTime;
+    }
+
+    @Override
+    public String toString() {
+        return "KwaixiaodianCostDetail{" +
+                "id=" + id +
+                ", dataLongDate=" + dataLongDate +
+                ", dataType=" + dataType +
+                ", companyId=" + companyId +
+                ", oid=" + oid +
+                ", shopId=" + shopId +
+                ", itemId=" + itemId +
+                ", skuId='" + skuId + '\'' +
+                ", combinationSkuId='" + combinationSkuId + '\'' +
+                ", statDate=" + statDate +
+                ", orderTemp=" + orderTemp +
+                ", dataCreateTime=" + dataCreateTime +
+                ", dataUpdateTime=" + dataUpdateTime +
+                '}';
+    }
+}
+

+ 238 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianCostDetailEnd.java

@@ -0,0 +1,238 @@
+package com.ruixuan.isc.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruixuan.common.annotation.Excel;
+import com.ruixuan.common.core.domain.BaseEntity;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+
+/**
+ * 快手小店成本详情对象 kwaixiaodian_cost_detail
+ *
+ * @author ruoyi
+ * @date 2024-11-28
+ */
+public class KwaixiaodianCostDetailEnd extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * $column.columnComment
+     */
+    private Long id;
+
+    /**
+     * 1-普通商品,2-组合商品
+     */
+    @Excel(name = "1-普通商品,2-组合商品")
+    private Integer dataType;
+
+    /**
+     * 序号
+     */
+    @Excel(name = "序号")
+    private Integer sortNum;
+
+    /**
+     * 公司ID
+     */
+    @Excel(name = "公司ID")
+    private Long companyId;
+
+    /**
+     * 订单ID
+     */
+    @Excel(name = "订单ID")
+    private Long oid;
+
+    /**
+     * 店铺ID
+     */
+    @Excel(name = "店铺ID")
+    private Long shopId;
+
+    /**
+     * itemId
+     */
+    @Excel(name = "itemId")
+    private Long itemId;
+
+    /**
+     * skuId
+     */
+    @Excel(name = "skuId")
+    private String skuId;
+
+    /**
+     * 组合skuId
+     */
+    @Excel(name = "组合skuId")
+    private String combinationSkuId;
+
+    /**
+     * 成本价
+     */
+    @Excel(name = "成本价")
+    private BigDecimal costPrice;
+
+    /**
+     * 出单日期
+     */
+    @Excel(name = "出单日期")
+    private Long statDate;
+
+    /**
+     * 出单日期时间戳
+     */
+    @Excel(name = "出单日期时间戳")
+    private Long orderTemp;
+
+
+    /**
+     * 数据入库时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "数据入库时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date dataCreateTime;
+
+    /**
+     * 数据修改时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "数据修改时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date dataUpdateTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Integer getDataType() {
+        return dataType;
+    }
+
+    public void setDataType(Integer dataType) {
+        this.dataType = dataType;
+    }
+
+    public Integer getSortNum() {
+        return sortNum;
+    }
+
+    public void setSortNum(Integer sortNum) {
+        this.sortNum = sortNum;
+    }
+
+    public Long getCompanyId() {
+        return companyId;
+    }
+
+    public void setCompanyId(Long companyId) {
+        this.companyId = companyId;
+    }
+
+    public Long getOid() {
+        return oid;
+    }
+
+    public void setOid(Long oid) {
+        this.oid = oid;
+    }
+
+    public Long getShopId() {
+        return shopId;
+    }
+
+    public void setShopId(Long shopId) {
+        this.shopId = shopId;
+    }
+
+    public Long getItemId() {
+        return itemId;
+    }
+
+    public void setItemId(Long itemId) {
+        this.itemId = itemId;
+    }
+
+    public String getSkuId() {
+        return skuId;
+    }
+
+    public void setSkuId(String skuId) {
+        this.skuId = skuId;
+    }
+
+    public String getCombinationSkuId() {
+        return combinationSkuId;
+    }
+
+    public void setCombinationSkuId(String combinationSkuId) {
+        this.combinationSkuId = combinationSkuId;
+    }
+
+    public BigDecimal getCostPrice() {
+        return costPrice;
+    }
+
+    public void setCostPrice(BigDecimal costPrice) {
+        this.costPrice = costPrice;
+    }
+
+    public Long getStatDate() {
+        return statDate;
+    }
+
+    public void setStatDate(Long statDate) {
+        this.statDate = statDate;
+    }
+
+    public Long getOrderTemp() {
+        return orderTemp;
+    }
+
+    public void setOrderTemp(Long orderTemp) {
+        this.orderTemp = orderTemp;
+    }
+
+    public Date getDataCreateTime() {
+        return dataCreateTime;
+    }
+
+    public void setDataCreateTime(Date dataCreateTime) {
+        this.dataCreateTime = dataCreateTime;
+    }
+
+    public Date getDataUpdateTime() {
+        return dataUpdateTime;
+    }
+
+    public void setDataUpdateTime(Date dataUpdateTime) {
+        this.dataUpdateTime = dataUpdateTime;
+    }
+
+    @Override
+    public String toString() {
+        return "KwaixiaodianCostDetailEnd{" +
+                "id=" + id +
+                ", dataType=" + dataType +
+                ", sortNum=" + sortNum +
+                ", companyId=" + companyId +
+                ", oid=" + oid +
+                ", shopId=" + shopId +
+                ", itemId=" + itemId +
+                ", skuId='" + skuId + '\'' +
+                ", combinationSkuId='" + combinationSkuId + '\'' +
+                ", costPrice=" + costPrice +
+                ", statDate=" + statDate +
+                ", orderTemp=" + orderTemp +
+                ", dataCreateTime=" + dataCreateTime +
+                ", dataUpdateTime=" + dataUpdateTime +
+                '}';
+    }
+}
+

+ 28 - 4
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/KwaiJSTMapper.java

@@ -1,10 +1,7 @@
 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 com.ruixuan.isc.entity.*;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -21,4 +18,31 @@ public interface KwaiJSTMapper {
     void replacekwaixiaodianJstPurchase(@Param("list") List<KwaixiaodianJstPurchase> jstList);
 
     void replaceKwaixiaodianJstPurchaseItems(@Param("list") List<KwaixiaodianJstPurchaseItems> itemList);
+
+    List<JSONObject> getOrderListBySku(@Param("skuNick") String skuNick);
+
+    List<JSONObject> getSkuInfo(@Param("skuNick") String skuNick);
+
+
+    void addDpSkuCost(@Param("adds") List<KwaixiaodianCostDetail> adds);
+
+    List<JSONObject> getSkuDataList(@Param("date") Long date);
+
+    void deleteDpSkuDats(@Param("skuNick") String skuNick);
+
+    void deleteZHSkuDats(@Param("skuNick") String skuNick);
+
+    List<JSONObject> getItemsRange(@Param("skuNick") String skuNick);
+
+    void updateCostInfo(@Param("skuNick") String skuNick);
+
+    List<JSONObject> getCostDetail(@Param("skuNick") String skuNick);
+
+    void batchUpdate(@Param("list") List<JSONObject> list);
+
+    void addsCostDetailEnds(@Param("adds") List<KwaixiaodianCostDetailEnd> adds);
+
+    void deleteCostDetailEnd(@Param("skuNick") String skuNick);
+
+    List<JSONObject> getCleanDataList(Long date);
 }

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

@@ -2,10 +2,20 @@ package com.ruixuan.isc.service;
 
 import com.alibaba.fastjson.JSONObject;
 
+import java.util.List;
+
 public interface IKwaiJSTService {
     JSONObject refreshToken();
 
     void queryAndInsertSku(String date);
 
     void queryAndInsertPurchase(String dates);
+
+    JSONObject costDetail(String skuNick, Integer dataType);
+
+    List<JSONObject> getSkuDataList(Long date);
+
+    JSONObject cleanCost(String skuNick);
+
+    List<JSONObject> getCleanDataList(Long date);
 }

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

@@ -2,13 +2,13 @@ package com.ruixuan.isc.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.ruixuan.common.utils.Check;
+import com.ruixuan.common.utils.DateUtils;
 import com.ruixuan.common.utils.http.HttpUtil;
+import com.ruixuan.common.weixin.CorpWexinUtils;
 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.entity.*;
 import com.ruixuan.isc.mapper.KwaiJSTMapper;
 import com.ruixuan.isc.service.IKwaiJSTService;
 import com.ruixuan.isc.utils.JSTSignUtils;
@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -234,6 +235,201 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
         log.info("{} 完毕", date);
     }
 
+    @Override
+    public JSONObject costDetail(String skuNick, Integer dataType) {
+        JSONObject returnJSon = new JSONObject();
+
+        try {
+            if (dataType == 1) {
+                kwaiJSTMapper.deleteDpSkuDats(skuNick);
+            }
+            if (dataType == 2) {
+                kwaiJSTMapper.deleteZHSkuDats(skuNick);
+            }
+            List<JSONObject> orderList = kwaiJSTMapper.getOrderListBySku(skuNick);
+            if (Check.isNull(orderList)) {
+                returnJSon.put("code", 200);
+                returnJSon.put("message", "根据此sku未查询到数据");
+                return returnJSon;
+            }
+            List<KwaixiaodianCostDetail> adds = new ArrayList<>();
+            Long date = Long.valueOf(DateUtils.getNowDate("YYYYMMdd"));
+            // 单品sku
+            if (dataType == 1) {
+                for (int i = 0; i < orderList.size(); i++) {
+                    JSONObject jsonObject = orderList.get(i);
+                    Long companyId = jsonObject.getLong("companyId");
+                    Long oid = jsonObject.getLong("oid");
+                    Long itemId = jsonObject.getLong("itemId");
+                    Long shopId = jsonObject.getLong("shopId");
+                    Integer num = jsonObject.getInteger("num");
+                    Long statDate = jsonObject.getLong("statDate");
+                    Long orderTemp = jsonObject.getLong("orderTemp");
+                    for (int j = 0; j < num; j++) {
+                        KwaixiaodianCostDetail addJson = new KwaixiaodianCostDetail();
+                        addJson.setCompanyId(companyId);
+                        addJson.setOid(oid);
+                        addJson.setItemId(itemId);
+                        addJson.setShopId(shopId);
+                        addJson.setSkuId(skuNick);
+                        addJson.setStatDate(statDate);
+                        addJson.setOrderTemp(orderTemp);
+                        addJson.setDataType(dataType);
+                        addJson.setDataLongDate(date);
+                        adds.add(addJson);
+                    }
+                }
+            } else if (dataType == 2) { // 组合sku
+                List<JSONObject> skuInfo = kwaiJSTMapper.getSkuInfo(skuNick);
+                if (Check.isNull(skuInfo)) {
+                    returnJSon.put("code", 200);
+                    returnJSon.put("message", "根据此组合sku未查询到sku明细");
+                    return returnJSon;
+                }
+                for (int i = 0; i < orderList.size(); i++) { // 循环订单
+                    JSONObject jsonObject = orderList.get(i);
+                    Long companyId = jsonObject.getLong("companyId");
+                    Long oid = jsonObject.getLong("oid");
+                    Long itemId = jsonObject.getLong("itemId");
+                    Long shopId = jsonObject.getLong("shopId");
+                    Integer num = jsonObject.getInteger("num");
+                    Long statDate = jsonObject.getLong("statDate");
+                    Long orderTemp = jsonObject.getLong("orderTemp");
+                    for (int j = 0; j < num; j++) {  // 循环订单数量
+                        for (int k = 0; k < skuInfo.size(); k++) { // 循环此组合sku下的单品sku
+                            JSONObject skuDetailJson = skuInfo.get(k);
+                            String combinationSkuId = skuDetailJson.getString("combinationSkuId");
+                            String skuId = skuDetailJson.getString("skuId");
+                            Integer qty = skuDetailJson.getInteger("qty");
+                            for (int l = 0; l < qty; l++) {  // 循环单品sku数量
+                                KwaixiaodianCostDetail addJson = new KwaixiaodianCostDetail();
+                                addJson.setCompanyId(companyId);
+                                addJson.setOid(oid);
+                                addJson.setItemId(itemId);
+                                addJson.setShopId(shopId);
+                                addJson.setSkuId(skuId);
+                                addJson.setCombinationSkuId(combinationSkuId);
+                                addJson.setStatDate(statDate);
+                                addJson.setOrderTemp(orderTemp);
+                                addJson.setDataType(dataType);
+                                addJson.setDataLongDate(date);
+                                adds.add(addJson);
+                            }
+                        }
+                    }
+                }
+            }
+            if (!Check.isNull(adds)) {
+                List<List<KwaixiaodianCostDetail>> partition = Lists.partition(adds, 2000);
+                for (int i = 0; i < partition.size(); i++) {
+                    List<KwaixiaodianCostDetail> kwaixiaodianCostDetails = partition.get(i);
+                    if (!Check.isNull(kwaixiaodianCostDetails)) {
+                        kwaiJSTMapper.addDpSkuCost(kwaixiaodianCostDetails);
+                    }
+                }
+            }
+            log.info("{},suk数据处理完成", skuNick);
+        } catch (Exception e) {
+            e.printStackTrace();
+            this.send("快手小店成本数据清洗失败,请处理,序号:1");
+        }
+
+        return returnJSon;
+    }
+
+    @Override
+    public List<JSONObject> getSkuDataList(Long date) {
+        return kwaiJSTMapper.getSkuDataList(date);
+    }
+
+    @Override
+    public JSONObject cleanCost(String skuNick) {
+        JSONObject returnJson = new JSONObject();
+
+        try {
+            kwaiJSTMapper.deleteCostDetailEnd(skuNick);
+            List<JSONObject> ranges = kwaiJSTMapper.getItemsRange(skuNick);
+            if (Check.isNull(ranges)) { // 如果此sku未查询到采购记录,那么出单成本为0
+                returnJson.put("code", 200);
+                returnJson.put("message", "未查询到采购记录");
+                return returnJson;
+            }
+            List<JSONObject> costDetail = kwaiJSTMapper.getCostDetail(skuNick); // 根据此skuId未查询到数据
+            if (Check.isNull(costDetail)) {
+                returnJson.put("code", 200);
+                returnJson.put("message", "未查询到订单记录");
+                return returnJson;
+            }
+            Integer dataSize = costDetail.size() - 1;
+            Integer sortNum = 0;
+            Boolean isBreak = false;
+            List<KwaixiaodianCostDetailEnd> costDetailEnds = new ArrayList<>();
+            for (int i = 0; i < ranges.size(); i++) {
+                JSONObject rangeJson = ranges.get(i);
+                Integer startQty = rangeJson.getInteger("startQty");
+                Integer endQty = rangeJson.getInteger("endQty");
+                BigDecimal price = rangeJson.getBigDecimal("price");
+                List<JSONObject> details = new ArrayList<>();
+                if (dataSize >= endQty) { // 如果数据量大于采购
+                    details = costDetail.subList(startQty, endQty + 1);
+                } else { // 如果数据量小于采购,获取到数据的最后一条
+                    details = costDetail.subList(startQty, dataSize + 1);
+                    isBreak = true;
+                }
+                for (int j = 0; j < details.size(); j++) {
+                    sortNum++;
+                    KwaixiaodianCostDetailEnd addCostDetailEnd = new KwaixiaodianCostDetailEnd();
+                    JSONObject info = details.get(j);
+                    Long oid = info.getLong("oid");
+                    Integer dataType = info.getInteger("dataType");
+                    Long companyId = info.getLong("companyId");
+                    Long shopId = info.getLong("shopId");
+                    Long itemId = info.getLong("itemId");
+                    String skuId = info.getString("skuId");
+                    String combinationSkuId = info.getString("combinationSkuId");
+                    Long statDate = info.getLong("statDate");
+                    Long orderTemp = info.getLong("orderTemp");
+                    addCostDetailEnd.setCompanyId(companyId);
+                    addCostDetailEnd.setOid(oid);
+                    addCostDetailEnd.setItemId(itemId);
+                    addCostDetailEnd.setShopId(shopId);
+                    addCostDetailEnd.setSkuId(skuId);
+                    addCostDetailEnd.setCombinationSkuId(combinationSkuId);
+                    addCostDetailEnd.setStatDate(statDate);
+                    addCostDetailEnd.setOrderTemp(orderTemp);
+                    addCostDetailEnd.setDataType(dataType);
+                    addCostDetailEnd.setSortNum(sortNum);
+                    addCostDetailEnd.setCostPrice(price);
+                    costDetailEnds.add(addCostDetailEnd);
+                }
+                if (isBreak) {
+                    break;
+                }
+
+            }
+            if (!Check.isNull(costDetailEnds)) {
+                List<List<KwaixiaodianCostDetailEnd>> partition = Lists.partition(costDetailEnds, 2000);
+                for (int i = 0; i < partition.size(); i++) {
+                    List<KwaixiaodianCostDetailEnd> kwaixiaodianCostDetailEnds = partition.get(i);
+                    if (!Check.isNull(kwaixiaodianCostDetailEnds)) {
+                        kwaiJSTMapper.addsCostDetailEnds(kwaixiaodianCostDetailEnds);
+                    }
+                }
+            }
+            log.info("{},suk数据处理最终清洗完成", skuNick);
+        } catch (Exception e) {
+            e.printStackTrace();
+            this.send("快手小店成本数据清洗失败,请处理,序号:2,sukId:" + skuNick);
+        }
+
+        return null;
+    }
+
+    @Override
+    public List<JSONObject> getCleanDataList(Long date) {
+        return kwaiJSTMapper.getCleanDataList(date);
+    }
+
     private void addPurchase(Map<String, Object> params, String secret, String date, int pageIndex) throws InterruptedException {
         boolean hasNext = false;
         JSONObject biz = new JSONObject();
@@ -263,7 +459,7 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
                             KwaixiaodianJstPurchase jst = JSONObject.parseObject(skuInfo.toJSONString(), KwaixiaodianJstPurchase.class);
                             jstList.add(jst);
                             if (!Check.isNull(skuInfo.getJSONArray("items"))) {
-                                addPurchaseItems(jst.getPoDate(),skuInfo.getJSONArray("items"));
+                                addPurchaseItems(jst.getPoDate(), skuInfo.getJSONArray("items"));
                             }
                         }
                     }
@@ -280,7 +476,7 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
         }
     }
 
-    private void addPurchaseItems(String poDate,JSONArray items) {
+    private void addPurchaseItems(String poDate, JSONArray items) {
         List<KwaixiaodianJstPurchaseItems> itemList = new ArrayList<>();
         for (int i = 0; i < items.size(); i++) {
             JSONObject it = items.getJSONObject(i);
@@ -292,4 +488,14 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
             kwaiJSTMapper.replaceKwaixiaodianJstPurchaseItems(itemList);
         }
     }
+
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
+
+    private void send(String text) {
+        JSONObject weChat = new JSONObject();
+        weChat.put("wexin_id", "YuMeng");
+        weChat.put("corp_id", "ww24b8a47826f5875f");
+        corpWexinUtils.sendMessage(weChat, text);
+    }
 }

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

@@ -9,6 +9,37 @@
             refresh_token =#{refreshToken}
         WHERE id = #{id}
     </update>
+    <update id="updateCostInfo" parameterType="java.lang.String">
+        UPDATE kwaixiaodian_cost_detail
+        SET cost_price  = 0,
+            data_status = 2
+        WHERE sku_id = #{skuNick}
+          AND data_status = 1
+
+    </update>
+    <update id="batchUpdate" >
+        <foreach collection="list" item="item" index="index">
+            update kwaixiaodian_cost_detail
+            set cost_price = #{item.costPrice},
+            sort_num = #{item.sortNum},
+            data_status = #{item.dataStatus}
+            where id = #{item.id};
+        </foreach>
+
+    </update>
+    <delete id="deleteDpSkuDats" parameterType="java.lang.String">
+        DELETE from kwaixiaodian_cost_detail WHERE sku_id = #{skuNick}
+    </delete>
+    <delete id="deleteZHSkuDats" parameterType="java.lang.String">
+        DELETE
+        FROM kwaixiaodian_cost_detail
+        WHERE combination_sku_id = #{skuNick}
+    </delete>
+    <delete id="deleteCostDetailEnd" parameterType="java.lang.String">
+        DELETE
+        FROM kwaixiaodian_cost_detail_end
+        WHERE sku_id = #{skuNick}
+    </delete>
 
 
     <select id="getList" resultType="com.alibaba.fastjson.JSONObject">
@@ -16,6 +47,51 @@
 
         FROM kwaixiaodian_jst_token
     </select>
+    <select id="getOrderListBySku" resultType="com.alibaba.fastjson.JSONObject"
+            parameterType="java.lang.String">
+        SELECT company_id AS 'companyId', oid AS 'oid', item_id AS 'itemId', shop_id AS 'shopId', sku_nick AS 'skuNick', num AS 'num', stat_date AS 'statDate', create_time AS 'orderTemp'
+        FROM kwaixiaodian_order_cursor_list
+        WHERE sku_nick = #{skuNick}
+          AND status NOT IN (0, 10, 30, 80)
+        ORDER BY num DESC
+    </select>
+    <select id="getSkuInfo" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.String">
+        SELECT t1.sku_id AS 'combinationSkuId', t1.src_sku_id AS 'skuId', t1.qty AS 'qty', t2.cost_price AS 'costPrice', t2.sale_price AS 'salePrice'
+        FROM kwaixiaodian_jst_items t1
+                 LEFT JOIN kwaixiaodian_jst t2 ON t1.src_sku_id = t2.sku_id
+        WHERE t1.sku_id = #{skuNick}
+    </select>
+    <select id="getSkuDataList" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Long">
+        SELECT t1.sku_nick AS 'skuNick', t2.data_type AS 'dataType'
+        FROM kwaixiaodian_order_cursor_list t1
+                 LEFT JOIN kwaixiaodian_jst t2
+                           ON t1.sku_nick = t2.sku_id
+        WHERE t1.stat_date >= #{date}
+          AND t1.sku_nick IS NOT NULL
+          AND t1.sku_nick != ''
+  AND t2.data_type IS NOT NULL
+        GROUP BY sku_nick
+    </select>
+    <select id="getItemsRange" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.String">
+        SELECT start_qty AS 'startQty', end_qty AS 'endQty', price
+        FROM kwaixiaodian_jst_purchase_items_range
+        WHERE sku_id = #{skuNick}
+        ORDER BY sku_num ASC
+    </select>
+    <select id="getCostDetail" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.String">
+        SELECT id,
+               oid,
+               data_type AS 'dataType', company_id AS 'companyId', shop_id AS 'shopId', item_id AS 'itemId', sku_id AS 'skuId', combination_sku_id AS 'combinationSkuId', stat_date AS 'statDate', order_temp AS 'orderTemp'
+        FROM kwaixiaodian_cost_detail
+        WHERE sku_id = #{skuNick}
+        ORDER BY order_temp
+    </select>
+    <select id="getCleanDataList" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Long">
+        SELECT sku_id AS 'skuId'
+        FROM kwaixiaodian_cost_detail
+        WHERE data_long_date = #{date}
+        GROUP BY sku_id
+    </select>
 
 
     <insert id="replaceKwaixiaodianJst">
@@ -221,4 +297,66 @@
             )
         </foreach>
     </insert>
+    <insert id="addDpSkuCost" >
+        replace into `ruixuan`.kwaixiaodian_cost_detail(
+        data_type,
+        company_id,
+        oid,
+        shop_id,
+        item_id,
+        sku_id,
+        combination_sku_id,
+        stat_date,
+        order_temp,
+        data_long_date
+        )
+        values
+        <foreach collection="adds" item="add" separator=",">
+            (
+            #{add.dataType},
+            #{add.companyId},
+            #{add.oid},
+            #{add.shopId},
+            #{add.itemId},
+            #{add.skuId},
+            #{add.combinationSkuId},
+            #{add.statDate},
+            #{add.orderTemp},
+            #{add.dataLongDate}
+            )
+        </foreach>
+    </insert>
+    <insert id="addsCostDetailEnds">
+        replace into `ruixuan`.kwaixiaodian_cost_detail_end(
+        data_type,
+        sort_num,
+        company_id,
+        oid,
+        shop_id,
+        item_id,
+        sku_id,
+        combination_sku_id,
+        stat_date,
+        order_temp,
+        cost_price
+        )
+        values
+        <foreach collection="adds" item="add" separator=",">
+            (
+            #{add.dataType},
+            #{add.sortNum},
+            #{add.companyId},
+            #{add.oid},
+            #{add.shopId},
+            #{add.itemId},
+            #{add.skuId},
+            #{add.combinationSkuId},
+            #{add.statDate},
+            #{add.orderTemp},
+            #{add.costPrice}
+
+            )
+        </foreach>
+
+    </insert>
 </mapper>