| | |
| | | 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.dto.*; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | |
| | | 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.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Resource |
| | | private InsReportMapper insReportMapper; |
| | | |
| | | @Autowired |
| | | ProcessReportMapper1 processReportMapper; |
| | | |
| | | @Value("${wordUrl}") |
| | | private String wordUrl; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | |
| | | @Resource |
| | | private StandardMethodListMapper standardMethodListMapper; |
| | | |
| | | @Resource |
| | | private InsOrderStateMapper insOrderStateMapper; |
| | |
| | | map.put("head", PrintChina.printChina(ReportPageDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("pageInsReport"); |
| | | if (map1.get("look") == 1) reportPageDto.setCreateUser(map1.get("userId")); |
| | | 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)); |
| | | map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto))); |
| | | return map; |
| | | } |
| | | |
| | |
| | | } 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(); |
| | | //手动上传报告地址 |
| | |
| | | put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); |
| | | }}, finalUrl); |
| | | wordToPdf(finalUrl, sealUrl); |
| | | |
| | | InsOrder insOrder = new InsOrder(); |
| | | insOrder.setId(insReportMapper.selectById(id).getInsOrderId()); |
| | | insOrder.setState(4); |
| | | insOrderMapper.updateById(insOrder); |
| | | /*新增cnas7.8报告结果*/ |
| | | ProcessReport processReport = new ProcessReport(); |
| | | processReport.setInsReportCode(insReport.getCode()); |
| | | processReportMapper.insert(processReport); |
| | | return insReportMapper.updateById(insReport); |
| | | } |
| | | |
| | |
| | | if (files != null) { |
| | | for (File f : files) { |
| | | // 根据文件名查询id |
| | | String name = f.getName(); |
| | | InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().like(InsReport::getCode, f.getName().replace(".docx", ""))); |
| | | if (ObjectUtils.isEmpty(insReport)) { |
| | | throw new ErrorException("没有找到 " + f.getName() + " 这个文件对应的报告数据"); |
| | |
| | | @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)); |
| | | //先判断该订单是否可以去生产报告(是否结束试验) |
| | | 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); |
| | | for (InsReportDto1 insReportDto1 : insReportDto1s) { |
| | | if (ObjectUtils.isNotEmpty(insReportDto1.getInsReportDto2s())){ |
| | | wordUtils.generateReport(insReportDto.getId(), insReportDto1); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | throw new ErrorException("该订单还未结束试验,无法生产报告!"); |
| | | throw new ErrorException("该订单还未结束试验,无法生成报告!"); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | //查出该订单下每个站点下的检验次数 |
| | | @Override |
| | | public List<InsOrderState> getInsOrderStateCount(Integer id) { |
| | | List<InsOrderState> insOrderStates = insOrderStateMapper.getInsOrderStateCount(id); |
| | | return insOrderStates; |
| | | public List<InsOrderStateDto> getInsOrderStateCount(Integer id) { |
| | | List<InsOrderStateDto> insOrderStateDtos = new ArrayList<>(); |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, id)); |
| | | for (InsSample insSample : insSamples) { |
| | | InsOrderStateDto insOrderStateDto = new InsOrderStateDto(); |
| | | insOrderStateDto.setInsSample(insSample); |
| | | List<InsOrderState> insOrderStates = insOrderStateMapper.getInsOrderStateCount(id, insSample.getId()); |
| | | insOrderStateDto.setInsOrderStates(insOrderStates); |
| | | insOrderStateDtos.add(insOrderStateDto); |
| | | } |
| | | return insOrderStateDtos; |
| | | } |
| | | |
| | | |
| | |
| | | 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); |
| | |
| | | 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); |
| | | |
| | | //添加骑缝章 |
| | | stamperCheckMarkPDF(pdfPath.replace(".pdf", "-1.pdf"), pdfPath, imgUrl + "/" + sealUrl); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |