Bläddra i källkod

字段格式化

lwhhszx 2 år sedan
förälder
incheckning
5fa9e3e81a

+ 8 - 8
pom.xml

@@ -140,14 +140,14 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>16</source>
-                    <target>16</target>
-                </configuration>
-            </plugin>
+<!--            <plugin>-->
+<!--                <groupId>org.apache.maven.plugins</groupId>-->
+<!--                <artifactId>maven-compiler-plugin</artifactId>-->
+<!--                <configuration>-->
+<!--                    <source>16</source>-->
+<!--                    <target>16</target>-->
+<!--                </configuration>-->
+<!--            </plugin>-->
         </plugins>
     </build>
 

+ 5 - 3
src/main/java/com/example/demo/controller/AssoTaskPersonelController.java

@@ -32,7 +32,7 @@ public class AssoTaskPersonelController {
     @PostMapping("/getStar")
     public List<PatentCell> getPatentStar(@RequestBody WebQueryDTO WebQueryDTO) throws Exception {
         List<PatentCell> patentData = null;
-        if (WebQueryDTO.getWebConfigId() == 1) {
+        if (WebQueryDTO.getWebConfigId() == 1||WebQueryDTO.getWebConfigId() == 4) {
             patentData = uploadFromWebService.getPatentStar(WebQueryDTO);
         }
 //        else if (id == 2) {
@@ -58,8 +58,10 @@ public class AssoTaskPersonelController {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
       String date ="2022.1.1";
         Date date1 = simpleDateFormat.parse(date);
-        Integer ts = (int) date1.getTime();
-        System.out.println(ts);
+
+      Long ts =  date1.getTime()/1000;
+      Integer a = Integer.parseInt(String.valueOf(ts));
+        System.out.println(ts+"ni"+a);
 
 
     }

+ 30 - 17
src/main/java/com/example/demo/controller/QuartzController.java

@@ -5,48 +5,61 @@ import com.example.demo.domain.QrtzTask;
 import com.example.demo.model.dto.QuartzTaskDTO;
 import com.example.demo.service.JobService;
 import com.example.demo.service.QrTaskService;
+import com.example.demo.util.Response;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import org.quartz.SchedulerException;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 
 @RestController
-@RequestMapping(Constants.QUARTZ_API + "/job")
+@Tag(name = "任务管理")
+@RequestMapping(Constants.QUARTZ_API + "/task")
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class QuartzController {
     private final JobService jobService;
     private final QrTaskService qrTaskService;
-@PostMapping("/add")
-    public void addJob(@RequestBody QuartzTaskDTO quartzTaskDTO) throws InterruptedException, SchedulerException {
-    QrtzTask qrtzTask= qrTaskService.addQuartzTask(quartzTaskDTO);
-    if(quartzTaskDTO.getTaskType().equals(1))
-    {
-    jobService.addJob(qrtzTask);
-    }
 
+    @Operation(summary = "添加任务")
+    @PostMapping("/addTask")
+    public void addTask(@RequestBody QuartzTaskDTO quartzTaskDTO) throws SchedulerException {
+        QrtzTask qrtzTask = qrTaskService.addQuartzTask(quartzTaskDTO);
+        if (quartzTaskDTO.getTaskType().equals(1)) {
+            jobService.addJob(qrtzTask);
+        }
     }
-
-    @GetMapping("/delete")
-    public void delete(Integer taskId) throws InterruptedException, SchedulerException {
-        jobService.deleteJob(taskId);
-
+    @Operation(summary = "删除任务")
+    @PostMapping("/deleteTasks")
+    public String deleteTasks(@RequestBody List<Integer> taskIds) throws SchedulerException {
+        return Response.success(qrTaskService.deleteQuartzTask(taskIds));
     }
+    @Operation(summary = "查询任务")
+    @PostMapping("/getTasks")
+    public String getTasks(@RequestBody QuartzTaskDTO quartzTaskDTO) {
+        return Response.success(qrTaskService.getTasks(quartzTaskDTO));
+    }
+
+    @Operation(summary = "更新任务")
     @PostMapping("/update")
     public void update(@RequestBody QuartzTaskDTO quartzTaskDTO) throws InterruptedException, SchedulerException {
-        QrtzTask qrtzTask=   qrTaskService.updateQuartzTask(quartzTaskDTO);
+        QrtzTask qrtzTask = qrTaskService.updateQuartzTask(quartzTaskDTO);
         jobService.updateJob(qrtzTask);
 
     }
 
+    @Operation(summary = "暂停任务")
     @GetMapping("/pauseJob")
-    public void pauseJob(Integer taskId) throws InterruptedException, SchedulerException {
+    public void pauseJob(Integer taskId) throws SchedulerException {
         jobService.pauseJob(taskId);
 
     }
-
+    @Operation(summary = "继续任务")
     @GetMapping("/resumeJob")
-    public void resumeJob(Integer taskId) throws InterruptedException, SchedulerException {
+    public void resumeJob(Integer taskId) throws SchedulerException {
         jobService.resumeJob(taskId);
 
     }

+ 41 - 0
src/main/java/com/example/demo/controller/WebConfigController.java

@@ -0,0 +1,41 @@
+package com.example.demo.controller;
+
+import com.example.demo.base.Constants;
+import com.example.demo.domain.QrtzTask;
+import com.example.demo.model.dto.QuartzTaskDTO;
+import com.example.demo.service.JobService;
+import com.example.demo.service.QrTaskService;
+import com.example.demo.service.WebConfigCellService;
+import com.example.demo.service.WebConfigService;
+import com.example.demo.util.Response;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import org.quartz.SchedulerException;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.web.bind.annotation.*;
+
+
+@RestController
+@Tag(name = "网站配置接口")
+@RequestMapping(Constants.QUARTZ_API + "/config")
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class WebConfigController {
+    private final WebConfigService webConfigService;
+    private final WebConfigCellService webConfigCellService;
+
+    //获得所有配置
+    @Operation(summary = "获得所有配置")
+    @GetMapping("/getAllConfig")
+    public String getAllConfig() {
+        return Response.success(webConfigService.getAllConfig());
+
+    }
+
+    //根据配置类型获得配置元素
+    @Operation(summary = "根据配置类型获得配置元素")
+    @GetMapping("/getConfigCell")
+    public String getConfigCell(Integer type) {
+        return Response.success(webConfigCellService.getConfigCell(type));
+    }
+}

+ 4 - 0
src/main/java/com/example/demo/domain/QrtzTask.java

@@ -54,4 +54,8 @@ public class QrtzTask extends BaseEntity<QrtzTask> {
     private Date createTime;
     @TableField(value = "task_order")
     private Integer taskOrder;
+    @TableField(value = "config_id")
+    private Integer configId;
+    @TableField(value = "config_cells")
+    private String configCells;
 }

+ 4 - 117
src/main/java/com/example/demo/domain/WebConfig.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
 
 import java.io.Serializable;
 
@@ -11,6 +12,7 @@ import java.io.Serializable;
  * 网站配置
  * @TableName web_config
  */
+@Data
 @TableName(value ="web_config")
 public class WebConfig implements Serializable {
     /**
@@ -39,123 +41,8 @@ public class WebConfig implements Serializable {
      */
     private String webPassword;
 
-    @TableField(exist = false)
-    private static final long serialVersionUID = 1L;
+    @TableField(value = "web_type")
+    private Integer webType;
 
-    /**
-     * ID
-     */
-    public Integer getId() {
-        return id;
-    }
-
-    /**
-     * ID
-     */
-    public void setId(Integer id) {
-        this.id = id;
-    }
-
-    /**
-     * 网站名称
-     */
-    public String getWebName() {
-        return webName;
-    }
-
-    /**
-     * 网站名称
-     */
-    public void setWebName(String webName) {
-        this.webName = webName;
-    }
-
-    /**
-     * 网站地址
-     */
-    public String getWebAddress() {
-        return webAddress;
-    }
-
-    /**
-     * 网站地址
-     */
-    public void setWebAddress(String webAddress) {
-        this.webAddress = webAddress;
-    }
-
-    /**
-     * 账号
-     */
-    public String getWebAccount() {
-        return webAccount;
-    }
-
-    /**
-     * 账号
-     */
-    public void setWebAccount(String webAccount) {
-        this.webAccount = webAccount;
-    }
-
-    /**
-     * 网站密码
-     */
-    public String getWebPassword() {
-        return webPassword;
-    }
-
-    /**
-     * 网站密码
-     */
-    public void setWebPassword(String webPassword) {
-        this.webPassword = webPassword;
-    }
-
-    @Override
-    public boolean equals(Object that) {
-        if (this == that) {
-            return true;
-        }
-        if (that == null) {
-            return false;
-        }
-        if (getClass() != that.getClass()) {
-            return false;
-        }
-        WebConfig other = (WebConfig) that;
-        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
-            && (this.getWebName() == null ? other.getWebName() == null : this.getWebName().equals(other.getWebName()))
-            && (this.getWebAddress() == null ? other.getWebAddress() == null : this.getWebAddress().equals(other.getWebAddress()))
-            && (this.getWebAccount() == null ? other.getWebAccount() == null : this.getWebAccount().equals(other.getWebAccount()))
-            && (this.getWebPassword() == null ? other.getWebPassword() == null : this.getWebPassword().equals(other.getWebPassword()));
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
-        result = prime * result + ((getWebName() == null) ? 0 : getWebName().hashCode());
-        result = prime * result + ((getWebAddress() == null) ? 0 : getWebAddress().hashCode());
-        result = prime * result + ((getWebAccount() == null) ? 0 : getWebAccount().hashCode());
-        result = prime * result + ((getWebPassword() == null) ? 0 : getWebPassword().hashCode());
-        return result;
-    }
 
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(getClass().getSimpleName());
-        sb.append(" [");
-        sb.append("Hash = ").append(hashCode());
-        sb.append(", id=").append(id);
-        sb.append(", webName=").append(webName);
-        sb.append(", webAddress=").append(webAddress);
-        sb.append(", webAccount=").append(webAccount);
-        sb.append(", webPassword=").append(webPassword);
-        sb.append(", serialVersionUID=").append(serialVersionUID);
-        sb.append("]");
-        return sb.toString();
-    }
 }

+ 31 - 0
src/main/java/com/example/demo/domain/WebConfigCell.java

@@ -0,0 +1,31 @@
+package com.example.demo.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 网站配置
+ * @TableName web_config
+ */
+@Data
+@TableName(value ="web_config_cell")
+public class WebConfigCell implements Serializable {
+    /**
+     * ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Integer id;
+    @TableField(value = "config_type")
+    private Integer configType;
+    @TableField(value = "cell_value")
+    private String cellValue;
+    @TableField(value="cell_name")
+    private String cellName;
+
+
+}

+ 22 - 0
src/main/java/com/example/demo/mapper/WebConfigCellMapper.java

@@ -0,0 +1,22 @@
+package com.example.demo.mapper;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.demo.domain.WebConfig;
+import com.example.demo.domain.WebConfigCell;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author admin
+* @description 针对表【web_config(网站配置)】的数据库操作Mapper
+* @createDate 2023-03-08 18:51:17
+* @Entity cn.cslg.pas.domain.WebConfig
+*/
+@Mapper
+public interface WebConfigCellMapper extends BaseMapper<WebConfigCell> {
+
+}
+
+
+
+

+ 4 - 0
src/main/java/com/example/demo/model/dto/QuartzTaskDTO.java

@@ -2,6 +2,8 @@ package com.example.demo.model.dto;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class QuartzTaskDTO {
     private Integer projectId;
@@ -11,4 +13,6 @@ public class QuartzTaskDTO {
     private Integer webConfigId;
     private Integer taskId;
     private Integer taskType;
+    private Integer taskState;
+    private List<String> conCells;
 }

+ 19 - 0
src/main/java/com/example/demo/model/dto/TaskWebSocketDTO.java

@@ -0,0 +1,19 @@
+package com.example.demo.model.dto;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+@Data
+@Accessors(chain = true)
+public class TaskWebSocketDTO {
+    private Integer projectId;
+    private Integer total;
+    private Integer index;
+    private Integer taskId;
+    private Boolean complete;
+    private String url;
+    private String fileName;
+    private Integer taskType;
+    private Long percentage;
+    private String oldName;
+}

+ 3 - 0
src/main/java/com/example/demo/model/dto/WebQueryDTO.java

@@ -2,6 +2,8 @@ package com.example.demo.model.dto;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class WebQueryDTO {
     private Integer projectId;
@@ -9,4 +11,5 @@ public class WebQueryDTO {
     private Integer webConfigId;
     private Integer taskId;
     private Integer reportId;
+    private List<String> conCells;
 }

+ 0 - 6
src/main/java/com/example/demo/service/JobService.java

@@ -43,9 +43,6 @@ public class JobService {
     public void pauseJob(Integer taskId) throws SchedulerException {
         QuartzVO quartzVO=this.generateQuartzVO(taskId);
         qrTaskService.updateState(taskId,0);
-//        TriggerKey triggerKey = TriggerKey.triggerKey(quartzVO.getTriggerName(), quartzVO.getTriggerGroupName());
-//        scheduler.pauseTrigger(triggerKey);
-//        scheduler.unscheduleJob(triggerKey);
         JobKey jobKey = JobKey.jobKey(quartzVO.getJobName(),quartzVO.getJobGroupName());
         scheduler.pauseJob(jobKey);
     }
@@ -58,9 +55,6 @@ public class JobService {
     public void resumeJob(Integer taskId) throws SchedulerException {
         QuartzVO quartzVO=this.generateQuartzVO(taskId);
          qrTaskService.updateState(taskId,1);
-//        TriggerKey triggerKey = TriggerKey.triggerKey(quartzVO.getTriggerName(), quartzVO.getTriggerGroupName());
-//        scheduler.pauseTrigger(triggerKey);
-//        scheduler.unscheduleJob(triggerKey);
         JobKey jobKey = JobKey.jobKey(quartzVO.getJobName(), quartzVO.getJobGroupName());
         scheduler.resumeJob(jobKey);
     }

+ 56 - 6
src/main/java/com/example/demo/service/QrTaskService.java

@@ -1,13 +1,18 @@
 package com.example.demo.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.example.demo.domain.QrtzTask;
 import com.example.demo.model.dto.QuartzTaskDTO;
 import lombok.RequiredArgsConstructor;
+import org.quartz.SchedulerException;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import com.example.demo.mapper.QrtzTaskMapper;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author admin
  * @description 针对表【qrtz_task(定时任务表)】的数据库操作Service实现
@@ -16,35 +21,80 @@ import com.example.demo.mapper.QrtzTaskMapper;
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class QrTaskService extends ServiceImpl<QrtzTaskMapper, QrtzTask> {
-
+    private final JobService jobService;
     /**
+     * 添加定时任务
+     *
      * @param quartzTaskDTO
      */
     public QrtzTask addQuartzTask(QuartzTaskDTO quartzTaskDTO) {
+      List<String> cells =  quartzTaskDTO.getConCells();
         QrtzTask qrtzTask = new QrtzTask();
+        if(cells==null){
+            qrtzTask.setConfigCells("");
+        }
+        else{
+            qrtzTask.setConfigCells(String.join(",",cells));
+        }
         qrtzTask.setConditions(quartzTaskDTO.getConditions());
         qrtzTask.setProjectId(quartzTaskDTO.getProjectId());
-        qrtzTask.setTaskState(1);
+        qrtzTask.setTaskState(0);
         qrtzTask.setCrons(quartzTaskDTO.getCron());
+        qrtzTask.setTaskType(quartzTaskDTO.getTaskType());
+        qrtzTask.setConfigId(quartzTaskDTO.getWebConfigId());
         qrtzTask.insert();
         return qrtzTask;
     }
 
     public QrtzTask updateQuartzTask(QuartzTaskDTO quartzTaskDTO) {
-        QrtzTask qrtzTask =this.getById(quartzTaskDTO.getTaskId());
+        QrtzTask qrtzTask = this.getById(quartzTaskDTO.getTaskId());
         qrtzTask.setConditions(quartzTaskDTO.getConditions());
         qrtzTask.setCrons(quartzTaskDTO.getCron());
         qrtzTask.updateById();
         return qrtzTask;
     }
 
-
-    public QrtzTask updateState(Integer taskId,Integer state) {
-        QrtzTask qrtzTask =this.getById(taskId);
+    public QrtzTask updateState(Integer taskId, Integer state) {
+        QrtzTask qrtzTask = this.getById(taskId);
         qrtzTask.setTaskState(state);
         qrtzTask.updateById();
         return qrtzTask;
     }
+
+    /**
+     * 删除任务
+     *
+     * @param taskIds
+     */
+    public List<Integer> deleteQuartzTask(List<Integer> taskIds) throws SchedulerException {
+        List<Integer> reIds= new ArrayList<>();
+        LambdaQueryWrapper<QrtzTask> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(QrtzTask::getId, taskIds);
+        List<QrtzTask> qrtzTaskList = this.list(wrapper);
+        for (QrtzTask qrtzTask : qrtzTaskList) {
+            Boolean flag = this.removeById(qrtzTask.getId());
+            if (flag) {
+                reIds.add(qrtzTask.getId());
+            }
+            if (qrtzTask.getTaskType().equals(1)) {
+                jobService.deleteJob(qrtzTask.getId());
+            }
+        }
+        return reIds;
+    }
+
+
+    public List<QrtzTask> getTasks(QuartzTaskDTO quartzTaskDTO) {
+        LambdaQueryWrapper<QrtzTask> queryWrapper =new LambdaQueryWrapper<>();
+        if(quartzTaskDTO.getTaskType()!=null){
+            queryWrapper.eq(QrtzTask::getTaskType,quartzTaskDTO.getTaskType());
+        }
+        if(quartzTaskDTO.getTaskName()!=null){
+            queryWrapper.like(QrtzTask::getTaskName,quartzTaskDTO.getTaskName());
+        }
+        return this.list(queryWrapper);
+    }
+
 }
 
 

+ 2 - 0
src/main/java/com/example/demo/service/TaskAddJob.java

@@ -26,6 +26,8 @@ public class TaskAddJob extends QuartzJobBean {
         task.setTaskType(0);
         task.setConditions(qrtzTask.getConditions());
         task.setProjectId(qrtzTask.getProjectId());
+        task.setConfigId(qrtzTask.getConfigId());
+        task.setConfigCells(qrtzTask.getConfigCells());
         task.setTaskState(0);
         task.insert();
         logger.info("添加任务"+"信息是"+task);

+ 313 - 273
src/main/java/com/example/demo/service/UploadFromWebService.java

@@ -2,11 +2,17 @@ package com.example.demo.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+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.model.dto.TaskWebSocketDTO;
 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 lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.openqa.selenium.By;
@@ -14,6 +20,7 @@ import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.htmlunit.HtmlUnitWebElement;
 import org.openqa.selenium.interactions.Actions;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.support.ui.WebDriverWait;
@@ -39,293 +46,326 @@ public class UploadFromWebService {
     private final FileUtils fileUtils;
     private final OutInterfaceService outInterfaceService;
     private final WebConfigService webConfigService;
-
+     private final QrTaskService qrTaskService;
     // 查询并上传(专利之星)
-    @Async("singleThreadAsyncTaskExecutor")
     public List<PatentCell> getPatentStar(WebQueryDTO webQueryDTO) throws Exception {
-        String conditions = webQueryDTO.getConditions();
-        Integer id = webQueryDTO.getWebConfigId();
-        conditions = this.formatConditions(conditions);
-        //根据id 获得网站配置
-        WebConfig webConfig = webConfigService.getConfigById(id);
         List<PatentCell> patentCells = new ArrayList<>();
-        //1.获得驱动
-        System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
-        // 2.页面最大化
-        ChromeOptions chromeOptions = new ChromeOptions();
-        chromeOptions.addArguments("--start-maximized");
-        // 3.创建驱动
-        WebDriver driver = new ChromeDriver(chromeOptions);
-        // 4.创建动作
-        Actions action = new Actions(driver);
-        //设置等待时间
-        long formSecond1 = 50;
-        WebDriverWait wait1 = new WebDriverWait(driver, formSecond1);
-        // 打开智慧芽首页
-        driver.get(webConfig.getWebAddress());
-        wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("loginname")));
-        WebElement loginName = driver.findElement(By.id("loginname"));
-        WebElement password = driver.findElement(By.id("password"));
-        loginName.sendKeys(webConfig.getWebAccount());
-        password.sendKeys(webConfig.getWebPassword());
-        WebElement loginButton = driver.findElement(By.id("login"));
-        loginButton.click();
-        //获得表格搜索按钮并点击
-        wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("tablepage")));
-        WebElement tablePage = driver.findElement(By.id("tablepage"));
-        WebElement tablePagea = tablePage.findElement(By.tagName("a"));
-        tablePagea.click();
-        //获得搜索框并点击
-        wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("TxtSearch")));
-        WebElement TxtSearch = driver.findElement(By.id("TxtSearch"));
-        TxtSearch.sendKeys(conditions);
-        WebElement searchBtn = driver.findElement(By.id("searchbtn2"));
-        searchBtn.click();
-        wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("tcdNumber")));
-        List<WebElement> tcdNumbers = driver.findElements(By.className("tcdNumber"));
-        String pagesText = tcdNumbers.get(tcdNumbers.size() - 1).getText();
-        int page = Integer.parseInt(pagesText);
-        String Handle = driver.getWindowHandle();
-        //创建一个map集合存放浏览器句柄
-        HashMap<String, String> handleMap = new HashMap<>();
-        //将智慧芽句柄放到map中
-        handleMap.put("mainPage", Handle);
-        for (int p = 0; p < 1; p++) {
-            //等待数据加载
-            wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("patent")));
-            TimeUnit.MILLISECONDS.sleep(1000);//毫秒
-            //获得列表
-            List<WebElement> patentContents = driver.findElements(By.className("patent"));
-            // 页面元素标签
-            for (int i = 0; i < patentContents.size(); i++) {
-                PatentCell patentCell = new PatentCell();
-                patentCell.setProjectId(webQueryDTO.getProjectId());
-                patentCell.setReportId(webQueryDTO.getReportId());
-                wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("title-color")));
-                WebElement titleA = patentContents.get(i).findElement(By.className("title-color"));
-                titleA.click();
-                //9、获取到所有的句柄
-                Set<String> set = driver.getWindowHandles();
-                //10、循环找到详情窗口句柄
-                for (String s : set) {
-                    //10.1、将详情窗口的句柄放到map中
-                    if (!s.equals(Handle)) {
-                        handleMap.put("detail", s);
+
+        try {
+            List<String> cells = webQueryDTO.getConCells();
+            String conditions = webQueryDTO.getConditions();
+            Integer id = webQueryDTO.getWebConfigId();
+            conditions = this.formatConditions(conditions);
+            //根据id 获得网站配置
+            WebConfig webConfig = webConfigService.getConfigById(id);
+            //1.获得驱动
+            System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
+            // 2.页面最大化
+            ChromeOptions chromeOptions = new ChromeOptions();
+            chromeOptions.addArguments("--start-maximized");
+            // 3.创建驱动
+            WebDriver driver = new ChromeDriver(chromeOptions);
+            // 4.创建动作
+            Actions action = new Actions(driver);
+            //设置等待时间
+            long formSecond1 = 10;
+            WebDriverWait wait1 = new WebDriverWait(driver, formSecond1);
+            // 打开专利之星首页
+            driver.get(webConfig.getWebAddress());
+            wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("loginname")));
+            WebElement loginName = driver.findElement(By.id("loginname"));
+            WebElement password = driver.findElement(By.id("password"));
+            loginName.sendKeys(webConfig.getWebAccount());
+            password.sendKeys(webConfig.getWebPassword());
+            WebElement loginButton = driver.findElement(By.id("login"));
+            loginButton.click();
+            TimeUnit.MILLISECONDS.sleep(5000);//毫秒
+            //获得表格搜索按钮并点击
+            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 tablePagea = tablePage.findElement(By.tagName("a"));
+            tablePagea.click();
+            TimeUnit.MILLISECONDS.sleep(5000);//毫秒
+            //获得搜索框并点击
+            wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("TxtSearch")));
+            WebElement TxtSearch = driver.findElement(By.id("TxtSearch"));
+            TxtSearch.sendKeys(conditions);
+            WebElement searchBtn = driver.findElement(By.id("searchbtn2"));
+            searchBtn.click();
+            wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("tcdNumber")));
+            List<WebElement> tcdNumbers = driver.findElements(By.className("tcdNumber"));
+            String pagesText = tcdNumbers.get(tcdNumbers.size() - 1).getText();
+            int page = Integer.parseInt(pagesText);
+            String Handle = driver.getWindowHandle();
+            //创建一个map集合存放浏览器句柄
+            HashMap<String, String> handleMap = new HashMap<>();
+            //将智慧芽句柄放到map中
+            handleMap.put("mainPage", Handle);
+            WebElement pagNum = driver.findElement(By.className("page_num"));
+            pagNum.clear();
+            pagNum.sendKeys("4");
+            WebElement pagBtn = driver.findElement(By.className("page_btn"));
+            pagBtn.click();
+            TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+            for (int p = 4; p < page; p++) {
+                //等待数据加载
+                wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("patent")));
+                TimeUnit.MILLISECONDS.sleep(1000);//毫秒
+                //获得列表
+                List<WebElement> patentContents = driver.findElements(By.className("patent"));
+                // 页面元素标签
+                for (int i = 4; i < patentContents.size(); i++) {
+                    PatentCell patentCell = new PatentCell();
+                    patentCell.setProjectId(webQueryDTO.getProjectId());
+                    patentCell.setReportId(webQueryDTO.getReportId());
+                    wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("title-color")));
+                    WebElement titleA = patentContents.get(i).findElement(By.className("title-color"));
+                    titleA.click();
+                    TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                    //9、获取到所有的句柄
+                    Set<String> set = driver.getWindowHandles();
+                    //10、循环找到详情窗口句柄
+                    for (String s : set) {
+                        //10.1、将详情窗口的句柄放到map中
+                        if (!s.equals(Handle)) {
+                            handleMap.put("detail", s);
+                        }
                     }
-                }
-                driver.switchTo().window(handleMap.get("detail"));
-                wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("item-content")));
-                WebElement itemContent = driver.findElement(By.className("item-content"));
-                List<WebElement> divItems = itemContent.findElements(By.tagName("div"));
-                for (int t = 0; t < divItems.size(); t++) {
-                    WebElement temEle = divItems.get(t);
-                    String text = temEle.getText();
-                    String value = "";
-                    String[] strings = text.split(":");
-                    if (strings.length > 1) {
-                        value = strings[1].trim();
-                        String key = strings[0].trim();
+                    driver.switchTo().window(handleMap.get("detail"));
+                    wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("item-content")));
+                    WebElement itemContent = driver.findElement(By.className("item-content"));
+                    List<WebElement> divItems = itemContent.findElements(By.tagName("div"));
+                    for (int t = 0; t < divItems.size(); t++) {
+                        WebElement temEle = divItems.get(t);
+                        String text = temEle.getText();
+                        String value = "";
+                        String[] strings = text.split(":");
+                        if (strings.length > 1) {
+                            value = strings[1].trim();
+                            String key = strings[0].trim();
 
-                        switch (key) {
-                            case "申请号":
-                                patentCell.setApplicationNo(value);
-                                break;
-                            case "申请日":
-                                patentCell.setApplicationDate(value);
-                                break;
-                            case "国家/省市":
-                                patentCell.setCountry(value);
-                                break;
-                            case "公开号":
-                                patentCell.setPublicNo(value);
-                                break;
-                            case "公开日":
-                                patentCell.setPubilcDate(value);
-                                break;
-                            case "授权公告号":
-                                patentCell.setPublicAccreditNo(value);
-                                break;
-                            case "授权公告日":
-                                patentCell.setPublicAccreditDate(value);
-                                break;
-                            case "主分类号":
-                                patentCell.setMainIpc(value);
-                                break;
-                            case "分类号":
-                                patentCell.setIpc(this.StringToList(value, ";"));
-                                break;
-                            case "申请人":
-                                patentCell.setApplicationPersons(this.StringToList(value, "  "));
-                                break;
-                            case "申请人地址":
-                                patentCell.setApplicationAddress(this.StringToList(value, "  "));
-                                break;
-                            case "发明人":
-                                patentCell.setInventors(this.StringToList(value, "  "));
-                                break;
-                            case "当前权利人":
-                                patentCell.setApplicationCurrents(this.StringToList(value, "  "));
-                                break;
-                            case "代理人":
-                                patentCell.setAgencyPersons(this.StringToList(value, "  "));
-                                break;
-                            case "代理机构":
-                                patentCell.setAgency(value);
-                                break;
-                            case "范畴分类":
-                                patentCell.setClassical(value);
-                                break;
-                            case "当前状态":
-                                patentCell.setStatue(value);
-                                break;
+                            switch (key) {
+                                case "申请号":
+                                    patentCell.setApplicationNo(value);
+                                    break;
+                                case "申请日":
+                                    patentCell.setApplicationDate(value);
+                                    break;
+                                case "国家/省市":
+                                    patentCell.setCountry(value);
+                                    break;
+                                case "公开号":
+                                    patentCell.setPublicNo(value);
+                                    break;
+                                case "公开日":
+                                    patentCell.setPubilcDate(value);
+                                    break;
+                                case "授权公告号":
+                                    patentCell.setPublicAccreditNo(value);
+                                    break;
+                                case "授权公告日":
+                                    patentCell.setPublicAccreditDate(value);
+                                    break;
+                                case "主分类号":
+                                    patentCell.setMainIpc(value);
+                                    break;
+                                case "分类号":
+                                    patentCell.setIpc(this.StringToList(value, ";"));
+                                    break;
+                                case "申请人":
+                                    patentCell.setApplicationPersons(this.StringToList(value, "  "));
+                                    break;
+                                case "申请人地址":
+                                    patentCell.setApplicationAddress(this.StringToList(value, "  "));
+                                    break;
+                                case "发明人":
+                                    patentCell.setInventors(this.StringToList(value, "  "));
+                                    break;
+                                case "当前权利人":
+                                    patentCell.setApplicationCurrents(this.StringToList(value, "  "));
+                                    break;
+                                case "代理人":
+                                    patentCell.setAgencyPersons(this.StringToList(value, "  "));
+                                    break;
+                                case "代理机构":
+                                    patentCell.setAgency(value);
+                                    break;
+                                case "范畴分类":
+                                    patentCell.setClassical(value);
+                                    break;
+                                case "当前状态":
+                                    patentCell.setStatue(value);
+                                    break;
+                            }
                         }
                     }
-                }
-                //获得摘要
-                WebElement abstrElement = driver.findElement(By.className("item-summary"));
-                List<WebElement> spans = abstrElement.findElements(By.tagName("span"));
-                String abstrText = spans.get(0).getText();
-                patentCell.setAbstrText(abstrText);
-                //获得主权要
-                String mainRight = spans.get(1).getText();
-                patentCell.setMainRignt(mainRight);
-                //获得图片路径
-                wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("item-img")));
-                WebElement picElement = driver.findElement(By.className("item-img"));
-                WebElement imag = picElement.findElement(By.tagName("img"));
-                String url = imag.getAttribute("src");
-                url = fileUtils.uploadToLocal(url, ".jpg").getPath();
-                patentCell.setPicUrl(url);
-                //获得权要
-                WebElement CLElement = driver.findElement(By.id("itemCL"));
-                CLElement.click();
-                wait1.until(ExpectedConditions.presenceOfElementLocated(By.tagName("claim-text")));
-                List<WebElement> rightElements = driver.findElements(By.tagName("claim-text"));
-                List<String> rights = new ArrayList<>();
-                rightElements.forEach(item -> {
-                    rights.add(item.getText());
-                });
-                patentCell.setRights(rights);
-                //获得说明书
-                WebElement DSElement = driver.findElement(By.id("itemDS"));
-                DSElement.click();
-                wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("title1")));
-                WebElement titleElement = driver.findElement(By.id("title1"));
-                patentCell.setTitle(titleElement.getText());
-                StringBuilder stringBuilder = new StringBuilder();
-                int flag = 1;
-                //技术领域
-                WebElement textElement1 = driver.findElement(By.id("technical-field001"));
-                List<WebElement> textP1 = textElement1.findElements(By.tagName("p"));
-                stringBuilder.append(textP1.get(0).getText());
-                stringBuilder.append("\r\n");
-                for (int t = 1; t < textP1.size(); t++) {
-                    String tem = String.format("%04d", flag);
-                    stringBuilder.append("[" + tem + "]" + textP1.get(t).getText());
-                    stringBuilder.append("\r\n");
-                    flag += 1;
-                }
-                //背景技术
-                WebElement textElement2 = driver.findElement(By.id("background-art001"));
-                List<WebElement> textP2 = textElement2.findElements(By.tagName("p"));
-                stringBuilder.append(textP2.get(0).getText());
-                stringBuilder.append("\r\n");
-                for (int t = 1; t < textP2.size(); t++) {
-                    String tem = String.format("%04d", flag);
-                    stringBuilder.append("[" + tem + "]" + textP2.get(t).getText());
-                    stringBuilder.append("\r\n");
-                    flag += 1;
-                }
-                //说明文本
-                WebElement textElement3 = driver.findElement(By.id("disclosure001"));
-                List<WebElement> textP3 = textElement3.findElements(By.tagName("p"));
-                stringBuilder.append(textP3.get(0).getText());
-                stringBuilder.append("\r\n");
-                for (int t = 1; t < textP3.size(); t++) {
-                    String tem = String.format("%04d", flag);
-                    stringBuilder.append("[" + tem + "]" + textP3.get(t).getText());
-                    stringBuilder.append("\r\n");
-                    flag += 1;
-                }
-                //发明内容
-                WebElement textElement4 = driver.findElement(By.id("disclosure001"));
-                List<WebElement> textP4 = textElement4.findElements(By.tagName("p"));
-                stringBuilder.append(textP4.get(0).getText());
-                stringBuilder.append("\r\n");
-                for (int t = 1; t < textP4.size(); t++) {
-                    String tem = String.format("%04d", flag);
-                    stringBuilder.append("[" + tem + "]" + textP4.get(t).getText());
-                    stringBuilder.append("\r\n");
-                    flag += 1;
-                }
-                //附图说明
-                WebElement textElement5 = driver.findElement(By.id("description-of-drawings001"));
-                List<WebElement> textP5 = textElement5.findElements(By.tagName("p"));
-                stringBuilder.append(textP5.get(0).getText());
-                stringBuilder.append("\r\n");
-                for (int t = 1; t < textP5.size(); t++) {
-                    String tem = String.format("%04d", flag);
-                    stringBuilder.append("[" + tem + "]" + textP5.get(t).getText());
-                    stringBuilder.append("\r\n");
-                    flag += 1;
-                }
-                patentCell.setPatentInstructionText(stringBuilder.toString());
-                //获得pdf文档
-                WebElement PDFElement = driver.findElement(By.id("itemPdf"));
-                PDFElement.click();
-                wait1.until(ExpectedConditions.presenceOfElementLocated(By.tagName("embed")));
-                WebElement PDFFile = driver.findElement(By.tagName("embed"));
-                String pdfUrl = PDFFile.getAttribute("src");
-                UploadFileDTO fileDTO = fileUtils.uploadToLocal(pdfUrl, ".PDF");
-                patentCell.setPDFName(fileDTO.getFileName());
-                patentCell.setPDFSize(fileDTO.getFileSize());
-                patentCell.setPDFUrl(fileDTO.getPath());
-                patentCell.setPdf(fileDTO);
-                //获得法律状态
-                WebElement flztElement = driver.findElement(By.id("flztbtn"));
-                flztElement.click();
-                wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("legalContainer")));
-                WebElement tBody = driver.findElement(By.id("legalContainer"));
-                TimeUnit.MILLISECONDS.sleep(1000);//毫秒
-                List<WebElement> trs =tBody.findElements(By.tagName("tr"));
+                    //获得摘要
+                    WebElement abstrElement = driver.findElement(By.className("item-summary"));
+                    List<WebElement> spans = abstrElement.findElements(By.tagName("span"));
+                    if (cells.contains(1)) {
+                        String abstrText = spans.get(0).getText();
+                        patentCell.setAbstrText(abstrText);
+                    }
 
