|
@@ -12,6 +12,7 @@ import com.example.demo.model.dto.TaskWebSocketDTO;
|
|
|
import com.example.demo.model.dto.WebQueryDTO;
|
|
|
import com.example.demo.util.*;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.openqa.selenium.By;
|
|
|
import org.openqa.selenium.WebDriver;
|
|
|
import org.openqa.selenium.WebElement;
|
|
@@ -20,6 +21,7 @@ import org.openqa.selenium.chrome.ChromeOptions;
|
|
|
import org.openqa.selenium.interactions.Actions;
|
|
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -36,6 +38,7 @@ import java.util.regex.Pattern;
|
|
|
* @description 针对表【qrtz_task(定时任务表)】的数据库操作Service实现
|
|
|
* @createDate 2023-03-15 13:40:32
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class UploadFromWebService {
|
|
@@ -44,6 +47,8 @@ public class UploadFromWebService {
|
|
|
private final WebConfigService webConfigService;
|
|
|
private final QrTaskService qrTaskService;
|
|
|
private final QrTaskDetailService qrTaskDetailService;
|
|
|
+ @Value("${driverUrl}")
|
|
|
+ private String url;
|
|
|
|
|
|
// 查询并上传(专利之星)
|
|
|
public List<PatentCell> getPatentStar(WebQueryDTO webQueryDTO) throws Exception {
|
|
@@ -64,13 +69,14 @@ public class UploadFromWebService {
|
|
|
//根据id 获得网站配置
|
|
|
WebConfig webConfig = webConfigService.getConfigById(id);
|
|
|
//1.获得驱动
|
|
|
- System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
|
|
|
- // 2.页面最大化
|
|
|
- ChromeOptions chromeOptions = new ChromeOptions();
|
|
|
+ // System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
|
|
|
+ System.setProperty("webdriver.chrome.driver", url);
|
|
|
+ ChromeOptions chromeOptions = new ChromeOptions();
|
|
|
// 设置无头模式
|
|
|
chromeOptions.setHeadless(Boolean.TRUE);
|
|
|
// 设置无轨 开发时还是不要加,可以看到浏览器效果
|
|
|
chromeOptions.addArguments("-headless");
|
|
|
+ chromeOptions.addArguments("no-sandbox");
|
|
|
// 3.创建驱动
|
|
|
WebDriver driver = new ChromeDriver(chromeOptions);
|
|
|
// 4.创建动作
|
|
@@ -161,7 +167,6 @@ public class UploadFromWebService {
|
|
|
.setTaskDetailState(6)
|
|
|
.setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "null");
|
|
|
return null;
|
|
|
-
|
|
|
}
|
|
|
PatentCell patentCell = new PatentCell();
|
|
|
patentCell.setProjectId(webQueryDTO.getProjectId());
|
|
@@ -396,6 +401,8 @@ public class UploadFromWebService {
|
|
|
}
|
|
|
}
|
|
|
QrtzTaskDetail qrtzTaskDetail11 =qrTaskDetailService.getById(qrtzTaskDetail.getId());
|
|
|
+ percentage = count == 0 ? 0 : (count.equals(successNum) ? (successNum * 1D) : (successNum + 1D) / count * 100D);
|
|
|
+ percentage = MathUtils.saveTwoDecimal(percentage);
|
|
|
WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
|
|
|
.setId(webQueryDTO.getTaskId())
|
|
|
.setProjectId(webQueryDTO.getProjectId())
|
|
@@ -445,10 +452,12 @@ public class UploadFromWebService {
|
|
|
qrtzTask.updateById();
|
|
|
driver.quit();
|
|
|
} catch (Exception e) {
|
|
|
+ log.error(e.toString());
|
|
|
//任务执行情况状态设为失败,任务条件状态设为已完成(若是任务条件是定时任务则设为等待下一次执行)
|
|
|
qrtzTaskDetail.setTaskDetailState(3);
|
|
|
qrtzTaskDetail.setSuccessNum(successNum);
|
|
|
qrtzTaskDetail.setDefaultNum(qrtzTaskDetail.getAllNum() - successNum);
|
|
|
+ qrtzTaskDetail.setFailure("拉取节点失败");
|
|
|
qrtzTaskDetail.setEndTime(new Date());
|
|
|
qrtzTaskDetail.updateById();
|
|
|
if (qrtzTask.getTaskType() == 1) {
|