|
@@ -1,12 +1,15 @@
|
|
package cn.com.ctop.kuaishou.modules.report.service.impl;
|
|
package cn.com.ctop.kuaishou.modules.report.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.utils.HttpUtils2;
|
|
import cn.com.ctop.common.module.utils.HttpUtils2;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAgentAccount;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAgent;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAgent;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAgentSum;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAgentSum;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouAgentAccountMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAgentMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAgentMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAgentSumMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAgentSumMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
|
|
import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.apache.http.client.CookieStore;
|
|
import org.apache.http.client.CookieStore;
|
|
@@ -25,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@@ -40,6 +44,8 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
private KuaishouReportDailyAgentMapper kuaishouReportDailyAgentMapper;
|
|
private KuaishouReportDailyAgentMapper kuaishouReportDailyAgentMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private KuaishouReportDailyAgentSumMapper kuaishouReportDailyAgentSumMapper;
|
|
private KuaishouReportDailyAgentSumMapper kuaishouReportDailyAgentSumMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
private String chromeDriver;
|
|
private String chromeDriver;
|
|
@Override
|
|
@Override
|
|
@@ -47,7 +53,8 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
kuaishouReportDailyAgentMapper.replaceBatch(list);
|
|
kuaishouReportDailyAgentMapper.replaceBatch(list);
|
|
}
|
|
}
|
|
|
|
|
|
- public void getReport(String startDate,String endDate){
|
|
|
|
|
|
+ public boolean loginAgent(){
|
|
|
|
+ boolean loginStatus = false;
|
|
System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
|
|
System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
|
|
String url = "https://agent.e.kuaishou.com";
|
|
String url = "https://agent.e.kuaishou.com";
|
|
ChromeOptions chromeOptions = new ChromeOptions();
|
|
ChromeOptions chromeOptions = new ChromeOptions();
|
|
@@ -75,15 +82,7 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
//点击登录
|
|
//点击登录
|
|
loginElement.click();
|
|
loginElement.click();
|
|
Thread.sleep(3000L);
|
|
Thread.sleep(3000L);
|
|
- Map<String,String> headerMap = new HashMap<String,String>();
|
|
|
|
- headerMap.put("Accept","application/json");
|
|
|
|
- headerMap.put("Accept-Encoding","gzip, deflate, br");
|
|
|
|
- headerMap.put("Accept-Language","zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
|
|
|
|
- headerMap.put("Connection","keep-alive");
|
|
|
|
- headerMap.put("Host","agent.e.kuaishou.com");
|
|
|
|
- headerMap.put("Referer","https://agent.e.kuaishou.com/");
|
|
|
|
- headerMap.put("Content-Type","application/json;charset=utf-8");
|
|
|
|
- headerMap.put("User-Agent",HttpUtils2.USER_AGENT);
|
|
|
|
|
|
+
|
|
Set<Cookie> cookies = webDriver.manage().getCookies();
|
|
Set<Cookie> cookies = webDriver.manage().getCookies();
|
|
Iterator iterator = cookies.iterator();
|
|
Iterator iterator = cookies.iterator();
|
|
CookieStore cookieStore = new BasicCookieStore();
|
|
CookieStore cookieStore = new BasicCookieStore();
|
|
@@ -103,8 +102,88 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
clientCookie.setPath(cookieMap.get("path"));
|
|
clientCookie.setPath(cookieMap.get("path"));
|
|
HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
}
|
|
}
|
|
- String currentDate = startDate;
|
|
|
|
|
|
+ loginStatus = true;
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ loginStatus = false;
|
|
|
|
+ }finally {
|
|
|
|
+ webDriver.manage().deleteAllCookies();
|
|
|
|
+// webDriver.close();
|
|
|
|
+ webDriver.quit();
|
|
|
|
+ }
|
|
|
|
+ return loginStatus;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean getAccount(int currentPage){
|
|
|
|
+ boolean hasNextPage = false;
|
|
|
|
+ try {
|
|
|
|
+ if(currentPage == 1){
|
|
|
|
+ if (!loginAgent()){
|
|
|
|
+ return hasNextPage;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Map<String,String> headerMap = new HashMap<String,String>();
|
|
|
|
+ headerMap.put("Accept","application/json");
|
|
|
|
+ headerMap.put("Accept-Encoding","gzip, deflate, br");
|
|
|
|
+ headerMap.put("Accept-Language","zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
|
|
|
|
+ headerMap.put("Connection","keep-alive");
|
|
|
|
+ headerMap.put("Host","agent.e.kuaishou.com");
|
|
|
|
+ headerMap.put("Referer","https://agent.e.kuaishou.com/");
|
|
|
|
+ headerMap.put("Content-Type","application/json;charset=utf-8");
|
|
|
|
+ headerMap.put("User-Agent",HttpUtils2.USER_AGENT);
|
|
|
|
+ String postData = "{\"pageInfo\":{\"currentPage\":"+currentPage+",\"pageSize\":200,\"total\":1000},\"reviewStatus\":\"-1\",\"selectType\":1,\"selectValue\":\"\",\"createBeginTime\":0,\"createEndTime\":0}";
|
|
|
|
+ String listUrl = "https://agent.e.kuaishou.com/rest/dsp/agent/account/list";
|
|
|
|
+ String result = HttpUtils2.httpPostRequestTest(listUrl,postData,headerMap);
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
+ mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
|
|
|
+ JsonNode resultNode = mapper.readTree(result);
|
|
|
|
+ Integer code = resultNode.get("result").intValue();
|
|
|
|
+ if(code == 1) {
|
|
|
|
+ Iterator<JsonNode> iterator1 = resultNode.get("adDspAccountList").elements();
|
|
|
|
+ int i = 0;
|
|
|
|
+ List<KuaishouAgentAccount> accountList = new ArrayList<>();
|
|
|
|
+ while (iterator1.hasNext()) {
|
|
|
|
+ hasNextPage = true;
|
|
|
|
+ JsonNode dataNode = iterator1.next();
|
|
|
|
+ KuaishouAgentAccount agentAccount = mapper.readValue(dataNode.toString(),KuaishouAgentAccount.class);
|
|
|
|
+ agentAccount.setBalance(agentAccount.getBalance().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setContractRebate(agentAccount.getContractRebate().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setCreditBalance(agentAccount.getCreditBalance().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setDirectRebate(agentAccount.getDirectRebate().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setExtendedBalance(agentAccount.getExtendedBalance().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setKuaibiBalance(agentAccount.getKuaibiBalance().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setPreRebate(agentAccount.getPreRebate().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setPushBalance(agentAccount.getPushBalance().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setRebate(agentAccount.getRebate().divide(new BigDecimal(1000)));
|
|
|
|
+ agentAccount.setTotalBalance(agentAccount.getTotalBalance().divide(new BigDecimal(1000)));
|
|
|
|
+ accountList.add(agentAccount);
|
|
|
|
+ }
|
|
|
|
+ if (accountList != null && accountList.size() > 0){
|
|
|
|
+ kuaishouAgentAccountMapper.replaceBatch(accountList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return hasNextPage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getReport(String startDate,String endDate){
|
|
|
|
+ try{
|
|
|
|
+ if (!loginAgent()){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String currentDate = startDate;
|
|
|
|
+ Map<String,String> headerMap = new HashMap<String,String>();
|
|
|
|
+ headerMap.put("Accept","application/json");
|
|
|
|
+ headerMap.put("Accept-Encoding","gzip, deflate, br");
|
|
|
|
+ headerMap.put("Accept-Language","zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
|
|
|
|
+ headerMap.put("Connection","keep-alive");
|
|
|
|
+ headerMap.put("Host","agent.e.kuaishou.com");
|
|
|
|
+ headerMap.put("Referer","https://agent.e.kuaishou.com/");
|
|
|
|
+ headerMap.put("Content-Type","application/json;charset=utf-8");
|
|
|
|
+ headerMap.put("User-Agent",HttpUtils2.USER_AGENT);
|
|
while(DateUtils.compareDate(currentDate,endDate)<=0){
|
|
while(DateUtils.compareDate(currentDate,endDate)<=0){
|
|
String listUrl = "https://agent.e.kuaishou.com/rest/dsp/agent/account/data/list";
|
|
String listUrl = "https://agent.e.kuaishou.com/rest/dsp/agent/account/data/list";
|
|
String postData = "{\"agentId\":403756224,\"date\":\""+currentDate+"\",\"sortKey\":\"totalCharge\",\"isAscending\":false,\"pageInfo\":{\"totalCount\":1616,\"currentPage\":1,\"pageSize\":999999}}";
|
|
String postData = "{\"agentId\":403756224,\"date\":\""+currentDate+"\",\"sortKey\":\"totalCharge\",\"isAscending\":false,\"pageInfo\":{\"totalCount\":1616,\"currentPage\":1,\"pageSize\":999999}}";
|
|
@@ -123,17 +202,17 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
KuaishouReportDailyAgentSum kuaishouReportDailyAgentSum = new KuaishouReportDailyAgentSum();
|
|
KuaishouReportDailyAgentSum kuaishouReportDailyAgentSum = new KuaishouReportDailyAgentSum();
|
|
kuaishouReportDailyAgentSum.setBalance(dataNode.get("totalBalanceDouble").decimalValue());
|
|
kuaishouReportDailyAgentSum.setBalance(dataNode.get("totalBalanceDouble").decimalValue());
|
|
kuaishouReportDailyAgentSum.setConvertClickRate(dataNode.get("actionbarClickRatio").decimalValue());
|
|
kuaishouReportDailyAgentSum.setConvertClickRate(dataNode.get("actionbarClickRatio").decimalValue());
|
|
- kuaishouReportDailyAgentSum.setConvertCount(dataNode.get("actionbarClick").asLong());
|
|
|
|
|
|
+ kuaishouReportDailyAgentSum.setConvertCount(dataNode.get("actionbarClick").asInt());
|
|
kuaishouReportDailyAgentSum.setCost(dataNode.get("totalChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setCost(dataNode.get("totalChargedInYuan").decimalValue());
|
|
- kuaishouReportDailyAgentSum.setCostCampaignCount(dataNode.get("chargedCampaignCount").asLong());
|
|
|
|
|
|
+ kuaishouReportDailyAgentSum.setCostCampaignCount(dataNode.get("chargedCampaignCount").asInt());
|
|
kuaishouReportDailyAgentSum.setDate(sdf.parse(currentDate));
|
|
kuaishouReportDailyAgentSum.setDate(sdf.parse(currentDate));
|
|
- kuaishouReportDailyAgentSum.setFengmianClickCount(dataNode.get("adPhotoClick").asLong());
|
|
|
|
|
|
+ kuaishouReportDailyAgentSum.setFengmianClickCount(dataNode.get("adPhotoClick").asInt());
|
|
kuaishouReportDailyAgentSum.setFengmianClickRate(dataNode.get("clickRatio").decimalValue());
|
|
kuaishouReportDailyAgentSum.setFengmianClickRate(dataNode.get("clickRatio").decimalValue());
|
|
- kuaishouReportDailyAgentSum.setFengmianShowCount(dataNode.get("impression").asLong());
|
|
|
|
|
|
+ kuaishouReportDailyAgentSum.setFengmianShowCount(dataNode.get("impression").asInt());
|
|
kuaishouReportDailyAgentSum.setFandianCost(dataNode.get("rebateRealChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setFandianCost(dataNode.get("rebateRealChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setJiliCost(dataNode.get("directRebateRealChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setJiliCost(dataNode.get("directRebateRealChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setKuangfanCost(dataNode.get("contractRebateRealChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setKuangfanCost(dataNode.get("contractRebateRealChargedInYuan").decimalValue());
|
|
- kuaishouReportDailyAgentSum.setSucaiShowCount(dataNode.get("click").asLong());
|
|
|
|
|
|
+ kuaishouReportDailyAgentSum.setSucaiShowCount(dataNode.get("click").asInt());
|
|
kuaishouReportDailyAgentSum.setXianjinCost(dataNode.get("realChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setXianjinCost(dataNode.get("realChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setXinyongCost(dataNode.get("creditRealChargedInYuan").decimalValue());
|
|
kuaishouReportDailyAgentSum.setXinyongCost(dataNode.get("creditRealChargedInYuan").decimalValue());
|
|
QueryWrapper<KuaishouReportDailyAgentSum> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<KuaishouReportDailyAgentSum> queryWrapper = new QueryWrapper<>();
|
|
@@ -172,14 +251,8 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
System.out.println("代理商日报"+currentDate+"入库完成");
|
|
System.out.println("代理商日报"+currentDate+"入库完成");
|
|
currentDate = DateUtils.addDay(currentDate,1);
|
|
currentDate = DateUtils.addDay(currentDate,1);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- } finally {
|
|
|
|
- webDriver.manage().deleteAllCookies();
|
|
|
|
-// webDriver.close();
|
|
|
|
- webDriver.quit();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|