-                List<PatentCell.PatentAffair> affairs =new ArrayList<>();
-                trs.forEach(item->{
-                    List<WebElement> tds =item.findElements(By.tagName("td"));
-                        PatentCell.PatentAffair affair =new PatentCell.PatentAffair();
-                        affair.setDateTime(tds.get(0).getText());
-                        affair.setSimpleStatus(tds.get(1).getText());
-                        affair.setStatus(tds.get(2).getText());
-             affairs.add(affair);
-                });
-                patentCell.setPatentAffairs(affairs);
+                    //获得图片路径
+                    wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("item-img")));
+                    WebElement picElement = driver.findElement(By.className("item-img"));
+                    WebElement imag = picElement.findElement(By.tagName("img"));
+                    String url = imag.getAttribute("src");
+                    url = fileUtils.uploadToLocal(url, ".jpg").getPath();
+                    patentCell.setPicUrl(url);
+                    if (cells.contains(2)) {
+                        //获得主权要
+                        String mainRight = spans.get(1).getText();
+                        patentCell.setMainRignt(mainRight);
+                        //获得权要
+                        WebElement CLElement = driver.findElement(By.id("itemCL"));
+                        CLElement.click();
+                        TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                        wait1.until(ExpectedConditions.presenceOfElementLocated(By.tagName("claim-text")));
+                        List<WebElement> rightElements = driver.findElements(By.tagName("claim-text"));
+                        List<String> rights = new ArrayList<>();
+                        rightElements.forEach(item -> {
+                            rights.add(item.getText());
+                        });
+                        patentCell.setRights(rights);
+                    }
+                    if (cells.contains(3)) {
+                        //获得说明书
+                        WebElement DSElement = driver.findElement(By.id("itemDS"));
+                        DSElement.click();
+                        TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                        wait1.until(ExpectedConditions.presenceOfElementLocated(By.tagName("invention-title")));
+                        WebElement titleElement = driver.findElement(By.tagName("invention-title"));
+                        patentCell.setTitle(titleElement.getText());
+                        StringBuilder stringBuilder = new StringBuilder();
+                        int flag = 1;
+                        //技术领域
+                        WebElement textElement1 = driver.findElement(By.tagName("description"));
+                        List<WebElement> textP1 = textElement1.findElements(By.tagName("p"));
+                        stringBuilder.append(textP1.get(0).getText());
+                        stringBuilder.append("\r\n");
+                        for (int t = 1; t < textP1.size(); t++) {
+                            String tem = String.format("%04d", flag);
+                            stringBuilder.append("[" + tem + "]" + textP1.get(t).getText());
+                            stringBuilder.append("\r\n");
+                            flag += 1;
+                        }
+                        patentCell.setPatentInstructionText(stringBuilder.toString());
+                    }
+                    //获得pdf文档
+                    if (cells.contains(4)) {
+                        WebElement PDFElement = driver.findElement(By.id("itemPdf"));
+                        PDFElement.click();
+                        TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
+                        List<WebElement> PDFFile = driver.findElements(By.tagName("embed"));
+                        String pdfUrl = "";
+                        if (PDFFile.size() == 0) {
+                            List<WebElement> PDFFiles = driver.findElements(By.className("pdfbtn"));
+                            if (PDFFiles.size() != 0) {
+                                pdfUrl = PDFFiles.get(0).getAttribute("data-url");
+                            } else {
+                                WebElement suBtn = driver.findElement(By.className("layui-layer-btn0"));
+                                suBtn.click();
+                                TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                            }
 
-                if(patentCell.getPublicNo()!=null){
-                    patentCell.setPatentNo(patentCell.getPublicNo());
-                    patentCell.setPublicNo(patentCell.getPublicAccreditNo());
-                }
-                else{
-                    patentCell.setPatentNo(patentCell.getPublicAccreditNo());
-                }
-                if (patentCell.getPatentNo() != null) {
-                    String res = outInterfaceService.importPatents(patentCell);
-                    JSONObject jsonObject = JSONObject.parseObject(res);
-                    if (jsonObject.get("code").toString().equals("500")) {
-                        return null;
+                        } else {
+                            pdfUrl = PDFFile.get(0).getAttribute("src");
+                        }
+                        if (pdfUrl != "") {
+                            UploadFileDTO fileDTO = fileUtils.uploadToLocal(pdfUrl, ".PDF");
+                            patentCell.setPDFName(fileDTO.getFileName());
+                            patentCell.setPDFSize(fileDTO.getFileSize());
+                            patentCell.setPDFUrl(fileDTO.getPath());
+                            patentCell.setPdf(fileDTO);
+                        }
                     }
+
+                    if (cells.contains(5)) {
+                        //获得法律状态
+                        WebElement flztElement = driver.findElement(By.id("flztbtn"));
+                        flztElement.click();
+                        TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                        wait1.until(ExpectedConditions.presenceOfElementLocated(By.id("legalContainer")));
+                        WebElement tBody = driver.findElement(By.id("legalContainer"));
+                        TimeUnit.MILLISECONDS.sleep(1000);//毫秒
+                        List<WebElement> trs = tBody.findElements(By.tagName("tr"));
+
+                        List<PatentCell.PatentAffair> affairs = new ArrayList<>();
+                        trs.forEach(item -> {
+                            List<WebElement> tds = item.findElements(By.tagName("td"));
+                            PatentCell.PatentAffair affair = new PatentCell.PatentAffair();
+                            affair.setDateTime(tds.get(0).getText());
+                            affair.setSimpleStatus(tds.get(1).getText());
+                            affair.setStatus(tds.get(2).getText());
+                            affairs.add(affair);
+                        });
+                        patentCell.setPatentAffairs(affairs);
+
+                        if (patentCell.getPublicNo() != null) {
+                            patentCell.setPatentNo(patentCell.getPublicNo());
+
+                        } else {
+                            patentCell.setPatentNo(patentCell.getPublicAccreditNo());
+                            patentCell.setPublicNo(patentCell.getPublicAccreditNo());
+                        }
+                    }
+                    if (patentCell.getPatentNo() != null) {
+                        String res = outInterfaceService.importPatents(patentCell);
+                        JSONObject jsonObject = JSONObject.parseObject(res);
+                        if (jsonObject.get("code").toString().equals("500")) {
+                            return null;
+                        }
+                    }
+
+                    WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
+                            .setTaskId(webQueryDTO.getTaskId())
+                            .setProjectId(webQueryDTO.getProjectId())
+                            .setComplete(false)
+                            .setIndex(i)
+                            .setTaskType(Constants.TASK_IMPORT_PATENT)
+                            .setPercentage(count == 0 ? 0 : Math.round((count.equals(i) ? (i * 1D) : (i + 1D)) / count * 100D))
+                            .setFileName("")
+                            .setUrl("")
+                            .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS),"");
+                    patentCells.add(patentCell);
+                    driver.close();
+                    driver.switchTo().window(handleMap.get("mainPage"));
                 }
