它是一个图片的地址,如何让渲染成功?源代码
List<ProductionSpecification> specList = productionSpecificationDataService.selectProductionSpecificationDataList(productionSpecificationData);
specList.forEach(spec->{
// 构建模板数据
Map<String, Object> data = new HashMap<>();
// 客户与项目信息
data.put("customerName", spec.getCustomerName());
data.put("projectName", spec.getProjectName());
data.put("batteryFinishedProductMaterialNumber", spec.getBatteryFinishedProductMaterialNumber());
data.put("pcbSemiFinishedProductMaterialNumber", spec.getPcbSemiFinishedProductMaterialNumber());
// 电芯信息
data.put("batteryCellBrand", spec.getBatteryCellBrand());
data.put("batteryCellModel", spec.getBatteryCellModel());
data.put("maxBatteryCellInternalResistance", spec.getMaxBatteryCellInternalResistance());
data.put("batteryCellGroupMaxInternalResistanceDifference", spec.getBatteryCellGroupMaxInternalResistanceDifference());
data.put("batteryCellGroupMaxVoltageDifference", spec.getBatteryCellGroupMaxVoltageDifference());
data.put("batteryCellGroupMaxCapacityDifference", spec.getBatteryCellGroupMaxCapacityDifference());
data.put("batteryCellPowerOnSequencePcb", spec.getBatteryCellPowerOnSequencePcb());
// PCB信息
data.put("pcbSilkScreen", spec.getPcbSilkScreen());
data.put("pcbMaterialNumber", spec.getPcbMaterialNumber());
// 充电保护设置
data.put("level1ChargeOvervoltageProtection", spec.getLevel1ChargeOvervoltageProtection());
data.put("level1ChargeOvervoltageProtectionDelay", spec.getLevel1ChargeOvervoltageProtectionDelay());
data.put("level1ChargeOvervoltageProtectionRelease", spec.getLevel1ChargeOvervoltageProtectionRelease());
data.put("level2ChargeOvervoltageProtection", spec.getLevel2ChargeOvervoltageProtection());
data.put("level2ChargeOvervoltageProtectionDelay", spec.getLevel2ChargeOvervoltageProtectionDelay());
// 放电保护设置
data.put("dischargeUndervoltageProtection", spec.getDischargeUndervoltageProtection());
data.put("dischargeUndervoltageProtectionDelay", spec.getDischargeUndervoltageProtectionDelay());
data.put("dischargeUndervoltageProtectionRelease", spec.getDischargeUndervoltageProtectionRelease());
// 过流保护设置
data.put("chargeOvercurrentProtection", spec.getChargeOvercurrentProtection());
data.put("chargeOvercurrentProtectionDelay", spec.getChargeOvercurrentProtectionDelay());
data.put("chargeOvercurrentRelease", spec.getChargeOvercurrentRelease());
data.put("level1DischargeOvercurrentProtection", spec.getLevel1DischargeOvercurrentProtection());
data.put("level1DischargeOvercurrentProtectionDelay", spec.getLevel1DischargeOvercurrentProtectionDelay());
data.put("level2DischargeOvercurrentProtection", spec.getLevel2DischargeOvercurrentProtection());
data.put("level2DischargeOvercurrentProtectionDelay", spec.getLevel2DischargeOvercurrentProtectionDelay());
// 短路保护
data.put("shortCircuitProtection", spec.getShortCircuitProtection());
data.put("shortCircuitProtectionDelay", spec.getShortCircuitProtectionDelay());
data.put("dischargeOvercurrentRelease", spec.getDischargeOvercurrentRelease());
// 阻抗与功耗
data.put("packInternalResistance", spec.getPackInternalResistance());
data.put("jpPointConnectivityTest", spec.getJpPointConnectivityTest());
data.put("ntc1ResistanceTest", spec.getNtc1ResistanceTest());
data.put("ntc2ResistanceTest", spec.getNtc2ResistanceTest());
data.put("bMinusToPMinusResistance", spec.getbMinusToPMinusResistance());
data.put("bPlusToPPositiveResistance", spec.getbPlusToPPositiveResistance());
data.put("operatingPowerConsumption", spec.getOperatingPowerConsumption());
data.put("sleepPowerConsumption", spec.getSleepPowerConsumption());
// 充放电状态
data.put("normalCharging", spec.getNormalCharging());
data.put("normalDischarging", spec.getNormalDischarging());
data.put("openCircuitVoltage", spec.getOpenCircuitVoltage());
// 充电模式
data.put("ccCvCharging", spec.getCcCvCharging());
// 活化流程
data.put("fullActivationStand", spec.getFullActivationStand());
data.put("constantCurrentDischarge", spec.getConstantCurrentDischarge());
data.put("fullActivationChargeToShipmentVoltage", spec.getFullActivationChargeToShipmentVoltage());
data.put("simpleActivationChargeToShipmentVoltage", spec.getSimpleActivationChargeToShipmentVoltage());
data.put("simpleActivationStand", spec.getSimpleActivationStand());
// 放电容量
data.put("dischargeCapacity", spec.getDischargeCapacity());
// 图纸链接
data.put("pcbSchematicDiagramTop", spec.getPcbSchematicDiagramTop());
data.put("pcbSchematicDiagramBottom", spec.getPcbSchematicDiagramBottom());
data.put("pcmPortDiagram", spec.getPcmPortDiagram());
data.put("batteryOutputPortDiagram", spec.getBatteryOutputPortDiagram());
data.put("ntcResistanceRTTable1", spec.getNtcResistanceRTTable1());
data.put("ntcResistanceRTTable2", spec.getNtcResistanceRTTable2());
// 测试方法勾选框
data.put("checkbox1", spec.getCheckbox1());
data.put("checkbox2", spec.getCheckbox2());
data.put("checkbox3", spec.getCheckbox3());
data.put("checkbox4", spec.getCheckbox4());
data.put("checkbox5", spec.getCheckbox5());
data.put("checkbox6", spec.getCheckbox6());
data.put("checkbox7", spec.getCheckbox7());
data.put("checkbox8", spec.getCheckbox8());
data.put("checkbox9", spec.getCheckbox9());
data.put("checkbox10", spec.getCheckbox10());
data.put("checkbox11", spec.getCheckbox11());
data.put("checkbox12", spec.getCheckbox12());
data.put("checkbox13", spec.getCheckbox13());
data.put("checkbox14", spec.getCheckbox14());
data.put("checkbox15", spec.getCheckbox15());
data.put("checkbox16", spec.getCheckbox16());
data.put("checkbox17", spec.getCheckbox17());
data.put("checkbox18", spec.getCheckbox18());
data.put("checkbox19", spec.getCheckbox19());
data.put("checkbox20", spec.getCheckbox20());
data.put("checkbox21", spec.getCheckbox21());
data.put("checkbox22", spec.getCheckbox22());
data.put("checkbox23", spec.getCheckbox23());
data.put("checkbox24", spec.getCheckbox24());
data.put("checkbox25", spec.getCheckbox25());
data.put("checkbox26", spec.getCheckbox26());
data.put("checkbox27", spec.getCheckbox27());
data.put("checkbox28", spec.getCheckbox28());
data.put("checkbox29", spec.getCheckbox29());
// 版本记录(拼接为字符串)
if (spec.getVersionRecordList() != null && !spec.getVersionRecordList().isEmpty()) {
StringBuilder versionRecords = new StringBuilder();
for (ProductionSpecificationVersionRecord record : spec.getVersionRecordList()) {
versionRecords.append("版本: ").append(record.getRevision())
.append(", 更新人: ").append(record.getUpdateBy())
.append(", 时间: ").append(record.getUpdateTime())
.append("\n");
}
data.put("versionRecords", versionRecords.toString());
}
// 加载模板
ClassPathResource resource = new ClassPathResource("templates/production_specification_temlate.docx");
try (InputStream in = resource.getInputStream()) {
XWPFTemplate template = XWPFTemplate.compile(in).render(data);
// 设置响应头
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=production_specification.docx");
// 输出文件
template.write(response.getOutputStream());
} catch (IOException e) {
// 处理异常,可以抛出运行时异常或返回错误响应
throw new RuntimeException("读取模板文件失败", e);
}
});
最新发布