|
@@ -0,0 +1,296 @@
|
|
|
+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.entity.vo.ItemCheck;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouSupplyChainMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.RocketSupplyChainMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.YufuSupplyChainMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.RocketSupplyChainService;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.YufuSupplyChainService;
|
|
|
+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.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
+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 YufuSupplyChainServiceImpl extends ServiceImpl<YufuSupplyChainMapper, KuaishouSupplyChain> implements YufuSupplyChainService {
|
|
|
+ private static String url = "https://cps.kwaixiaodian.com/distribute/pc/investment/order/list";
|
|
|
+ @Autowired
|
|
|
+ private ISendMessageService sendMessageService;
|
|
|
+ @Autowired
|
|
|
+ private YufuSupplyChainMapper yufuSupplyChainMapper;
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ 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("rocket团长抓取订单数据入参,开始时间:{},结束时间:{},数据:{}", 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("rocket快分销数据返回异常:", resultStr);
|
|
|
+ sendMessageService.sendMessage("113dee46c7df464da78c07a985e92cd1", "rocketcookie失效,请及时更新。媒体返回信息:" + resultStr);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject dataJson = result.getJSONObject("data");
|
|
|
+ if (Check.isNull(dataJson)) {
|
|
|
+ log.error("rocket数据返回为data数据为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray list = dataJson.getJSONArray("list");
|
|
|
+ if (Check.isNull(list)) {
|
|
|
+ log.error("rocket数据返回为list数据为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ log.info("rocket当前数据条数:{}", list.size());
|
|
|
+ List<KuaishouSupplyChain> ruixuanSupplyChains = new ArrayList<>();
|
|
|
+ List<KuaishouSupplyChain> mgsSupplyChains = new ArrayList<>();
|
|
|
+ List<KuaishouSupplyChain> rocketSupplyChains = new ArrayList<>();
|
|
|
+ List<KuaishouSupplyChain> yufuSupplyChains = 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);
|
|
|
+ Long itemId = null;
|
|
|
+ if (!Check.isNull(item)) {
|
|
|
+ itemId = item.getLong("itemId");
|
|
|
+ supplyChain.setItemId(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.setStatHour(DateUtils.getHour(jsonObject.getLong("orderCreateTime")));
|
|
|
+ supplyChain.setItemCommissionRate(itemMap.get(item.getLong("itemId")));
|
|
|
+ Criteria criteria = new Criteria();
|
|
|
+ criteria = Criteria.where("_id").is(itemId);
|
|
|
+ Query query = new Query(criteria);
|
|
|
+ ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
|
|
|
+ if (Check.isNull(itemCheck)) {
|
|
|
+ yufuSupplyChains.add(supplyChain);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(itemCheck)) {
|
|
|
+ String ownership = itemCheck.getOwnership();
|
|
|
+ if ("yufu".equals(ownership)) {
|
|
|
+ yufuSupplyChains.add(supplyChain);
|
|
|
+ }
|
|
|
+ if ("ruixuan".equals(ownership)) {
|
|
|
+ ruixuanSupplyChains.add(supplyChain);
|
|
|
+ }
|
|
|
+ if ("miaogousi".equals(ownership)) {
|
|
|
+ mgsSupplyChains.add(supplyChain);
|
|
|
+ }
|
|
|
+ if ("rocket".equals(ownership)) {
|
|
|
+ rocketSupplyChains.add(supplyChain);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (!Check.isNull(yufuSupplyChains)) {
|
|
|
+ yufuSupplyChainMapper.replaceYufuSupplyChains(yufuSupplyChains);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(ruixuanSupplyChains)) {
|
|
|
+ yufuSupplyChainMapper.replaceRuixuanSupplyChains(ruixuanSupplyChains);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(mgsSupplyChains)) {
|
|
|
+ yufuSupplyChainMapper.replaceMgsSupplyChains(mgsSupplyChains);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(rocketSupplyChains)) {
|
|
|
+ yufuSupplyChainMapper.replaceRocketSupplyChains(rocketSupplyChains);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (list.size() >= 100) {
|
|
|
+ getOrderList(cookie, offset + 100, orderCreateTimeStart, orderCreateTimeEnd, itemMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getCookie() {
|
|
|
+ return yufuSupplyChainMapper.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("rocket数据返回为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer code = result.getInteger("result");
|
|
|
+ if (code != 1) {
|
|
|
+ log.info("rocket返回异常:", resultStr);
|
|
|
+ sendMessageService.sendMessage("113dee46c7df464da78c07a985e92cd1", "rocket供应链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);
|
|
|
+ }
|
|
|
+ yufuSupplyChainMapper.replaceSettlement(supplyChains);
|
|
|
+ Thread.sleep(2000L);
|
|
|
+ if (list.size() >= 5000) {
|
|
|
+ getSettlementData(cookie, offset + 5000, orderCreateTimeStart, orderCreateTimeEnd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getDataList(Long statDate) {
|
|
|
+ return yufuSupplyChainMapper.getDataList(statDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getPromoterDataList(Long statDate) {
|
|
|
+ return yufuSupplyChainMapper.getPromoterDataList(statDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deletePromoterBindChannelByDate(Long date) {
|
|
|
+ yufuSupplyChainMapper.deletePromoterBindChannelByDate(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cleanKuaiShouPromoterBindChannel(Long date) {
|
|
|
+ yufuSupplyChainMapper.cleanKuaiShouPromoterBindChannel(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getSamplesData(String startDate) {
|
|
|
+ return yufuSupplyChainMapper.getSamplesData(startDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cleanBytedancePromoterBindChannel(Long date) {
|
|
|
+ yufuSupplyChainMapper.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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|