-                patentCells.add(patentCell);
-                driver.close();
-                driver.switchTo().window(handleMap.get("mainPage"));
-            }
-            wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("tcdPageCode")));
+                wait1.until(ExpectedConditions.presenceOfElementLocated(By.className("tcdPageCode")));
 
-            List<WebElement> nexts = driver.findElements(By.className("nextPage"));
-            if (nexts.size() != 0) {
-                nexts.get(0).click();
+                List<WebElement> nexts = driver.findElements(By.className("nextPage"));
+                if (nexts.size() != 0) {
+                    nexts.get(0).click();
+                    TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                }
             }
+
+            WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
+                    .setTaskId(webQueryDTO.getTaskId())
+                    .setProjectId(webQueryDTO.getProjectId())
+                    .setComplete(true)
+                    .setIndex(count)
+                    .setTaskType(Constants.TASK_IMPORT_PATENT)
+                    .setPercentage(100L)
+                    .setFileName("")
+                    .setUrl("")
+                    .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "");
+            QrtzTask qrtzTask = qrTaskService.getById(webQueryDTO.getTaskId());
+            qrtzTask.setTaskState(2);
+            qrtzTask.updateById();
+            driver.quit();
+        }
+        catch (Exception e){
+            QrtzTask qrtzTask = qrTaskService.getById(webQueryDTO.getTaskId());
+            qrtzTask.setTaskState(3);
+            qrtzTask.updateById();
         }
