|
@@ -51,41 +51,30 @@ public class PatentExportService {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
@Async
|
|
@Async
|
|
- public String exportPatent(List<String> patentNos) throws IOException {
|
|
|
|
|
|
+ public byte[] exportPatent(List<String> patentNos) throws IOException {
|
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
- String patentExportJson = CommonService.readJsonFile("patentExport.json");
|
|
|
|
-// List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
|
-//
|
|
|
|
-// String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
|
|
|
|
|
|
+ String patentExportJson = ExcuteConfigUtils.excuteConfigJson();
|
|
//selected字符串转PatentExportVO集合
|
|
//selected字符串转PatentExportVO集合
|
|
- List<PatentExportVO> selected = Optional.ofNullable(JsonUtils.jsonToList(patentExportJson, PatentExportVO.class))
|
|
|
|
|
|
+ List<PatentExportVO> patentExportVOS = Optional.ofNullable(JsonUtils.jsonToList(patentExportJson, PatentExportVO.class))
|
|
.orElse(new ArrayList<>());
|
|
.orElse(new ArrayList<>());
|
|
- //导出文件名
|
|
|
|
- if (selected.isEmpty()) {
|
|
|
|
- throw new IllegalArgumentException("没有选择要导出的字段数据");
|
|
|
|
|
|
+ if (patentExportVOS.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());
|
|
|
|
|
|
+ //字段名 key的集合(标头:例如patentNo)
|
|
|
|
+ List<String> columns = patentExportVOS.stream().map(PatentExportVO::getValue).distinct().collect(Collectors.toList());
|
|
|
|
+ //中文 name的集合
|
|
|
|
+ List<String> headers = patentExportVOS.stream().map(PatentExportVO::getName).collect(Collectors.toList());
|
|
if (columns.size() != headers.size()) {
|
|
if (columns.size() != headers.size()) {
|
|
- throw new XiaoShiException("数量不匹配");
|
|
|
|
|
|
+ throw new XiaoShiException("字段数不匹配");
|
|
}
|
|
}
|
|
- //新建工作簿
|
|
|
|
- HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
|
|
|
|
- //新建sheet页
|
|
|
|
- HSSFSheet sheet = hssfWorkbook.createSheet();
|
|
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
sheet.setDefaultColumnWidth(30);
|
|
sheet.setDefaultColumnWidth(30);
|
|
- //新建标头行
|
|
|
|
- HSSFRow headerRow = sheet.createRow(0);
|
|
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
headerRow.setHeight((short) 500);
|
|
headerRow.setHeight((short) 500);
|
|
- //新建标头行格式
|
|
|
|
- HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();
|
|
|
|
- //新建普通行格式
|
|
|
|
- HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();
|
|
|
|
- //遍历设置标头
|
|
|
|
- for (int i = 0; i < headers.size(); i++) {
|
|
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
HSSFCell cell = headerRow.createCell(i);
|
|
HSSFCell cell = headerRow.createCell(i);
|
|
ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
@@ -96,21 +85,31 @@ public class PatentExportService {
|
|
cell.setCellStyle(headerCellStyle);
|
|
cell.setCellStyle(headerCellStyle);
|
|
cell.setCellValue(headers.get(i));
|
|
cell.setCellValue(headers.get(i));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
Integer total = patentNos.size();
|
|
Integer total = patentNos.size();
|
|
Integer defaultNum = 0;
|
|
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<>();
|
|
|
|
+
|
|
|
|
+ //获取专利信息
|
|
PatentColumnDTO patent = esPatentService.selectPatentByAppNo(patentNos.get(i));
|
|
PatentColumnDTO patent = esPatentService.selectPatentByAppNo(patentNos.get(i));
|
|
if (patent == null) {
|
|
if (patent == null) {
|
|
defaultNum++;
|
|
defaultNum++;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //遍历字段 配置map集合
|
|
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());
|
|
|
|
- // 使用反射获取属性值
|
|
|
|
|
|
+ //解析出的patentExportVOS根据value匹配column字段,拿出对应字段的配置
|
|
|
|
+ PatentExportVO patentExportVO = patentExportVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(new PatentExportVO());
|
|
|
|
+ //使用反射获取属性值 (例如:title->patent.getTitile())
|
|
Object value = GenerateObjectUtil.getPropertyValue(patent, patentExportVO.getValue());
|
|
Object value = GenerateObjectUtil.getPropertyValue(patent, patentExportVO.getValue());
|
|
if (value != null) {
|
|
if (value != null) {
|
|
|
|
+ //解析专利配置文件
|
|
String json = CommonService.readJsonFile("patent.json");
|
|
String json = CommonService.readJsonFile("patent.json");
|
|
List<PatentConfigVO> patentConfigVOS = JSON.parseArray(json, PatentConfigVO.class);
|
|
List<PatentConfigVO> patentConfigVOS = JSON.parseArray(json, PatentConfigVO.class);
|
|
PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
|
|
PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
|
|
@@ -122,15 +121,18 @@ public class PatentExportService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //新建一普通行
|
|
|
|
- HSSFRow row = sheet.createRow(i + 1);
|
|
|
|
|
|
+
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
row.setHeight((short) 800);
|
|
row.setHeight((short) 800);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //填入数据
|
|
for (String key : map.keySet()) {
|
|
for (String key : map.keySet()) {
|
|
int index = headers.indexOf(key);
|
|
int index = headers.indexOf(key);
|
|
if (index != -1) {
|
|
if (index != -1) {
|
|
HSSFCell cell = row.createCell(index);
|
|
HSSFCell cell = row.createCell(index);
|
|
ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
- commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
commonCellStyle.setWrapText(true);
|
|
commonCellStyle.setWrapText(true);
|
|
cell.setCellStyle(commonCellStyle);
|
|
cell.setCellStyle(commonCellStyle);
|
|
if (StringUtils.isNotNull(map.get(key))) {
|
|
if (StringUtils.isNotNull(map.get(key))) {
|
|
@@ -140,11 +142,7 @@ public class PatentExportService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
hssfWorkbook.write(out);
|
|
hssfWorkbook.write(out);
|
|
- String fileGuid = "";
|
|
|
|
- if (out.toByteArray() != null && out.toByteArray().length != 0) {
|
|
|
|
- fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
|
|
|
|
- }
|
|
|
|
- return fileGuid;
|
|
|
|
|
|
+ return out.toByteArray();
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
throw new FileNotFoundException();
|
|
throw new FileNotFoundException();
|
|
}
|
|
}
|