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