| | |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.aspose.words.License; |
| | | import com.aspose.words.SaveFormat; |
| | | import com.aspose.words.*; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | |
| | | import com.itextpdf.text.pdf.PdfContentByte; |
| | | import com.itextpdf.text.pdf.PdfReader; |
| | | import com.itextpdf.text.pdf.PdfStamper; |
| | | import com.ruoyi.common.config.MinioConfig; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.enums.AttachmentType; |
| | | import com.ruoyi.common.mapper.AttachmentTableMapper; |
| | | import com.ruoyi.common.pojo.AttachmentTable; |
| | | import com.ruoyi.common.service.AttachmentTableService; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.dto.ReportPageDto; |
| | | import com.ruoyi.inspect.mapper.*; |
| | | import com.ruoyi.inspect.mapper.InsOrderMapper; |
| | | import com.ruoyi.inspect.mapper.InsOrderStateMapper; |
| | | import com.ruoyi.inspect.mapper.InsReportApproveConfigMapper; |
| | | import com.ruoyi.inspect.mapper.InsReportMapper; |
| | | import com.ruoyi.inspect.pojo.InsOrder; |
| | | import com.ruoyi.inspect.pojo.InsOrderState; |
| | | import com.ruoyi.inspect.pojo.InsReport; |
| | | import com.ruoyi.process.pojo.ProcessReport; |
| | | import com.ruoyi.inspect.service.InsReportService; |
| | | import com.ruoyi.process.mapper.ProcessReportMapper; |
| | | import com.ruoyi.process.pojo.ProcessReport; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import io.minio.MinioClient; |
| | | import io.minio.PutObjectArgs; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Slf4j |
| | | public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport> |
| | | implements InsReportService { |
| | | |
| | | @Resource |
| | | private AttachmentTableMapper attachmentTableMapper; |
| | | |
| | | @Resource |
| | | private AttachmentTableService attachmentTableService; |
| | | |
| | | @Resource |
| | | private MinioConfig minioConfig; |
| | | |
| | | |
| | | |
| | | @Resource |
| | |
| | | } |
| | | } |
| | | QueryWrapper<ReportPageDto> wrapper = QueryWrappers.queryWrappers(reportPageDto); |
| | | if(Objects.nonNull(reportPageDto) && Objects.nonNull(reportPageDto.getCreateTimeRange())){ |
| | | if(Objects.nonNull(reportPageDto.getCreateTimeRange())){ |
| | | wrapper.gt(reportPageDto.getCreateTimeRange().size()>1,"create_time",reportPageDto.getCreateTimeRange().get(0)) |
| | | .lt(reportPageDto.getCreateTimeRange().size()>1,"create_time",reportPageDto.getCreateTimeRange().get(1)); |
| | | } |
| | | IPage<ReportPageDto> iPage = insReportMapper.pageInsReport(page, wrapper, laboratory); |
| | | return iPage; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int inReport(String url, Integer id) { |
| | |
| | | |
| | | // è¿å |
| | | @Override |
| | | public void upReportUrl(Integer id,Integer type) { |
| | | List<AttachmentTable> attachmentTables = attachmentTableMapper.selectList(new LambdaQueryWrapper<AttachmentTable>() |
| | | .eq(AttachmentTable::getSubclassId, id) |
| | | .eq(AttachmentTable::getOtherTableName, AttachmentType.getAttachmentValue(type)) |
| | | .orderByAsc(AttachmentTable::getId)); |
| | | if(CollectionUtils.isNotEmpty(attachmentTables)) { |
| | | // è·åææçid |
| | | List<Integer> collect = attachmentTables.stream().map(AttachmentTable::getId).collect(Collectors.toList()); |
| | | // é¤äºç¬¬ä¸ä¸ªå
¨é¨å é¤ å 餿æçéä»¶ |
| | | collect.remove(0); |
| | | if(collect.size() > 0) { |
| | | attachmentTableMapper.deleteBatchIds(collect); |
| | | public int upReportUrl(Integer id) { |
| | | InsReport insReport = insReportMapper.selectById(id); |
| | | String fileName = insReport.getUrlS().replace("/word/", ""); |
| | | if(Strings.isNotEmpty(fileName)) { |
| | | String path = wordUrl + File.separator + fileName; |
| | | File file = new File(path); |
| | | if (file.exists()) { |
| | | file.delete(); |
| | | } |
| | | } |
| | | return insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate().eq(InsReport::getId, id).set(InsReport::getUrlS, null)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | //æäº¤ |
| | | @Override |
| | | public int writeReport(Integer id) { |
| | | int userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | InsReport insReport = insReportMapper.selectById(id); |
| | | insReport.setId(id); |
| | | insReport.setState(1); |
| | | insReport.setWriteTime(LocalDateTime.now());//æäº¤æ¶é´ |
| | | insReport.setWriteUserId(userId);//æäº¤äºº |
| | | insReport.setWriteUserId(Integer.getInteger(SecurityUtils.getUserId().toString()));//æäº¤äºº |
| | | //è·åæäº¤äººçç¾åå°å |
| | | String signatureUrl; |
| | | try { |
| | | signatureUrl = userMapper.selectById(Integer.getInteger(SecurityUtils.getUserId().toString())).getSignatureUrl(); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("æ¾ä¸å°ç¼å¶äººçç¾å"); |
| | | } |
| | | //ç³»ç»çææ¥åå°å |
| | | String url = insReport.getUrl(); |
| | | //æå¨ä¸ä¼ æ¥åå°å |
| | | String urlS = insReport.getUrlS(); |
| | | wordInsertUrl(new HashMap<String, Object>() {{ |
| | | put("writeUrl", new FilePictureRenderData(100,50,imgUrl + "/" + signatureUrl)); |
| | | }}, (urlS == null ? url : urlS).replace("/word", wordUrl)); |
| | | // ä¿®æ¹ä¸´æ¶pdf |
| | | String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); |
| | | insReport.setTempUrlPdf("/word/" + tempUrlPdf); |
| | | return insReportMapper.updateById(insReport); |
| | | } |
| | | |
| | | /** |
| | | * åå»ºä¸´æ¶æä»¶ |
| | | * @param inputStream è¾å
¥æµ |
| | | * @param suffix åç¼ |
| | | * @return |
| | | */ |
| | | public String temporaryFile(InputStream inputStream,String suffix) { |
| | | String tempFilePath = ""; |
| | | try { |
| | | File tempFile = File.createTempFile(UUID.randomUUID().toString(), suffix); |
| | | tempFile.deleteOnExit(); |
| | | // å°è¾å
¥æµå
容èµå¼çä¸´æ¶æä»¶ |
| | | try(FileOutputStream fileInputStream = new FileOutputStream(tempFile)) { |
| | | byte[] bytes = new byte[1024]; |
| | | int len; |
| | | while((len = inputStream.read(bytes)) != -1) { |
| | | fileInputStream.write(bytes,0,len); |
| | | } |
| | | // è·åä¸´æ¶æä»¶çè·¯å¾ |
| | | tempFilePath = tempFile.getAbsolutePath(); |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return tempFilePath; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å°æä»¶ä¸ä¼ å°Minio |
| | | * @return |
| | | */ |
| | | public void uploadMinio(String url,Integer id) { |
| | | String suffix = url.substring(url.lastIndexOf(".")); |
| | | // éæ°ä¸ä¼ å°MinIo |
| | | File file = new File(url); |
| | | String fileName = UUID.randomUUID().toString() + suffix; |
| | | FileInputStream stream = null; |
| | | try { |
| | | MinioClient build = MinioClient.builder().endpoint(minioConfig.getEndpoint(), minioConfig.getPort(), minioConfig.getSecure()) |
| | | .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey()) |
| | | .build(); |
| | | stream = new FileInputStream(file); |
| | | build.putObject( |
| | | PutObjectArgs.builder() |
| | | .bucket(minioConfig.getBucketName()) |
| | | .object(fileName) |
| | | .stream(stream, file.length(), -1) |
| | | .contentType("application/octet-stream") |
| | | .userMetadata(Collections.singletonMap("Content-Disposition", "attachment; filename=\"" + fileName + "\"")) |
| | | .build() |
| | | ); |
| | | // ä¿åå°æ°æ®åº |
| | | AttachmentTable attachmentTable = new AttachmentTable(); |
| | | attachmentTable.setBucketName(minioConfig.getBucketName()); |
| | | attachmentTable.setFileName(fileName); |
| | | attachmentTable.setSubclassId(id); |
| | | attachmentTable.setOtherTableName(AttachmentType.getAttachmentValue(1)); |
| | | attachmentTableMapper.insert(attachmentTable); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //å®¡æ ¸ |
| | | @Override |
| | | public int examineReport(Integer id, Integer isExamine, String examineTell) { |
| | | int userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | InsReport insReport = insReportMapper.selectById(id); |
| | | insReport.setIsExamine(isExamine); |
| | | if (ObjectUtils.isNotEmpty(examineTell)) { |
| | | insReport.setExamineTell(examineTell); |
| | | } |
| | | insReport.setExamineUserId(userId);//å®¡æ ¸äºº |
| | | insReport.setExamineUserId(Integer.getInteger(SecurityUtils.getUserId().toString()));//å®¡æ ¸äºº |
| | | insReport.setExamineTime(LocalDateTime.now());//å®¡æ ¸æ¶é´ |
| | | if (isExamine == 0) { |
| | | //å¦æå®¡æ ¸ä¸éè¿ |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int ratifyReport(Integer id, Integer isRatify, String ratifyTell) { |
| | | int userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | InsReport insReport = insReportMapper.selectById(id); |
| | | insReport.setIsRatify(isRatify); |
| | | if (ObjectUtils.isNotEmpty(ratifyTell)) { |
| | | insReport.setRatifyTell(ratifyTell); |
| | | } |
| | | insReport.setRatifyUserId(userId);//æ¹å人 |
| | | insReport.setRatifyUserId(Integer.getInteger(SecurityUtils.getUserId().toString()));//æ¹å人 |
| | | insReport.setRatifyTime(LocalDateTime.now());//æ¹åæ¶é´ |
| | | if (isRatify == 0) { |
| | | //妿æ¹åä¸éè¿ |
| | |
| | | |
| | | @Override |
| | | public Map<String, Object> getReportCountInfo(ReportPageDto reportPageDto) { |
| | | int userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | User user = userMapper.selectById(userId);//å½åç»å½ç人 |
| | | User user = userMapper.selectById(SecurityUtils.getUserId());//å½åç»å½ç人 |
| | | //è·åå½å人æå±å®éªå®¤id |
| | | String departLimsId = user.getDepartLimsId(); |
| | | String laboratory = null; |
| | |
| | | } |
| | | } |
| | | QueryWrapper<ReportPageDto> wrapper = QueryWrappers.queryWrappers(reportPageDto); |
| | | if(Objects.nonNull(reportPageDto) && Objects.nonNull(reportPageDto.getCreateTimeRange())){ |
| | | if(Objects.nonNull(reportPageDto.getCreateTimeRange())){ |
| | | wrapper.gt(reportPageDto.getCreateTimeRange().size()>1,"create_time",reportPageDto.getCreateTimeRange().get(0)) |
| | | .lt(reportPageDto.getCreateTimeRange().size()>1,"create_time",reportPageDto.getCreateTimeRange().get(1)); |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void batchApprovalReport(List<Integer> ids) { |
| | | redisTemplate.setKeySerializer(new StringRedisSerializer()); |
| | | Integer userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | Integer userId = Integer.parseInt(SecurityUtils.getUserId().toString()); |
| | | String key = SYNC_REPORT_KEY_PREFIX+userId; |
| | | //æ§è¡åå é¤ä¹åçkeys |
| | | deleteRedisKeys(key); |
| | |
| | | |
| | | @Override |
| | | public Map<String, Object> getBatchApprovalProgress() { |
| | | Integer userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | Integer userId = Integer.parseInt(SecurityUtils.getUserId().toString()); |
| | | String key = SYNC_REPORT_KEY_PREFIX + userId; |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("hasProgress",false); |
| | |
| | | */ |
| | | public String wordToPdfTemp(String path) { |
| | | try { |
| | | return wordToPdf(path, path.replace(".docx", "")); |
| | | return wordToPdf(path, path.replace(".docx", ".pdf")); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("转æ¢å¤±è´¥"); |
| | | } |
| | |
| | | //çæä¸ä¸ªç©ºçPDFæä»¶ |
| | | File file; |
| | | //夿æ¯å¦æ¯è¿åæ¥å |
| | | file = File.createTempFile(pdfPath, ".pdf"); |
| | | file.deleteOnExit(); |
| | | 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); |
| | | String name = file.getName(); |
| | | return file.getAbsolutePath(); |
| | | return file.getName(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | // @Override |
| | | // public void wordToPdf(String path, String sealUrl) { |
| | | // CompletableFuture.supplyAsync(() -> { |
| | | // try { |
| | | // wordToPdf(path, path.replace(".docx", ".pdf"), sealUrl); |
| | | // return null; |
| | | // } catch (Exception e) { |
| | | // throw new ErrorException("转æ¢å¤±è´¥"); |
| | | // } |
| | | // }).thenAccept(res -> { |
| | | // }).exceptionally(e -> { |
| | | // e.printStackTrace(); |
| | | // return null; |
| | | // }); |
| | | // } |
| | | |
| | | |
| | | |
| | | // 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); |
| | | // if (!license.getIsLicensed()) { |
| | | // System.out.println("Licenseéªè¯ä¸éè¿..."); |
| | | // return null; |
| | | // } |
| | | // //çæä¸ä¸ªç©ºçPDFæä»¶ |
| | | // File file = new File(pdfPath.replace(".pdf", "-1.pdf")); |
| | | // os = new FileOutputStream(file); |
| | | // //è¦è½¬æ¢çwordæä»¶ |
| | | // com.aspose.words.Document doc = new com.aspose.words.Document(wordPath); |
| | | // doc.save(os, SaveFormat.PDF); |
| | | // |
| | | // //æ·»å éªç¼ç« |
| | | // stamperCheckMarkPDF(pdfPath.replace(".pdf", "-1.pdf"), pdfPath, imgUrl + "/" + sealUrl); |
| | | // |
| | | // |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } finally { |
| | | // if (os != null) { |
| | | // try { |
| | | // os.close(); |
| | | // } catch (IOException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // } |
| | | // return null; |
| | | // } |
| | | |
| | | /** |
| | | * åå²å¾ç |
| | |
| | | stamp.close(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |