|
@@ -1,35 +1,31 @@
|
|
package com.example.demo.service;
|
|
package com.example.demo.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.example.demo.base.Constants;
|
|
import com.example.demo.base.Constants;
|
|
-import com.example.demo.domain.*;
|
|
|
|
-import com.example.demo.mapper.QrtzTaskMapper;
|
|
|
|
-import com.example.demo.model.dto.QuartzTaskDTO;
|
|
|
|
|
|
+import com.example.demo.domain.dto.UploadFileDTO;
|
|
|
|
+import com.example.demo.domain.entity.PatentCell;
|
|
|
|
+import com.example.demo.domain.entity.QrtzTask;
|
|
|
|
+import com.example.demo.domain.entity.QrtzTaskDetail;
|
|
|
|
+import com.example.demo.domain.entity.WebConfig;
|
|
import com.example.demo.model.dto.TaskWebSocketDTO;
|
|
import com.example.demo.model.dto.TaskWebSocketDTO;
|
|
import com.example.demo.model.dto.WebQueryDTO;
|
|
import com.example.demo.model.dto.WebQueryDTO;
|
|
-import com.example.demo.util.FileUtils;
|
|
|
|
-import com.example.demo.util.Response;
|
|
|
|
-import com.example.demo.util.ResponseEnum;
|
|
|
|
-import com.example.demo.util.WebSocketServer;
|
|
|
|
-import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
|
|
|
+import com.example.demo.util.*;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.openqa.selenium.By;
|
|
import org.openqa.selenium.By;
|
|
import org.openqa.selenium.WebDriver;
|
|
import org.openqa.selenium.WebDriver;
|
|
import org.openqa.selenium.WebElement;
|
|
import org.openqa.selenium.WebElement;
|
|
import org.openqa.selenium.chrome.ChromeDriver;
|
|
import org.openqa.selenium.chrome.ChromeDriver;
|
|
import org.openqa.selenium.chrome.ChromeOptions;
|
|
import org.openqa.selenium.chrome.ChromeOptions;
|
|
-import org.openqa.selenium.htmlunit.HtmlUnitWebElement;
|
|
|
|
import org.openqa.selenium.interactions.Actions;
|
|
import org.openqa.selenium.interactions.Actions;
|
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.DecimalFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
@@ -47,16 +43,25 @@ public class UploadFromWebService {
|
|
private final OutInterfaceService outInterfaceService;
|
|
private final OutInterfaceService outInterfaceService;
|
|
private final WebConfigService webConfigService;
|
|
private final WebConfigService webConfigService;
|
|
private final QrTaskService qrTaskService;
|
|
private final QrTaskService qrTaskService;
|
|
|
|
+ private final QrTaskDetailService qrTaskDetailService;
|
|
|
|
|
|
// 查询并上传(专利之星)
|
|
// 查询并上传(专利之星)
|
|
public List<PatentCell> getPatentStar(WebQueryDTO webQueryDTO) throws Exception {
|
|
public List<PatentCell> getPatentStar(WebQueryDTO webQueryDTO) throws Exception {
|
|
List<PatentCell> patentCells = new ArrayList<>();
|
|
List<PatentCell> patentCells = new ArrayList<>();
|
|
-
|
|
|
|
|
|
+ //当前任务执行情况
|
|
|
|
+ QrtzTaskDetail qrtzTaskDetail = qrTaskDetailService.getById(webQueryDTO.getTaskId());
|
|
|
|
+ Integer successNum1 = qrtzTaskDetail.getSuccessNum();
|
|
|
|
+ Integer startPage = successNum1 / 5;
|
|
|
|
+ Integer startNum = successNum1 % 5;
|
|
|
|
+ //当前任务条件
|
|
|
|
+ QrtzTask qrtzTask = qrTaskService.getById(qrtzTaskDetail.getTaskId());
|
|
|
|
+ //专利成功条数
|
|
|
|
+ int successNum = 0;
|
|
try {
|
|
try {
|
|
List<String> cells = webQueryDTO.getConCells();
|
|
List<String> cells = webQueryDTO.getConCells();
|
|
String conditions = webQueryDTO.getConditions();
|
|
String conditions = webQueryDTO.getConditions();
|
|
Integer id = webQueryDTO.getWebConfigId();
|
|
Integer id = webQueryDTO.getWebConfigId();
|
|
- conditions = this.formatConditions(conditions);
|
|
|
|
|
|
+ //conditions = this.formatConditions(conditions);
|
|
//根据id 获得网站配置
|
|
//根据id 获得网站配置
|
|
WebConfig webConfig = webConfigService.getConfigById(id);
|
|
WebConfig webConfig = webConfigService.getConfigById(id);
|
|
//1.获得驱动
|
|
//1.获得驱动
|
|
@@ -83,9 +88,6 @@ public class UploadFromWebService {
|
|
TimeUnit.MILLISECONDS.sleep(5000);//毫秒
|
|
TimeUnit.MILLISECONDS.sleep(5000);//毫秒
|
|
//获得表格搜索按钮并点击
|
|
//获得表格搜索按钮并点击
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("tablepage")));
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("tablepage")));
|
|
- WebElement countEle = driver.findElement(By.className("allcountlab"));
|
|
|
|
- String countText = countEle.getText();
|
|
|
|
- Integer count = Integer.parseInt(countText);
|
|
|
|
WebElement tablePage = driver.findElement(By.id("tablepage"));
|
|
WebElement tablePage = driver.findElement(By.id("tablepage"));
|
|
WebElement tablePagea = tablePage.findElement(By.tagName("a"));
|
|
WebElement tablePagea = tablePage.findElement(By.tagName("a"));
|
|
tablePagea.click();
|
|
tablePagea.click();
|
|
@@ -100,6 +102,13 @@ public class UploadFromWebService {
|
|
List<WebElement> tcdNumbers = driver.findElements(By.className("tcdNumber"));
|
|
List<WebElement> tcdNumbers = driver.findElements(By.className("tcdNumber"));
|
|
String pagesText = tcdNumbers.get(tcdNumbers.size() - 1).getText();
|
|
String pagesText = tcdNumbers.get(tcdNumbers.size() - 1).getText();
|
|
int page = Integer.parseInt(pagesText);
|
|
int page = Integer.parseInt(pagesText);
|
|
|
|
+ //获得总数
|
|
|
|
+ WebElement countEle = driver.findElement(By.className("allcountlab"));
|
|
|
|
+ String countText = countEle.getText();
|
|
|
|
+ Integer count = Integer.parseInt(countText);
|
|
|
|
+ //总数赋值给当前任务执行情况的总量属性
|
|
|
|
+ qrtzTaskDetail.setAllNum(count);
|
|
|
|
+ qrtzTaskDetail.updateById();
|
|
String Handle = driver.getWindowHandle();
|
|
String Handle = driver.getWindowHandle();
|
|
//创建一个map集合存放浏览器句柄
|
|
//创建一个map集合存放浏览器句柄
|
|
HashMap<String, String> handleMap = new HashMap<>();
|
|
HashMap<String, String> handleMap = new HashMap<>();
|
|
@@ -111,14 +120,14 @@ public class UploadFromWebService {
|
|
WebElement pagBtn = driver.findElement(By.className("page_btn"));
|
|
WebElement pagBtn = driver.findElement(By.className("page_btn"));
|
|
pagBtn.click();
|
|
pagBtn.click();
|
|
TimeUnit.MILLISECONDS.sleep(10000);//毫秒
|
|
TimeUnit.MILLISECONDS.sleep(10000);//毫秒
|
|
- for (int p = 4; p < page; p++) {
|
|
|
|
|
|
+ for (int p = startPage; p < page; p++) {
|
|
//等待数据加载
|
|
//等待数据加载
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("patent")));
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("patent")));
|
|
TimeUnit.MILLISECONDS.sleep(1000);//毫秒
|
|
TimeUnit.MILLISECONDS.sleep(1000);//毫秒
|
|
//获得列表
|
|
//获得列表
|
|
List<WebElement> patentContents = driver.findElements(By.className("patent"));
|
|
List<WebElement> patentContents = driver.findElements(By.className("patent"));
|
|
// 页面元素标签
|
|
// 页面元素标签
|
|
- for (int i = 4; i < patentContents.size(); i++) {
|
|
|
|
|
|
+ for (int i = 1; i < patentContents.size(); i++) {
|
|
PatentCell patentCell = new PatentCell();
|
|
PatentCell patentCell = new PatentCell();
|
|
patentCell.setProjectId(webQueryDTO.getProjectId());
|
|
patentCell.setProjectId(webQueryDTO.getProjectId());
|
|
patentCell.setReportId(webQueryDTO.getReportId());
|
|
patentCell.setReportId(webQueryDTO.getReportId());
|
|
@@ -139,7 +148,21 @@ public class UploadFromWebService {
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("item-content")));
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("item-content")));
|
|
WebElement itemContent = driver.findElement(By.className("item-content"));
|
|
WebElement itemContent = driver.findElement(By.className("item-content"));
|
|
List<WebElement> divItems = itemContent.findElements(By.tagName("div"));
|
|
List<WebElement> divItems = itemContent.findElements(By.tagName("div"));
|
|
- for (int t = 0; t < divItems.size(); t++) {
|
|
|
|
|
|
+ for (int t = startNum; t < divItems.size(); t++) {
|
|
|
|
+ //查看任务状态
|
|
|
|
+ QrtzTaskDetail qrtzTaskDetail1 = qrTaskDetailService.getById(webQueryDTO.getTaskId());
|
|
|
|
+ if (qrtzTaskDetail1.getTaskDetailState().equals(7)) {
|
|
|
|
+ qrtzTaskDetail1.setTaskDetailState(5);
|
|
|
|
+ qrtzTaskDetail1.setSuccessNum(successNum);
|
|
|
|
+ qrtzTaskDetail1.updateById();
|
|
|
|
+ return null;
|
|
|
|
+ } else if (qrtzTaskDetail1.getTaskDetailState().equals(8)) {
|
|
|
|
+ qrtzTaskDetail1.setTaskDetailState(6);
|
|
|
|
+ qrtzTaskDetail1.setSuccessNum(successNum);
|
|
|
|
+ qrtzTaskDetail1.updateById();
|
|
|
|
+ return null;
|
|
|
|
+
|
|
|
|
+ }
|
|
WebElement temEle = divItems.get(t);
|
|
WebElement temEle = divItems.get(t);
|
|
String text = temEle.getText();
|
|
String text = temEle.getText();
|
|
String value = "";
|
|
String value = "";
|
|
@@ -206,7 +229,7 @@ public class UploadFromWebService {
|
|
//获得摘要
|
|
//获得摘要
|
|
WebElement abstrElement = driver.findElement(By.className("item-summary"));
|
|
WebElement abstrElement = driver.findElement(By.className("item-summary"));
|
|
List<WebElement> spans = abstrElement.findElements(By.tagName("span"));
|
|
List<WebElement> spans = abstrElement.findElements(By.tagName("span"));
|
|
- if (cells.contains(1)) {
|
|
|
|
|
|
+ if (cells.contains("1")) {
|
|
String abstrText = spans.get(0).getText();
|
|
String abstrText = spans.get(0).getText();
|
|
patentCell.setAbstrText(abstrText);
|
|
patentCell.setAbstrText(abstrText);
|
|
}
|
|
}
|
|
@@ -218,7 +241,7 @@ public class UploadFromWebService {
|
|
String url = imag.getAttribute("src");
|
|
String url = imag.getAttribute("src");
|
|
url = fileUtils.uploadToLocal(url, ".jpg").getPath();
|
|
url = fileUtils.uploadToLocal(url, ".jpg").getPath();
|
|
patentCell.setPicUrl(url);
|
|
patentCell.setPicUrl(url);
|
|
- if (cells.contains(2)) {
|
|
|
|
|
|
+ if (cells.contains("2")) {
|
|
//获得主权要
|
|
//获得主权要
|
|
String mainRight = spans.get(1).getText();
|
|
String mainRight = spans.get(1).getText();
|
|
patentCell.setMainRignt(mainRight);
|
|
patentCell.setMainRignt(mainRight);
|
|
@@ -234,7 +257,7 @@ public class UploadFromWebService {
|
|
});
|
|
});
|
|
patentCell.setRights(rights);
|
|
patentCell.setRights(rights);
|
|
}
|
|
}
|
|
- if (cells.contains(3)) {
|
|
|
|
|
|
+ if (cells.contains("3")) {
|
|
//获得说明书
|
|
//获得说明书
|
|
WebElement DSElement = driver.findElement(By.id("itemDS"));
|
|
WebElement DSElement = driver.findElement(By.id("itemDS"));
|
|
DSElement.click();
|
|
DSElement.click();
|
|
@@ -258,7 +281,7 @@ public class UploadFromWebService {
|
|
patentCell.setPatentInstructionText(stringBuilder.toString());
|
|
patentCell.setPatentInstructionText(stringBuilder.toString());
|
|
}
|
|
}
|
|
//获得pdf文档
|
|
//获得pdf文档
|
|
- if (cells.contains(4)) {
|
|
|
|
|
|
+ if (cells.contains("4")) {
|
|
WebElement PDFElement = driver.findElement(By.id("itemPdf"));
|
|
WebElement PDFElement = driver.findElement(By.id("itemPdf"));
|
|
PDFElement.click();
|
|
PDFElement.click();
|
|
TimeUnit.MILLISECONDS.sleep(10000);//毫秒
|
|
TimeUnit.MILLISECONDS.sleep(10000);//毫秒
|
|
@@ -287,7 +310,7 @@ public class UploadFromWebService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (cells.contains(5)) {
|
|
|
|
|
|
+ if (cells.contains("5")) {
|
|
//获得法律状态
|
|
//获得法律状态
|
|
WebElement flztElement = driver.findElement(By.id("flztbtn"));
|
|
WebElement flztElement = driver.findElement(By.id("flztbtn"));
|
|
flztElement.click();
|
|
flztElement.click();
|
|
@@ -307,36 +330,52 @@ public class UploadFromWebService {
|
|
affairs.add(affair);
|
|
affairs.add(affair);
|
|
});
|
|
});
|
|
patentCell.setPatentAffairs(affairs);
|
|
patentCell.setPatentAffairs(affairs);
|
|
|
|
+ }
|
|
|
|
+ successNum++;
|
|
|
|
+ if (patentCell.getPublicNo() != null) {
|
|
|
|
+ patentCell.setPatentNo(patentCell.getPublicNo());
|
|
|
|
|
|
- if (patentCell.getPublicNo() != null) {
|
|
|
|
- patentCell.setPatentNo(patentCell.getPublicNo());
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- patentCell.setPatentNo(patentCell.getPublicAccreditNo());
|
|
|
|
- patentCell.setPublicNo(patentCell.getPublicAccreditNo());
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
+ patentCell.setPatentNo(patentCell.getPublicAccreditNo());
|
|
|
|
+ patentCell.setPublicNo(patentCell.getPublicAccreditNo());
|
|
}
|
|
}
|
|
if (patentCell.getPatentNo() != null) {
|
|
if (patentCell.getPatentNo() != null) {
|
|
String res = outInterfaceService.importPatents(patentCell);
|
|
String res = outInterfaceService.importPatents(patentCell);
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
if (jsonObject.get("code").toString().equals("500")) {
|
|
if (jsonObject.get("code").toString().equals("500")) {
|
|
|
|
+ //任务执行情况状态设为失败,任务条件状态设为已完成(若是任务条件是定时任务则设为等待下一次执行)
|
|
|
|
+ qrtzTaskDetail.setTaskDetailState(3);
|
|
|
|
+ qrtzTaskDetail.setSuccessNum(successNum);
|
|
|
|
+ qrtzTaskDetail.setDefaultNum(count - successNum);
|
|
|
|
+ qrtzTaskDetail.setEndTime(new Date());
|
|
|
|
+ qrtzTaskDetail.updateById();
|
|
|
|
+ if (qrtzTask.getTaskType() == 1) {
|
|
|
|
+ qrtzTask.setTaskState(4);
|
|
|
|
+ } else {
|
|
|
|
+ qrtzTask.setTaskState(3);
|
|
|
|
+ }
|
|
|
|
+ qrtzTask.updateById();
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //计算进度值
|
|
|
|
+ double percentage = count == 0 ? 0 : (count.equals(successNum) ? (successNum * 1D) : (successNum + 1D) / count * 100D);
|
|
|
|
+ percentage = MathUtils.saveTwoDecimal(percentage);
|
|
WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
|
|
WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
|
|
.setTaskId(webQueryDTO.getTaskId())
|
|
.setTaskId(webQueryDTO.getTaskId())
|
|
.setProjectId(webQueryDTO.getProjectId())
|
|
.setProjectId(webQueryDTO.getProjectId())
|
|
.setComplete(false)
|
|
.setComplete(false)
|
|
- .setIndex(i)
|
|
|
|
|
|
+ .setIndex(successNum)
|
|
.setTaskType(Constants.TASK_IMPORT_PATENT)
|
|
.setTaskType(Constants.TASK_IMPORT_PATENT)
|
|
- .setPercentage(count == 0 ? 0 : Math.round((count.equals(i) ? (i * 1D) : (i + 1D)) / count * 100D))
|
|
|
|
|
|
+ .setPercentage(percentage)
|
|
.setFileName("")
|
|
.setFileName("")
|
|
.setUrl("")
|
|
.setUrl("")
|
|
- .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "");
|
|
|
|
|
|
+ .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "null");
|
|
patentCells.add(patentCell);
|
|
patentCells.add(patentCell);
|
|
driver.close();
|
|
driver.close();
|
|
driver.switchTo().window(handleMap.get("mainPage"));
|
|
driver.switchTo().window(handleMap.get("mainPage"));
|
|
|
|
+
|
|
}
|
|
}
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("tcdPageCode")));
|
|
wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("tcdPageCode")));
|
|
|
|
|
|
@@ -353,19 +392,35 @@ public class UploadFromWebService {
|
|
.setComplete(true)
|
|
.setComplete(true)
|
|
.setIndex(count)
|
|
.setIndex(count)
|
|
.setTaskType(Constants.TASK_IMPORT_PATENT)
|
|
.setTaskType(Constants.TASK_IMPORT_PATENT)
|
|
- .setPercentage(100L)
|
|
|
|
|
|
+ .setPercentage(100D)
|
|
.setFileName("")
|
|
.setFileName("")
|
|
.setUrl("")
|
|
.setUrl("")
|
|
.setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "");
|
|
.setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "");
|
|
- QrtzTask qrtzTask = qrTaskService.getById(webQueryDTO.getTaskId());
|
|
|
|
- qrtzTask.setTaskState(2);
|
|
|
|
- qrtzTask.setEndTime(new Date());
|
|
|
|
|
|
+ //任务执行情况状态设为成功,任务条件状态设为已完成(若是任务条件是定时任务则设为等待下一次执行)
|
|
|
|
+ qrtzTaskDetail.setTaskDetailState(2);
|
|
|
|
+ qrtzTaskDetail.setSuccessNum(successNum);
|
|
|
|
+ qrtzTaskDetail.setDefaultNum(qrtzTaskDetail.getAllNum() - successNum);
|
|
|
|
+ qrtzTaskDetail.setEndTime(new Date());
|
|
|
|
+ qrtzTaskDetail.updateById();
|
|
|
|
+ if (qrtzTask.getTaskType() == 1) {
|
|
|
|
+ qrtzTask.setTaskState(4);
|
|
|
|
+ } else {
|
|
|
|
+ qrtzTask.setTaskState(2);
|
|
|
|
+ }
|
|
qrtzTask.updateById();
|
|
qrtzTask.updateById();
|
|
driver.quit();
|
|
driver.quit();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- QrtzTask qrtzTask = qrTaskService.getById(webQueryDTO.getTaskId());
|
|
|
|
- qrtzTask.setTaskState(3);
|
|
|
|
- qrtzTask.setEndTime(new Date());
|
|
|
|
|
|
+ //任务执行情况状态设为失败,任务条件状态设为已完成(若是任务条件是定时任务则设为等待下一次执行)
|
|
|
|
+ qrtzTaskDetail.setTaskDetailState(3);
|
|
|
|
+ qrtzTaskDetail.setSuccessNum(successNum);
|
|
|
|
+ qrtzTaskDetail.setDefaultNum(qrtzTaskDetail.getAllNum() - successNum);
|
|
|
|
+ qrtzTaskDetail.setEndTime(new Date());
|
|
|
|
+ qrtzTaskDetail.updateById();
|
|
|
|
+ if (qrtzTask.getTaskType() == 1) {
|
|
|
|
+ qrtzTask.setTaskState(4);
|
|
|
|
+ } else {
|
|
|
|
+ qrtzTask.setTaskState(3);
|
|
|
|
+ }
|
|
qrtzTask.updateById();
|
|
qrtzTask.updateById();
|
|
}
|
|
}
|
|
return patentCells;
|
|
return patentCells;
|