| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | | |
| | | @Value("${twoCode}") |
| | | private String twoCode; |
| | | |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | |
| | | @Resource |
| | | private StandardMethodListMapper standardMethodListMapper; |
| | | |
| | | @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) { |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | //批准 |
| | | @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)) { |
| | |
| | | throw new ErrorException("找不到批准人的签名"); |
| | | } |
| | | //获取场所的报告专用章 |
| | | String sealUrl; |
| | | /* 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("找不到报告专用章"); |
| | | if (sealUrl == null) throw new ErrorException("找不到报告专用章");*/ |
| | | //系统生成报告地址 |
| | | String url = insReport.getUrl(); |
| | | //手动上传报告地址 |
| | |
| | | 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()); |
| | |
| | | for (File f : files) { |
| | | // 根据文件名查询id |
| | | 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() + " 这个文件对应的报告数据"); |
| | | } |
| | |
| | | // 复制文件到指定路径 |
| | | 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("文件上传失败"); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | |
| | |
| | | os = new FileOutputStream(file); |
| | | //要转换的word文件 |
| | | com.aspose.words.Document doc = new com.aspose.words.Document(wordPath); |
| | | TableCollection tables = doc.getFirstSection().getBody().getTables(); |
| | | for (Table table : tables) { |
| | | RowCollection rows = table.getRows(); |
| | | table.setAllowAutoFit(false); |
| | | for (Row row : rows) { |
| | | CellCollection cells = row.getCells(); |
| | | for (Cell cell : cells) { |
| | | CellFormat cellFormat = cell.getCellFormat(); |
| | | cellFormat.setFitText(false); //设置自适应关闭 |
| | | cellFormat.setWrapText(true); // 设置自动换行 |
| | | } |
| | | } |
| | | } |
| | | doc.save(os, SaveFormat.PDF); |
| | | |
| | | //添加骑缝章 |