ソースを参照

字段格式化

lwhhszx 2 年 前
コミット
8ee011d608

+ 13 - 0
src/main/java/com/example/demo/config/AsyncExceptionHandler.java

@@ -0,0 +1,13 @@
+package com.example.demo.config;
+
+import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
+
+import java.lang.reflect.Method;
+
+public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {
+
+    @Override
+    public void handleUncaughtException(Throwable ex, Method method, Object... params) {
+        ex.printStackTrace();
+    }
+}

+ 54 - 0
src/main/java/com/example/demo/config/AsyncTaskPoolConfig.java

@@ -0,0 +1,54 @@
+package com.example.demo.config;
+
+import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.task.AsyncTaskExecutor;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+@EnableAsync
+@Configuration
+public class AsyncTaskPoolConfig implements AsyncConfigurer {
+
+    @Bean("singleThreadAsyncTaskExecutor")
+    public AsyncTaskExecutor singleThreadAsyncTaskExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(1);
+        executor.setMaxPoolSize(1);
+        executor.setQueueCapacity(64);
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        executor.initialize();
+        return executor;
+    }
+
+    @Override
+    @Bean("testExecutor")
+    public Executor getAsyncExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        //配置核心线程数
+        executor.setCorePoolSize(8);
+        //配置最大线程数
+        executor.setMaxPoolSize(16);
+        //配置队列大小
+        executor.setQueueCapacity(64);
+        //配置线程池中的线程的名称前缀
+        executor.setThreadNamePrefix("async-service-");
+
+        // 设置拒绝策略:当pool已经达到max size的时候,如何处理新任务
+        // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        //执行初始化
+        executor.initialize();
+        return executor;
+    }
+
+    @Override
+    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
+        return new AsyncExceptionHandler();
+    }
+}

+ 37 - 0
src/main/java/com/example/demo/config/QuartzConfig.java

@@ -0,0 +1,37 @@
+package com.example.demo.config;
+
+import com.example.demo.service.TaskAddJob;
+import com.example.demo.service.WebUploadJob;
+import org.quartz.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 定义任务描述和具体的执行时间
+ */
+@Configuration
+public class QuartzConfig {
+    @Bean
+    public JobDetail jobDetail() {
+        //指定任务描述具体的实现类
+        return JobBuilder.newJob(WebUploadJob.class)
+                // 指定任务的名称
+                .withIdentity("dongAoJob")
+                // 任务描述
+                .withDescription("任务描述:用于输出冬奥欢迎语")
+                // 每次任务执行后进行存储
+                .storeDurably()
+                .build();
+    }
+    
+    @Bean
+    public Trigger trigger() {
+        //创建触发器
+        return TriggerBuilder.newTrigger()
+                // 绑定工作任务
+                .forJob(jobDetail())
+                // 每隔 5 秒执行一次 job
+                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
+                .build();
+    }
+}

+ 18 - 0
src/main/java/com/example/demo/config/WebMvcConfig.java

@@ -0,0 +1,18 @@
+package com.example.demo.config;
+
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+    public class WebMvcConfig implements WebMvcConfigurer {
+        @Override
+        public void addResourceHandlers(ResourceHandlerRegistry registry) {
+            // /images/**是静态映射, file:/root/images/是文件在服务器的路径
+            registry.addResourceHandler("/**")
+                    .addResourceLocations("file:D:/QMS/target/file/");
+        }
+    }
+
+

+ 20 - 45
src/main/java/com/example/demo/controller/AssoTaskPersonelController.java

@@ -2,6 +2,7 @@ package com.example.demo.controller;
 
 import com.example.demo.base.Constants;
 import com.example.demo.domain.PatentCell;
+import com.example.demo.model.dto.WebQueryDTO;
 import com.example.demo.service.UploadFromWebService;
 import com.example.demo.util.FileUtils;
 import io.swagger.v3.oas.annotations.Operation;
