|
@@ -1,18 +1,19 @@
|
|
package cn.cslg.pas.service.business;
|
|
package cn.cslg.pas.service.business;
|
|
|
|
|
|
-import cn.cslg.pas.common.core.base.Constants;
|
|
|
|
|
|
+import cn.cslg.pas.common.dto.ExportTaskDTO;
|
|
import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
-import cn.cslg.pas.common.dto.PatentDTO;
|
|
|
|
import cn.cslg.pas.common.dto.PatentExport.PatentExportVO;
|
|
import cn.cslg.pas.common.dto.PatentExport.PatentExportVO;
|
|
-import cn.cslg.pas.common.dto.PatentExport.TaskParams;
|
|
|
|
-import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
|
import cn.cslg.pas.common.utils.*;
|
|
import cn.cslg.pas.common.utils.*;
|
|
-import cn.cslg.pas.common.vo.TaskWebSocketDTO;
|
|
|
|
|
|
+import cn.cslg.pas.common.vo.ConfigVOS.PatentConfigVO;
|
|
|
|
+import cn.cslg.pas.common.vo.WebSocketMessageVO;
|
|
import cn.cslg.pas.common.vo.business.PatentNoVO;
|
|
import cn.cslg.pas.common.vo.business.PatentNoVO;
|
|
import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
|
|
import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
|
|
+import cn.cslg.pas.factorys.PatentExportFactory.GetValueImp;
|
|
|
|
+import cn.cslg.pas.factorys.PatentExportFactory.PatentExportFactory;
|
|
import cn.cslg.pas.service.business.es.EsPatentService;
|
|
import cn.cslg.pas.service.business.es.EsPatentService;
|
|
-import cn.cslg.pas.service.business.es.EsService;
|
|
|
|
|
|
+import cn.cslg.pas.service.common.MessageService;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
@@ -20,6 +21,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
@@ -29,6 +31,7 @@ import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * Excel导出专利
|
|
* @Author xiexiang
|
|
* @Author xiexiang
|
|
* @Date 2024/1/3
|
|
* @Date 2024/1/3
|
|
*/
|
|
*/
|
|
@@ -37,26 +40,32 @@ import java.util.stream.Collectors;
|
|
public class PatentExportService {
|
|
public class PatentExportService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private FileUtils fileUtils;
|
|
|
|
|
|
+ private PDFExportFirstPageService pdfExportFirstPageService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private EsService esService;
|
|
|
|
|
|
+ private EsPatentService patentService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private PDFExportFirstPageService pdfExportFirstPageService;
|
|
|
|
|
|
+ private MessageService messageService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private EsPatentService patentService;
|
|
|
|
|
|
+ private PatentExportFactory patentExportFactory;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ParseByteToFileUtils parseByteToFileUtils;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ImportTaskService importTaskService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 导出专利
|
|
* 导出专利
|
|
|
|
+ *
|
|
* @param EsVO
|
|
* @param EsVO
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public byte[] exportPatent(EsCustomFieldBatchVO EsVO) throws IOException {
|
|
|
|
|
|
+ @Async
|
|
|
|
+ public void exportPatent(EsCustomFieldBatchVO EsVO) throws IOException {
|
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
|
|
String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
|
|
//selected字符串转PatentExportVO集合
|
|
//selected字符串转PatentExportVO集合
|
|
@@ -101,25 +110,33 @@ public class PatentExportService {
|
|
//根据projectId查询专利信息
|
|
//根据projectId查询专利信息
|
|
List<String> patentNos = pdfExportFirstPageService.getPatentNo(EsVO);
|
|
List<String> patentNos = pdfExportFirstPageService.getPatentNo(EsVO);
|
|
if (patentNos.isEmpty()) {
|
|
if (patentNos.isEmpty()) {
|
|
- return null;
|
|
|
|
|
|
+ throw new XiaoShiException("未获取到专利信息");
|
|
}
|
|
}
|
|
|
|
+ Integer total = patentNos.size();
|
|
|
|
+ Integer defaultNum = 0;
|
|
for (int i = 0; i < patentNos.size(); i++) {
|
|
for (int i = 0; i < patentNos.size(); i++) {
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
PatentNoVO patentNoVO = new PatentNoVO();
|
|
PatentNoVO patentNoVO = new PatentNoVO();
|
|
patentNoVO.setPatentNo(patentNos.get(i));
|
|
patentNoVO.setPatentNo(patentNos.get(i));
|
|
-
|
|
|
|
PatentColumnDTO patent = patentService.selectPatentDetail(patentNoVO);
|
|
PatentColumnDTO patent = patentService.selectPatentDetail(patentNoVO);
|
|
-
|
|
|
|
if (patent == null) {
|
|
if (patent == null) {
|
|
|
|
+ defaultNum++;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
-
|
|
|
|
for (int j = 0; j < columns.size(); j++) {
|
|
for (int j = 0; j < columns.size(); j++) {
|
|
String column = columns.get(j);
|
|
String column = columns.get(j);
|
|
PatentExportVO patentExportVO = selected.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(new PatentExportVO());
|
|
PatentExportVO patentExportVO = selected.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(new PatentExportVO());
|
|
// 使用反射获取属性值
|
|
// 使用反射获取属性值
|
|
Object value = GenerateObjectUtil.getPropertyValue(patent, patentExportVO.getValue());
|
|
Object value = GenerateObjectUtil.getPropertyValue(patent, patentExportVO.getValue());
|
|
- map.put(patentExportVO.getName(), value);
|
|
|
|
|
|
+ if (value != null) {
|
|
|
|
+ String json = CommonService.readJsonFile("patent.json");
|
|
|
|
+ List<PatentConfigVO> patentConfigVOS = JSON.parseArray(json, PatentConfigVO.class);
|
|
|
|
+ PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
|
|
|
|
+ String exportClass = patentConfigVO.getExportClass();
|
|
|
|
+ GetValueImp getValueImp = patentExportFactory.getClass(exportClass);
|
|
|
|
+ String reValue = getValueImp.getValue(value);
|
|
|
|
+ map.put(patentExportVO.getName(), reValue);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
//新建一普通行
|
|
//新建一普通行
|
|
HSSFRow row = sheet.createRow(i + 1);
|
|
HSSFRow row = sheet.createRow(i + 1);
|
|
@@ -137,17 +154,41 @@ public class PatentExportService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ WebSocketMessageVO webSocketMessageVO =new WebSocketMessageVO();
|
|
|
|
+ webSocketMessageVO.setProjectId(EsVO.getProjectId());
|
|
|
|
+ webSocketMessageVO.setCreateId("328");
|
|
|
|
+ webSocketMessageVO.setCode(602);
|
|
|
|
+ webSocketMessageVO.setAllNum(total);
|
|
|
|
+ webSocketMessageVO.setCurrentNum(i+1);
|
|
|
|
+ webSocketMessageVO.setState(1);
|
|
|
|
+ messageService.sendPatentExportMessage(webSocketMessageVO);
|
|
}
|
|
}
|
|
hssfWorkbook.write(out);
|
|
hssfWorkbook.write(out);
|
|
- return out.toByteArray();
|
|
|
|
-
|
|
|
|
|
|
+ WebSocketMessageVO webSocketMessageVO =new WebSocketMessageVO();
|
|
|
|
+ webSocketMessageVO.setProjectId(EsVO.getProjectId());
|
|
|
|
+ webSocketMessageVO.setCreateId("328");
|
|
|
|
+ webSocketMessageVO.setAllNum(total);
|
|
|
|
+ webSocketMessageVO.setCurrentNum(total);
|
|
|
|
+ webSocketMessageVO.setState(2);
|
|
|
|
+ messageService.sendPatentExportMessage(webSocketMessageVO);
|
|
|
|
+ String fileGuid = "";
|
|
|
|
+ if (out.toByteArray() != null && out.toByteArray().length != 0) {
|
|
|
|
+ fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray());
|
|
|
|
+ }
|
|
|
|
+ ExportTaskDTO exportTaskDTO = new ExportTaskDTO();
|
|
|
|
+ exportTaskDTO.setProjectId(EsVO.getProjectId());
|
|
|
|
+ exportTaskDTO.setType(6);
|
|
|
|
+ exportTaskDTO.setFileGuid(fileGuid);
|
|
|
|
+ exportTaskDTO.setAllNum(total);
|
|
|
|
+ exportTaskDTO.setDefaultNum(defaultNum);
|
|
|
|
+ Integer taskId = importTaskService.addExportExcel(exportTaskDTO);
|
|
|
|
+ if (taskId == null) {
|
|
|
|
+ throw new XiaoShiException("导出记录失败");
|
|
|
|
+ }
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
throw new FileNotFoundException();
|
|
throw new FileNotFoundException();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|