| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.spire.doc.Document; |
| | | import com.spire.doc.FileFormat; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.InsOrderPlanDTO; |
| | | import com.yuanchu.mom.dto.ReportPageDto; |
| | | import com.yuanchu.mom.dto.SampleOrderDto; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.InsOrderMapper; |
| | | 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 lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | 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 |
| | |
| | | |
| | | @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) { |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | if (isExamine==0){ |
| | | //如果审核不通过 |
| | | insReport.setState(0);//提交状态改为待提交 |
| | | return insReportMapper.updateById(insReport); |
| | | } |
| | | //获取审核人的签名地址 |
| | | String signatureUrl = userMapper.selectById(insReport.getExamineUserId()).getSignatureUrl(); |
| | |
| | | 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 (isRatify==0){ |
| | | //如果批准不通过 |
| | | insReport.setState(0);//提交状态改为待提交 |
| | | return insReportMapper.updateById(insReport); |
| | | } |
| | | //获取审核人的签名地址 |
| | | String signatureUrl = userMapper.selectById(insReport.getRatifyUserId()).getSignatureUrl(); |
| | |
| | | String url = insReport.getUrl(); |
| | | //手动上传报告地址 |
| | | String urlS = insReport.getUrlS(); |
| | | |
| | | wordInsertUrl(new HashMap<String, Object>(){{ |
| | | put("ratifyUrl", Pictures.ofLocal(imgUrl+"/"+signatureUrl).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(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { |
| | | Document document = new Document(); |
| | | document.loadFromFile(path); |
| | | document.saveToFile(path.replace(".docx", ".pdf"), FileFormat.PDF); |
| | | System.out.println(path.replace(".docx", ".pdf")); |
| | | return null; |
| | | } catch (Exception e) { |
| | | throw new ErrorException("转换失败"); |
| | | } |
| | | }).thenAccept(res -> { |
| | | }).exceptionally(e -> { |
| | | e.printStackTrace(); |
| | | return null; |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |