|
@@ -1,10 +1,16 @@
|
|
|
package com.example.xiaoshiweixinback.service.exportPatent;
|
|
|
|
|
|
+import com.example.xiaoshiweixinback.business.exception.XiaoShiException;
|
|
|
import com.example.xiaoshiweixinback.business.utils.*;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.patent.PatentColumnDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.PatentConfigVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.PatentExportVO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.esConfig.EsConfigVO;
|
|
|
import com.example.xiaoshiweixinback.factorys.patentExportFactory.GetValueImp;
|
|
|
import com.example.xiaoshiweixinback.factorys.patentExportFactory.PatentExportFactory;
|
|
|
import com.example.xiaoshiweixinback.service.importPatent.CommonService;
|
|
|
+import com.example.xiaoshiweixinback.service.importPatent.EsPatentService;
|
|
|
+import com.example.xiaoshiweixinback.service.importPatent.excel.ExcuteDataToVOService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
@@ -34,142 +40,113 @@ public class PatentExportService {
|
|
|
private PatentExportFactory patentExportFactory;
|
|
|
@Autowired
|
|
|
private ParseByteToFileUtils parseByteToFileUtils;
|
|
|
+ @Autowired
|
|
|
+ private EsPatentService esPatentService;
|
|
|
|
|
|
-// /**
|
|
|
-// * 导出专利
|
|
|
-// *
|
|
|
-// * @param exportTask
|
|
|
-// * @return
|
|
|
-// * @throws IOException
|
|
|
-// */
|
|
|
-// @Async
|
|
|
-// public void exportPatent(ExportTaskDTO exportTask) throws IOException {
|
|
|
-// EsCustomFieldBatchVO EsVO = exportTask.getEsVO();
|
|
|
-// try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
-// String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
|
|
|
-// //selected字符串转PatentExportVO集合
|
|
|
-// List<PatentExportVO> selected = Optional.ofNullable(JsonUtils.jsonToList(esSelected, PatentExportVO.class))
|
|
|
-// .orElse(new ArrayList<>());
|
|
|
-// //导出文件名
|
|
|
-// if (selected.isEmpty()) {
|
|
|
-// throw new IllegalArgumentException("没有选择要导出的字段数据");
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 导出专利
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public String exportPatent(List<String> patentNos) throws IOException {
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
+ String patentExportJson = CommonService.readJsonFile("patentExport.json");
|
|
|
+// List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
//
|
|
|
-// //key的集合(标头:例如patentNo)
|
|
|
-// List<String> columns = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getValue).distinct().collect(Collectors.toList());
|
|
|
-// //name的集合
|
|
|
-// List<String> headers = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
|
|
|
-// if (columns.size() != headers.size()) {
|
|
|
-// throw new XiaoShiException("数量不匹配");
|
|
|
-// }
|
|
|
-// //新建工作簿
|
|
|
-// HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
|
|
|
-// //新建sheet页
|
|
|
-// HSSFSheet sheet = hssfWorkbook.createSheet();
|
|
|
-// sheet.setDefaultColumnWidth(30);
|
|
|
-// //新建标头行
|
|
|
-// HSSFRow headerRow = sheet.createRow(0);
|
|
|
-// headerRow.setHeight((short) 500);
|
|
|
-// //新建标头行格式
|
|
|
-// HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();
|
|
|
-// //新建普通行格式
|
|
|
-// HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();
|
|
|
-// //遍历设置标头
|
|
|
-// for (int i = 0; i < headers.size(); i++) {
|
|
|
-// HSSFCell cell = headerRow.createCell(i);
|
|
|
-// ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
-// headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
-// headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
-// headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
-// headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
-// headerCellStyle.setWrapText(true);
|
|
|
-// cell.setCellStyle(headerCellStyle);
|
|
|
-// cell.setCellValue(headers.get(i));
|
|
|
-// }
|
|
|
-// //根据projectId查询专利信息
|
|
|
-// List<String> patentNos = pdfExportFirstPageService.getPatentNo(EsVO);
|
|
|
-// if (patentNos.isEmpty()) {
|
|
|
-// throw new XiaoShiException("未获取到专利信息");
|
|
|
-// }
|
|
|
-// Integer total = patentNos.size();
|
|
|
-// Integer defaultNum = 0;
|
|
|
-// for (int i = 0; i < patentNos.size(); i++) {
|
|
|
-// Map<String, Object> map = new LinkedHashMap<>();
|
|
|
-// PatentNoVO patentNoVO = new PatentNoVO();
|
|
|
-// patentNoVO.setPatentNo(patentNos.get(i));
|
|
|
-// PatentColumnDTO patent = patentService.selectPatentDetail(patentNoVO);
|
|
|
-// if (patent == null) {
|
|
|
-// defaultNum++;
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// for (int j = 0; j < columns.size(); j++) {
|
|
|
-// String column = columns.get(j);
|
|
|
-// PatentExportVO patentExportVO = selected.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(new PatentExportVO());
|
|
|
-// // 使用反射获取属性值
|
|
|
-// Object value = GenerateObjectUtil.getPropertyValue(patent, patentExportVO.getValue());
|
|
|
-// 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);
|
|
|
-// if (getValueImp != null) {
|
|
|
-// String reValue = getValueImp.getValue(value);
|
|
|
-// map.put(patentExportVO.getName(), reValue);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //新建一普通行
|
|
|
-// HSSFRow row = sheet.createRow(i + 1);
|
|
|
-// row.setHeight((short) 800);
|
|
|
-// for (String key : map.keySet()) {
|
|
|
-// int index = headers.indexOf(key);
|
|
|
-// if (index != -1) {
|
|
|
-// HSSFCell cell = row.createCell(index);
|
|
|
-// ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
-// commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
-// commonCellStyle.setWrapText(true);
|
|
|
-// cell.setCellStyle(commonCellStyle);
|
|
|
-// if (StringUtils.isNotNull(map.get(key))) {
|
|
|
-// cell.setCellValue(String.valueOf(map.get(key)));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
|
|
|
-// webSocketMessageVO.setProjectId(EsVO.getProjectId());
|
|
|
-// webSocketMessageVO.setCreateId(exportTask.getCreateId());
|
|
|
-// webSocketMessageVO.setCode(602);
|
|
|
-// webSocketMessageVO.setAllNum(total);
|
|
|
-// webSocketMessageVO.setCurrentNum(i+1);
|
|
|
-// webSocketMessageVO.setTaskId(exportTask.getTaskId());
|
|
|
-// webSocketMessageVO.setState(1);
|
|
|
-// messageService.sendPatentExportMessage(webSocketMessageVO);
|
|
|
-// }
|
|
|
-// hssfWorkbook.write(out);
|
|
|
-// WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
|
|
|
-// webSocketMessageVO.setProjectId(EsVO.getProjectId());
|
|
|
-// webSocketMessageVO.setCreateId(exportTask.getCreateId());
|
|
|
-// webSocketMessageVO.setCode(603);
|
|
|
-// webSocketMessageVO.setAllNum(total);
|
|
|
-// webSocketMessageVO.setCurrentNum(total);
|
|
|
-// webSocketMessageVO.setTaskId(exportTask.getTaskId());
|
|
|
-// webSocketMessageVO.setState(2);
|
|
|
-// messageService.sendPatentExportMessage(webSocketMessageVO);
|
|
|
-// String fileGuid = "";
|
|
|
-// if (out.toByteArray() != null && out.toByteArray().length != 0) {
|
|
|
-// fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
|
|
|
-// }
|
|
|
-// exportTask.setFileGuid(fileGuid);
|
|
|
-// exportTask.setAllNum(total);
|
|
|
-// exportTask.setDefaultNum(defaultNum);
|
|
|
-// exportTask.setDoneNum(total - defaultNum);
|
|
|
-// exportTask.setState(2);
|
|
|
-// Integer taskId = importTaskService.updateExportTask(exportTask);
|
|
|
-// if (taskId == null) {
|
|
|
-// throw new XiaoShiException("导出记录失败");
|
|
|
-// }
|
|
|
-// } catch (FileNotFoundException e) {
|
|
|
-// throw new FileNotFoundException();
|
|
|
-// }
|
|
|
-// }
|
|
|
+// String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
|
|
|
+ //selected字符串转PatentExportVO集合
|
|
|
+ List<PatentExportVO> selected = Optional.ofNullable(JsonUtils.jsonToList(patentExportJson, PatentExportVO.class))
|
|
|
+ .orElse(new ArrayList<>());
|
|
|
+ //导出文件名
|
|
|
+ if (selected.isEmpty()) {
|
|
|
+ throw new IllegalArgumentException("没有选择要导出的字段数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ //key的集合(标头:例如patentNo)
|
|
|
+ List<String> columns = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getValue).distinct().collect(Collectors.toList());
|
|
|
+ //name的集合
|
|
|
+ List<String> headers = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
|
|
|
+ if (columns.size() != headers.size()) {
|
|
|
+ throw new XiaoShiException("数量不匹配");
|
|
|
+ }
|
|
|
+ //新建工作簿
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
|
|
|
+ //新建sheet页
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
+ //新建标头行
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
+ //新建标头行格式
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();
|
|
|
+ //新建普通行格式
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();
|
|
|
+ //遍历设置标头
|
|
|
+ for (int i = 0; i < headers.size(); i++) {
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
+ }
|
|
|
+ Integer total = patentNos.size();
|
|
|
+ Integer defaultNum = 0;
|
|
|
+ for (int i = 0; i < patentNos.size(); i++) {
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ PatentColumnDTO patent = esPatentService.selectPatentByAppNo(patentNos.get(i));
|
|
|
+ if (patent == null) {
|
|
|
+ defaultNum++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (int j = 0; j < columns.size(); j++) {
|
|
|
+ String column = columns.get(j);
|
|
|
+ PatentExportVO patentExportVO = selected.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(new PatentExportVO());
|
|
|
+ // 使用反射获取属性值
|
|
|
+ Object value = GenerateObjectUtil.getPropertyValue(patent, patentExportVO.getValue());
|
|
|
+ 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);
|
|
|
+ if (getValueImp != null) {
|
|
|
+ String reValue = getValueImp.getValue(value);
|
|
|
+ map.put(patentExportVO.getName(), reValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //新建一普通行
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);
|
|
|
+ row.setHeight((short) 800);
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ int index = headers.indexOf(key);
|
|
|
+ if (index != -1) {
|
|
|
+ HSSFCell cell = row.createCell(index);
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
+ if (StringUtils.isNotNull(map.get(key))) {
|
|
|
+ cell.setCellValue(String.valueOf(map.get(key)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ hssfWorkbook.write(out);
|
|
|
+ String fileGuid = "";
|
|
|
+ if (out.toByteArray() != null && out.toByteArray().length != 0) {
|
|
|
+ fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
|
|
|
+ }
|
|
|
+ return fileGuid;
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ throw new FileNotFoundException();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|