-//        driver.quit();
         return patentCells;
     }
 

+ 30 - 0
src/main/java/com/example/demo/service/WebConfigCellService.java

@@ -0,0 +1,30 @@
+package com.example.demo.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.example.demo.domain.WebConfig;
+import com.example.demo.domain.WebConfigCell;
+import com.example.demo.mapper.WebConfigCellMapper;
+import com.example.demo.mapper.WebConfigMapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author admin
+ * @description 针对表【web_config(网站配置)】的数据库操作Service实现
+ * @createDate 2023-03-08 18:51:17
+ */
+@Service
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class WebConfigCellService extends ServiceImpl<WebConfigCellMapper, WebConfigCell> {
+ public List<WebConfigCell>  getConfigCell(Integer type){
+     LambdaQueryWrapper<WebConfigCell> wrapper =new LambdaQueryWrapper<>();
+     wrapper.eq(WebConfigCell::getConfigType,type);
+     List<WebConfigCell> webConfigCells =this.list(wrapper);
+     return webConfigCells;
+ }
+
+}

+ 6 - 0
src/main/java/com/example/demo/service/WebConfigService.java

@@ -8,6 +8,8 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * @author admin
  * @description 针对表【web_config(网站配置)】的数据库操作Service实现
@@ -24,4 +26,8 @@ public class WebConfigService extends ServiceImpl<WebConfigMapper, WebConfig> {
         return new WebConfig();
     }
 
