|
@@ -1,15 +1,23 @@
|
|
|
package com.ruixuan.jiaoyang.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ruixuan.common.utils.Check;
|
|
|
+import com.ruixuan.common.utils.http.HttpUtils;
|
|
|
+import com.ruixuan.jiaoyang.entity.JyAuthOrder;
|
|
|
import com.ruixuan.jiaoyang.mapper.JiaoYangReportMapper;
|
|
|
import com.ruixuan.jiaoyang.service.IJiaoYangReportService;
|
|
|
+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;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class JiaoYangReportServiceImpl implements IJiaoYangReportService {
|
|
|
@Autowired
|
|
|
private JiaoYangReportMapper jiaoYangReportMapper;
|
|
@@ -115,8 +123,8 @@ public class JiaoYangReportServiceImpl implements IJiaoYangReportService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<JSONObject> getTopItem(Long date, Long promoterId,String fieId,String sort) {
|
|
|
- return jiaoYangReportMapper.getTopItem(date,promoterId,fieId,sort);
|
|
|
+ public List<JSONObject> getTopItem(Long date, Long promoterId, String fieId, String sort) {
|
|
|
+ return jiaoYangReportMapper.getTopItem(date, promoterId, fieId, sort);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -128,4 +136,68 @@ public class JiaoYangReportServiceImpl implements IJiaoYangReportService {
|
|
|
public List<JSONObject> getDataByDate(Long strDateTimsToInt) {
|
|
|
return jiaoYangReportMapper.getDataByDate(strDateTimsToInt);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getJiaoYangCookie() {
|
|
|
+ return jiaoYangReportMapper.getJiaoYangCookie();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAuthItem(String cookie, Integer offset) throws InterruptedException {
|
|
|
+ Thread.sleep(1000L);
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("limit", 10);
|
|
|
+ params.put("offset", offset);
|
|
|
+ params.put("status", 1);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Cookie", cookie);
|
|
|
+ String postUrl = "https://cps.kwaixiaodian.com/gateway/distribute/app/section/mcn/query/empower/item/list";
|
|
|
+ String resultStr = HttpUtils.httpPostRequest(postUrl, params, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(resultStr);
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ log.error("骄阳授权商品数据返回为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer code = result.getInteger("result");
|
|
|
+ if (code != 1) {
|
|
|
+ log.info("骄阳授权商品数据返回异常:", resultStr);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject dataJson = result.getJSONObject("data");
|
|
|
+ if (Check.isNull(dataJson)) {
|
|
|
+ log.error("骄阳授权商品返回为data数据为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray list = dataJson.getJSONArray("mcnEmpowerItem");
|
|
|
+ if (Check.isNull(list)) {
|
|
|
+ log.error("骄阳授权商品返回为list数据为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ log.info("骄阳授权商品当前数据条数:{}", list.size());
|
|
|
+ List<JyAuthOrder> adds = new ArrayList<>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ JSONObject jsonObject = list.getJSONObject(i);
|
|
|
+ JyAuthOrder order = new JyAuthOrder();
|
|
|
+ order.setItemId(jsonObject.getLong("itemId"));
|
|
|
+ order.setItemName(jsonObject.getString("itemName"));
|
|
|
+ order.setItemImageUrl(jsonObject.getString("itemImageUrl"));
|
|
|
+ order.setItemPriceView(jsonObject.getString("itemPriceView"));
|
|
|
+ order.setCommissionRateView(jsonObject.getString("commissionRateView"));
|
|
|
+ order.setPromoterId(jsonObject.getString("promoterId"));
|
|
|
+ order.setPromoterNick(jsonObject.getString("promoterNick"));
|
|
|
+ order.setPromoterPhoto(jsonObject.getString("promoterPhoto"));
|
|
|
+ order.setMcnCommissionRateView(jsonObject.getString("mcnCommissionRateView"));
|
|
|
+ adds.add(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ jiaoYangReportMapper.replaceItems(adds);
|
|
|
+ if (list.size() >= 10) {
|
|
|
+ getAuthItem(cookie, offset + 10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getAuthItemList(Map<String, Object> requestMap) {
|
|
|
+ return jiaoYangReportMapper.getAuthItemList(requestMap);
|
|
|
+ }
|
|
|
}
|