Browse Source

导入开发

lwhhszx 2 years ago
parent
commit
7cfc54e343

+ 4 - 0
PAS/pom.xml

@@ -172,6 +172,10 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-quartz</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 35 - 0
PAS/src/main/java/cn/cslg/pas/common/config/QuartzConfig.java

@@ -0,0 +1,35 @@
+package cn.cslg.pas.common.config;
+
+import cn.cslg.pas.service.upLoadPatent.PatentToDbTaskJob;
+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(PatentToDbTaskJob.class)
+                // 指定任务的名称
+                .withIdentity("webUploadJob", "Default")
+                // 每次任务执行后进行存储
+                .storeDurably()
+                .build();
+    }
+
+    @Bean
+    public Trigger trigger() {
+        //创建触发器
+        return TriggerBuilder.newTrigger()
+                // 绑定工作任务
+                .forJob(jobDetail())
+                // 每隔 5 秒执行一次 job
+                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
+                .withIdentity("webUploadTrigger", "Default")
+                .build();
+    }
+}

+ 12 - 1
PAS/src/main/java/cn/cslg/pas/controller/UserController.java

@@ -5,6 +5,7 @@ import cn.cslg.pas.common.model.vo.UserVO;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.domain.User;
 import cn.cslg.pas.service.UserService;