@@ -11,11 +12,12 @@ import org.openqa.selenium.JavascriptExecutor;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.springframework.context.annotation.Lazy;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
@@ -25,19 +27,19 @@ import java.util.Set;
 @RequestMapping(Constants.QUARTZ_API + "/AssoTaskPersonel")
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class AssoTaskPersonelController {
-    private final FileUtils fileUtils;
     private final UploadFromWebService uploadFromWebService;
 
-    @GetMapping("/getStar")
-    public List<PatentCell> getPatentStar(String conditions, Integer id) throws Exception {
+    @PostMapping("/getStar")
+    public List<PatentCell> getPatentStar(@RequestBody WebQueryDTO WebQueryDTO) throws Exception {
         List<PatentCell> patentData = null;
-        if (id == 1) {
-            patentData = uploadFromWebService.getPatentStar(conditions, id);
-        } else if (id == 2) {
-            patentData = uploadFromWebService.getHeXiang(conditions, id);
-        } else if (id == 3) {
-            //patentData = uploadFromWebService.getPatentya();
+        if (WebQueryDTO.getWebConfigId() == 1) {
+            patentData = uploadFromWebService.getPatentStar(WebQueryDTO);
         }
+//        else if (id == 2) {
+////            patentData = uploadFromWebService.getHeXiang(conditions, id);
+//        } else if (id == 3) {
+//            //patentData = uploadFromWebService.getPatentya();
+//        }
         return patentData;
     }
 
@@ -52,39 +54,12 @@ public class AssoTaskPersonelController {
 
     @GetMapping("/test")
     @Operation(summary = "分页获取对比专利")
-    public void test(String patentVO) throws IOException, InterruptedException {
-        System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
-        // 1.创建webdriver驱动
-        WebDriver driver = new ChromeDriver();
-        //4、创建一个map集合存放浏览器句柄
-        HashMap<String, String> handleMap = new HashMap<>();
-
-        //5、访问百度
-        driver.get("https://www.baidu.com/");
-
-        //6、获取到打开百度窗口的句柄
-        String baiDuHandle = driver.getWindowHandle();
-
-        //7、将百度句柄放到map中
-        handleMap.put("baidu", baiDuHandle);
-
-        //8、新开一个窗口,用js来完成
-        String js = "window.open('https://www.sogou.com');";
-        ((JavascriptExecutor) driver).executeScript(js);
-
-        //9、获取到所有的句柄
-        Set<String> set = driver.getWindowHandles();
-        //10、循环找到搜狗窗口句柄
-        for (String s : set) {
-            //10.1、将搜狗的句柄放到map中
-            if (!s.equals("baiDuHandle"))
-                handleMap.put("souGou", s);
-        }
-
-        //11、切换到搜狗的窗口
-        driver.switchTo().window(handleMap.get("souGou"));
-        driver.switchTo().window(handleMap.get("baidu"));
-        driver.close();
+    public void test(String patentVO) throws IOException, InterruptedException, ParseException {
+        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);
 
 
     }

+ 10 - 3
src/main/java/com/example/demo/controller/QuartzController.java

@@ -1,8 +1,10 @@
 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 lombok.RequiredArgsConstructor;
 import org.quartz.SchedulerException;
 import org.springframework.context.annotation.Lazy;
@@ -14,10 +16,14 @@ import org.springframework.web.bind.annotation.*;
 @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 {
-
-    jobService.addJob(quartzTaskDTO);
+    QrtzTask qrtzTask= qrTaskService.addQuartzTask(quartzTaskDTO);
+    if(quartzTaskDTO.getTaskType().equals(1))
+    {
+    jobService.addJob(qrtzTask);
+    }
 
     }
 
@@ -28,7 +34,8 @@ public class QuartzController {
     }
     @PostMapping("/update")
     public void update(@RequestBody QuartzTaskDTO quartzTaskDTO) throws InterruptedException, SchedulerException {
-        jobService.updateJob(quartzTaskDTO);
+        QrtzTask qrtzTask=   qrTaskService.updateQuartzTask(quartzTaskDTO);
+        jobService.updateJob(qrtzTask);
 
     }
 

+ 60 - 10
src/main/java/com/example/demo/domain/PatentCell.java

@@ -1,6 +1,7 @@
 package com.example.demo.domain;
 
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import lombok.Data;
 
 import java.util.Date;
@@ -34,7 +35,14 @@ public class PatentCell {
     申请号
      */
     private String applicationNo;
-
+/*
+专题库id
+ */
+    private Integer projectId;
+    /*
+报告id
+ */
+    private Integer reportId;
     private String country;
     private String applicationDate;
     private String pubilcDate;
@@ -49,28 +57,29 @@ public class PatentCell {
     /*
     主分类号
      */
-    private String mainTypeNo;
+    private String mainIpc;
     /*
       分类号
        */
-    private String typeNo;
+    private List<String> ipc;
     /*
     申请人
      */
-    private String applicationPerson;
+    private List<String> applicationPersons;
     /*
 申请人地址
  */
-    private String applicationAddress;
+    private List<String> applicationAddress;
     /*
   发明人
    */
-    private String inventor;
+    private List<String> inventors;
 
     /*
     当前权利人
      */
-    private String patentApplication;
+    private List<String> applicationCurrents;
+    private List<String> applicationCurrentAddress;
     /*
     范畴分类
      */
@@ -96,12 +105,53 @@ public class PatentCell {
     private List<String> rights;
 
     /*
-    PDF文档
-     */
-    private String PDF;
+        PDF文档路径
+         */
+    private String PDFUrl;
 
     /*
+   PDF文档大小
+    */
+    private Long PDFSize;
+    private String PDFName;
+    private UploadFileDTO pdf;
+    /*
     说明书
      */
     private String patentInstructionText;
+    /*
+   公开号
+     */
+    private String publicNo;
+    /*
+    代理机构
+     */
+   private  String agency;
+   /*
+   代理人
+    */
+    private List<String> agencyPersons;
+   /*专利法律状态
+
+    */
+    List<PatentAffair> patentAffairs ;
+    @Data
+    public static  class PatentAffair{
+        /**
+         * 法律状态
+         */
+        private String status;
+
+        /**
+         * 发生日期
+         */
+        private String dateTime;
+        /**
+         * 简单法律状态
+         */
+
+        private String simpleStatus;
+
+
+    }
 }

+ 8 - 2
src/main/java/com/example/demo/domain/QrtzTask.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
+import java.util.Date;
+
 import lombok.Data;
 
 /**
@@ -46,6 +48,10 @@ public class QrtzTask extends BaseEntity<QrtzTask> {
     private Integer defaultNum;
     @TableField(value = "crons")
     private String crons;
-
-
+    @TableField(value = "task_type")
+    private Integer taskType;
+    @TableField(value = "create_time")
+    private Date createTime;
+    @TableField(value = "task_order")
+    private Integer taskOrder;
 }

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

@@ -10,4 +10,5 @@ public class QuartzTaskDTO {
     private String conditions;
     private Integer webConfigId;
     private Integer taskId;
+    private Integer taskType;
 }

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

@@ -0,0 +1,12 @@
+package com.example.demo.model.dto;
+
+import lombok.Data;
+
+@Data
+public class WebQueryDTO {
+    private Integer projectId;
+    private String conditions;
+    private Integer webConfigId;
+    private Integer taskId;
+    private Integer reportId;
+}

+ 9 - 8
src/main/java/com/example/demo/service/JobService.java

@@ -33,6 +33,7 @@ public class JobService {
         scheduler.unscheduleJob(triggerKey);
         JobKey jobKey = JobKey.jobKey(quartzVO.getJobName(), quartzVO.getJobGroupName());
         scheduler.deleteJob(jobKey);
+        qrTaskService.removeById(taskId);
     }
     /**
      * 暂停job
@@ -69,14 +70,14 @@ public class JobService {
      *
      * @param
      */
-    public void updateJob( QuartzTaskDTO quartzTaskDTO) {
+    public void updateJob( QrtzTask qrtzTask) {
         //更新任务
-     QrtzTask qrtzTask=   qrTaskService.updateQuartzTask(quartzTaskDTO);
-        QuartzVO quartzVO=this.generateQuartzVO(quartzTaskDTO.getTaskId());
+
+        QuartzVO quartzVO=this.generateQuartzVO(qrtzTask.getId());
         JobDataMap jobDataMap =new JobDataMap();
         jobDataMap.put("qrtzTask",qrtzTask);
         TriggerKey oldTriggerKey = TriggerKey.triggerKey(quartzVO.getTriggerName(), quartzVO.getTriggerGroupName());
-        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzTaskDTO.getCron());
+        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(qrtzTask.getCrons());
         CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                 .withIdentity(oldTriggerKey).usingJobData(jobDataMap).withSchedule(scheduleBuilder).build();
         try {
@@ -92,14 +93,14 @@ public class JobService {
      * @throws SchedulerException
      */
     @Transactional
-    public void addJob(QuartzTaskDTO quartzTaskDTO) throws SchedulerException {
+    public void addJob(QrtzTask qrtzTask) throws SchedulerException {
         //添加一条任务记录
-        QrtzTask qrtzTask= qrTaskService.addQuartzTask(quartzTaskDTO);
+
         QuartzVO quartzVO=this.generateQuartzVO(qrtzTask.getId());
         JobDataMap jobDataMap =new JobDataMap();
         jobDataMap.put("qrtzTask",qrtzTask);
-        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(quartzTaskDTO.getCron());
-        JobDetail jobDetail = JobBuilder.newJob(WebUploadJob.class).withIdentity(quartzVO.getJobName(),quartzVO.getJobGroupName()).build();
+        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(qrtzTask.getCrons());
+        JobDetail jobDetail = JobBuilder.newJob(TaskAddJob.class).withIdentity(quartzVO.getJobName(),quartzVO.getJobGroupName()).build();
         Trigger trigger = TriggerBuilder.newTrigger().withIdentity(quartzVO.getTriggerName(), quartzVO.getTriggerGroupName())
                 .withSchedule(cronScheduleBuilder).usingJobData(jobDataMap).build();
         scheduler.scheduleJob(jobDetail, trigger);

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

@@ -0,0 +1,26 @@
+package com.example.demo.service;
+
+import com.example.demo.domain.QrtzTask;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.DisallowConcurrentExecution;
+import org.quartz.JobDataMap;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.scheduling.quartz.QuartzJobBean;
+
+/**
+ * 定义任务
+ */
+@DisallowConcurrentExecution
+public class TaskAddJob extends QuartzJobBean {
+
+    private static final Log logger = LogFactory.getLog(TaskAddJob.class);
+
+    @Override
+    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
+        JobDataMap jobDataMap =   context.getTrigger().getJobDataMap();
+        QrtzTask qrtzTask = (QrtzTask) jobDataMap.get("qrtzTask");
+        logger.info("添加任务"+"信息是"+qrtzTask);
+    }
+}

+ 124 - 61
src/main/java/com/example/demo/service/UploadFromWebService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.example.demo.domain.*;
 import com.example.demo.mapper.QrtzTaskMapper;
 import com.example.demo.model.dto.QuartzTaskDTO;
+import com.example.demo.model.dto.WebQueryDTO;
 import com.example.demo.util.FileUtils;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
@@ -17,14 +18,12 @@ import org.openqa.selenium.interactions.Actions;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.support.ui.WebDriverWait;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -42,8 +41,11 @@ public class UploadFromWebService {
     private final WebConfigService webConfigService;
 
     // 查询并上传(专利之星)
-    public List<PatentCell> getPatentStar(String conditions, Integer id) throws Exception {
-        conditions=this.formatConditions(conditions);
+    @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<>();
@@ -97,6 +99,8 @@ public class UploadFromWebService {
             // 页面元素标签
             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();
@@ -119,40 +123,62 @@ public class UploadFromWebService {
                     String value = "";
                     String[] strings = text.split(":");
                     if (strings.length > 1) {
-                        value = strings[1];
-                    }
-                    switch (t) {
-                        case 0:
-                            patentCell.setApplicationNo(value);
-                        case 1:
-                            patentCell.setApplicationDate(value);
-                        case 2:
-                            patentCell.setCountry(value);
-                        case 3:
-                            patentCell.setPatentNo(value);
-                        case 4:
-                            patentCell.setPubilcDate(value);
-                        case 5:
-                            patentCell.setPublicAccreditNo(value);
-                        case 6:
-                            patentCell.setPublicAccreditDate(value);
-                        case 7:
-                            patentCell.setMainTypeNo(value);
-                        case 8:
-                            patentCell.setTypeNo(value);
-                        case 9:
-                            patentCell.setApplicationNo(value);
-                        case 10:
-                            patentCell.setApplicationAddress(value);
-                        case 11:
-                            patentCell.setInventor(value);
-                        case 12:
-                            patentCell.setPatentApplication(value);
-                        case 13:
-                            patentCell.setClassical(value);
-                        case 14:
-                            patentCell.setStatue(value);
-                            break;
+                        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;
+                        }
                     }
                 }
                 //获得摘要
@@ -168,7 +194,7 @@ public class UploadFromWebService {
                 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");
+                url = fileUtils.uploadToLocal(url, ".jpg").getPath();
                 patentCell.setPicUrl(url);
                 //获得权要
                 WebElement CLElement = driver.findElement(By.id("itemCL"));
@@ -250,19 +276,45 @@ public class UploadFromWebService {
                 wait1.until(ExpectedConditions.presenceOfElementLocated(By.tagName("embed")));
                 WebElement PDFFile = driver.findElement(By.tagName("embed"));
                 String pdfUrl = PDFFile.getAttribute("src");
-                pdfUrl = fileUtils.uploadToLocal(pdfUrl, ".PDF");
-                patentCell.setPDF(pdfUrl);
-//            String res =   outInterfaceService.importPatents(patentCell);
-//            JSONObject jsonObject =JSONObject.parseObject(res);
-//            if(jsonObject.get("code").toString().equals("0")){
-//                return null;
-//            }
+                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"));
+
+                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());
+                    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;
+                    }
+                }
                 patentCells.add(patentCell);
-                //上传
-                MultipartFile file = FileUtils.urlToMultipartFile(patentCell.getPDF(), ".PDF");
-                UploadFileDTO fileDTO = fileUtils.uploadFile(file);
-                String path = fileUtils.getPath(fileDTO.getPath());
-                patentCell.setUrl(path);
                 driver.close();
                 driver.switchTo().window(handleMap.get("mainPage"));
             }
@@ -372,33 +424,44 @@ public class UploadFromWebService {
         for (JSONObject jsonObject1 : sources) {
             jsonObject = jsonObject1;
         }
-      condition=  condition.replace(" ", "");
-      condition=  condition.replace("&&", "*");
-        condition=condition.replace("||", "+");
+        condition = condition.replace(" ", "");
+        condition = condition.replace("&&", "*");
+        condition = condition.replace("||", "+");
         StringBuilder stringBuilder = new StringBuilder("F XX ");
         String pattern = "\\([^)]*\\)";
         Pattern p = Pattern.compile(pattern);
         Matcher m = p.matcher(condition);
         while (m.find()) {    // 当字符串中有匹配到 {} 时
             String param = m.group(0);
-            String cell = formatParam(param,jsonObject);
-         condition= condition.replace(param,cell);
+            String cell = formatParam(param, jsonObject);
+            condition = condition.replace(param, cell);
 
         }
         return condition;
     }
 
     public String formatParam(String param, JSONObject jsonObject) {
-      param=   param.replace("(", "");
-        param=  param.replace(")", "");
+        param = param.replace("(", "");
+        param = param.replace(")", "");
         String[] params = param.split("=");// {} 和里面的内容
         StringBuilder stringBuilder = new StringBuilder("(" + params[1]);
         stringBuilder.append("/");
         String cell = jsonObject.get(params[0]).toString();
-        stringBuilder.append(cell +")");
+        stringBuilder.append(cell + ")");
         return stringBuilder.toString();
     }
 
+    //将值转换为list
+    public List<String> StringToList(String value, String split) {
+        List<String> list = new ArrayList<>();
+        if (value != null && value != "") {
+            String[] temValue = value.split(split);
+            list = new ArrayList<>(Arrays.asList(temValue));
+        }
+        return list;
+
+    }
+
 }
 
 

+ 43 - 6
src/main/java/com/example/demo/service/WebUploadJob.java

@@ -1,24 +1,61 @@
 package com.example.demo.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.example.demo.domain.QrtzTask;
+import lombok.SneakyThrows;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.checkerframework.checker.units.qual.A;
+import org.quartz.DisallowConcurrentExecution;
 import org.quartz.JobDataMap;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.quartz.QuartzJobBean;
 
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
 /**
  * 定义任务
  */
+
+@DisallowConcurrentExecution
 public class WebUploadJob extends QuartzJobBean {
 
     private static final Log logger = LogFactory.getLog(WebUploadJob.class);
-
+    @Autowired
+    private QrTaskService qrTaskService;
     @Override
-    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
-        JobDataMap jobDataMap =   context.getTrigger().getJobDataMap();
-        QrtzTask qrtzTask = (QrtzTask) jobDataMap.get("qrtzTask");
-        logger.info("信息是"+qrtzTask);
-    }
+    public void executeInternal(JobExecutionContext context) throws JobExecutionException {
+
+            //查找是否有任务正在进行
+            LambdaQueryWrapper<QrtzTask> queryWrapper =new LambdaQueryWrapper<>();
+            queryWrapper.eq(QrtzTask::getTaskState,1);
+            List<QrtzTask> qrtzTaskList =  qrTaskService.list(queryWrapper);
+            //当无任务在进行时
+            if(qrtzTaskList.size()==0){
+                LambdaQueryWrapper<QrtzTask> getDoingWrapper = new LambdaQueryWrapper<>();
+                getDoingWrapper.eq(QrtzTask::getTaskState,0)
+                        .orderByAsc(QrtzTask::getCreateTime).last("limit 1");
+                QrtzTask qrtzTask = qrTaskService.getOne(getDoingWrapper);
+                if(qrtzTask!=null) {
+                    logger.info("上传任务" + "信息是" + qrtzTask);
+                    try {
+                        TimeUnit.MILLISECONDS.sleep(10000);//毫秒
+                        qrtzTask.setTaskState(2);
+                        qrtzTask.updateById();
+                        logger.info(qrtzTask.getId() + "任务完成");
+                    } catch (Exception e) {
+                        qrtzTask.setTaskType(3);
+                        qrtzTask.updateById();
+                        logger.info(qrtzTask.getId() + "任务出错");
+
+                    }
+                }
+            }
+
+        }
+
 }

+ 2 - 3
src/main/java/com/example/demo/util/FileUtils.java

@@ -253,11 +253,10 @@ public class FileUtils {
     }
 
 
-    public  String uploadToLocal(String  url,String type) throws Exception {
+    public  UploadFileDTO uploadToLocal(String  url,String type) throws Exception {
         MultipartFile file = FileUtils.urlToMultipartFile(url,type);
         UploadFileDTO fileDTO = fileUtils.uploadFile(file);
-        String path = fileUtils.getPath(fileDTO.getPath());
-     return  path;
+     return  fileDTO;
 
     }