模版导出

This commit is contained in:
hzj
2025-10-10 11:23:01 +08:00
parent 043eb653de
commit 7a7e0bd985
3 changed files with 33 additions and 7 deletions

View File

@@ -164,7 +164,7 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
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) {
e.printStackTrace();
}
@@ -358,7 +358,8 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
.distinct()
.count();
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "";
})
}).sorted(Comparator
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
// 用分号连接
.collect(Collectors.joining(StrUtil.COMMA));
bjReportDTO.setBusVoltageList(result);
@@ -385,7 +386,8 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
.distinct()
.count();
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "";
})
}).sorted(Comparator
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
// 用分号连接
.collect(Collectors.joining(StrUtil.COMMA));
strBuilderInner.append(resultContent).append(";");
@@ -415,7 +417,8 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
.distinct()
.count();
return pqsDicDataMap.get(scale).getDicName() + "母线" + busNum + "";
})
}).sorted(Comparator
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
// 用分号连接
.collect(Collectors.joining(StrUtil.COMMA));
return result;
@@ -431,11 +434,34 @@ public class EasyPoiWordExportServiceImpl implements EasyPoiWordExportService {
.distinct()
.count();
return busNum + ""+pqsDicDataMap.get(scale).getDicName() + "母线" ;
})
}).sorted(Comparator
.comparing(EasyPoiWordExportServiceImpl::extractVoltageNumber).reversed())
// 用分号连接
.collect(Collectors.joining(StrUtil.COMMA));
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){
Map<String, List<LedgerBaseInfoDTO>> scaleMap = ledgerList.stream().collect(Collectors.groupingBy(LedgerBaseInfoDTO::getScale));
String result = scaleMap.entrySet().stream()

View File

@@ -25,9 +25,9 @@ public class WordTemplate {
public static void main(String[] args) throws Exception {
// 模板文件路径
// 1. 处理模板路径并获取输入流
// String temPath = getTemplateInputStream("template/test.docx");
// String temPath = getTemplateInputStream("template/bj_report.docx");
// if (temPath == null) {
// throw new FileNotFoundException("模板文件不存在: template/test.docx");
// throw new FileNotFoundException("模板文件不存在: template/bj_report.docx");
// }
// // 准备数据
// Map<String, Object> map = new HashMap<>();

Binary file not shown.