From 8ce50189f0b00d62390d67fd27f859ca7831616b Mon Sep 17 00:00:00 2001
From: value <z1292839451@163.com>
Date: 星期四, 23 五月 2024 17:32:44 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 235 insertions(+), 1 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 d114de5..ea79da8 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,10 +1,40 @@
package com.yuanchu.mom.service.impl;
+import com.aspose.words.License;
+import com.aspose.words.SaveFormat;
+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.yuanchu.mom.common.GetLook;
+import com.yuanchu.mom.common.PrintChina;
+import com.yuanchu.mom.dto.ReportPageDto;
+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.service.InsReportService;
-import com.yuanchu.mom.mapper.InsReportMapper;
+import com.yuanchu.mom.utils.QueryWrappers;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
+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 java.nio.file.Files;
+import java.nio.file.Paths;
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
/**
* @author Administrator
@@ -15,6 +45,210 @@
public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport>
implements InsReportService{
+ @Resource
+ private GetLook getLook;
+
+ @Resource
+ private UserMapper userMapper;
+
+ @Resource
+ private InsReportMapper insReportMapper;
+
+ @Value("${wordUrl}")
+ private String wordUrl;
+
+ @Value("${file.path}")
+ private String imgUrl;
+
+ @Resource
+ private InsOrderMapper insOrderMapper;
+
+ @Override
+ public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) {
+ Map<String, Object> map = new HashMap<>();
+ 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)));
+ return map;
+ }
+
+ @Override
+ public int inReport(String url, Integer id) {
+ InsReport insReport = new InsReport();
+ insReport.setId(id);
+ insReport.setUrlS(url);
+ return insReportMapper.updateById(insReport);
+ }
+
+ @Override
+ public int upReportUrl(Integer id) {
+ return insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate().eq(InsReport::getId, id).set(InsReport::getUrlS, null));
+ }
+
+ //鎻愪氦
+ @Override
+ public int writeReport(Integer id) {
+ InsReport insReport = insReportMapper.selectById(id);
+ insReport.setId(id);
+ insReport.setState(1);
+ insReport.setWriteUserId(getLook.selectPowerByMethodAndUserId(null).get("userId"));//鎻愪氦浜�
+ insReport.setWriteTime(LocalDateTime.now());//鎻愪氦鏃堕棿
+ //鑾峰彇鎻愪氦浜虹殑绛惧悕鍦板潃
+ String signatureUrl;
+ try {
+ signatureUrl = userMapper.selectById(insReport.getWriteUserId()).getSignatureUrl();
+ }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));
+ return insReportMapper.updateById(insReport);
+ }
+
+ //瀹℃牳
+ @Override
+ public int examineReport(Integer id, Integer isExamine, String examineTell) {
+ InsReport insReport = insReportMapper.selectById(id);
+ insReport.setIsExamine(isExamine);
+ if (ObjectUtils.isNotEmpty(examineTell)) {
+ insReport.setExamineTell(examineTell);
+ }
+ insReport.setExamineUserId(getLook.selectPowerByMethodAndUserId(null).get("userId"));//瀹℃牳浜�
+ insReport.setExamineTime(LocalDateTime.now());//瀹℃牳鏃堕棿
+ if (isExamine==0){
+ //濡傛灉瀹℃牳涓嶉�氳繃
+ insReport.setState(0);//鎻愪氦鐘舵�佹敼涓哄緟鎻愪氦
+ return insReportMapper.updateById(insReport);
+ }
+ //鑾峰彇瀹℃牳浜虹殑绛惧悕鍦板潃
+ String signatureUrl;
+ try {
+ signatureUrl = userMapper.selectById(insReport.getExamineUserId()).getSignatureUrl();
+ }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));
+ return insReportMapper.updateById(insReport);
+ }
+
+ //鎵瑰噯
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int ratifyReport(Integer id, Integer isRatify, String ratifyTell) {
+ InsReport insReport = insReportMapper.selectById(id);
+ insReport.setIsRatify(isRatify);
+ if (ObjectUtils.isNotEmpty(ratifyTell)) {
+ insReport.setRatifyTell(ratifyTell);
+ }
+ insReport.setRatifyUserId(getLook.selectPowerByMethodAndUserId(null).get("userId"));//鎵瑰噯浜�
+ insReport.setRatifyTime(LocalDateTime.now());//鎵瑰噯鏃堕棿
+ if (isRatify==0){
+ //濡傛灉鎵瑰噯涓嶉�氳繃
+ insReport.setState(0);//鎻愪氦鐘舵�佹敼涓哄緟鎻愪氦
+ return insReportMapper.updateById(insReport);
+ }
+ //鑾峰彇鎵瑰噯浜虹殑绛惧悕鍦板潃
+ String signatureUrl;
+ try {
+ signatureUrl = userMapper.selectById(insReport.getRatifyUserId()).getSignatureUrl();
+ }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();
+ //鎵嬪姩涓婁紶鎶ュ憡鍦板潃
+ 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));
+ InsOrder insOrder = new InsOrder();
+ insOrder.setId(insReportMapper.selectById(id).getInsOrderId());
+ insOrder.setState(4);
+ insOrderMapper.updateById(insOrder);
+ return insReportMapper.updateById(insReport);
+ }
+
+ @Override
+ public int wordInsertUrl(Map<String, Object> map, String url) {
+ XWPFTemplate template = XWPFTemplate.compile(url).render(map);
+ try {
+ template.writeAndClose(Files.newOutputStream(Paths.get(url)));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return 1;
+ }
+
+ @Override
+ public void wordToPdf(String path) {
+ CompletableFuture.supplyAsync(() -> {
+ try {
+ wordToPdf(path, path.replace(".docx", ".pdf"));
+ return null;
+ } catch (Exception e) {
+ throw new ErrorException("杞崲澶辫触");
+ }
+ }).thenAccept(res -> {
+ }).exceptionally(e -> {
+ e.printStackTrace();
+ return null;
+ });
+ }
+
+ public String wordToPdf(String wordPath,String pdfPath) {
+ FileOutputStream os = null;
+ try {
+ //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃
+// InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml");
+ InputStream is = new ClassPathResource("/lib/license.xml").getInputStream();
+ License license = new License();
+ license.setLicense(is);
+ if (!license.getIsLicensed()) {
+ System.out.println("License楠岃瘉涓嶉�氳繃...");
+ return null;
+ }
+ //鐢熸垚涓�涓┖鐨凱DF鏂囦欢
+ File file = new File(pdfPath);
+ os = new FileOutputStream(file);
+ //瑕佽浆鎹㈢殑word鏂囦欢
+ com.aspose.words.Document doc = new com.aspose.words.Document(wordPath);
+ doc.save(os, SaveFormat.PDF);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
}
--
Gitblit v1.9.3