Browse Source

分销团长订单列表(游标方式) 接口化

zhaoxian 1 year ago
parent
commit
33fc34a6e8

+ 7 - 0
ruixuan-common/src/main/java/com/ruixuan/common/utils/DateUtils.java

@@ -452,6 +452,13 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         return dateList;
     }
 
+    public static String tempToDate(long millis) {
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        Date d1 = new Date(millis);
+        String d2 = simpleDateFormat.format(d1);
+        return d2;
+    }
+
     public static void main(String[] args) {
         System.out.println(getAllDatesOfTwoTimes("2023-02-01", "2023-02-15"));
     }

+ 8 - 2
ruixuan-live/src/main/java/com/ruixuan/isc/controller/SupplyChainController.java

@@ -292,9 +292,9 @@ public class SupplyChainController extends BaseController {
             requestMap.put("userId", requestJson.getLong("userId"));
         }
         List<JSONObject> list = new ArrayList<>();
-        if(!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))){
+        if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
             list = supplyChainService.exportOrder(requestMap);
-        }else if(!Check.isNull(requestJson.getString("bindStartDate")) && !Check.isNull(requestJson.getString("bindEndDate"))){
+        } else if (!Check.isNull(requestJson.getString("bindStartDate")) && !Check.isNull(requestJson.getString("bindEndDate"))) {
             list = supplyChainService.exportBindOrder(requestMap);
         }
 
@@ -1876,4 +1876,10 @@ public class SupplyChainController extends BaseController {
     }
 
 
+    @GetMapping("/addList")
+    @ApiOperation(value = "分销团长订单列表(游标方式)")
+    public void addList(String beginDate, String endDate) {
+        supplyChainService.addList(beginDate, endDate, null);
+    }
+
 }

+ 9 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KuaishouAccessToken.java

