inspect-server/pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/resources/mapper/InsOrderMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/resources/mapper/InsReportMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/resources/mapper/InsSampleMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
inspect-server/pom.xml
@@ -25,7 +25,11 @@ <artifactId>aspose-words</artifactId> <version>15.12.0</version> </dependency> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.0.6</version> </dependency> <dependency> <groupId>com.yuanchu.mom</groupId> <artifactId>framework</artifactId> inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -823,27 +823,22 @@ List<TableRenderData> tables1 = new ArrayList<>(); TableRenderData tableRenderData = new TableRenderData(); tableRenderData.setRows(new ArrayList<>()); double totalHeight = 0.0; // 用于跟踪当前表格的总行高 double heightThreshold = 8000.0; // 阈值,例如40cm*28px*15twips double heightThreshold = 8000.0; // 阈值, List<RowRenderData> firstTwoRows = new ArrayList<>(); // 保存前两行以便复制到新表格 // 保存前两行以便复制到新表格 if (rows.size() >= 2) { firstTwoRows.add(rows.get(0)); firstTwoRows.add(rows.get(1)); } for (RowRenderData row : rows) { double rowHeight = row.getRowStyle().getHeight(); // 获取当前行的行高 totalHeight += rowHeight; // 更新总行高 if (totalHeight >= heightThreshold) { // 创建新表格并复制前两行 TableRenderData newTableRenderData = new TableRenderData(); newTableRenderData.setRows(new ArrayList<>(firstTwoRows)); //设置样式 TableStyle tableStyle = new TableStyle(); tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100}); tableStyle.setWidth("10000"); @@ -858,7 +853,6 @@ tableStyle.setBottomBorder(borderStyle); tableRenderData.setTableStyle(tableStyle); newTableRenderData.setTableStyle(tableStyle); tables1.add(tableRenderData); tableRenderData = newTableRenderData; totalHeight = rowHeight; @@ -866,6 +860,7 @@ tableRenderData.getRows().add(row); } if (!tableRenderData.getRows().isEmpty()) { //设置样式 TableStyle tableStyle = new TableStyle(); tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100}); tableStyle.setWidth("10000"); @@ -881,7 +876,6 @@ tableRenderData.setTableStyle(tableStyle); tables1.add(tableRenderData); } tables1.forEach(table -> { Map<String, Object> tableMap = new HashMap<>(); tableMap.put("table", table); @@ -1293,14 +1287,6 @@ List<String> list = new ArrayList<>(maps.keySet()); for (int a = list.size() - 1; a >= 0; a--) { Map<String, Integer> v = maps.get(list.get(a)); /* for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) { if (v.get("ec") > v.get("sc")) { TableTools.mergeCellsHorizonal(table, v.get("sr") + j, v.get("sc"), v.get("ec")); } } if (v.get("er") > v.get("sr")) { TableTools.mergeCellsVertically(table, v.get("sc"), v.get("sr"), v.get("er")); }*/ for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) { if (v.get("ec") > v.get("sc")) { XWPFTableRow row = table.getRow(v.get("sr") + j); @@ -1338,11 +1324,11 @@ } catch (IOException e) { throw new RuntimeException(e); } //处理中英文换行的问题 try { FileInputStream stream1 = new FileInputStream(path); XWPFDocument document1 = new XWPFDocument(stream1); List<XWPFTable> xwpfTables1 = document1.getTables(); //处理中英文换行的问题 for (int i = 1; i < xwpfTables1.size() - (deviceList == null ? 1 : 2); i++) { for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) { for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) { @@ -1359,35 +1345,6 @@ } xwpfParagraph.setAlignment(ParagraphAlignment.CENTER); } /*if (k == 2 || k == 3 || k == 4) { if (k == 2 && xwpfTables1.get(i).getRows().get(j).getTableCells().get(k-1).getText().contains("@@")) { XWPFTableCell cell = xwpfTables1.get(i).getRow(j).getCell(k); CTTblWidth tblWidth = cell.getCTTc().addNewTcPr().addNewTcW(); tblWidth.setType(STTblWidth.DXA); tblWidth.setW(BigInteger.valueOf((int) (4.79 * 1440 / 2.54))); } if (k == 3 && xwpfTables1.get(i).getRows().get(j).getTableCells().get(k - 2).getText().contains("@@")) { XWPFTableCell cell = xwpfTables1.get(i).getRow(j).getCell(k); CTTblWidth tblWidth = cell.getCTTc().addNewTcPr().addNewTcW(); tblWidth.setType(STTblWidth.DXA); tblWidth.setW(BigInteger.valueOf((int) (1.49 * 1440 / 2.54))); } if (k == 4 && xwpfTables1.get(i).getRows().get(j).getTableCells().get(k - 3).getText().contains("@@")) { XWPFTableCell cell = xwpfTables1.get(i).getRow(j).getCell(k); CTTblWidth tblWidth = cell.getCTTc().addNewTcPr().addNewTcW(); tblWidth.setType(STTblWidth.DXA); tblWidth.setW(BigInteger.valueOf((int) (3.51 * 1440 / 2.54))); } } if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@@")) { String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText(); text = text.replace("@@",""); xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph(); XWPFRun run = xwpfParagraph.createRun(); run.setText(text); xwpfParagraph.setAlignment(ParagraphAlignment.CENTER); }*/ } } } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
@@ -1,13 +1,17 @@ package com.yuanchu.mom.service.impl; import com.aspose.words.License; import com.aspose.words.SaveFormat; import com.aspose.words.*; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.data.Pictures; import com.itextpdf.text.BadElementException; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; import com.yuanchu.mom.common.GetLook; import com.yuanchu.mom.common.PrintChina; import com.yuanchu.mom.dto.ReportPageDto; @@ -25,10 +29,10 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; import java.time.LocalDateTime; @@ -37,13 +41,13 @@ import java.util.concurrent.CompletableFuture; /** * @author Administrator * @description 针对表【ins_report(检验报告)】的数据库操作Service实现 * @createDate 2024-03-17 22:10:02 */ * @author Administrator * @description 针对表【ins_report(检验报告)】的数据库操作Service实现 * @createDate 2024-03-17 22:10:02 */ @Service public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport> implements InsReportService{ implements InsReportService { @Resource private GetLook getLook; @@ -98,16 +102,16 @@ String signatureUrl; try { signatureUrl = userMapper.selectById(insReport.getWriteUserId()).getSignatureUrl(); }catch (Exception e){ } catch (Exception e) { throw new ErrorException("找不到编制人的签名"); } //系统生成报告地址 String url = insReport.getUrl(); //手动上传报告地址 String urlS = insReport.getUrlS(); wordInsertUrl(new HashMap<String, Object>(){{ put("writeUrl", Pictures.ofLocal(imgUrl+"/"+signatureUrl).create()); }}, (urlS==null?url:urlS).replace("/word", wordUrl)); wordInsertUrl(new HashMap<String, Object>() {{ put("writeUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); }}, (urlS == null ? url : urlS).replace("/word", wordUrl)); return insReportMapper.updateById(insReport); } @@ -121,7 +125,7 @@ } insReport.setExamineUserId(getLook.selectPowerByMethodAndUserId(null).get("userId"));//审核人 insReport.setExamineTime(LocalDateTime.now());//审核时间 if (isExamine==0){ if (isExamine == 0) { //如果审核不通过 insReport.setState(0);//提交状态改为待提交 return insReportMapper.updateById(insReport); @@ -130,16 +134,16 @@ String signatureUrl; try { signatureUrl = userMapper.selectById(insReport.getExamineUserId()).getSignatureUrl(); }catch (Exception e){ } catch (Exception e) { throw new ErrorException("找不到审核人的签名"); } //系统生成报告地址 String url = insReport.getUrl(); //手动上传报告地址 String urlS = insReport.getUrlS(); wordInsertUrl(new HashMap<String, Object>(){{ put("examineUrl", Pictures.ofLocal(imgUrl+"/"+signatureUrl).create()); }}, (urlS==null?url:urlS).replace("/word", wordUrl)); wordInsertUrl(new HashMap<String, Object>() {{ put("examineUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); }}, (urlS == null ? url : urlS).replace("/word", wordUrl)); return insReportMapper.updateById(insReport); } @@ -154,7 +158,7 @@ } insReport.setRatifyUserId(getLook.selectPowerByMethodAndUserId(null).get("userId"));//批准人 insReport.setRatifyTime(LocalDateTime.now());//批准时间 if (isRatify==0){ if (isRatify == 0) { //如果批准不通过 insReport.setState(0);//提交状态改为待提交 return insReportMapper.updateById(insReport); @@ -163,27 +167,44 @@ String signatureUrl; try { signatureUrl = userMapper.selectById(insReport.getRatifyUserId()).getSignatureUrl(); }catch (Exception e){ } catch (Exception e) { throw new ErrorException("找不到批准人的签名"); } //获取场所的报告专用章 String sealUrl; try { String laboratory = insOrderMapper.selectById(insReport.getInsOrderId()).getLaboratory(); sealUrl = insReportMapper.getLaboratoryByName(laboratory); }catch (Exception e){ } catch (Exception e) { throw new ErrorException("找不到报告专用章"); } if(sealUrl==null) throw new ErrorException("找不到报告专用章"); if (sealUrl == null) throw new ErrorException("找不到报告专用章"); //系统生成报告地址 String url = insReport.getUrl(); //手动上传报告地址 String urlS = insReport.getUrlS(); wordInsertUrl(new HashMap<String, Object>(){{ put("ratifyUrl", Pictures.ofLocal(imgUrl+"/"+signatureUrl).create()); put("seal1", Pictures.ofLocal(imgUrl+"/"+sealUrl).create()); put("seal2", Pictures.ofLocal(imgUrl+"/"+sealUrl).create()); }}, (urlS==null?url:urlS).replace("/word", wordUrl)); wordToPdf((urlS == null ? url : urlS).replace("/word", wordUrl)); String finalUrl = (urlS == null ? url : urlS).replace("/word", wordUrl); wordInsertUrl(new HashMap<String, Object>() {{ put("ratifyUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); put("seal1", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); }}, finalUrl); wordToPdf(finalUrl); String replace = finalUrl.replace(".docx", ".pdf"); CompletableFuture.supplyAsync(() -> { try { stamperCheckMarkPDF(replace,replace,sealUrl); return null; } catch (Exception e) { throw new ErrorException("骑缝章插入失败"); } }).thenAccept(res -> { }).exceptionally(e -> { e.printStackTrace(); return null; }); InsOrder insOrder = new InsOrder(); insOrder.setId(insReportMapper.selectById(id).getInsOrderId()); insOrder.setState(4); @@ -218,7 +239,7 @@ }); } public String wordToPdf(String wordPath,String pdfPath) { public String wordToPdf(String wordPath, String pdfPath) { FileOutputStream os = null; try { //凭证 不然切换后有水印 @@ -261,8 +282,66 @@ } return null; } /** * 切割图片 * @param Path 图片路径 * @param n 切割份数 */ public static com.itextpdf.text.Image[] slicingImages(String Path, int n) throws IOException, BadElementException { com.itextpdf.text.Image[] nImage = new com.itextpdf.text.Image[n]; ByteArrayOutputStream out = new ByteArrayOutputStream(); BufferedImage img = ImageIO.read(new File(Path)); int h = img.getHeight(); int w = img.getWidth(); int sw = w/n; for(int i=0;i<n;i++){ BufferedImage subImg; if(i==n-1){//最后剩余部分 subImg = img.getSubimage(i * sw, 0, w-i*sw, h); }else {//前n-1块均匀切 subImg = img.getSubimage(i * sw, 0, sw, h); } ImageIO.write(subImg,Path.substring(Path.lastIndexOf('.')+1),out); nImage[i] = com.itextpdf.text.Image.getInstance(out.toByteArray()); out.flush(); out.reset(); } return nImage; } /** * 盖骑缝章 * * @param infilePath 原PDF路径 * @param outFilePath 输出PDF路径 */ public static void stamperCheckMarkPDF(String infilePath,String outFilePath,String picPath) throws IOException, DocumentException { PdfReader reader = new PdfReader(infilePath);//选择需要印章的pdf PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outFilePath));//加完印章后的pdf com.itextpdf.text.Rectangle pageSize = reader.getPageSize(1);//获得第一页 float height = pageSize.getHeight(); float width = pageSize.getWidth(); int nums = reader.getNumberOfPages(); com.itextpdf.text.Image[] nImage = slicingImages(picPath,nums);//生成骑缝章切割图片 for(int n=1;n<=nums;n++){ PdfContentByte over = stamp.getOverContent(n);//设置在第几页打印印章 com.itextpdf.text.Image img = nImage[n-1];//选择图片 img.setAbsolutePosition(width-img.getWidth(),height/2-img.getHeight()/2);//控制图片位置 over.addImage(img); } stamp.close(); } } inspect-server/src/main/resources/mapper/InsOrderMapper.xml
@@ -96,7 +96,7 @@ ir.url, ir.url_s, (select count(*) from ins_sample isa2 where isa2.ins_order_id = io.id) sample_num, where isa2.ins_order_id = io.id and isa2.sample_code NOT REGEXP '/') sample_num, concat(ROUND((select count(*) from ins_product ip where state = 1 and ins_result is not null and ip.ins_sample_id in (select id from ins_sample where ins_sample.ins_order_id= io.id )) / (select count(*) from ins_product ip2 inspect-server/src/main/resources/mapper/InsReportMapper.xml
@@ -35,11 +35,11 @@ </if> </select> <select id="getLaboratoryByName" resultType="java.lang.String"> select s.address from `center-lims`.seal s left join `center-lims`.laboratory l on s.lab_id = l.id select s.address from seal s left join laboratory l on s.lab_id = l.id where l.laboratory_name = #{name} and s.type = '报告类型' order by l.create_time desc order by s.create_time desc limit 1 </select> </mapper> inspect-server/src/main/resources/mapper/InsSampleMapper.xml
@@ -163,6 +163,7 @@ and state = 1 and ins_fiber_id is null and ins_fibers_id is null and isa.sample_code NOT REGEXP '/' </select> <select id="getInsOrderAndSample" resultMap="sampleDto"> select isa.*,