|
@@ -0,0 +1,245 @@
|
|
|
|
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import cn.com.ctop.common.module.service.ISendMessageService;
|
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouSupplyChain;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouSupplyChainSettlement;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouSupplyChainMapper;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.MgsSupplyChainMapper;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouSupplyChainService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IMgsSupplyChainService;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 快手电商-供应链订单信息
|
|
|
|
+ *
|
|
|
|
+ * @author jeecg-boot
|
|
|
|
+ * 2022-12-01
|
|
|
|
+ * @version V1.0
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class MgsSupplyChainServiceImpl extends ServiceImpl<KuaishouSupplyChainMapper, KuaishouSupplyChain> implements IMgsSupplyChainService {
|
|
|
|
+ private static String url = "https://cps.kwaixiaodian.com/distribute/pc/investment/order/list";
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISendMessageService sendMessageService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MgsSupplyChainMapper mgsSupplyChainMapper;
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ System.err.println(DateUtils.tempToLongDateStr(1706112000000L));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public void getOrderList(String cookie, Integer offset, Long orderCreateTimeStart, Long orderCreateTimeEnd, Map<Long, Long> itemMap) throws Exception {
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ log.info("mgs团长抓取订单数据入参,开始时间:{},结束时间:{},数据:{}", DateUtils.tempToLongDateStr(orderCreateTimeStart), DateUtils.tempToLongDateStr(orderCreateTimeEnd), offset);
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ if (!Check.isNull(orderCreateTimeStart)) {
|
|
|
|
+ params.put("orderCreateTimeStart", orderCreateTimeStart);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(orderCreateTimeEnd)) {
|
|
|
|
+ params.put("orderCreateTimeEnd", orderCreateTimeEnd);
|
|
|
|
+ }
|
|
|
|
+ params.put("fundType", 1);
|
|
|
|
+ params.put("timeType", 1);
|
|
|
|
+ params.put("limit", 100);
|
|
|
|
+ params.put("offset", offset);
|
|
|
|
+
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Cookie", cookie);
|
|
|
|
+
|
|
|
|
+ String resultStr = HttpUtils.KuaiShouttpGetRequest(url, params, headers);
|
|
|
|
+ JSONObject result = JSONObject.parseObject(resultStr);
|
|
|
|
+ if (Check.isNull(result)) {
|
|
|
|
+ log.error("快分销数据返回为空");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Integer code = result.getInteger("result");
|
|
|
|
+ if (code != 1) {
|
|
|
|
+ log.info("mgs快分销数据返回异常:", resultStr);
|
|
|
|
+ sendMessageService.sendMessage("113dee46c7df464da78c07a985e92cd1", "mgscookie失效,请及时更新。媒体返回信息:" + resultStr);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject dataJson = result.getJSONObject("data");
|
|
|
|
+ if (Check.isNull(dataJson)) {
|
|
|
|
+ log.error("mgs数据返回为data数据为空");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray list = dataJson.getJSONArray("list");
|
|
|
|
+ if (Check.isNull(list)) {
|
|
|
|
+ log.error("mgs数据返回为list数据为空");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ log.info("mgs当前数据条数:{}", list.size());
|
|
|
|
+ List<KuaishouSupplyChain> supplyChains = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = list.getJSONObject(i);
|
|
|
|
+ KuaishouSupplyChain supplyChain = new KuaishouSupplyChain();
|
|
|
|
+ supplyChain.setOid(jsonObject.getLong("oid"));
|
|
|
|
+ JSONObject item = jsonObject.getJSONArray("itemList").getJSONObject(0);
|
|
|
|
+ if (!Check.isNull(item)) {
|
|
|
|
+ supplyChain.setItemId(item.getLong("itemId"));
|
|
|
|
+ supplyChain.setItemTitle(item.getString("itemTitle"));
|
|
|
|
+ supplyChain.setReservePrice(item.getLong("reservePrice"));
|
|
|
|
+ supplyChain.setImageUrl(item.getString("imageUrl"));
|
|
|
|
+ }
|
|
|
|
+ supplyChain.setOrderStatus(jsonObject.getInteger("orderStatus"));
|
|
|
|
+ supplyChain.setOrderCreateTime(jsonObject.getLong("orderCreateTime"));
|
|
|
|
+ supplyChain.setSendStatus(jsonObject.getInteger("sendStatus"));
|
|
|
|
+ supplyChain.setSettlementBizType(jsonObject.getInteger("settlementBizType"));
|
|
|
|
+ supplyChain.setSettlementBizTypeDesc(jsonObject.getString("settlementBizTypeDesc"));
|
|
|
|
+ supplyChain.setSendTime(jsonObject.getLong("sendTime"));
|
|
|
|
+ supplyChain.setRecvTime(jsonObject.getLong("recvTime"));
|
|
|
|
+ supplyChain.setSellerId(jsonObject.getLong("sellerId"));
|
|
|
|
+ supplyChain.setPromoterId(jsonObject.getLong("promoterId"));
|
|
|
|
+ supplyChain.setPromoterNickName(filterSupplement(jsonObject.getString("promoterNickName")));
|
|
|
|
+ supplyChain.setActivityId(jsonObject.getLong("activityId"));
|
|
|
|
+ supplyChain.setOrderAmount(jsonObject.getLong("orderAmount"));
|
|
|
|
+ supplyChain.setPayAmount(jsonObject.getLong("payAmount"));
|
|
|
|
+ supplyChain.setRegimentalPromotionRate(jsonObject.getLong("regimentalPromotionRate"));
|
|
|
|
+ supplyChain.setShareRate(jsonObject.getLong("shareRate"));
|
|
|
|
+ supplyChain.setBaseAmount(jsonObject.getLong("baseAmount"));
|
|
|
|
+ supplyChain.setServiceAmount(jsonObject.getLong("serviceAmount"));
|
|
|
|
+ supplyChain.setRegimentalPromotionAmount(jsonObject.getLong("regimentalPromotionAmount"));
|
|
|
|
+ supplyChain.setTotalRegimentalSettleAmount(jsonObject.getLong("totalRegimentalSettleAmount"));
|
|
|
|
+ supplyChain.setStatDate(DateUtils.tempToDate(jsonObject.getLong("orderCreateTime")));
|
|
|
|
+ supplyChain.setItemCommissionRate(itemMap.get(item.getLong("itemId")));
|
|
|
|
+ supplyChains.add(supplyChain);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ mgsSupplyChainMapper.replace(supplyChains);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (list.size() >= 100) {
|
|
|
|
+ getOrderList(cookie, offset + 100, orderCreateTimeStart, orderCreateTimeEnd, itemMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<JSONObject> getCookie() {
|
|
|
|
+ return mgsSupplyChainMapper.getCookie();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void getSettlementData(String cookie, Integer offset, Long orderCreateTimeStart, Long orderCreateTimeEnd) throws Exception {
|
|
|
|
+
|
|
|
|
+ String getUrl = "https://cps.kwaixiaodian.com/distribute/pc/investment/bill/list";
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ if (!Check.isNull(orderCreateTimeStart)) {
|
|
|
|
+ params.put("settlementTimeStart", orderCreateTimeStart);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(orderCreateTimeEnd)) {
|
|
|
|
+ params.put("settlementTimeEnd", orderCreateTimeEnd);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ params.put("limit", 5000);
|
|
|
|
+ params.put("offset", offset);
|
|
|
|
+ params.put("activityUserType", 1);
|
|
|
|
+
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Cookie", cookie);
|
|
|
|
+
|
|
|
|
+ String resultStr = HttpUtils.KuaiShouttpGetRequest(getUrl, params, headers);
|
|
|
|
+ JSONObject result = JSONObject.parseObject(resultStr);
|
|
|
|
+ if (Check.isNull(result)) {
|
|
|
|
+ log.error("mgs数据返回为空");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Integer code = result.getInteger("result");
|
|
|
|
+ if (code != 1) {
|
|
|
|
+ log.info("mgs返回异常:", resultStr);
|
|
|
|
+ sendMessageService.sendMessage("113dee46c7df464da78c07a985e92cd1", "mgs供应链cookie失效,请及时更新。媒体返回信息:" + resultStr);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject dataJson = result.getJSONObject("data");
|
|
|
|
+ if (Check.isNull(dataJson)) {
|
|
|
|
+ log.error("快分销数据返回为data数据为空");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray list = dataJson.getJSONArray("list");
|
|
|
|
+ if (Check.isNull(list)) {
|
|
|
|
+ log.error("快分销数据返回为list数据为空");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ log.info("快分销当前数据条数:{}", list.size());
|
|
|
|
+ List<KuaishouSupplyChainSettlement> supplyChains = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = list.getJSONObject(i);
|
|
|
|
+ KuaishouSupplyChainSettlement supplyChain = new KuaishouSupplyChainSettlement();
|
|
|
|
+ supplyChain.setOid(jsonObject.getLong("oid"));
|
|
|
|
+ supplyChain.setSettlementAmount(jsonObject.getLong("settlementAmount"));
|
|
|
|
+ supplyChain.setSettlementTime(jsonObject.getLong("settlementTime"));
|
|
|
|
+
|
|
|
|
+ supplyChains.add(supplyChain);
|
|
|
|
+ }
|
|
|
|
+ mgsSupplyChainMapper.replaceSettlement(supplyChains);
|
|
|
|
+ Thread.sleep(2000L);
|
|
|
|
+ if (list.size() >= 5000) {
|
|
|
|
+ getSettlementData(cookie, offset + 5000, orderCreateTimeStart, orderCreateTimeEnd);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<JSONObject> getDataList(Long statDate) {
|
|
|
|
+ return mgsSupplyChainMapper.getDataList(statDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<JSONObject> getPromoterDataList(Long statDate) {
|
|
|
|
+ return mgsSupplyChainMapper.getPromoterDataList(statDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void deletePromoterBindChannelByDate(Long date) {
|
|
|
|
+ mgsSupplyChainMapper.deletePromoterBindChannelByDate(date);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void cleanKuaiShouPromoterBindChannel(Long date) {
|
|
|
|
+ mgsSupplyChainMapper.cleanKuaiShouPromoterBindChannel(date);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<JSONObject> getSamplesData(String startDate) {
|
|
|
|
+ return mgsSupplyChainMapper.getSamplesData(startDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void cleanBytedancePromoterBindChannel(Long date) {
|
|
|
|
+ mgsSupplyChainMapper.cleanBytedancePromoterBindChannel(date);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String filterSupplement(String content) {
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ for (char ch : content.toCharArray()) {
|
|
|
|
+ if (!Character.isHighSurrogate(ch) && !Character.isLowSurrogate(ch)) {
|
|
|
|
+ sb.append(ch);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|