|
@@ -1,21 +1,41 @@
|
|
package com.ruixuan.isc.service.impl;
|
|
package com.ruixuan.isc.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.kuaishou.merchant.open.api.KsMerchantApiException;
|
|
|
|
+import com.kuaishou.merchant.open.api.client.AccessTokenKsMerchantClient;
|
|
|
|
+import com.kuaishou.merchant.open.api.common.utils.GsonUtils;
|
|
|
|
+import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionCpsLeaderOrderCursorListRequest;
|
|
|
|
+import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionCpsLeaderOrderCursorListResponse;
|
|
import com.ruixuan.common.utils.Check;
|
|
import com.ruixuan.common.utils.Check;
|
|
|
|
+import com.ruixuan.common.utils.DateUtils;
|
|
|
|
+import com.ruixuan.isc.entity.KuaishouAccessToken;
|
|
|
|
+import com.ruixuan.isc.entity.KuaishouSupplyChain;
|
|
|
|
+import com.ruixuan.isc.mapper.KuaishouItemListMapper;
|
|
import com.ruixuan.isc.mapper.SupplyChainMapper;
|
|
import com.ruixuan.isc.mapper.SupplyChainMapper;
|
|
|
|
+import com.ruixuan.isc.service.IAccessTokenService;
|
|
import com.ruixuan.isc.service.ISupplyChainService;
|
|
import com.ruixuan.isc.service.ISupplyChainService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class SupplyChainServiceImpl implements ISupplyChainService {
|
|
public class SupplyChainServiceImpl implements ISupplyChainService {
|
|
@Autowired
|
|
@Autowired
|
|
private SupplyChainMapper supplyChainMapper;
|
|
private SupplyChainMapper supplyChainMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaishouItemListMapper itemListMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAccessTokenService accessTokenService;
|
|
|
|
+
|
|
// 获取订单数据
|
|
// 获取订单数据
|
|
@Override
|
|
@Override
|
|
public List<JSONObject> getOrderList(Map<String, Object> requestMap) {
|
|
public List<JSONObject> getOrderList(Map<String, Object> requestMap) {
|
|
@@ -375,4 +395,123 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
|
|
return supplyChainMapper.selectOrderInfoByItemIdsBytedance(itemIds, startDate, endDate);
|
|
return supplyChainMapper.selectOrderInfoByItemIdsBytedance(itemIds, startDate, endDate);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void addList(String beginDate, String endDate, String pcursor) {
|
|
|
|
+ String url = "https://openapi.kwaixiaodian.com";
|
|
|
|
+ Long beginTime = DateUtils.getStartLongTime(beginDate);
|
|
|
|
+ Long endTime = DateUtils.getEndLongTime(endDate);
|
|
|
|
+ Map<Long, Long> itemMap = getItemMap();
|
|
|
|
+ List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
|
|
|
|
+ for (KuaishouAccessToken accessToken : tokens) {
|
|
|
|
+ getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Map<Long, Long> itemMap) {
|
|
|
|
+ List<KuaishouSupplyChain> list = new ArrayList<>();
|
|
|
|
+ String appKey = accessToken.getAppKey();
|
|
|
|
+ String signSecret = accessToken.getSignSecret();
|
|
|
|
+ AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
|
|
|
|
+ OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
|
|
|
|
+ request.setAccessToken(accessToken.getAccessToken());
|
|
|
|
+ request.setApiMethodVersion(1L);
|
|
|
|
+
|
|
|
|
+ //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
|
|
|
|
+ request.setSortType(1);
|
|
|
|
+ //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
|
|
|
|
+ request.setQueryType(2);
|
|
|
|
+ //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
|
|
|
|
+ request.setCpsOrderStatus(0);
|
|
|
|
+ request.setDistributorId(0l);
|
|
|
|
+ request.setBeginTime(beginTime);
|
|
|
|
+ request.setEndTime(endTime);
|
|
|
|
+ request.setPcursor(pcursor);
|
|
|
|
+ request.setPageize(100);
|
|
|
|
+ request.setFundType(1);
|
|
|
|
+
|
|
|
|
+ OpenDistributionCpsLeaderOrderCursorListResponse response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.execute(request);
|
|
|
|
+ } catch (KsMerchantApiException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
|
|
|
|
+ String code = obj.getString("code");
|
|
|
|
+ if ("1".equals(code)) {
|
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
|
+ pcursor = data.getString("pcursor");
|
|
|
|
+ JSONArray orderView = data.getJSONArray("orderView");
|
|
|
|
+ for (int i = 0; i < orderView.size(); i++) {
|
|
|
|
+ JSONObject info = orderView.getJSONObject(i);
|
|
|
|
+ KuaishouSupplyChain chain = organizeData(info, itemMap);
|
|
|
|
+ list.add(chain);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.error("===查询分销团长订单列表(https://openapi.kwaixiaodian.com)失败,信息:{}" + obj.getString("msg"));
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Check.isNotNull(list) && list.size() > 0) {
|
|
|
|
+ supplyChainMapper.replaceAll(list);
|
|
|
|
+ }
|
|
|
|
+ if (!"nomore".equals(pcursor)) {
|
|
|
|
+ getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private KuaishouSupplyChain organizeData(JSONObject jsonObject, Map<Long, Long> itemMap) {
|
|
|
|
+ KuaishouSupplyChain supplyChain = new KuaishouSupplyChain();
|
|
|
|
+ supplyChain.setOid(jsonObject.getLong("oid"));
|
|
|
|
+
|
|
|
|
+ JSONObject item = jsonObject.getJSONArray("cpsOrderProductView").getJSONObject(0);
|
|
|
|
+ if (!Check.isNull(item)) {
|
|
|
|
+ supplyChain.setItemId(item.getLong("itemId"));
|
|
|
|
+ supplyChain.setItemTitle(item.getString("itemTitle"));
|
|
|
|
+ supplyChain.setReservePrice(item.getLong("itemPrice"));
|
|
|
|
+ supplyChain.setImageUrl(itemListMapper.getItemImgUrl(item.getLong("itemId")));
|
|
|
|
+ supplyChain.setSellerId(item.getLong("sellerId"));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ supplyChain.setOrderStatus(jsonObject.getInteger("cpsOrderStatus"));
|
|
|
|
+ supplyChain.setOrderCreateTime(jsonObject.getLong("orderCreateTime"));
|
|
|
|
+ supplyChain.setSendStatus(jsonObject.getInteger("sendStatus"));
|
|
|
|
+ supplyChain.setSettlementBizType(jsonObject.getInteger("settlementBizType"));
|
|
|
|
+ supplyChain.setSettlementBizTypeDesc(getSettlementBizTypeDesc(jsonObject.getInteger("settlementBizType")));
|
|
|
|
+ supplyChain.setSendTime(jsonObject.getLong("sendTime"));
|
|
|
|
+ supplyChain.setRecvTime(jsonObject.getLong("recvTime"));
|
|
|
|
+ supplyChain.setPromoterId(jsonObject.getLong("promotionId"));
|
|
|
|
+ supplyChain.setPromoterNickName(jsonObject.getString("promotionNickName"));
|
|
|
|
+ supplyChain.setActivityId(jsonObject.getLong("activityId"));
|
|
|
|
+ supplyChain.setOrderAmount(jsonObject.getLong("payAmount"));
|
|
|
|
+ supplyChain.setPayAmount(jsonObject.getLong("payAmount"));
|
|
|
|
+ supplyChain.setRegimentalPromotionRate(jsonObject.getLong("regimentalPromotionRate"));
|
|
|
|
+ supplyChain.setShareRate(jsonObject.getLong("shareRateStr"));
|
|
|
|
+ supplyChain.setBaseAmount(jsonObject.getLong("baseAmount"));
|
|
|
|
+ supplyChain.setRegimentalPromotionAmount(jsonObject.getLong("regimentalPromotionAmount") / 1000);
|
|
|
|
+ supplyChain.setTotalRegimentalSettleAmount(jsonObject.getLong("settlementAmount"));
|
|
|
|
+ supplyChain.setStatDate(DateUtils.tempToDate(jsonObject.getLong("orderCreateTime")));
|
|
|
|
+ supplyChain.setItemCommissionRate(itemMap.get(item.getLong("itemId")));
|
|
|
|
+ return supplyChain;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getSettlementBizTypeDesc(Integer settlementBizType) {
|
|
|
|
+ return settlementBizType == 1 ? "快分销" : "聚力计划";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取订单佣金率
|
|
|
|
+ public Map<Long, Long> getItemMap() {
|
|
|
|
+ Map<Long, Long> returnMap = new HashMap<>();
|
|
|
|
+ List<JSONObject> list = itemListMapper.itemList();
|
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = list.get(i);
|
|
|
|
+ returnMap.put(jsonObject.getLong("itemId"), jsonObject.getLong("itemCommissionRate"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return returnMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|