模版导出
This commit is contained in:
@@ -164,7 +164,7 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
|
|||||||
|
|
||||||
Map<String,Object> map = mapper.convertValue(bjReportDTO,Map.class);
|
Map<String,Object> map = mapper.convertValue(bjReportDTO,Map.class);
|
||||||
|
|
||||||
WordTemplate.generateWordDownload("template/test.docx", response, bjReportDTO.getDateFormat()+"重要敏感用户电压暂降事件监测情况.docx", map);
|
WordTemplate.generateWordDownload("template/bj_report.docx", response, bjReportDTO.getDateFormat()+"重要敏感用户电压暂降事件监测情况.docx", map);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,8 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.count();
|
.count();
|
||||||
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "条";
|
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "条";
|
||||||
})
|
}).sorted(Comparator
|
||||||
|
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
|
||||||
// 用分号连接
|
// 用分号连接
|
||||||
.collect(Collectors.joining(StrUtil.COMMA));
|
.collect(Collectors.joining(StrUtil.COMMA));
|
||||||
bjReportDTO.setBusVoltageList(result);
|
bjReportDTO.setBusVoltageList(result);
|
||||||
@@ -385,7 +386,8 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.count();
|
.count();
|
||||||
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "条";
|
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "条";
|
||||||
})
|
}).sorted(Comparator
|
||||||
|
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
|
||||||
// 用分号连接
|
// 用分号连接
|
||||||
.collect(Collectors.joining(StrUtil.COMMA));
|
.collect(Collectors.joining(StrUtil.COMMA));
|
||||||
strBuilderInner.append(resultContent).append(";");
|
strBuilderInner.append(resultContent).append(";");
|
||||||
@@ -415,7 +417,8 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.count();
|
.count();
|
||||||
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "条";
|
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "条";
|
||||||
})
|
}).sorted(Comparator
|
||||||
|
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
|
||||||
// 用分号连接
|
// 用分号连接
|
||||||
.collect(Collectors.joining(StrUtil.COMMA));
|
.collect(Collectors.joining(StrUtil.COMMA));
|
||||||
return result;
|
return result;
|
||||||
@@ -431,11 +434,34 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.count();
|
.count();
|
||||||
return busNum + "条"+pqsDicDataMap.get(scale).getDicName() + "母线" ;
|
return busNum + "条"+pqsDicDataMap.get(scale).getDicName() + "母线" ;
|
||||||
})
|
}).sorted(Comparator
|
||||||
|
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
|
||||||
// 用分号连接
|
// 用分号连接
|
||||||
.collect(Collectors.joining(StrUtil.COMMA));
|
.collect(Collectors.joining(StrUtil.COMMA));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 提取kV前的数字(核心方法)
|
||||||
|
*/
|
||||||
|
public static Integer extractVoltageNumber(String text) {
|
||||||
|
if (text == null || text.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用正则表达式匹配数字+kV的模式
|
||||||
|
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("(\\d+)kV");
|
||||||
|
java.util.regex.Matcher matcher = pattern.matcher(text);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(matcher.group(1));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("数字格式错误: " + matcher.group(1));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private String stationVoltageDeal(List<LedgerBaseInfoDTO> ledgerList,Map<String,PqsDicData> pqsDicDataMap){
|
private String stationVoltageDeal(List<LedgerBaseInfoDTO> ledgerList,Map<String,PqsDicData> pqsDicDataMap){
|
||||||
Map<String, List<LedgerBaseInfoDTO>> scaleMap = ledgerList.stream().collect(Collectors.groupingBy(LedgerBaseInfoDTO::getScale));
|
Map<String, List<LedgerBaseInfoDTO>> scaleMap = ledgerList.stream().collect(Collectors.groupingBy(LedgerBaseInfoDTO::getScale));
|
||||||
String result = scaleMap.entrySet().stream()
|
String result = scaleMap.entrySet().stream()
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ public class WordTemplate {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// 模板文件路径
|
// 模板文件路径
|
||||||
// 1. 处理模板路径并获取输入流
|
// 1. 处理模板路径并获取输入流
|
||||||
// String temPath = getTemplateInputStream("template/test.docx");
|
// String temPath = getTemplateInputStream("template/bj_report.docx");
|
||||||
// if (temPath == null) {
|
// if (temPath == null) {
|
||||||
// throw new FileNotFoundException("模板文件不存在: template/test.docx");
|
// throw new FileNotFoundException("模板文件不存在: template/bj_report.docx");
|
||||||
// }
|
// }
|
||||||
// // 准备数据
|
// // 准备数据
|
||||||
// Map<String, Object> map = new HashMap<>();
|
// Map<String, Object> map = new HashMap<>();
|
||||||
|
|||||||
BIN
event_smart/src/main/resources/template/bj_report.docx
Normal file
BIN
event_smart/src/main/resources/template/bj_report.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user