+import cn.cslg.pas.service.upLoadPatent.UploadTaskService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
@@ -28,7 +29,7 @@ import java.io.IOException;
 public class UserController {
 
     private final UserService userService;
-
+    private final UploadTaskService uploadTaskService;
     @GetMapping("list")
     @Operation(summary = "租户列表")
     public String getPageList(UserVO params) throws IOException {
@@ -57,4 +58,14 @@ public class UserController {
     public String delete(Integer id) {
         return userService.delete(id);
     }
+
+    @PostMapping("test")
+    @Operation(summary = "删除用户")
+    public String test(Integer id) {
+        uploadTaskService.test();
+        return "test";
+    }
+
+
+
 }

+ 2 - 0
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcuteUploadSettingService.java

@@ -9,6 +9,8 @@ import org.springframework.stereotype.Service;
 import java.util.List;
 
 /**
+ * 解析数据源配置文件
+ *
  * @Author chenyu
  * @Date 2023/5/31
  */

+ 11 - 0
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/MessageService.java

@@ -0,0 +1,11 @@
+package cn.cslg.pas.service.upLoadPatent;
+
+
+import org.springframework.stereotype.Service;
+
+/**处理消息通知
+ * @Author 李仁杰
+ */
+@Service
+public class MessageService {
+}

+ 64 - 0
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/PantentQueueService.java

@@ -0,0 +1,64 @@
+package cn.cslg.pas.service.upLoadPatent;
+
+import cn.cslg.pas.common.model.vo.UploadParamsVO;
+import org.apache.poi.ss.formula.functions.T;
+
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/** 将专利信息存入队列或从队列取出
+ * @author 李仁杰
+ */
+public class PantentQueueService {
+    private Queue<UploadParamsVO> queue = new LinkedList<>();
+    private Boolean flag =false;
+    private CountDownLatch latch = new CountDownLatch(10);
+    //将专利信息存入队列
+    public void addPatnetToQueue() throws InterruptedException {
+        Boolean t =false;
+        try {
+            for(int i=0;i<10;i++){
+                UploadParamsVO up = new UploadParamsVO();
+                up.setFirstAddress(i+"");
+                System.out.println("进入队列" + up.getFirstAddress());
+                queue.add(up);
+                //通知消费者线程
+                latch.countDown();
+                Thread.sleep(1000);
+            }
+        }
+        finally {
+        }
+
+        flag=true;
+    }
+    //将专利信息从队列取出
+    public void pushPantentToDb() throws InterruptedException {
+        try {
+            while(true){
+                if(queue.isEmpty()){
+                    if(flag){
+                        System.out.println("退出循环");
+                        return;
+                    }
+                    else{
+                        latch.countDown();
+                    }
+                }
+                else{
+//                    Thread.sleep(5000);
+//                    t=queue.remove();
+//                    System.out.println("出队列"+t);
+                }
+            }
+
+        } finally {
+
+        }
+    }
+
+}

+ 34 - 0
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/PatentToDbTaskJob.java

@@ -0,0 +1,34 @@
+package cn.cslg.pas.service.upLoadPatent;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.DisallowConcurrentExecution;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.quartz.QuartzJobBean;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 定义任务
+ */
+@Slf4j
+@DisallowConcurrentExecution
+public class PatentToDbTaskJob extends QuartzJobBean {
+
+
+    @Override
+    public void executeInternal(JobExecutionContext context) throws JobExecutionException {
+         //1获得任务信息
+        // 2根据不同的任务类型,选择不同方法上传任务
+
+
+    }
+
+}

+ 0 - 60
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ThreadSafeQueue.java

@@ -1,60 +0,0 @@
-package cn.cslg.pas.service.upLoadPatent;
-
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * 以下是一个基于Java的线程安全队列类的示例代码:
- * <p>
- * 这个线程安全队列类使用了ReentrantLock来控制并发访问,并使用了两个Condition对象,用于阻塞线程,直到队列不再是满的或空闲的。
- * 在enqueue()和dequeue()方法中,使用了try-finally块来确保锁始终被释放。这样,即使发生异常,也能够保证锁被释放,从而避免死锁。
- */
-public class ThreadSafeQueue<T> {
-    private Queue<T> queue = new LinkedList<>();
-    private final Lock lock = new ReentrantLock();
-    private final Condition notEmpty = lock.newCondition();
-    private final Condition notFull = lock.newCondition();
-    private int maxSize;
-
-    public ThreadSafeQueue(int maxSize) {
-        this.maxSize = maxSize;
-    }
-
-    public void enqueue(T item) throws InterruptedException {
-        lock.lock();
-        try {
-            while (queue.size() == maxSize) {
-                notFull.await();
-            }
-            System.out.println("一个数据准备进入队列");
-            queue.add(item);
-            System.out.println(queue.size());
-            notEmpty.signalAll();
-        } finally {
-            lock.unlock();
-        }
-    }
-
-    public T dequeue() throws InterruptedException {
-        lock.lock();
-        try {
-            while (queue.isEmpty()) {
-                notEmpty.await();
-            }
-            System.out.println("一个数据准备出队列");
-            T item = queue.remove();
-            System.out.println(queue.size());
-            notFull.signalAll();
-            return item;
-        } finally {
-            lock.unlock();
-        }
-    }
-
-}
-
-
-

+ 17 - 40
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadTaskService.java

@@ -6,6 +6,7 @@ import cn.cslg.pas.common.utils.FileUtils;
 import cn.cslg.pas.common.utils.ReadExcelUtils;
 import cn.cslg.pas.service.TaskService;
 import lombok.RequiredArgsConstructor;
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -13,6 +14,10 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 
+/**
+ * @Author  李仁杰
+ * 导入任务类
+ */
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class UploadTaskService {
@@ -21,49 +26,21 @@ public class UploadTaskService {
     private final TaskService taskService;
     private final ReadExcelUtils readExcelUtils;
 
-    public Integer upLoadPatent(MultipartFile file) throws InterruptedException, IOException {
-        //1.检查文档合法性
-        UploadFileDTO fileDTO = fileUtils.uploadFile(file);
-        //获得文件路径
-        String filePath = fileUtils.getPath(fileDTO.getPath());
-        Integer total = ReadExcelUtils.textExcel(filePath);
-        if (total <= 0) {
-            return -1;
-        }
+    /**
+     * 添加导入任务
+     */
+    public void addTask(){
+
+
 
-        //2.解析文档
-        //4.建立任务
-        Integer projectId = null;
-//        Integer taskId = taskService.add(fileDTO, projectId, null, total- 1, 1, 0, file.getOriginalFilename());
-        ThreadSafeQueue<UploadParamsVO> threadSafeQueue = new ThreadSafeQueue<>(8);
-        for (int i = 0; i < total; i++) {
 
-            //3.装载实体类
-            UploadParamsVO uploadParamsVO = new UploadParamsVO();
-            uploadParamsVO.setFirstAddress(i + "");
-            //5.上传到库
-            Thread thread1 = new Thread(() -> {
-                try {
-                    threadSafeQueue.enqueue(uploadParamsVO);
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            });
-            thread1.start();
-            Thread thread2 = new Thread(() -> {
-                try {
-                    threadSafeQueue.dequeue();
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            });
-            thread2.start();
-        }
-        return 1;
-    }
 
 
-    public static void main(String[] args) throws InterruptedException {
-//        UploadTaskService.upLoadPatent();
     }
+
+    public void pauseTask(){}
+
+    public void deleteTask(){}
+
+
 }

+ 12 - 0
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/scheduleTaskService.java

@@ -0,0 +1,12 @@
+package cn.cslg.pas.service.upLoadPatent;
+
+
+import org.springframework.stereotype.Service;
+
+/**
+ * 调度任务类
+ * @autor 李仁杰
+ */
+@Service
+public class scheduleTaskService {
+}

+ 32 - 0
PAS/src/main/resources/application-dev.yml

@@ -23,5 +23,37 @@ spring:
         login-password: Cslg2022+
       web-stat-filter:
         exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
+  quartz:
+    #相关属性配置
+    properties:
+      org:
+        quartz:
+          scheduler:
+            instanceName: DefaultQuartzScheduler
+            instanceId: AUTO
+          jobStore:
+            class: org.springframework.scheduling.quartz.LocalDataSourceJobStore
+            driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
+            tablePrefix: QRTZ_
+            isClustered: false
+            clusterCheckinInterval: 10000
+            useProperties: false
+          threadPool:
+            class: org.quartz.simpl.SimpleThreadPool
+            threadCount: 10
+            threadPriority: 5
+            threadsInheritContextClassLoaderOfInitializingThread: true
+          dataSource:
+            default:
+              URL: jdbc:mysql://192.168.1.24:3306/pas?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=GMT%2B8
+              user: root
+              password: rrzTwWAYX8Gxh5JH
+              driver: com.mysql.jdbc.Driver
+
+    #数据库方式
+    job-store-type: jdbc
+    #初始化表结构
+    jdbc:
+      initialize-schema: always
 authorUrl: http://localhost:8871
 PCSUrl: http://localhost:8871