@@ -11,6 +11,7 @@ public class KuaishouAccessToken extends BaseEntity {
     private String refreshToken;
     private String appKey;
     private String appSecret;
+    private String signSecret;
 
     public static long getSerialVersionUID() {
         return serialVersionUID;
@@ -48,6 +49,14 @@ public class KuaishouAccessToken extends BaseEntity {
         this.appKey = appKey;
     }
 
+    public String getSignSecret() {
+        return signSecret;
+    }
+
+    public void setSignSecret(String signSecret) {
+        this.signSecret = signSecret;
+    }
+
     public String getAppSecret() {
         return appSecret;
     }

+ 180 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KuaishouSupplyChain.java

@@ -0,0 +1,180 @@
+package com.ruixuan.isc.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruixuan.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * 快手电商-供应链订单信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2022-12-01
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "kuaishou_supply_chain对象", description = "快手电商-供应链订单信息")
+public class KuaishouSupplyChain {
+
+    /**
+     * id
+     */
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 订单ID
+     */
+    @Excel(name = "订单ID", width = 15)
+    @ApiModelProperty(value = "订单ID")
+    private Long oid;
+    /**
+     * 商品ID
+     */
+    @Excel(name = "商品ID", width = 15)
+    @ApiModelProperty(value = "商品ID")
+    private Long itemId;
+    /**
+     * 商品标题
+     */
+    @Excel(name = "商品标题", width = 15)
+    @ApiModelProperty(value = "商品标题")
+    private String itemTitle;
+    /**
+     * 商品单价
+     */
+    @Excel(name = "商品单价", width = 15)
+    @ApiModelProperty(value = "商品单价")
+    private Long reservePrice;
+    /**
+     * 商品图片
+     */
+    @Excel(name = "商品图片", width = 15)
+    @ApiModelProperty(value = "商品图片")
+    private String imageUrl;
+    /**
+     * 订单状态
+     */
+    @Excel(name = "订单状态", width = 15)
+    @ApiModelProperty(value = "订单状态")
+    private Integer orderStatus;
+    /**
+     * 订单创建时间
+     */
+    @Excel(name = "订单创建时间", width = 15)
+    @ApiModelProperty(value = "订单创建时间")
+    private Long orderCreateTime;
+    /**
+     * 是否发货
+     */
+    @Excel(name = "是否发货", width = 15)
+    @ApiModelProperty(value = "是否发货")
+    private Integer sendStatus;
+    /**
+     * 订单类型
+     */
+    @Excel(name = "订单类型", width = 15)
+    @ApiModelProperty(value = "订单类型")
+    private Integer settlementBizType;
+    /**
+     * 订单类型翻译
+     */
+    @Excel(name = "订单类型翻译", width = 15)
+    @ApiModelProperty(value = "订单类型翻译")
+    private String settlementBizTypeDesc;
+    /**
+     * 发货时间
+     */
+    @Excel(name = "发货时间", width = 15)
+    @ApiModelProperty(value = "发货时间")
+    private Long sendTime;
+    /**
+     * 收获时间
+     */
+    @Excel(name = "收获时间", width = 15)
+    @ApiModelProperty(value = "收获时间")
+    private Long recvTime;
+    /**
+     * 商家id
+     */
+    @Excel(name = "商家id", width = 15)
+    @ApiModelProperty(value = "商家id")
+    private Long sellerId;
+    /**
+     * 达人id
+     */
+    @Excel(name = "达人id", width = 15)
+    @ApiModelProperty(value = "达人id")
+    private Long promoterId;
+    /**
+     * 达人昵称
+     */
+    @Excel(name = "达人昵称", width = 15)
+    @ApiModelProperty(value = "达人昵称")
+    private String promoterNickName;
+    /**
+     * 活动id
+     */
+    @Excel(name = "活动id", width = 15)
+    @ApiModelProperty(value = "活动id")
+    private Long activityId;
+    /**
+     * 订单金额
+     */
+    @Excel(name = "订单金额", width = 15)
+    @ApiModelProperty(value = "订单金额")
+    private Long orderAmount;
+    /**
+     * 付款金额
+     */
+    @Excel(name = "付款金额", width = 15)
+    @ApiModelProperty(value = "付款金额")
+    private Long payAmount;
+    /**
+     * 服务费率
+     */
+    @Excel(name = "服务费率", width = 15)
+    @ApiModelProperty(value = "服务费率")
+    private Long regimentalPromotionRate;
+    /**
+     * 分成比例
+     */
+    @Excel(name = "分成比例", width = 15)
+    @ApiModelProperty(value = "分成比例")
+    private Long shareRate;
+    /**
+     * 货款基数
+     */
+    @Excel(name = "货款基数", width = 15)
+    @ApiModelProperty(value = "货款基数")
+    private Long baseAmount;
+    /**
+     * 技术服务费
+     */
+    @Excel(name = "技术服务费", width = 15)
+    @ApiModelProperty(value = "技术服务费")
+    private Long serviceAmount;
+    /**
+     * 预估服务费收入
+     */
+    @Excel(name = "预估服务费收入", width = 15)
+    @ApiModelProperty(value = "预估服务费收入")
+    private Long regimentalPromotionAmount;
+    /**
+     * 结算服务费收入
+     */
+    @Excel(name = "结算服务费收入", width = 15)
+    @ApiModelProperty(value = "结算服务费收入")
+    private Long totalRegimentalSettleAmount;
+    private String statDate;
+    private Long itemCommissionRate;
+    private Date createTime;
+    private Date updateTime;
+}

+ 4 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/KuaishouItemListMapper.java

@@ -55,5 +55,9 @@ public interface KuaishouItemListMapper {
     Long selectMaxRelateId();
 
     List<JSONObject> getListByRelateId(@Param("relateId") Long relateId);
+
+    String getItemImgUrl(Long itemId);
+
+    List<JSONObject> itemList();
 }
 

+ 3 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/SupplyChainMapper.java

@@ -1,6 +1,7 @@
 package com.ruixuan.isc.mapper;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ruixuan.isc.entity.KuaishouSupplyChain;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -142,4 +143,6 @@ public interface SupplyChainMapper {
     List<JSONObject> bdReportListV2ByBind(Map<String, Object> requestMap);
 
     List<JSONObject> exportBindOrder(Map<String, Object> requestMap);
+
+    void replaceAll(@Param("list") List<KuaishouSupplyChain> list);
 }

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

@@ -2,6 +2,8 @@ package com.ruixuan.isc.service;
 
 import com.ruixuan.isc.entity.KuaishouAccessToken;
 
+import java.util.List;
+
 public interface IAccessTokenService {
 
     KuaishouAccessToken getAccessToken(Long regId);
@@ -9,4 +11,6 @@ public interface IAccessTokenService {
     void refreshAccessToken();
 
      void refreshByteDanceAccessToken();
+
+    List<KuaishouAccessToken> getTokenInfos();
 }

+ 2 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/ISupplyChainService.java

@@ -164,4 +164,6 @@ public interface ISupplyChainService {
 
 
     List<JSONObject> exportBindOrder(Map<String, Object> requestMap);
+
+    void addList(String beginDate, String endDate,String pcursor);
 }

+ 5 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/AccessTokenServiceImpl.java

@@ -107,4 +107,9 @@ public class AccessTokenServiceImpl implements IAccessTokenService {
             }
         }
     }
