From d8ba960d180c0ad08b7dfb5a17e7ad351ca2eb62 Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期三, 30 十月 2024 11:00:36 +0800 Subject: [PATCH] 报告转pdf格式错误异常解决 --- inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java | 159 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 110 insertions(+), 49 deletions(-) diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java index 9800317..6bb76f0 100644 --- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java +++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java @@ -1,12 +1,24 @@ package com.yuanchu.mom.service.impl; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.aspose.words.*; +import com.aspose.words.Document; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 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.deepoove.poi.config.Configure; +import com.deepoove.poi.config.ConfigureBuilder; +import com.deepoove.poi.data.*; +import com.deepoove.poi.data.style.*; +import com.deepoove.poi.data.style.Style; +import com.deepoove.poi.data.style.TableStyle; +import com.deepoove.poi.util.TableTools; import com.itextpdf.text.BadElementException; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfContentByte; @@ -14,16 +26,24 @@ import com.itextpdf.text.pdf.PdfStamper; import com.yuanchu.mom.common.GetLook; import com.yuanchu.mom.common.PrintChina; +import com.yuanchu.mom.dto.InsReportDto; +import com.yuanchu.mom.dto.InsReportDto1; import com.yuanchu.mom.dto.ReportPageDto; +import com.yuanchu.mom.dto.SampleProductDto; import com.yuanchu.mom.exception.ErrorException; -import com.yuanchu.mom.mapper.InsOrderMapper; -import com.yuanchu.mom.mapper.InsReportMapper; -import com.yuanchu.mom.mapper.UserMapper; -import com.yuanchu.mom.pojo.InsOrder; -import com.yuanchu.mom.pojo.InsReport; +import com.yuanchu.mom.mapper.*; +import com.yuanchu.mom.pojo.*; import com.yuanchu.mom.service.InsReportService; +import com.yuanchu.mom.service.StandardTemplateService; +import com.yuanchu.mom.utils.JackSonUtil; +import com.yuanchu.mom.utils.MatrixToImageWriter; import com.yuanchu.mom.utils.QueryWrappers; +import com.yuanchu.mom.utils.WordUtils; import com.yuanchu.mom.vo.Result; +import org.apache.commons.io.IOUtils; +import org.apache.logging.log4j.util.Strings; +import org.apache.poi.xwpf.usermodel.*; +import org.apache.poi.xwpf.usermodel.ParagraphAlignment; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -43,6 +63,8 @@ import java.util.*; import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -72,8 +94,44 @@ @Value("${file.path}") private String imgUrl; + @Value("${twoCode}") + private String twoCode; + @Resource private InsOrderMapper insOrderMapper; + + @Resource + private InsOrderStateMapper insOrderStateMapper; + + @Resource + WordUtils wordUtils; + + @Resource + private InsProductMapper insProductMapper; + + @Resource + private InsProductResultMapper insProductResultMapper; + + @Resource + private InsProductResult2Mapper insProductResult2Mapper; + + @Resource + private InsOrderUserMapper insOrderUserMapper; + + @Resource + private InsSampleMapper insSampleMapper; + + @Resource + private InsSampleUserMapper insSampleUserMapper; + + @Resource + private CustomMapper customMapper; + + @Resource + private InsOrderFileMapper insOrderFileMapper; + + @Resource + private StandardTemplateService standardTemplateService; @Override public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) { @@ -81,7 +139,19 @@ map.put("head", PrintChina.printChina(ReportPageDto.class)); Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("pageInsReport"); if (map1.get("look") == 1) reportPageDto.setCreateUser(map1.get("userId")); - map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto))); + User user = userMapper.selectById(map1.get("userId"));//褰撳墠鐧诲綍鐨勪汉 + //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id + String departLimsId = user.getDepartLimsId(); + String laboratory = null; + if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) { + String[] split = departLimsId.split(","); + //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙) + String departLims = insOrderMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); + if (departLims.contains("瀹為獙瀹�")) { + laboratory = departLims; + } + } + map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto), laboratory)); return map; } @@ -158,7 +228,7 @@ //鎵瑰噯 @Override @Transactional(rollbackFor = Exception.class) - public int ratifyReport(Integer id, Integer isRatify, String ratifyTell) { + public int ratifyReport(Integer id, Integer isRatify, String ratifyTell, String sealUrl) { InsReport insReport = insReportMapper.selectById(id); insReport.setIsRatify(isRatify); if (ObjectUtils.isNotEmpty(ratifyTell)) { @@ -178,15 +248,6 @@ } catch (Exception e) { throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�"); } - //鑾峰彇鍦烘墍鐨勬姤鍛婁笓鐢ㄧ珷 - String sealUrl; - try { - String laboratory = insOrderMapper.selectById(insReport.getInsOrderId()).getLaboratory(); - sealUrl = insReportMapper.getLaboratoryByName(laboratory); - } catch (Exception e) { - throw new ErrorException("鎵句笉鍒版姤鍛婁笓鐢ㄧ珷"); - } - if (sealUrl == null) throw new ErrorException("鎵句笉鍒版姤鍛婁笓鐢ㄧ珷"); //绯荤粺鐢熸垚鎶ュ憡鍦板潃 String url = insReport.getUrl(); //鎵嬪姩涓婁紶鎶ュ憡鍦板潃 @@ -198,20 +259,6 @@ put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); }}, finalUrl); wordToPdf(finalUrl, sealUrl); - - /* 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()); @@ -287,7 +334,7 @@ for (File f : files) { // 鏍规嵁鏂囦欢鍚嶆煡璇d String name = f.getName(); - InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().like(InsReport::getCode, f.getName().replace(".docx", "").replace("JCZX", "JCZX/"))); + InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().like(InsReport::getCode, f.getName().replace(".docx", ""))); if (ObjectUtils.isEmpty(insReport)) { throw new ErrorException("娌℃湁鎵惧埌 " + f.getName() + " 杩欎釜鏂囦欢瀵瑰簲鐨勬姤鍛婃暟鎹�"); } @@ -304,8 +351,7 @@ // 澶嶅埗鏂囦欢鍒版寚瀹氳矾寰� Files.copy(f.toPath(), new File(urlString).toPath(), StandardCopyOption.REPLACE_EXISTING); inReport("/word/" + pathName, insReport.getId()); - } - catch (IOException e) { + } catch (IOException e) { throw new ErrorException("鏂囦欢涓婁紶澶辫触"); } } @@ -322,6 +368,36 @@ } } return 0; + } + + //鏄惁闇�瑕佺敓鎴愭姤鍛�: 0涓嶉渶瑕�;1闇�瑕� + @Override + @Transactional(rollbackFor = Exception.class) + public int isReport(InsReportDto insReportDto) { + //鍏堝垽鏂璁㈠崟鏄惁鍙互鍘荤敓浜ф姤鍛� + Long count = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, insReportDto.getId()).eq(InsOrderState::getInsState, 5)); + if (count > 0) { + if (insReportDto.getState() == 1) { + List<InsReportDto1> insReportDto1s = insReportDto.getInsReportDto1s(); + wordUtils.generateReport(insReportDto.getId(), insReportDto1s); + } else { + //缁撴潫璁㈠崟 + InsOrder insOrder = new InsOrder(); + insOrder.setId(insReportDto.getId()); + insOrder.setState(4); + insOrderMapper.updateById(insOrder); + } + } else { + throw new ErrorException("璇ヨ鍗曡繕鏈粨鏉熻瘯楠�,鏃犳硶鐢熶骇鎶ュ憡!"); + } + return 0; + } + + //鏌ュ嚭璇ヨ鍗曚笅姣忎釜绔欑偣涓嬬殑妫�楠屾鏁� + @Override + public List<InsOrderState> getInsOrderStateCount(Integer id) { + List<InsOrderState> insOrderStates = insOrderStateMapper.getInsOrderStateCount(id); + return insOrderStates; } @@ -400,20 +476,6 @@ public String wordToPdf(String wordPath, String pdfPath, String sealUrl) { FileOutputStream os = null; try { - //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃 -// InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml"); - /*String url; - try { - InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml"); - File file = File.createTempFile("temp", ".tmp"); - OutputStream outputStream = new FileOutputStream(file); - IOUtils.copy(inputStream, outputStream); - url = file.getAbsolutePath(); - } catch (FileNotFoundException e) { - throw new ErrorException("鎵句笉鍒版ā鏉挎枃浠�"); - } catch (IOException e) { - throw new RuntimeException(e); - }*/ InputStream is = new ClassPathResource("/lib/license.xml").getInputStream(); License license = new License(); license.setLicense(is); @@ -430,7 +492,6 @@ //娣诲姞楠戠紳绔� stamperCheckMarkPDF(pdfPath.replace(".pdf", "-1.pdf"), pdfPath, imgUrl + "/" + sealUrl); - } catch (Exception e) { e.printStackTrace(); -- Gitblit v1.9.3