+    public List<WebConfig> getAllConfig() {
+        return this.list();
+    }
+
 }

+ 17 - 9
src/main/java/com/example/demo/service/WebUploadJob.java

@@ -2,6 +2,7 @@ package com.example.demo.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.example.demo.domain.QrtzTask;
+import com.example.demo.model.dto.WebQueryDTO;
 import lombok.SneakyThrows;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -14,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.quartz.QuartzJobBean;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -27,6 +30,8 @@ public class WebUploadJob extends QuartzJobBean {
     private static final Log logger = LogFactory.getLog(WebUploadJob.class);
     @Autowired
     private QrTaskService qrTaskService;
+    @Autowired
+    private UploadFromWebService uploadFromWebService;
     @Override
     public void executeInternal(JobExecutionContext context) throws JobExecutionException {
 
@@ -43,21 +48,24 @@ public class WebUploadJob extends QuartzJobBean {
                         .orderByAsc(QrtzTask::getCreateTime).last("limit 1");
                 QrtzTask qrtzTask = qrTaskService.getOne(getDoingWrapper);
                 if(qrtzTask!=null) {
+                    qrtzTask.setTaskState(1);
+                    qrtzTask.updateById();
                     logger.info("上传任务" + "信息是" + qrtzTask);
+                    String[] cells =qrtzTask.getConfigCells().split(",");
+                    List<String>  conCells =new ArrayList<>(Arrays.asList(cells));
+                    WebQueryDTO webQueryDTO =new WebQueryDTO();
+                    webQueryDTO.setConCells(conCells);
+                    webQueryDTO.setWebConfigId(qrtzTask.getConfigId());
+                    webQueryDTO.setConditions(qrtzTask.getConditions());
+                    webQueryDTO.setProjectId(qrtzTask.getProjectId());
+                    webQueryDTO.setTaskId(qrtzTask.getId());
                     try {
-                        TimeUnit.MILLISECONDS.sleep(10000);//毫秒
-                        qrtzTask.setTaskState(2);
-                        qrtzTask.updateById();
-                        logger.info(qrtzTask.getId() + "任务完成");
+                        uploadFromWebService.getPatentStar(webQueryDTO);
                     } catch (Exception e) {
-                        qrtzTask.setTaskType(3);
-                        qrtzTask.updateById();
-                        logger.info(qrtzTask.getId() + "任务出错");
-
+                        e.printStackTrace();
                     }
                 }
             }
-
         }
 
 }