+
+    @Override
+    public List<KuaishouAccessToken> getTokenInfos() {
+        return accessTokenMapper.getTokenInfos();
+    }
 }

+ 139 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/SupplyChainServiceImpl.java

@@ -1,21 +1,41 @@
 package com.ruixuan.isc.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 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.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.service.IAccessTokenService;
 import com.ruixuan.isc.service.ISupplyChainService;
+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 SupplyChainServiceImpl implements ISupplyChainService {
     @Autowired
     private SupplyChainMapper supplyChainMapper;
 
+    @Autowired
+    private KuaishouItemListMapper itemListMapper;
+
+    @Autowired
+    private IAccessTokenService accessTokenService;
+
     // 获取订单数据 
     @Override
     public List<JSONObject> getOrderList(Map<String, Object> requestMap) {
@@ -375,4 +395,123 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
         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;
+    }
+
 }
+

File diff suppressed because it is too large
+ 74 - 31
ruixuan-live/src/main/resources/mapper/isc/KuaishouItemListMapper.xml


+ 64 - 0
ruixuan-live/src/main/resources/mapper/isc/SupplyChainMapper.xml

@@ -2386,4 +2386,68 @@
         </if>
         order by t2.orderNum desc
     </select>
+
+
+    <insert id="replaceAll">
+        replace into kuaishou_supply_chain(
+        oid,
+        item_id,
+        item_title,
+        reserve_price,
+        image_url,
+        order_status,
+        order_create_time,
+        send_status,
+        settlement_biz_type,
+        settlement_biz_type_desc,
+        send_time,
+        recv_time,
+        seller_id,
+        activity_id,
+        order_amount,
+        pay_amount,
+        regimental_promotion_rate,
+        share_rate,
+        base_amount,
+        service_amount,
+        regimental_promotion_amount,
+        total_regimental_settle_amount,
+        stat_date,
+        item_commission_rate,
+        promoter_id,
+        promoter_nick_name
+        )
+        values
+        <foreach collection="list" item="add" separator=",">
+            (
+            #{add.oid},
+            #{add.itemId},
+            #{add.itemTitle},
+            #{add.reservePrice},
+            #{add.imageUrl},
+            #{add.orderStatus},
+            #{add.orderCreateTime},
+            #{add.sendStatus},
+            #{add.settlementBizType},
+            #{add.settlementBizTypeDesc},
+            #{add.sendTime},
+            #{add.recvTime},
+            #{add.sellerId},
+            #{add.activityId},
+            #{add.orderAmount},
+            #{add.payAmount},
+            #{add.regimentalPromotionRate},
+            #{add.shareRate},
+            #{add.baseAmount},
+            #{add.serviceAmount},
+            #{add.regimentalPromotionAmount},
+            #{add.totalRegimentalSettleAmount},
+            #{add.statDate},
+            #{add.itemCommissionRate},
+            #{add.promoterId},
+            #{add.promoterNickName}
+            )
+        </foreach>
+    </insert>
+
 </mapper>