fix:报告数据组装

This commit is contained in:
FCL
2025-12-25 10:28:32 +08:00
parent b4bfece4b3
commit 575e40773d
5 changed files with 55 additions and 96 deletions

View File

@@ -61,7 +61,7 @@ public class ReportDocumentMainController extends AbstractFileUploadController i
@Resource private ReportDocumentMainService reportDocumentMainService;
@Resource private ReportDocumentDataService reportDocumentDataService;
@Resource private ReportDocumentTypeService reportDocumentTypeService;
@Resource private ConfigUserSignatureService configUserSignatureService;
@Resource private DataTemplateService dataTemplateService;
@RequestMapping("/testAsyncTask")
@@ -181,58 +181,9 @@ public class ReportDocumentMainController extends AbstractFileUploadController i
//处理签名
String docSig = vo.getDocumentSignature();
if(!ObjectUtils.isEmpty(docSig)){
JSONObject docSigJson = JSONObject.parseObject(docSig);
List<Long> sigIds = new ArrayList<>();
docSigJson.forEach((key, value) -> {
JSONObject obj = docSigJson.getJSONObject( key);
String signatureId = obj.getString("signatureId");
if(!ObjectUtils.isEmpty(signatureId))
sigIds.add(Long.parseLong(signatureId));
});
if(!sigIds.isEmpty()){
List<ConfigUserSignatureDO> sigList = configUserSignatureService.getByIdList(sigIds);
docSigJson.forEach((key, value) -> {
JSONObject obj = docSigJson.getJSONObject( key);
String signatureId = obj.getString("signatureId");
if(!ObjectUtils.isEmpty(signatureId)){
ConfigUserSignatureDO sig = sigList.stream().filter(item -> item.getId().equals(Long.parseLong(signatureId))).findFirst().orElse(null);
if(sig != null){
String base64 = sig.getSignatureContent();
obj.put("signatureIdBase64", base64);
}
}
});
}
vo.setDocumentSignature(docSigJson.toJSONString());
}
//处理抬头数据
// if("true".equals(editFlag)){
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// String formData = vo.getFormData();
// JSONObject formDataJson = new JSONObject();
// if(!ObjectUtils.isEmpty(formData))
// formDataJson = JSONObject.parseObject(formData);
// List<ReportDocumentDataDO> dataList = reportDocumentDataService.listByMainDataId(id).getData();
// ReportDocumentTypeDO typeDO = reportDocumentTypeService.getReportDocumentType(reportDocumentMain.getReportDocumentTypeId());
// String customConfig = typeDO.getCustomConfig();
// String defaultConclusion = "";
// if(!ObjectUtils.isEmpty(customConfig)){
// JSONObject config = JSONObject.parseObject(customConfig);
// defaultConclusion = config.getString("defaultConclusion");
// }
// formDataJson.put("conclusion", defaultConclusion);
// if(!dataList.isEmpty())
// formDataJson.put("sampleName", dataList.get(0).getSampleName());
// //处理检测标准
// String standard = assembleStandard(dataList);
// formDataJson.put("standard", standard);
// formDataJson.put("reportTime", sdf.format(new Date()));
// vo.setFormData(formDataJson.toJSONString());
// }
String docSigJsonStr = reportDocumentDataService.assembleSignature(docSig);
if(!ObjectUtils.isEmpty(docSigJsonStr))
vo.setDocumentSignature(docSigJsonStr);
return success(vo);
}

View File

@@ -118,19 +118,9 @@ public class ReportDocumentAssistService {
CommonResult<JSONArray> result = reportDocumentDataService.assembleDynamicData(mainDO, typeDO, pageFlag);
JSONArray data = result.getData();
String templateContent = templateDO.getFormContent();
JSONObject templateData = new JSONObject();
JSONArray tableList = data.getJSONArray(0);
JSONObject headerData = new JSONObject();
if(tableList != null && !tableList.isEmpty())
headerData = tableList.getJSONObject(0).clone();
templateData.put("headerData", headerData);
templateData.put("tableList", tableList);
templateData.put("formData", mainDO.getFormData());
templateData.put("signatureData", mainDO.getDocumentSignature());
JSONObject bodyJson = new JSONObject();
bodyJson.put("Template", templateContent);
bodyJson.put("Data", templateData.toJSONString());
bodyJson.put("Data", data.toJSONString());
String bodyStr = bodyJson.toJSONString();
log.info("html2pdf body: " + bodyStr);
log.info("html2pdf--start at {}", LocalDateTime.now());
@@ -142,12 +132,9 @@ public class ReportDocumentAssistService {
InputStream inputStream = response.bodyStream(); // 关键:返回原始 InputStream
//尝试从响应头中提取文件名
// String contentDisposition = response.header("Content-Disposition");
String documentCode = mainDO.getDocumentCode();
if(documentCode == null) documentCode = "";
String filename = documentCode + "检测报告.pdf";
// String filename = extractFilename(contentDisposition).orElse(defaultName);
//inputStream转byte[]
byte[] fileBytes = IOUtils.toByteArray(inputStream);
//上传到文件服务
@@ -172,24 +159,4 @@ public class ReportDocumentAssistService {
reportDocumentFileService.createReportDocumentFile(fileSaveReqVO);
return BeanUtils.toBean(fileRespDTO, ReportDocumentFileDO.class);
}
// private Optional<String> extractFilename(String contentDisposition) {
// if (contentDisposition != null && contentDisposition.contains("filename=")) {
// String filename = contentDisposition.substring(contentDisposition.indexOf("filename=") + 9);
// filename = filename.replaceAll("\"", "").trim();
// return Optional.of(filename);
// }
// return Optional.empty();
// }
// private String encodeFilename(String filename) {
// try {
// return URLEncoder.encode(filename, StandardCharsets.UTF_8.toString())
// .replaceAll("\\+", "%20");
// } catch (Exception e) {
// return "download.bin";
// }
// }
}

View File

@@ -25,7 +25,7 @@ public interface ReportDocumentDataService {
CommonResult<Long> countMainDataId(Long mainDataId);
CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds);
String assembleSignature(String docSig);
/**
* 创建检测报告明细