UploadTaskService.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package cn.cslg.pas.service.upLoadPatent;
  2. import cn.cslg.pas.common.model.dto.UploadFileDTO;
  3. import cn.cslg.pas.common.model.vo.UploadParamsVO;
  4. import cn.cslg.pas.common.utils.FileUtils;
  5. import cn.cslg.pas.service.TaskService;
  6. import lombok.RequiredArgsConstructor;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Lazy;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.web.multipart.MultipartFile;
  11. @Service
  12. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  13. public class UploadTaskService {
  14. private final FileUtils fileUtils;
  15. private final TaskService taskService;
  16. public static Integer upLoadPatent() throws InterruptedException {
  17. // //1.检查文档合法性
  18. // UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  19. // //获得文件路径
  20. // String filePath = fileUtils.getPath(fileDTO.getPath());
  21. // //当不合法时返回-1
  22. // if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx") && !filePath.endsWith(".XLS") && !filePath.endsWith(".XLSX")) {
  23. // return -1;
  24. // }
  25. //2.解析文档
  26. //4.建立任务
  27. Integer projectId =null;
  28. Integer total =1;
  29. // Integer taskId = taskService.add(fileDTO, projectId, null, total- 1, 1, 0, file.getOriginalFilename());
  30. for(int i=0;i<10;i++) {
  31. //3.装载实体类
  32. UploadParamsVO uploadParamsVO = new UploadParamsVO();
  33. //5.上传到库
  34. ThreadSafeQueue<UploadParamsVO> threadSafeQueue = new ThreadSafeQueue<>(100);
  35. Thread thread1 = new Thread(() -> {
  36. try {
  37. threadSafeQueue.enqueue(uploadParamsVO);
  38. } catch (InterruptedException e) {
  39. e.printStackTrace();
  40. }
  41. });
  42. thread1.start();
  43. Thread thread2 = new Thread(() -> {
  44. try {
  45. threadSafeQueue.dequeue();
  46. } catch (InterruptedException e) {
  47. e.printStackTrace();
  48. }
  49. });
  50. thread2.start();
  51. }
  52. return 1;
  53. }
  54. public static void main(String[] args) throws InterruptedException {
  55. UploadTaskService.upLoadPatent();
  56. }
  57. }