|
@@ -1,32 +1,40 @@
|
|
|
package cn.com.ctop.kuaishou.modules.report.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.utils.Base64Utils;
|
|
|
+import cn.com.ctop.common.module.utils.ChaojiyingUtils;
|
|
|
import cn.com.ctop.common.module.utils.HttpUtils2;
|
|
|
+import cn.com.ctop.kuaishou.modules.report.entity.KuaiShouDailyAgent;
|
|
|
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.KuaishouReportDailyAgentSum;
|
|
|
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaiShouDailyAgentMapper;
|
|
|
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.KuaishouReportDailyAgentSumMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
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.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.http.impl.client.BasicCookieStore;
|
|
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
-import org.openqa.selenium.By;
|
|
|
-import org.openqa.selenium.Cookie;
|
|
|
-import org.openqa.selenium.WebDriver;
|
|
|
-import org.openqa.selenium.WebElement;
|
|
|
+import org.openqa.selenium.NoSuchElementException;
|
|
|
+import org.openqa.selenium.*;
|
|
|
import org.openqa.selenium.chrome.ChromeDriver;
|
|
|
import org.openqa.selenium.chrome.ChromeOptions;
|
|
|
+import org.openqa.selenium.interactions.Actions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.File;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -42,17 +50,32 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouReportDailyAgentMapper, KuaishouReportDailyAgent> implements IKuaishouReportDailyAgentService {
|
|
|
@Autowired
|
|
|
- private KuaishouReportDailyAgentMapper kuaishouReportDailyAgentMapper;
|
|
|
+ private KuaiShouDailyAgentMapper kuaiShouDailyAgentMapper;
|
|
|
@Autowired
|
|
|
private KuaishouReportDailyAgentSumMapper kuaishouReportDailyAgentSumMapper;
|
|
|
@Autowired
|
|
|
private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
|
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
|
private String chromeDriver;
|
|
|
+ @Value("${jeecg.path.kuaishou-agent-image}")
|
|
|
+ private String kuaishouAgentImage;
|
|
|
|
|
|
@Override
|
|
|
- public void replaceBatch(List<KuaishouReportDailyAgent> list) {
|
|
|
- kuaishouReportDailyAgentMapper.replaceBatch(list);
|
|
|
+ public void replaceBatch(List<KuaiShouDailyAgent> list) {
|
|
|
+ for(KuaiShouDailyAgent agent:list){
|
|
|
+ kuaiShouDailyAgentMapper.insert(agent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void tapPoint(WebDriver driver, Integer x, Integer y) {
|
|
|
+ WebElement element = driver.findElement(By.tagName("iframe"));
|
|
|
+ Actions actions = new Actions(driver);
|
|
|
+ actions.moveToElement(element,x,y).click().perform();
|
|
|
+ try {
|
|
|
+ Thread.sleep(500L);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public boolean loginAgent() {
|
|
@@ -86,7 +109,27 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
|
//点击登录
|
|
|
loginElement.click();
|
|
|
Thread.sleep(3000L);
|
|
|
-
|
|
|
+ if (null!=webDriverGetElement(webDriver,By.tagName("iframe"))) {
|
|
|
+ log.error("【错误】快手登录出现验证码!");
|
|
|
+ File scrFile = captureElement(webDriver.findElement(By.tagName("iframe")));
|
|
|
+ //clickCharBg
|
|
|
+ FileUtils.copyFile(scrFile, new File(kuaishouAgentImage));
|
|
|
+ String result = ChaojiyingUtils.process(Base64Utils.imageToBase64(kuaishouAgentImage),9104);
|
|
|
+ String pointString = JSONObject.parseObject(result).getString("pic_str");
|
|
|
+ String[] split = pointString.split("\\|");
|
|
|
+ if(split.length>0){
|
|
|
+ for(int i=0;i<split.length;i++){
|
|
|
+ String pointStr = split[i];
|
|
|
+ String [] taps = pointStr.split(",");
|
|
|
+ tapPoint(webDriver,Integer.parseInt(taps[0]),Integer.parseInt(taps[1]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ webDriver.switchTo().frame(webDriver.findElement(By.tagName("iframe")));
|
|
|
+ webDriver.findElement(By.xpath("//div[@class='opArea']/span[@id='submit']")).click();
|
|
|
+ }
|
|
|
+ Thread.sleep(3000L);
|
|
|
+ webDriver.get("https://agent.e.kuaishou.com/#/index");
|
|
|
+ Thread.sleep(3000L);
|
|
|
Set<Cookie> cookies = webDriver.manage().getCookies();
|
|
|
Iterator iterator = cookies.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
@@ -116,6 +159,32 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
|
return loginStatus;
|
|
|
}
|
|
|
|
|
|
+ private WebElement webDriverGetElement(WebDriver webDriver,By by){
|
|
|
+ try {
|
|
|
+ return webDriver.findElement(by);
|
|
|
+ }catch (NoSuchElementException e){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public File captureElement(WebElement element) throws Exception {
|
|
|
+ WrapsDriver wrapsDriver = (WrapsDriver) element;
|
|
|
+ // 截图整个页面
|
|
|
+ File screen = ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.FILE);
|
|
|
+ FileUtils.copyFile(screen, new File(kuaishouAgentImage));
|
|
|
+ BufferedImage img = ImageIO.read(new File(kuaishouAgentImage));
|
|
|
+ // 获得元素的高度和宽度
|
|
|
+ int width = element.getSize().getWidth();
|
|
|
+ int height = element.getSize().getHeight();
|
|
|
+ // 得到元素的坐标
|
|
|
+ Point p = element.getLocation();
|
|
|
+ BufferedImage dest = img.getSubimage(p.x, p.y, width, height);
|
|
|
+ // 存为png格式
|
|
|
+ ImageIO.write(dest, "png", screen);
|
|
|
+ return screen;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public boolean getAccount(int currentPage) {
|
|
|
boolean hasNextPage = false;
|
|
@@ -174,7 +243,7 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
|
public void getReport(String startDate, String endDate) {
|
|
|
try {
|
|
|
if (!loginAgent()) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
String currentDate = startDate;
|
|
|
Map<String, String> headerMap = new HashMap<>();
|
|
@@ -197,7 +266,7 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
|
if (code == 1) {
|
|
|
Iterator<JsonNode> iterator1 = resultNode.get("data").elements();
|
|
|
int i = 0;
|
|
|
- List<KuaishouReportDailyAgent> reportList = new ArrayList<>();
|
|
|
+ List<KuaiShouDailyAgent> reportList = new ArrayList<>();
|
|
|
while (iterator1.hasNext()) {
|
|
|
JsonNode dataNode = iterator1.next();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
@@ -208,7 +277,7 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
|
kuaishouReportDailyAgentSum.setConvertCount(dataNode.get("actionbarClick").asLong());
|
|
|
kuaishouReportDailyAgentSum.setCost(dataNode.get("totalChargedInYuan").decimalValue());
|
|
|
kuaishouReportDailyAgentSum.setCostCampaignCount(dataNode.get("chargedCampaignCount").asLong());
|
|
|
- //- kuaishouReportDailyAgentSum.setDate(sdf.parse(currentDate));
|
|
|
+ kuaishouReportDailyAgentSum.setDate(currentDate);
|
|
|
kuaishouReportDailyAgentSum.setFengmianClickCount(dataNode.get("adPhotoClick").asLong());
|
|
|
kuaishouReportDailyAgentSum.setFengmianClickRate(dataNode.get("clickRatio").decimalValue());
|
|
|
kuaishouReportDailyAgentSum.setFengmianShowCount(dataNode.get("impression").asLong());
|
|
@@ -223,26 +292,27 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
|
kuaishouReportDailyAgentSumMapper.delete(queryWrapper);
|
|
|
kuaishouReportDailyAgentSumMapper.insert(kuaishouReportDailyAgentSum);
|
|
|
} else {
|
|
|
- KuaishouReportDailyAgent kuaishouReportDailyAgent = new KuaishouReportDailyAgent();
|
|
|
- kuaishouReportDailyAgent.setAccountId(dataNode.get("accountId").asInt());
|
|
|
- kuaishouReportDailyAgent.setAdvertiserCreateTime(new Date(dataNode.get("createTime").asLong()));
|
|
|
- kuaishouReportDailyAgent.setAdvertiserName(dataNode.get("accountName").asText());
|
|
|
- kuaishouReportDailyAgent.setBalance(dataNode.get("totalBalanceDouble").decimalValue());
|
|
|
+ KuaiShouDailyAgent kuaishouReportDailyAgent = new KuaiShouDailyAgent();
|
|
|
+ kuaishouReportDailyAgent.setAccountId(dataNode.get("accountId").asLong());
|
|
|
+// kuaishouReportDailyAgent.setAdvertiserCreateTime(new Date(dataNode.get("createTime").asLong()));
|
|
|
+ kuaishouReportDailyAgent.setAccountName(dataNode.get("accountName").asText());
|
|
|
+ kuaishouReportDailyAgent.setTotalBalanceInYuan(dataNode.get("totalBalanceDouble").decimalValue());
|
|
|
// kuaishouReportDailyAgent.setConvertClickRate(dataNode.get("actionbarClickRatio").decimalValue());
|
|
|
- kuaishouReportDailyAgent.setConvertCount(dataNode.get("actionbarClick").asInt());
|
|
|
- kuaishouReportDailyAgent.setCost(dataNode.get("totalChargedInYuan").decimalValue());
|
|
|
- kuaishouReportDailyAgent.setCostCampaignCount(dataNode.get("chargedCampaignCount").asInt());
|
|
|
- // kuaishouReportDailyAgent.setDate(sdf.parse(dataNode.get("dateTime").asText()));
|
|
|
- kuaishouReportDailyAgent.setFengmianClickCount(dataNode.get("adPhotoClick").asInt());
|
|
|
- // kuaishouReportDailyAgent.setFengmianClickRate(dataNode.get("clickRatio").decimalValue());
|
|
|
- kuaishouReportDailyAgent.setFengmianShowCount(dataNode.get("impression").asInt());
|
|
|
- kuaishouReportDailyAgent.setFandianCost(dataNode.get("rebateRealChargedInYuan").decimalValue());
|
|
|
- kuaishouReportDailyAgent.setJiliCost(dataNode.get("directRebateRealChargedInYuan").decimalValue());
|
|
|
- kuaishouReportDailyAgent.setKid(dataNode.get("userId").asInt());
|
|
|
- kuaishouReportDailyAgent.setKuangfanCost(dataNode.get("contractRebateRealChargedInYuan").decimalValue());
|
|
|
- kuaishouReportDailyAgent.setSucaiShowCount(dataNode.get("click").asInt());
|
|
|
- kuaishouReportDailyAgent.setXianjinCost(dataNode.get("realChargedInYuan").decimalValue());
|
|
|
- kuaishouReportDailyAgent.setXinyongCost(dataNode.get("creditRealChargedInYuan").decimalValue());
|
|
|
+ kuaishouReportDailyAgent.setAdItemClick(dataNode.get("actionbarClick").asLong());
|
|
|
+ kuaishouReportDailyAgent.setTotalChargedInYuan(dataNode.get("totalChargedInYuan").decimalValue());
|
|
|
+ kuaishouReportDailyAgent.setChargedCampaignCount(dataNode.get("chargedCampaignCount").asLong());
|
|
|
+ kuaishouReportDailyAgent.setDateTime(dataNode.get("dateTime").asText());
|
|
|
+ kuaishouReportDailyAgent.setAdPhotoClick(dataNode.get("adPhotoClick").asLong());
|
|
|
+ kuaishouReportDailyAgent.setPhotoClickRatio(dataNode.get("clickRatio").asText());
|
|
|
+ kuaishouReportDailyAgent.setAdPhotoImpression(dataNode.get("impression").asLong());
|
|
|
+ kuaishouReportDailyAgent.setTotalRebateRealChargedInYuan(dataNode.get("rebateRealChargedInYuan").decimalValue());
|
|
|
+ kuaishouReportDailyAgent.setDirectRebateRealChargedInYuan(dataNode.get("directRebateRealChargedInYuan").decimalValue());
|
|
|
+ //猜测可能是agentId
|
|
|
+ kuaishouReportDailyAgent.setAgentId(14L);
|
|
|
+ kuaishouReportDailyAgent.setContractRebateRealChargedInYuan(dataNode.get("contractRebateRealChargedInYuan").decimalValue());
|
|
|
+ kuaishouReportDailyAgent.setAdItemImpression(dataNode.get("click").asLong());
|
|
|
+ kuaishouReportDailyAgent.setRealChargedInYuan(dataNode.get("realChargedInYuan").decimalValue());
|
|
|
+ kuaishouReportDailyAgent.setCreditRealChargedInYuan(dataNode.get("creditRealChargedInYuan").decimalValue());
|
|
|
reportList.add(kuaishouReportDailyAgent);
|
|
|
}
|
|
|
i++;
|