|
@@ -1,23 +1,29 @@
|
|
|
package cn.cslg.report.service;
|
|
|
|
|
|
import cn.cslg.report.common.core.base.Constants;
|
|
|
+import cn.cslg.report.common.model.dto.TaskWebSocketDTO;
|
|
|
import cn.cslg.report.common.model.dto.UploadFileDTO;
|
|
|
import cn.cslg.report.common.model.vo.LoginVO;
|
|
|
import cn.cslg.report.common.model.vo.PersonnelVO;
|
|
|
import cn.cslg.report.common.model.vo.TaskParams;
|
|
|
-import cn.cslg.report.common.utils.FileUtils;
|
|
|
-import cn.cslg.report.common.utils.LogExceptionUtil;
|
|
|
-import cn.cslg.report.common.utils.Response;
|
|
|
+import cn.cslg.report.common.utils.*;
|
|
|
import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
|
|
|
+import cn.cslg.report.entity.ImportTask;
|
|
|
import cn.hutool.core.collection.IterUtil;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -222,24 +228,68 @@ public class BaseService {
|
|
|
}
|
|
|
|
|
|
//获得
|
|
|
- public TaskParams getImportPatentTaskParamsBro(MultipartFile file) {
|
|
|
+ public TaskParams getImportPatentTaskParamsBro(MultipartFile file,Integer reportId) throws IOException {
|
|
|
//上传文档
|
|
|
UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
|
//获得文档保存的路径
|
|
|
String path = fileUtils.getPath(fileDTO.getPath());
|
|
|
- List<List<Object>> rowList = new ArrayList<>();
|
|
|
- //解析excel文件并保存进map里
|
|
|
- List<Map<Object, Object>> mapList = new ArrayList<>();
|
|
|
- ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
|
|
|
- for (int i = 1; i < rowList.size(); i++) {
|
|
|
- mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
|
|
|
+
|
|
|
+ File file1 = new File(path);
|
|
|
+ String fileName = file1.getName();
|
|
|
+ Workbook workbook = null;
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(file1);
|
|
|
+ // excel类型
|
|
|
+ if (fileName.endsWith(".xls")) {
|
|
|
+ workbook = new HSSFWorkbook(fileInputStream);
|
|
|
+ } else if (fileName.endsWith(".xlsx")) {
|
|
|
+ workbook = new XSSFWorkbook(fileInputStream);
|
|
|
}
|
|
|
- TaskParams taskParams = new TaskParams();
|
|
|
- taskParams.setPath(path);
|
|
|
- taskParams.setTaskType(1);
|
|
|
- taskParams.setRowList(mapList);
|
|
|
- taskParams.setUserId(String.valueOf(loginUtils.getId()));
|
|
|
- taskParams.setOldName(file.getOriginalFilename());
|
|
|
+ Sheet sheet1 = workbook.getSheetAt(0); // excel文件的工作簿的名称
|
|
|
+ // 不作处理时获取的行数
|
|
|
+ int total = sheet1.getLastRowNum();
|
|
|
+ ImportTask importTask =new ImportTask();
|
|
|
+ importTask.setImportCount(total);
|
|
|
+ importTask.setReportId(reportId);
|
|
|
+ importTask.insert();
|
|
|
+ List<List<Object>> fileHead =new ArrayList<>();
|
|
|
+ //解析excel文件并保存进map里
|
|
|
+ ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) ->
|
|
|
+ { if(rowIndex==0)
|
|
|
+ { fileHead.add(row);}
|
|
|
+ else {
|
|
|
+ List<Map<Object, Object>> mapList = new ArrayList<>();
|
|
|
+ mapList.add(IterUtil.toMap(fileHead.get(0),row));
|
|
|
+ TaskParams taskParams = new TaskParams();
|
|
|
+ taskParams.setPath(path);
|
|
|
+ taskParams.setTaskType(1);
|
|
|
+ taskParams.setRowList(mapList);
|
|
|
+ taskParams.setUserId(String.valueOf(loginUtils.getId()));
|
|
|
+ taskParams.setOldName(file.getOriginalFilename());
|
|
|
+ taskParams.setTotal(total);
|
|
|
+ taskParams.setIndex((int) rowIndex);
|
|
|
+ try {
|
|
|
+ String a= outInterfaceService.importPatents(taskParams);
|
|
|
+ WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
|
|
|
+ .setTaskId(taskParams.getTaskId())
|
|
|
+ .setComplete(true)
|
|
|
+ .setIndex((int) rowIndex)
|
|
|
+ .setTaskType(Constants.TASK_IMPORT_PATENT)
|
|
|
+ .setPercentage(100L)
|
|
|
+ .setFileName("")
|
|
|
+ .setOldName(taskParams.getOldName())
|
|
|
+ .setUrl("")
|
|
|
+ .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), taskParams.getUserId());
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ );
|
|
|
+ TaskParams taskParams =new TaskParams();
|
|
|
return taskParams;
|
|
|
}
|
|
|
|