|
@@ -3,6 +3,7 @@ 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.common.utils.ReadExcelUtils;
|
|
|
import cn.cslg.pas.service.TaskService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -10,33 +11,34 @@ import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
@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;
|
|
|
-// }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
//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++) {
|
|
|
+ ThreadSafeQueue<UploadParamsVO> threadSafeQueue = new ThreadSafeQueue<>(8);
|
|
|
+ for(int i=0;i<total;i++) {
|
|
|
//3.装载实体类
|
|
|
UploadParamsVO uploadParamsVO = new UploadParamsVO();
|
|
|
+ uploadParamsVO.setFirstAddress(i+"");
|
|
|
//5.上传到库
|
|
|
- ThreadSafeQueue<UploadParamsVO> threadSafeQueue = new ThreadSafeQueue<>(100);
|
|
|
Thread thread1 = new Thread(() -> {
|
|
|
try {
|
|
|
threadSafeQueue.enqueue(uploadParamsVO);
|
|
@@ -59,6 +61,6 @@ public class UploadTaskService {
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws InterruptedException {
|
|
|
- UploadTaskService.upLoadPatent();
|
|
|
+// UploadTaskService.upLoadPatent();
|
|
|
}
|
|
|
}
|