|
@@ -9,6 +9,7 @@ import cn.cslg.report.common.model.vo.PersonnelVO;
|
|
|
import cn.cslg.report.common.model.vo.TaskParams;
|
|
|
import cn.cslg.report.common.utils.*;
|
|
|
import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
|
|
|
+import cn.cslg.report.entity.CompareFiles;
|
|
|
import cn.cslg.report.entity.ImportTask;
|
|
|
import cn.cslg.report.entity.Task;
|
|
|
import cn.cslg.report.service.business.ImportTaskService;
|
|
@@ -46,6 +47,7 @@ public class BaseService {
|
|
|
private final LoginUtils loginUtils;
|
|
|
private final CacheUtils cacheUtils;
|
|
|
private final ImportTaskService importTaskService;
|
|
|
+
|
|
|
/**
|
|
|
* @return 1.生成验证码的base64转码 2.生成的UUID 与Redis里面的验证码KEY值一致
|
|
|
* @title 获取验证码
|
|
@@ -161,8 +163,7 @@ public class BaseService {
|
|
|
try {
|
|
|
String resBody = outInterfaceService.getPartDepartmentFromPCS();
|
|
|
return resBody;
|
|
|
- }
|
|
|
- catch (Exception ex) {
|
|
|
+ } catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
log.error("权限系统获取部门列表失败,错误信息:" + LogExceptionUtil.getMessage(ex));
|
|
|
return Response.error(Constants.NET_ERROR);
|
|
@@ -201,6 +202,7 @@ public class BaseService {
|
|
|
return Response.error(Constants.NET_ERROR);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public String getPartPersonnelID(Integer id) {
|
|
|
try {
|
|
|
String resBody = outInterfaceService.getPartPersonnelID(id);
|
|
@@ -253,11 +255,11 @@ public class BaseService {
|
|
|
* @author lrj
|
|
|
*/
|
|
|
//获得
|
|
|
- public ImportTask getImportPatentTaskParamsBro(MultipartFile file,Integer reportId) throws IOException {
|
|
|
- Integer type =0;
|
|
|
- if(reportId==null){
|
|
|
- reportId =0;
|
|
|
- type=1;
|
|
|
+ public ImportTask getImportPatentTaskParamsBro(MultipartFile file, Integer reportId) throws IOException {
|
|
|
+ Integer type = 0;
|
|
|
+ if (reportId == null) {
|
|
|
+ reportId = 0;
|
|
|
+ type = 1;
|
|
|
}
|
|
|
//上传文档
|
|
|
UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
@@ -270,14 +272,14 @@ public class BaseService {
|
|
|
// excel类型
|
|
|
if (fileName.endsWith(".xls")) {
|
|
|
workbook = new HSSFWorkbook(fileInputStream);
|
|
|
- } else if (fileName.endsWith(".xlsx")||fileName.endsWith(".XLSX")) {
|
|
|
+ } else if (fileName.endsWith(".xlsx") || fileName.endsWith(".XLSX")) {
|
|
|
workbook = new XSSFWorkbook(fileInputStream);
|
|
|
}
|
|
|
Sheet sheet1 = workbook.getSheetAt(0); // excel文件的工作簿的名称
|
|
|
// 不作处理时获取的行数
|
|
|
int total = sheet1.getLastRowNum();
|
|
|
- PersonnelVO personnelVO =cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
- ImportTask importTask =new ImportTask();
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ ImportTask importTask = new ImportTask();
|
|
|
importTask.setImportCount(total);
|
|
|
importTask.setReportId(reportId);
|
|
|
importTask.setState(0);
|
|
@@ -292,65 +294,75 @@ public class BaseService {
|
|
|
|
|
|
|
|
|
@Async()
|
|
|
- public void uploadToPCS(ImportTask importTask){
|
|
|
- Integer total =importTask.getImportCount();
|
|
|
- List<List<Object>> fileHead =new ArrayList<>();
|
|
|
+ public void uploadToPCS(ImportTask importTask, Boolean asCompare) {
|
|
|
+ Integer total = importTask.getImportCount();
|
|
|
+ List<List<Object>> fileHead = new ArrayList<>();
|
|
|
//解析excel文件并保存进map里
|
|
|
- ExcelUtil.readBySax(fileUtils.getSystemPath()+importTask.getFilePath(), -1, (sheetIndex, rowIndex, row) ->
|
|
|
- { if(rowIndex==0)
|
|
|
- { fileHead.add(row);}
|
|
|
- else {
|
|
|
- Integer i = Math.toIntExact(rowIndex-1);
|
|
|
- List<Map<Object, Object>> mapList = new ArrayList<>();
|
|
|
- mapList.add(IterUtil.toMap(fileHead.get(0),row));
|
|
|
- TaskParams taskParams = new TaskParams();
|
|
|
- taskParams.setPath(fileUtils.getSystemPath()+importTask.getFilePath());
|
|
|
- taskParams.setTaskType(1);
|
|
|
- taskParams.setOldName(importTask.getTaskName());
|
|
|
- taskParams.setTotal(importTask.getImportCount());
|
|
|
- taskParams.setTaskId(importTask.getId());
|
|
|
- taskParams.setRowList(mapList);
|
|
|
- taskParams.setUserId(String.valueOf(importTask.getCreateUserId()));
|
|
|
- taskParams.setIndex((int) rowIndex);
|
|
|
- try {
|
|
|
- String res = outInterfaceService.importPatents(taskParams);
|
|
|
- JSONObject jsonObject =JSONObject.parseObject(res);
|
|
|
- if(jsonObject.get("code").toString().equals("0")){
|
|
|
- importTask.setState(3);
|
|
|
- importTask.updateById();
|
|
|
- WebSocketServer.sendInfo(Response.error("部分数据上传成功" + "\n" + "成功条数:" + i + "失败条数:" + (total-i)),taskParams.getUserId());
|
|
|
- throw new PermissionException("上传失败");
|
|
|
- }
|
|
|
- if((int) rowIndex==taskParams.getTotal())
|
|
|
- {
|
|
|
- importTask.setState(1);
|
|
|
- SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ ExcelUtil.readBySax(fileUtils.getSystemPath() + importTask.getFilePath(), -1, (sheetIndex, rowIndex, row) ->
|
|
|
+ {
|
|
|
+ if (rowIndex == 0) {
|
|
|
+ fileHead.add(row);
|
|
|
+ } else {
|
|
|
+ Integer i = Math.toIntExact(rowIndex - 1);
|
|
|
+ List<Map<Object, Object>> mapList = new ArrayList<>();
|
|
|
+ mapList.add(IterUtil.toMap(fileHead.get(0), row));
|
|
|
+ TaskParams taskParams = new TaskParams();
|
|
|
+ taskParams.setPath(fileUtils.getSystemPath() + importTask.getFilePath());
|
|
|
+ taskParams.setTaskType(1);
|
|
|
+ taskParams.setOldName(importTask.getTaskName());
|
|
|
+ taskParams.setTotal(importTask.getImportCount());
|
|
|
+ taskParams.setTaskId(importTask.getId());
|
|
|
+ taskParams.setRowList(mapList);
|
|
|
+ taskParams.setUserId(String.valueOf(importTask.getCreateUserId()));
|
|
|
+ taskParams.setIndex((int) rowIndex);
|
|
|
+ try {
|
|
|
+ String res = outInterfaceService.importPatents(taskParams);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject.get("code").toString().equals("0")) {
|
|
|
+ importTask.setState(3);
|
|
|
+ importTask.updateById();
|
|
|
+ WebSocketServer.sendInfo(Response.error("部分数据上传成功" + "\n" + "成功条数:" + i + "失败条数:" + (total - i)), taskParams.getUserId());
|
|
|
+ throw new PermissionException("上传失败");
|
|
|
+ }
|
|
|
+ //判断是否直接作为对比文件
|
|
|
+ if (asCompare) {
|
|
|
+ if (jsonObject.get("code").toString().equals("200")) {
|
|
|
+ CompareFiles compareFiles =new CompareFiles();
|
|
|
+ compareFiles.setReportId(importTask.getReportId());
|
|
|
+ compareFiles.setPatentNo(jsonObject.get("data").toString());
|
|
|
+ compareFiles.insert();
|
|
|
|
|
|
- Date date = new Date(System.currentTimeMillis());
|
|
|
- importTask.setFinishTime(formatter.parse(formatter.format(date)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ((int) rowIndex == taskParams.getTotal()) {
|
|
|
+ importTask.setState(1);
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ Date date = new Date(System.currentTimeMillis());
|
|
|
+ importTask.setFinishTime(formatter.parse(formatter.format(date)));
|
|
|
+ importTask.updateById();
|
|
|
+ }
|
|
|
+
|
|
|
+ //通过WebSocket 在每一次循环结束后 向前端发送完成进度
|
|
|
+ WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
|
|
|
+ .setTaskId(taskParams.getTaskId())
|
|
|
+ .setComplete(false)
|
|
|
+ .setIndex((int) rowIndex)
|
|
|
+ .setTaskType(Constants.TASK_IMPORT_PATENT)
|
|
|
+ .setPercentage(total == 0 ? 0 : Math.round((total.equals(i) ? (i * 1D) : (i + 1D)) / total * 100D))
|
|
|
+ .setFileName("")
|
|
|
+ .setOldName(taskParams.getOldName())
|
|
|
+ .setUrl("")
|
|
|
+ .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), taskParams.getUserId());
|
|
|
+ } catch (IOException | ParseException e) {
|
|
|
+ importTask.setState(3);
|
|
|
importTask.updateById();
|
|
|
+ e.printStackTrace();
|
|
|
+ WebSocketServer.sendInfo(Response.error("部分数据上传成功" + "\n" + "成功条数:" + i + "失败条数:" + (total - i)), taskParams.getUserId());
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- //通过WebSocket 在每一次循环结束后 向前端发送完成进度
|
|
|
- WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
|
|
|
- .setTaskId(taskParams.getTaskId())
|
|
|
- .setComplete(false)
|
|
|
- .setIndex((int) rowIndex)
|
|
|
- .setTaskType(Constants.TASK_IMPORT_PATENT)
|
|
|
- .setPercentage(total == 0 ? 0 : Math.round((total.equals(i) ? (i * 1D) : (i + 1D)) / total * 100D))
|
|
|
- .setFileName("")
|
|
|
- .setOldName(taskParams.getOldName())
|
|
|
- .setUrl("")
|
|
|
- .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), taskParams.getUserId());
|
|
|
- } catch (IOException | ParseException e) {
|
|
|
- importTask.setState(3);
|
|
|
- importTask.updateById();
|
|
|
- e.printStackTrace();
|
|
|
- WebSocketServer.sendInfo(Response.error("部分数据上传成功" + "\n" + "成功条数:" + i + "失败条数:" + (total-i)),taskParams.getUserId());
|
|
|
- return;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
);
|
|
|
WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
|
|
|
.setTaskId(importTask.getId())
|
|
@@ -362,9 +374,9 @@ public class BaseService {
|
|
|
.setOldName(importTask.getTaskName())
|
|
|
.setUrl("")
|
|
|
.setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), String.valueOf(importTask.getCreateUserId()));
|
|
|
- ImportTask importTask1 = importTaskService.getById(importTask.getId());
|
|
|
- importTask1.setState(2);
|
|
|
- importTask1.updateById();
|
|
|
+ ImportTask importTask1 = importTaskService.getById(importTask.getId());
|
|
|
+ importTask1.setState(2);
|
|
|
+ importTask1.updateById();
|
|
|
|
|
|
}
|
|
|
|