|
@@ -0,0 +1,64 @@
|
|
|
+package cn.cslg.pas.service.upLoadPatent;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.model.dto.UploadFileDTO;
|
|
|
+import cn.cslg.pas.common.model.vo.UploadParamsVO;
|
|
|
+import cn.cslg.pas.common.utils.FileUtils;
|
|
|
+import cn.cslg.pas.service.TaskService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
+public class UploadTaskService {
|
|
|
+
|
|
|
+ private final FileUtils fileUtils;
|
|
|
+ private final TaskService taskService;
|
|
|
+
|
|
|
+ public static Integer upLoadPatent() throws InterruptedException {
|
|
|
+// //1.检查文档合法性
|
|
|
+// UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
|
+// //获得文件路径
|
|
|
+// String filePath = fileUtils.getPath(fileDTO.getPath());
|
|
|
+// //当不合法时返回-1
|
|
|
+// if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx") && !filePath.endsWith(".XLS") && !filePath.endsWith(".XLSX")) {
|
|
|
+// return -1;
|
|
|
+// }
|
|
|
+ //2.解析文档
|
|
|
+ //4.建立任务
|
|
|
+ Integer projectId =null;
|
|
|
+ Integer total =1;
|
|
|
+// Integer taskId = taskService.add(fileDTO, projectId, null, total- 1, 1, 0, file.getOriginalFilename());
|
|
|
+
|
|
|
+ for(int i=0;i<10;i++) {
|
|
|
+ //3.装载实体类
|
|
|
+ UploadParamsVO uploadParamsVO = new UploadParamsVO();
|
|
|
+ //5.上传到库
|
|
|
+ ThreadSafeQueue<UploadParamsVO> threadSafeQueue = new ThreadSafeQueue<>(100);
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+}
|