fix:报告数据组装
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface ReportDocumentDataService {
|
||||
CommonResult<Long> countMainDataId(Long mainDataId);
|
||||
CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds);
|
||||
|
||||
|
||||
String assembleSignature(String docSig);
|
||||
|
||||
/**
|
||||
* 创建检测报告明细
|
||||
|
||||
@@ -3,19 +3,24 @@ package com.zt.plat.module.qms.business.reportdoc.service;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import com.zt.plat.module.qms.business.config.controller.vo.ConfigReportFieldPageReqVO;
|
||||
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigReportFieldDO;
|
||||
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigUserSignatureDO;
|
||||
import com.zt.plat.module.qms.business.config.service.ConfigReportFieldService;
|
||||
import com.zt.plat.module.qms.business.config.service.ConfigUserSignatureService;
|
||||
import com.zt.plat.module.qms.business.reportdoc.controller.vo.*;
|
||||
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentMainDO;
|
||||
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentTypeDO;
|
||||
import com.zt.plat.module.qms.business.reportdoc.dal.mapper.ReportDocumentDataMapper;
|
||||
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentDataDO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -37,10 +42,12 @@ import static com.zt.plat.module.qms.enums.QmsCommonConstant.FIELD_FIXED;
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class ReportDocumentDataServiceImpl implements ReportDocumentDataService {
|
||||
|
||||
@Resource private ReportDocumentDataMapper reportDocumentDataMapper;
|
||||
@Resource private ConfigReportFieldService configReportFieldService;
|
||||
@Resource private ConfigUserSignatureService configUserSignatureService;
|
||||
private final String colPrefix = "col";
|
||||
private final String sampleCodeKey = "SMP_CD";
|
||||
private final String sampleNameKey = "SMP_NAME";
|
||||
@@ -247,12 +254,13 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
|
||||
JSONArray result = new JSONArray();
|
||||
String formData = mainData.getFormData();
|
||||
String signatureData = mainData.getDocumentSignature();
|
||||
String signatureJsonStr = assembleSignature(signatureData);
|
||||
JSONObject formDataJson = new JSONObject();
|
||||
JSONObject signatureDataJson = new JSONObject();
|
||||
boolean hasSignatureData = false;
|
||||
if(!ObjectUtils.isEmpty(formData))
|
||||
formDataJson = JSONObject.parseObject(formData);
|
||||
if(!ObjectUtils.isEmpty(signatureData))
|
||||
signatureDataJson = JSONObject.parseObject(signatureData);
|
||||
if(!ObjectUtils.isEmpty(signatureJsonStr))
|
||||
hasSignatureData = true;
|
||||
for(int i=0;i<pageRowList.size();i++){
|
||||
JSONArray rows = pageRowList.getJSONArray(i);
|
||||
JSONObject resultData = new JSONObject();
|
||||
@@ -264,11 +272,12 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
|
||||
}
|
||||
resultData.put("headerData", headerData);
|
||||
resultData.put("tableList", rows);
|
||||
resultData.put("formData", formDataJson);
|
||||
resultData.put("signatureData", signatureDataJson);
|
||||
resultData.put("formData", formDataJson.clone());
|
||||
if(hasSignatureData)
|
||||
resultData.put("signatureData", JSONObject.parseObject(signatureJsonStr));
|
||||
result.add(resultData);
|
||||
}
|
||||
|
||||
log.error("assemblePageRowList result: {}", result.toJSONString());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -752,6 +761,38 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
|
||||
return CommonResult.success(reportDocumentDataMapper.selectCount(queryWrapper));
|
||||
}
|
||||
|
||||
/*
|
||||
* 处理报告签名*/
|
||||
@Override
|
||||
public String assembleSignature(String docSig) {
|
||||
if(ObjectUtils.isEmpty(docSig))
|
||||
return "";
|
||||
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())
|
||||
return "";
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
return docSigJson.toJSONString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds) {
|
||||
QueryWrapper<ReportDocumentDataDO> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
Reference in New Issue
Block a user