|
@@ -9,10 +9,11 @@ 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
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 com.google.gson.Gson;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.http.client.CookieStore;
|
|
import org.apache.http.client.CookieStore;
|
|
import org.apache.http.impl.client.BasicCookieStore;
|
|
import org.apache.http.impl.client.BasicCookieStore;
|
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
|
@@ -27,18 +28,18 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
-
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 代理商日报
|
|
* 代理商日报
|
|
|
|
+ *
|
|
* @author jeecg-boot
|
|
* @author jeecg-boot
|
|
- * @date 2019-12-13
|
|
|
|
* @version V1.0
|
|
* @version V1.0
|
|
|
|
+ * @date 2019-12-13
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouReportDailyAgentMapper, KuaishouReportDailyAgent> implements IKuaishouReportDailyAgentService {
|
|
public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouReportDailyAgentMapper, KuaishouReportDailyAgent> implements IKuaishouReportDailyAgentService {
|
|
@Autowired
|
|
@Autowired
|
|
@@ -49,12 +50,13 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
|
|
private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
private String chromeDriver;
|
|
private String chromeDriver;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void replaceBatch(List<KuaishouReportDailyAgent> list) {
|
|
public void replaceBatch(List<KuaishouReportDailyAgent> list) {
|
|
kuaishouReportDailyAgentMapper.replaceBatch(list);
|
|
kuaishouReportDailyAgentMapper.replaceBatch(list);
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean loginAgent(){
|
|
|
|
|
|
+ public boolean loginAgent() {
|
|
boolean loginStatus = false;
|
|
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";
|
|
@@ -104,10 +106,10 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
}
|
|
}
|
|
loginStatus = true;
|
|
loginStatus = true;
|
|
- }catch (Exception e) {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
loginStatus = false;
|
|
loginStatus = false;
|
|
- }finally {
|
|
|
|
|
|
+ } finally {
|
|
webDriver.manage().deleteAllCookies();
|
|
webDriver.manage().deleteAllCookies();
|
|
// webDriver.close();
|
|
// webDriver.close();
|
|
webDriver.quit();
|
|
webDriver.quit();
|
|
@@ -115,38 +117,38 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
return loginStatus;
|
|
return loginStatus;
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean getAccount(int currentPage){
|
|
|
|
|
|
+ public boolean getAccount(int currentPage) {
|
|
boolean hasNextPage = false;
|
|
boolean hasNextPage = false;
|
|
try {
|
|
try {
|
|
- if(currentPage == 1){
|
|
|
|
- if (!loginAgent()){
|
|
|
|
|
|
+ if (currentPage == 1) {
|
|
|
|
+ if (!loginAgent()) {
|
|
return hasNextPage;
|
|
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}";
|
|
|
|
|
|
+ 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 listUrl = "https://agent.e.kuaishou.com/rest/dsp/agent/account/list";
|
|
- String result = HttpUtils2.httpPostRequestTest(listUrl,postData,headerMap);
|
|
|
|
|
|
+ String result = HttpUtils2.httpPostRequestTest(listUrl, postData, headerMap);
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
|
JsonNode resultNode = mapper.readTree(result);
|
|
JsonNode resultNode = mapper.readTree(result);
|
|
Integer code = resultNode.get("result").intValue();
|
|
Integer code = resultNode.get("result").intValue();
|
|
- if(code == 1) {
|
|
|
|
|
|
+ if (code == 1) {
|
|
Iterator<JsonNode> iterator1 = resultNode.get("adDspAccountList").elements();
|
|
Iterator<JsonNode> iterator1 = resultNode.get("adDspAccountList").elements();
|
|
int i = 0;
|
|
int i = 0;
|
|
List<KuaishouAgentAccount> accountList = new ArrayList<>();
|
|
List<KuaishouAgentAccount> accountList = new ArrayList<>();
|
|
while (iterator1.hasNext()) {
|
|
while (iterator1.hasNext()) {
|
|
hasNextPage = true;
|
|
hasNextPage = true;
|
|
JsonNode dataNode = iterator1.next();
|
|
JsonNode dataNode = iterator1.next();
|
|
- KuaishouAgentAccount agentAccount = mapper.readValue(dataNode.toString(),KuaishouAgentAccount.class);
|
|
|
|
|
|
+ KuaishouAgentAccount agentAccount = mapper.readValue(dataNode.toString(), KuaishouAgentAccount.class);
|
|
agentAccount.setBalance(agentAccount.getBalance().divide(new BigDecimal(1000)));
|
|
agentAccount.setBalance(agentAccount.getBalance().divide(new BigDecimal(1000)));
|
|
agentAccount.setContractRebate(agentAccount.getContractRebate().divide(new BigDecimal(1000)));
|
|
agentAccount.setContractRebate(agentAccount.getContractRebate().divide(new BigDecimal(1000)));
|
|
agentAccount.setCreditBalance(agentAccount.getCreditBalance().divide(new BigDecimal(1000)));
|
|
agentAccount.setCreditBalance(agentAccount.getCreditBalance().divide(new BigDecimal(1000)));
|
|
@@ -159,48 +161,48 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
agentAccount.setTotalBalance(agentAccount.getTotalBalance().divide(new BigDecimal(1000)));
|
|
agentAccount.setTotalBalance(agentAccount.getTotalBalance().divide(new BigDecimal(1000)));
|
|
accountList.add(agentAccount);
|
|
accountList.add(agentAccount);
|
|
}
|
|
}
|
|
- if (accountList != null && accountList.size() > 0){
|
|
|
|
|
|
+ if (accountList != null && accountList.size() > 0) {
|
|
kuaishouAgentAccountMapper.replaceBatch(accountList);
|
|
kuaishouAgentAccountMapper.replaceBatch(accountList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return hasNextPage;
|
|
return hasNextPage;
|
|
}
|
|
}
|
|
|
|
|
|
- public void getReport(String startDate,String endDate){
|
|
|
|
- try{
|
|
|
|
- if (!loginAgent()){
|
|
|
|
|
|
+ public void getReport(String startDate, String endDate) {
|
|
|
|
+ try {
|
|
|
|
+ if (!loginAgent()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
String currentDate = startDate;
|
|
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){
|
|
|
|
|
|
+ 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) {
|
|
//{"agentId":403756224,"startDate":"2020-03-05","endDate":"2020-03-05","sortKey":"","isAscending":false,"pageInfo":{"pageSize":19,"currentPage":1,"totalCount":100}}
|
|
//{"agentId":403756224,"startDate":"2020-03-05","endDate":"2020-03-05","sortKey":"","isAscending":false,"pageInfo":{"pageSize":19,"currentPage":1,"totalCount":100}}
|
|
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,\"startDate\":\""+currentDate+"\",\"endDate\":\""+currentDate+"\",\"isAscending\":false,\"pageInfo\":{\"pageSize\":19,\"currentPage\":1,\"totalCount\":999999}}";
|
|
|
|
- String result = HttpUtils2.httpPostRequestTest(listUrl,postData,headerMap);
|
|
|
|
|
|
+ String postData = "{\"agentId\":403756224,\"startDate\":\"" + currentDate + "\",\"endDate\":\"" + currentDate + "\",\"isAscending\":false,\"pageInfo\":{\"pageSize\":19,\"currentPage\":1,\"totalCount\":999999}}";
|
|
|
|
+ String result = HttpUtils2.httpPostRequestTest(listUrl, postData, headerMap);
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
JsonNode resultNode = mapper.readTree(result);
|
|
JsonNode resultNode = mapper.readTree(result);
|
|
Integer code = resultNode.get("result").intValue();
|
|
Integer code = resultNode.get("result").intValue();
|
|
- if(code == 1){
|
|
|
|
|
|
+ if (code == 1) {
|
|
Iterator<JsonNode> iterator1 = resultNode.get("data").elements();
|
|
Iterator<JsonNode> iterator1 = resultNode.get("data").elements();
|
|
int i = 0;
|
|
int i = 0;
|
|
List<KuaishouReportDailyAgent> reportList = new ArrayList<>();
|
|
List<KuaishouReportDailyAgent> reportList = new ArrayList<>();
|
|
- while (iterator1.hasNext()){
|
|
|
|
|
|
+ while (iterator1.hasNext()) {
|
|
JsonNode dataNode = iterator1.next();
|
|
JsonNode dataNode = iterator1.next();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
- if(i == 0){
|
|
|
|
|
|
+ if (i == 0) {
|
|
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());
|
|
@@ -218,10 +220,10 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
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<>();
|
|
- queryWrapper.eq("date",currentDate);
|
|
|
|
|
|
+ queryWrapper.eq("date", currentDate);
|
|
kuaishouReportDailyAgentSumMapper.delete(queryWrapper);
|
|
kuaishouReportDailyAgentSumMapper.delete(queryWrapper);
|
|
kuaishouReportDailyAgentSumMapper.insert(kuaishouReportDailyAgentSum);
|
|
kuaishouReportDailyAgentSumMapper.insert(kuaishouReportDailyAgentSum);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
KuaishouReportDailyAgent kuaishouReportDailyAgent = new KuaishouReportDailyAgent();
|
|
KuaishouReportDailyAgent kuaishouReportDailyAgent = new KuaishouReportDailyAgent();
|
|
kuaishouReportDailyAgent.setAccountId(dataNode.get("accountId").asInt());
|
|
kuaishouReportDailyAgent.setAccountId(dataNode.get("accountId").asInt());
|
|
kuaishouReportDailyAgent.setAdvertiserCreateTime(new Date(dataNode.get("createTime").asLong()));
|
|
kuaishouReportDailyAgent.setAdvertiserCreateTime(new Date(dataNode.get("createTime").asLong()));
|
|
@@ -246,12 +248,13 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
}
|
|
}
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
- if(reportList != null && reportList.size() > 0){
|
|
|
|
|
|
+ if (reportList != null && reportList.size() > 0) {
|
|
replaceBatch(reportList);
|
|
replaceBatch(reportList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- System.out.println("代理商日报"+currentDate+"入库完成");
|
|
|
|
- currentDate = DateUtils.addDay(currentDate,1);
|
|
|
|
|
|
+
|
|
|
|
+ log.info("代理商日报:{}入库完成", currentDate);
|
|
|
|
+ currentDate = DateUtils.addDay(currentDate, 1);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|