+ 113 - 0
src/main/java/com/example/demo/util/WebSocketServer.java

@@ -0,0 +1,113 @@
+package com.example.demo.util;
+
+import com.example.demo.base.Constants;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.websocket.*;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+@Slf4j
+@Component
+@ServerEndpoint("aadad" + "/ws/{sid}")
+public class WebSocketServer {
+
+    //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
+    private static int onlineCount = 0;
+    //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
+    private static CopyOnWriteArraySet<WebSocketServer> webSocketSet
+            = new CopyOnWriteArraySet<WebSocketServer>();
+    //与某个客户端的连接会话,需要通过它来给客户端发送数据
+    private Session session;
+    //接收sid
+    private String sid = "";
+
+    /**
+     * 连接建立成功调用的方法
+     */
+    @OnOpen
+    public void onOpen(Session session, @PathParam("sid") String sid) {
+        this.session = session;
+        webSocketSet.add(this);     //加入set中
+        addOnlineCount();           //在线数加1
+        log.info("有新窗口开始监听:" + sid + ",当前在线人数为" + getOnlineCount());
+        this.sid = sid;
+        try {
+            sendMessage(Response.success("连接成功"));
+        } catch (IOException e) {
+            log.error("websocket IO异常");
+        }
+    }
+
+    /**
+     * 连接关闭调用的方法
+     */
+    @OnClose
+    public void onClose() {
+        webSocketSet.remove(this);  //从set中删除
+        subOnlineCount();           //在线数减1
+        log.info("有一连接关闭!当前在线人数为" + getOnlineCount());
+    }
+
+    /**
+     * 收到客户端消息后调用的方法
+     *
+     * @param message 客户端发送过来的消息
+     */
+    @OnMessage
+    public void onMessage(String message, Session session) {
+        log.info("收到来自窗口" + sid + "的信息:" + message);
+        //群发消息
+        for (WebSocketServer item : webSocketSet) {
+            try {
+                item.sendMessage(message);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @OnError
+    public void onError(Session session, Throwable error) {
+        log.error("发生错误");
+        error.printStackTrace();
+    }
+
+    //实现服务器主动推送
+    public synchronized void sendMessage(String message) throws IOException {
+        this.session.getBasicRemote().sendText(message);
+    }
+
+    //群发自定义消息
+    public synchronized static void sendInfo(String message, @PathParam("sid") String sid) {
+        log.info("推送消息到窗口" + sid + ",推送内容:" + message);
+        for (WebSocketServer item : webSocketSet) {
+            try {
+                //这里可以设定只推送给这个sid的,为null则全部推送
+                if (sid == null || "null".equals(sid)) {
+                    item.sendMessage(message);
+                } else if (item.sid.equals(sid)) {
+                    item.sendMessage(message);
+                }
+            } catch (IOException e) {
+                continue;
+            }
+        }
+    }
+
+    public static synchronized int getOnlineCount() {
+        return onlineCount;
+    }
+
+    public static synchronized void addOnlineCount() {
+        WebSocketServer.onlineCount++;
+    }
+
+    public static synchronized void subOnlineCount() {
+        WebSocketServer.onlineCount--;
+    }
+}
+