fix:报告数据组装
This commit is contained in:
@@ -150,8 +150,8 @@ public interface ErrorCodeConstants {
|
|||||||
|
|
||||||
/*=================================resource 资源管理 1_032_150_000 ~ 1_032_199_999 ==================================*/
|
/*=================================resource 资源管理 1_032_150_000 ~ 1_032_199_999 ==================================*/
|
||||||
// ----------设备管理----------
|
// ----------设备管理----------
|
||||||
ErrorCode DEVICE_INFOMATION_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备_设备信息不存在");
|
ErrorCode DEVICE_INFOMATION_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备信息不存在");
|
||||||
ErrorCode DEVICE_PRODUCT_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备_设备大类不存在");
|
ErrorCode DEVICE_PRODUCT_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备大类不存在");
|
||||||
ErrorCode DEVICE_MAINTAIN_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备维护数据不存在");
|
ErrorCode DEVICE_MAINTAIN_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备维护数据不存在");
|
||||||
ErrorCode DEVICE_MAINTAIN_ITEM_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备维护项不存在");
|
ErrorCode DEVICE_MAINTAIN_ITEM_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备维护项不存在");
|
||||||
ErrorCode DEVICE_CONFIG_BUSINESS_RULE_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备业务配置不存在");
|
ErrorCode DEVICE_CONFIG_BUSINESS_RULE_NOT_EXISTS = new ErrorCode(1_032_150_000, "设备业务配置不存在");
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class ReportDocumentMainController extends AbstractFileUploadController i
|
|||||||
@Resource private ReportDocumentMainService reportDocumentMainService;
|
@Resource private ReportDocumentMainService reportDocumentMainService;
|
||||||
@Resource private ReportDocumentDataService reportDocumentDataService;
|
@Resource private ReportDocumentDataService reportDocumentDataService;
|
||||||
@Resource private ReportDocumentTypeService reportDocumentTypeService;
|
@Resource private ReportDocumentTypeService reportDocumentTypeService;
|
||||||
@Resource private ConfigUserSignatureService configUserSignatureService;
|
|
||||||
@Resource private DataTemplateService dataTemplateService;
|
@Resource private DataTemplateService dataTemplateService;
|
||||||
|
|
||||||
@RequestMapping("/testAsyncTask")
|
@RequestMapping("/testAsyncTask")
|
||||||
@@ -181,58 +181,9 @@ public class ReportDocumentMainController extends AbstractFileUploadController i
|
|||||||
|
|
||||||
//处理签名
|
//处理签名
|
||||||
String docSig = vo.getDocumentSignature();
|
String docSig = vo.getDocumentSignature();
|
||||||
if(!ObjectUtils.isEmpty(docSig)){
|
String docSigJsonStr = reportDocumentDataService.assembleSignature(docSig);
|
||||||
JSONObject docSigJson = JSONObject.parseObject(docSig);
|
if(!ObjectUtils.isEmpty(docSigJsonStr))
|
||||||
List<Long> sigIds = new ArrayList<>();
|
vo.setDocumentSignature(docSigJsonStr);
|
||||||
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());
|
|
||||||
// }
|
|
||||||
return success(vo);
|
return success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,19 +118,9 @@ public class ReportDocumentAssistService {
|
|||||||
CommonResult<JSONArray> result = reportDocumentDataService.assembleDynamicData(mainDO, typeDO, pageFlag);
|
CommonResult<JSONArray> result = reportDocumentDataService.assembleDynamicData(mainDO, typeDO, pageFlag);
|
||||||
JSONArray data = result.getData();
|
JSONArray data = result.getData();
|
||||||
String templateContent = templateDO.getFormContent();
|
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();
|
JSONObject bodyJson = new JSONObject();
|
||||||
bodyJson.put("Template", templateContent);
|
bodyJson.put("Template", templateContent);
|
||||||
bodyJson.put("Data", templateData.toJSONString());
|
bodyJson.put("Data", data.toJSONString());
|
||||||
String bodyStr = bodyJson.toJSONString();
|
String bodyStr = bodyJson.toJSONString();
|
||||||
log.info("html2pdf body: " + bodyStr);
|
log.info("html2pdf body: " + bodyStr);
|
||||||
log.info("html2pdf--start at {}", LocalDateTime.now());
|
log.info("html2pdf--start at {}", LocalDateTime.now());
|
||||||
@@ -142,12 +132,9 @@ public class ReportDocumentAssistService {
|
|||||||
InputStream inputStream = response.bodyStream(); // 关键:返回原始 InputStream
|
InputStream inputStream = response.bodyStream(); // 关键:返回原始 InputStream
|
||||||
|
|
||||||
//尝试从响应头中提取文件名
|
//尝试从响应头中提取文件名
|
||||||
// String contentDisposition = response.header("Content-Disposition");
|
|
||||||
String documentCode = mainDO.getDocumentCode();
|
String documentCode = mainDO.getDocumentCode();
|
||||||
if(documentCode == null) documentCode = "";
|
if(documentCode == null) documentCode = "";
|
||||||
String filename = documentCode + "检测报告.pdf";
|
String filename = documentCode + "检测报告.pdf";
|
||||||
// String filename = extractFilename(contentDisposition).orElse(defaultName);
|
|
||||||
//inputStream转byte[]
|
|
||||||
byte[] fileBytes = IOUtils.toByteArray(inputStream);
|
byte[] fileBytes = IOUtils.toByteArray(inputStream);
|
||||||
|
|
||||||
//上传到文件服务
|
//上传到文件服务
|
||||||
@@ -172,24 +159,4 @@ public class ReportDocumentAssistService {
|
|||||||
reportDocumentFileService.createReportDocumentFile(fileSaveReqVO);
|
reportDocumentFileService.createReportDocumentFile(fileSaveReqVO);
|
||||||
return BeanUtils.toBean(fileRespDTO, ReportDocumentFileDO.class);
|
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<Long> countMainDataId(Long mainDataId);
|
||||||
CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds);
|
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 cn.hutool.core.collection.CollUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
import com.zt.plat.framework.common.pojo.PageResult;
|
import com.zt.plat.framework.common.pojo.PageResult;
|
||||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
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.controller.vo.ConfigReportFieldPageReqVO;
|
||||||
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigReportFieldDO;
|
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.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.controller.vo.*;
|
||||||
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentMainDO;
|
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.dataobject.ReportDocumentTypeDO;
|
||||||
import com.zt.plat.module.qms.business.reportdoc.dal.mapper.ReportDocumentDataMapper;
|
import com.zt.plat.module.qms.business.reportdoc.dal.mapper.ReportDocumentDataMapper;
|
||||||
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentDataDO;
|
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentDataDO;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -37,10 +42,12 @@ import static com.zt.plat.module.qms.enums.QmsCommonConstant.FIELD_FIXED;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Validated
|
@Validated
|
||||||
|
@Slf4j
|
||||||
public class ReportDocumentDataServiceImpl implements ReportDocumentDataService {
|
public class ReportDocumentDataServiceImpl implements ReportDocumentDataService {
|
||||||
|
|
||||||
@Resource private ReportDocumentDataMapper reportDocumentDataMapper;
|
@Resource private ReportDocumentDataMapper reportDocumentDataMapper;
|
||||||
@Resource private ConfigReportFieldService configReportFieldService;
|
@Resource private ConfigReportFieldService configReportFieldService;
|
||||||
|
@Resource private ConfigUserSignatureService configUserSignatureService;
|
||||||
private final String colPrefix = "col";
|
private final String colPrefix = "col";
|
||||||
private final String sampleCodeKey = "SMP_CD";
|
private final String sampleCodeKey = "SMP_CD";
|
||||||
private final String sampleNameKey = "SMP_NAME";
|
private final String sampleNameKey = "SMP_NAME";
|
||||||
@@ -247,12 +254,13 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
|
|||||||
JSONArray result = new JSONArray();
|
JSONArray result = new JSONArray();
|
||||||
String formData = mainData.getFormData();
|
String formData = mainData.getFormData();
|
||||||
String signatureData = mainData.getDocumentSignature();
|
String signatureData = mainData.getDocumentSignature();
|
||||||
|
String signatureJsonStr = assembleSignature(signatureData);
|
||||||
JSONObject formDataJson = new JSONObject();
|
JSONObject formDataJson = new JSONObject();
|
||||||
JSONObject signatureDataJson = new JSONObject();
|
boolean hasSignatureData = false;
|
||||||
if(!ObjectUtils.isEmpty(formData))
|
if(!ObjectUtils.isEmpty(formData))
|
||||||
formDataJson = JSONObject.parseObject(formData);
|
formDataJson = JSONObject.parseObject(formData);
|
||||||
if(!ObjectUtils.isEmpty(signatureData))
|
if(!ObjectUtils.isEmpty(signatureJsonStr))
|
||||||
signatureDataJson = JSONObject.parseObject(signatureData);
|
hasSignatureData = true;
|
||||||
for(int i=0;i<pageRowList.size();i++){
|
for(int i=0;i<pageRowList.size();i++){
|
||||||
JSONArray rows = pageRowList.getJSONArray(i);
|
JSONArray rows = pageRowList.getJSONArray(i);
|
||||||
JSONObject resultData = new JSONObject();
|
JSONObject resultData = new JSONObject();
|
||||||
@@ -264,11 +272,12 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
|
|||||||
}
|
}
|
||||||
resultData.put("headerData", headerData);
|
resultData.put("headerData", headerData);
|
||||||
resultData.put("tableList", rows);
|
resultData.put("tableList", rows);
|
||||||
resultData.put("formData", formDataJson);
|
resultData.put("formData", formDataJson.clone());
|
||||||
resultData.put("signatureData", signatureDataJson);
|
if(hasSignatureData)
|
||||||
|
resultData.put("signatureData", JSONObject.parseObject(signatureJsonStr));
|
||||||
result.add(resultData);
|
result.add(resultData);
|
||||||
}
|
}
|
||||||
|
log.error("assemblePageRowList result: {}", result.toJSONString());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,6 +761,38 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
|
|||||||
return CommonResult.success(reportDocumentDataMapper.selectCount(queryWrapper));
|
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
|
@Override
|
||||||
public CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds) {
|
public CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds) {
|
||||||
QueryWrapper<ReportDocumentDataDO> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<ReportDocumentDataDO> queryWrapper = new QueryWrapper<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user