Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -222,8 +222,13 @@ public class TestRecordController {
|
||||
|
||||
@ApiOperation("生成检验记录-贵阳禁毒")
|
||||
@GetMapping("/inspectionRecord")
|
||||
public R inspectionRecord(String entrustId, String materialType) throws Exception {
|
||||
return inspectRecordService.buildInspectionRecord(entrustId, materialType);
|
||||
public R inspectionRecord(String businessId, String materialType) throws Exception {
|
||||
return inspectRecordService.buildInspectionRecord(businessId, materialType);
|
||||
}
|
||||
|
||||
@ApiOperation("预览检验记录-贵阳禁毒")
|
||||
@GetMapping("/previewRecord")
|
||||
public void previewRecord(String businessId, String materialType, HttpServletResponse response) throws Exception {
|
||||
inspectRecordService.previewInspectionRecord(businessId, materialType, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package digital.laboratory.platform.inspection.service;
|
||||
|
||||
import digital.laboratory.platform.common.core.util.R;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author ChenJiangBao
|
||||
* @version 1.0
|
||||
@@ -12,9 +14,11 @@ public interface InspectRecordService {
|
||||
|
||||
/**
|
||||
* 生成检验记录-贵阳禁毒
|
||||
* @param entrustId 委托id
|
||||
* @param businessId 委托id
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
R buildInspectionRecord(String entrustId, String materialType) throws Exception;
|
||||
R buildInspectionRecord(String businessId, String materialType) throws Exception;
|
||||
|
||||
void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package digital.laboratory.platform.inspection.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
@@ -10,6 +10,7 @@ import com.deepoove.poi.config.Configure;
|
||||
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
||||
import com.deepoove.poi.xwpf.NiceXWPFDocument;
|
||||
import digital.laboratory.platform.common.core.util.R;
|
||||
import digital.laboratory.platform.common.feign.RemoteWord2PDFService;
|
||||
import digital.laboratory.platform.common.oss.service.OssFile;
|
||||
import digital.laboratory.platform.inspection.dto.TestRecordSampleDataDocDTO;
|
||||
import digital.laboratory.platform.inspection.entity.TestRecordInstrument;
|
||||
@@ -27,11 +28,14 @@ import digital.laboratory.platform.inspetion.api.entity.TargetObject;
|
||||
import digital.laboratory.platform.inspetion.api.entity.TestRecord;
|
||||
import digital.laboratory.platform.sys.entity.Drug;
|
||||
import digital.laboratory.platform.sys.enums.entrust.EntrustBiologyType;
|
||||
import feign.Response;
|
||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@@ -70,24 +74,50 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
||||
@Resource
|
||||
private TestRecordSampledataExpandService testRecordSampledataExpandService;
|
||||
|
||||
@Resource
|
||||
private RemoteWord2PDFService remoteWord2PDFService;
|
||||
|
||||
/**
|
||||
* 生成检验记录-贵阳禁毒
|
||||
*
|
||||
* @param entrustId 委托id
|
||||
* @param businessId 委托id
|
||||
* @param materialType 标注当前委托的检材是尿液还是毛发
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public R buildInspectionRecord(String entrustId, String materialType) throws Exception {
|
||||
EntrustInfo entrustInfo = entrustInfoService.getById(entrustId);
|
||||
public R buildInspectionRecord(String businessId, String materialType) throws Exception {
|
||||
EntrustInfo entrustInfo = entrustInfoService.getById(businessId);
|
||||
if (entrustInfo == null) {
|
||||
return R.ok(false, "委托信息不存在!");
|
||||
}
|
||||
if (entrustInfo.getBusinessType().equals(BusinessType.BOINT_CASE.getBusinessType())) {
|
||||
return R.ok(this.buildInVivoDocFile(entrustInfo, materialType), "生成成功!");
|
||||
}
|
||||
return R.ok(this.generateCommonDrugInpectRecord(entrustId));
|
||||
return R.ok(this.generateCommonDrugInpectRecord(businessId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception {
|
||||
|
||||
String path = (String) this.buildInspectionRecord(businessId, materialType).getData();
|
||||
java.io.ByteArrayOutputStream fosWord = new java.io.ByteArrayOutputStream();
|
||||
ossFile.fileGet(path, fosWord);
|
||||
ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray());
|
||||
fosWord.close();
|
||||
// 转换临时目录中的 word 文档为 PDF
|
||||
MockMultipartFile mockMultipartFile = new MockMultipartFile("file", "检验记录" + ".docx", "image/jpg", fisWord);
|
||||
String pdfFilePath = path.substring(0, path.lastIndexOf(".")) + ".pdf";
|
||||
Response response = remoteWord2PDFService.word2pdf(mockMultipartFile);
|
||||
fisWord.close();
|
||||
org.apache.commons.io.output.ByteArrayOutputStream outPDF = new org.apache.commons.io.output.ByteArrayOutputStream();
|
||||
IoUtil.copy(response.body().asInputStream(), outPDF, IoUtil.DEFAULT_MIDDLE_BUFFER_SIZE);
|
||||
ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray());
|
||||
outPDF.close();
|
||||
ossFile.fileSave(pdfFilePath, isPDF);
|
||||
isPDF.close();
|
||||
ossFile.fileGet(pdfFilePath, servletResponse.getOutputStream());
|
||||
System.out.println(String.format("转换为 PDF 结束"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,7 +393,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
||||
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
||||
Configure config = Configure.builder().
|
||||
bind("dataDtos", policy)
|
||||
.build();
|
||||
.build();
|
||||
return buildDocFileAndUploadToOss(entrustId, templatePath, config, docMap);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user