| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.inspect.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.aspose.words.License; |
| | | import com.aspose.words.SaveFormat; |
| | | 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.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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.FilePictureRenderData; |
| | | import com.itextpdf.text.BadElementException; |
| | | import com.itextpdf.text.DocumentException; |
| | | 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.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.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 org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @description é对表ãins_report(æ£éªæ¥å)ãçæ°æ®åºæä½Serviceå®ç° |
| | | * @createDate 2024-03-17 22:10:02 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport> |
| | | implements InsReportService { |
| | | |
| | | @Resource |
| | | private AttachmentTableMapper attachmentTableMapper; |
| | | |
| | | @Resource |
| | | private AttachmentTableService attachmentTableService; |
| | | |
| | | @Resource |
| | | private MinioConfig minioConfig; |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private UserMapper userMapper; |
| | | |
| | | @Resource |
| | | private InsReportMapper insReportMapper; |
| | | |
| | | @Resource |
| | | ProcessReportMapper processReportMapper; |
| | | |
| | | @Value("${wordUrl}") |
| | | private String wordUrl; |
| | | |
| | | @Value("${file.licenseUrl}") |
| | | private String licenseUrl; |
| | | |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | | |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | @Resource |
| | | private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| | | |
| | | @Resource |
| | | private InsOrderStateMapper insOrderStateMapper; |
| | | |
| | | private static final String SYNC_REPORT_KEY_PREFIX = "syncApprovalReport_lock_"; |
| | | |
| | | @Resource |
| | | private InsReportApproveConfigMapper insReportApproveConfigMapper; |
| | | |
| | | @Override |
| | | public IPage<ReportPageDto> pageInsReport(Page page, ReportPageDto reportPageDto) { |
| | | User user = userMapper.selectById(SecurityUtils.getUserId());//å½åç»å½ç人 |
| | | //è·åå½å人æå±å®éªå®¤id |
| | | String departLimsId = user.getDepartLimsId(); |
| | | String laboratory = null; |
| | | if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.isEmpty()) { |
| | | String[] split = departLimsId.split(","); |
| | | //æ¥è¯¢å¯¹åºæ¶æåç§°(éä¿¡å®éªå®¤,çµåå®éªå®¤,æ£æµå) |
| | | String departLims = insOrderMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); |
| | | if (departLims.contains("å®éªå®¤")) { |
| | | laboratory = departLims; |
| | | } |
| | | } |
| | | QueryWrapper<ReportPageDto> wrapper = QueryWrappers.queryWrappers(reportPageDto); |
| | | if(Objects.nonNull(reportPageDto) && 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) { |
| | | InsReport insReport = new InsReport(); |
| | | insReport.setId(id); |
| | | insReport.setUrlS(url); |
| | | return insReportMapper.updateById(insReport); |
| | | } |
| | | |
| | | // è¿å |
| | | @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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void downReport(Integer id,Integer type, HttpServletResponse response) { |
| | | InsReport insReport = insReportMapper.selectById(id); |
| | | String url = ""; |
| | | // 0 ä¸è½½docx 1 ä¸è½½pdf |
| | | if(type == 0) { |
| | | url = Strings.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl(); |
| | | }else { |
| | | url = insReport.getTempUrlPdf(); |
| | | } |
| | | if(Strings.isEmpty(url)){ |
| | | throw new ErrorException("æ¥åå°å为空"); |
| | | } |
| | | File file = new File(wordUrl + File.separator + url.replace("/word/", "")); |
| | | try { |
| | | String fileName = file.getName(); |
| | | if(fileName.indexOf("_") != -1) { |
| | | fileName = fileName.split("_")[1]; |
| | | } |
| | | fileName = URLEncoder.encode(fileName, "UTF-8"); |
| | | response.setContentType("application/octet-stream"); |
| | | response.setHeader("Content-disposition","attachment;filename=" + fileName); |
| | | ServletOutputStream stream = response.getOutputStream(); |
| | | FileInputStream fileInputStream = new FileInputStream(file); |
| | | byte[] bytes = new byte[1024]; |
| | | int byteRead; |
| | | while((byteRead = fileInputStream.read(bytes)) != -1){ |
| | | stream.write(bytes, 0, byteRead); |
| | | stream.flush(); |
| | | } |
| | | fileInputStream.close(); |
| | | stream.close(); |
| | | }catch (Exception e){ |
| | | throw new ErrorException("ä¸è½½å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //æäº¤ |
| | | @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);//æäº¤äºº |
| | | 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.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", 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); |
| | | } |
| | | |
| | | //æ¹å |
| | | @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.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(); |
| | | String finalUrl = (urlS == null ? url : urlS).replace("/word", wordUrl); |
| | | wordInsertUrl(new HashMap<String, Object>() {{ |
| | | put("ratifyUrl", new FilePictureRenderData(100,50,imgUrl + "/" + signatureUrl)); |
| | | put("seal1", new FilePictureRenderData(600,600,imgUrl + "/" + sealUrl)); |
| | | put("seal2", new FilePictureRenderData(600,600,imgUrl + "/" + sealUrl)); |
| | | }}, finalUrl); |
| | | wordToPdf(finalUrl, sealUrl); |
| | | |
| | | InsOrder insOrder = new InsOrder(); |
| | | insOrder.setId(insReportMapper.selectById(id).getInsOrderId()); |
| | | insOrder.setState(4); |
| | | insOrderMapper.updateById(insOrder); |
| | | // ä¿®æ¹ä¸´æ¶pdf |
| | | String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); |
| | | insReport.setTempUrlPdf("/word/" + tempUrlPdf); |
| | | /*æ°å¢cnas7.8æ¥åç»æ*/ |
| | | ProcessReport processReport = new ProcessReport(); |
| | | processReport.setInsReportCode(insReport.getCode()); |
| | | processReportMapper.insert(processReport); |
| | | 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 |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String downAll(String ids) { |
| | | List<Long> list = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList()); |
| | | List<InsReport> insReports = insReportMapper.selectBatchIds(list); |
| | | String zipFilePath = null; |
| | | // ä¸´æ¶æä»¶å¤¹è·¯å¾ |
| | | try { |
| | | String tempFolderPath = wordUrl + "/tempFolder"; |
| | | File tempFolder = new File(tempFolderPath); |
| | | if (tempFolder.exists()) { |
| | | deleteDirectory(tempFolder); // å 餿§çä¸´æ¶æä»¶å¤¹ |
| | | } |
| | | tempFolder.mkdirs(); // å建æ°çä¸´æ¶æä»¶å¤¹ |
| | | for (InsReport insReport : insReports) { |
| | | File sourceFile = new File((ObjectUtils.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl()).replace("/word", wordUrl)); |
| | | // ä¸è½½æä»¶åç§°å»é¤æ¶é´ |
| | | String destinationFileName = sourceFile.getName(); |
| | | if(destinationFileName.indexOf("_") != -1) { |
| | | destinationFileName = destinationFileName.split("_")[1]; |
| | | } |
| | | File destinationFile = new File(tempFolder, destinationFileName); |
| | | Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | // åç¼©ä¸´æ¶æä»¶å¤¹ |
| | | zipFilePath = wordUrl + "/zip/output.zip"; |
| | | zipDirectory(tempFolderPath, zipFilePath); |
| | | |
| | | // æ¸
çä¸´æ¶æä»¶å¤¹ |
| | | deleteDirectory(tempFolder); |
| | | |
| | | System.out.println("ZIPæä»¶åå»ºå®æï¼"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return "/word/zip/output.zip"; |
| | | } |
| | | |
| | | //æ¹éä¸ä¼ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int upAll(MultipartFile file) { |
| | | if (file != null) { |
| | | // æ ¹æ®æä»¶åæ¥è¯¢id |
| | | String fileName = file.getOriginalFilename(); |
| | | String code = fileName.replace(".docx", "").replace("JCZX", "JCZX/"); |
| | | if(fileName.lastIndexOf("_") != -1) { |
| | | code = code.substring(file.getOriginalFilename().lastIndexOf("_") + 1); |
| | | } |
| | | //æ¥è¯¢æªå®¡æ ¸çæ¥åæ°æ® |
| | | InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().eq(InsReport::getCode, code).eq(InsReport::getIsExamine,-9)); |
| | | if (ObjectUtils.isEmpty(insReport)) { |
| | | throw new ErrorException("没æç¼å·ä¸º" + code + "çæ¥åæè¯¥æ¥åå·²å®¡æ ¸éè¿"); |
| | | } |
| | | // 妿UrlSæå¼ å
å°è¯¥æä»¶å é¤ |
| | | if(Strings.isNotEmpty(insReport.getUrlS())) { |
| | | String url = wordUrl + File.separator + insReport.getUrlS().replace("/word/", ""); |
| | | File file1 = new File(url); |
| | | if(file1.exists()) { |
| | | file1.delete(); |
| | | } |
| | | } |
| | | String urlString; |
| | | String pathName; |
| | | String path = wordUrl; |
| | | File realpath = new File(path); |
| | | if (!realpath.exists()) { |
| | | realpath.mkdirs(); |
| | | } |
| | | pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + insReport.getCode().replace("/", "") + ".docx"; |
| | | urlString = realpath + "/" + pathName; |
| | | // å¤å¶æä»¶å°æå®è·¯å¾ |
| | | try { |
| | | Files.copy(file.getInputStream(), new File(urlString).toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | inReport("/word/" + pathName, insReport.getId()); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void withdraw(Map<String,Object> map) { |
| | | Integer id = Integer.parseInt(map.get("id").toString()); |
| | | List<String> list = JSONArray.parseArray(map.get("laboratory").toString(), String.class); |
| | | Integer insOrderId = insReportMapper.selectById(id).getInsOrderId(); |
| | | List<InsOrderState> insOrderStateS = insOrderStateMapper.selectList(new LambdaQueryWrapper<InsOrderState>() |
| | | .eq(InsOrderState::getInsOrderId, insOrderId) |
| | | .in(CollectionUtils.isNotEmpty(list),InsOrderState::getLaboratory, list)); |
| | | if(CollectionUtils.isNotEmpty(insOrderStateS)) { |
| | | List<Integer> collect = insOrderStateS.stream().map(InsOrderState::getId).collect(Collectors.toList()); |
| | | // ä¿®æ¹è¯¥ååè¯éªå®¤çç¶æä¸ºå¾
夿 ¸ï¼å 餿¥åä¿¡æ¯ |
| | | insOrderStateMapper.update(null,new LambdaUpdateWrapper<InsOrderState>() |
| | | .set(InsOrderState::getInsState,3) // å¾
夿 ¸ |
| | | .in(InsOrderState::getId,collect)); |
| | | insReportMapper.delete(new LambdaQueryWrapper<InsReport>().eq(InsReport::getId,id)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getLaboratoryByReportId(Integer id) { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | Integer insOrderId = insReportMapper.selectById(id).getInsOrderId(); |
| | | insOrderStateMapper.selectList(new LambdaQueryWrapper<InsOrderState>() |
| | | .eq(InsOrderState::getInsOrderId,insOrderId)) |
| | | .forEach(insOrderState -> { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("label",insOrderState.getLaboratory()); |
| | | map.put("value",insOrderState.getLaboratory()); |
| | | list.add(map); |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | @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);//å½åç»å½ç人 |
| | | //è·åå½å人æå±å®éªå®¤id |
| | | String departLimsId = user.getDepartLimsId(); |
| | | String laboratory = null; |
| | | if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.isEmpty()) { |
| | | String[] split = departLimsId.split(","); |
| | | //æ¥è¯¢å¯¹åºæ¶æåç§°(éä¿¡å®éªå®¤,çµåå®éªå®¤,æ£æµå) |
| | | String departLims = insOrderMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); |
| | | if (departLims.contains("å®éªå®¤")) { |
| | | laboratory = departLims; |
| | | } |
| | | } |
| | | QueryWrapper<ReportPageDto> wrapper = QueryWrappers.queryWrappers(reportPageDto); |
| | | if(Objects.nonNull(reportPageDto) && 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)); |
| | | |
| | | } |
| | | map.put("unSubmitCount",insReportMapper.findReportCountInfo(wrapper,laboratory,"ir.write_user_id").size()); |
| | | map.put("unExamineCount",insReportMapper.findReportCountInfo(wrapper,laboratory,"ir.is_examine").size()); |
| | | map.put("unRatifyCount",insReportMapper.findReportCountInfo(wrapper,laboratory,"ir.is_ratify").size()); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void batchApprovalReport(List<Integer> ids) { |
| | | redisTemplate.setKeySerializer(new StringRedisSerializer()); |
| | | Integer userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | String key = SYNC_REPORT_KEY_PREFIX+userId; |
| | | //æ§è¡åå é¤ä¹åçkeys |
| | | deleteRedisKeys(key); |
| | | synchronized (key) { |
| | | redisTemplate.opsForValue().set(key,1); |
| | | RequestContextHolder.setRequestAttributes(RequestContextHolder.getRequestAttributes(),true); |
| | | //弿¥æ§è¡å®¡æ¹æä½ |
| | | CompletableFuture.runAsync(() -> { |
| | | try { |
| | | runBatchApproval(ids,key); |
| | | }catch (Exception e){ |
| | | //å é¤key |
| | | deleteRedisKeys(key); |
| | | redisTemplate.opsForValue().set(key+"_exception",e.getMessage()); |
| | | } |
| | | },threadPoolTaskExecutor); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤redis key |
| | | * @param key |
| | | */ |
| | | private void deleteRedisKeys(String key){ |
| | | redisTemplate.delete(key); |
| | | redisTemplate.delete(key+"_num"); |
| | | redisTemplate.delete(key+"_count"); |
| | | redisTemplate.delete(key+"_surplus"); |
| | | redisTemplate.delete(key+"_exception"); |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡å®¡æ¹æä½ |
| | | * @param ids æ¥åidå表 |
| | | */ |
| | | private void runBatchApproval(List<Integer> ids,String keyPrefix) { |
| | | if(ids.isEmpty()){ |
| | | return; |
| | | } |
| | | long start = System.currentTimeMillis(); |
| | | String surplusKey = keyPrefix + "_surplus";//å©ä½æ¡æ° |
| | | String numKey = keyPrefix + "_num";//æ»è¿åº¦ |
| | | String countKey = keyPrefix + "_count";//æ»æ¡æ° |
| | | redisTemplate.opsForValue().set(countKey, ids.size()); |
| | | redisTemplate.opsForValue().set(surplusKey, ids.size()); |
| | | Object countObj = redisTemplate.opsForValue().get(countKey); |
| | | long parsed2 = Long.parseLong(String.valueOf(countObj)); |
| | | AtomicLong count = new AtomicLong(parsed2); |
| | | for (Integer id : ids) { |
| | | //ä¸å¡ä»£ç |
| | | InsReport insReport = insReportMapper.selectById(id); |
| | | String laboratory = insOrderMapper.selectById(insReport.getInsOrderId()).getLaboratory(); |
| | | //è·åç¾ååå°ç« |
| | | String sealUrl; |
| | | String writeUrl; |
| | | String examineUrl; |
| | | String ratifyUrl; |
| | | int writeId; |
| | | int examineId; |
| | | int ratifyId; |
| | | try { |
| | | sealUrl = insReportMapper.getLaboratoryByName(laboratory);//å°ç« |
| | | Map<String,Object> urlMap = insReportApproveConfigMapper.selectApprovalConfigByLaboratory(laboratory);//ç¾å |
| | | writeUrl = imgUrl + "/" + (Objects.isNull(urlMap.get("writeUrl"))?"":urlMap.get("writeUrl").toString());//ç¼å¶äººç¾åurl |
| | | examineUrl = imgUrl + "/" + (Objects.isNull(urlMap.get("examineUrl"))?"":urlMap.get("examineUrl").toString());//å®¡æ ¸äººç¾åurl |
| | | ratifyUrl = imgUrl + "/" + (Objects.isNull(urlMap.get("ratifyUrl"))?"":urlMap.get("ratifyUrl").toString());//æ¹å人ç¾åurl |
| | | writeId = Integer.parseInt(urlMap.get("writeId").toString());//ç¼å¶äºº |
| | | examineId = Integer.parseInt(urlMap.get("examineId").toString());//å®¡æ ¸äººç¾ |
| | | ratifyId =Integer.parseInt(urlMap.get("ratifyId").toString());//æ¹å人 |
| | | } catch (Exception e) { |
| | | throw new ErrorException("æ¾ä¸å°ç¾ååå°ç« "); |
| | | } |
| | | //设置æ¥åä¿¡æ¯ |
| | | insReport.setIsExamine(1); |
| | | insReport.setIsRatify(1); |
| | | insReport.setState(1); |
| | | insReport.setWriteUserId(writeId); |
| | | insReport.setExamineUserId(examineId); |
| | | insReport.setRatifyUserId(ratifyId); |
| | | if(Objects.isNull(insReport.getWriteTime())){ |
| | | insReport.setWriteTime(LocalDateTime.now()); |
| | | } |
| | | if(Objects.isNull(insReport.getExamineTime())){ |
| | | insReport.setExamineTime(LocalDateTime.now()); |
| | | } |
| | | if(Objects.isNull(insReport.getRatifyTime())){ |
| | | insReport.setRatifyTime(LocalDateTime.now()); |
| | | } |
| | | //æ´æ°è®¢åç¶æ |
| | | InsOrder insOrder = new InsOrder(); |
| | | insOrder.setId(insReport.getInsOrderId()); |
| | | insOrder.setState(4); |
| | | insOrderMapper.updateById(insOrder); |
| | | //ç³»ç»çææ¥åå°å |
| | | String url = insReport.getUrl(); |
| | | //æå¨ä¸ä¼ æ¥åå°å |
| | | String urlS = insReport.getUrlS(); |
| | | String finalUrl = (StringUtils.isBlank(urlS) ? url : urlS).replace("/word", wordUrl); |
| | | wordInsertUrl(new HashMap<String, Object>() {{ |
| | | put("writeUrl", new FilePictureRenderData(100,50,writeUrl)); |
| | | put("examineUrl", new FilePictureRenderData(100,50,examineUrl)); |
| | | put("ratifyUrl", new FilePictureRenderData(100,50,ratifyUrl)); |
| | | put("seal1", new FilePictureRenderData(600,600,imgUrl + "/" +sealUrl)); |
| | | put("seal2", new FilePictureRenderData(600,600,imgUrl + "/" +sealUrl)); |
| | | }}, finalUrl); |
| | | wordToPdf(finalUrl, sealUrl); |
| | | // ä¿®æ¹ä¸´æ¶pdf |
| | | String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); |
| | | insReport.setTempUrlPdf("/word/" + tempUrlPdf); |
| | | //æ´æ°æ¥åç¶æ |
| | | insReportMapper.updateById(insReport); |
| | | //æ´æ°redisçkey |
| | | Object o = redisTemplate.opsForValue().get(numKey); |
| | | if (Objects.isNull(o)) { |
| | | redisTemplate.opsForValue().set(numKey, 1); |
| | | } else { |
| | | long parsed = Long.parseLong(String.valueOf(o)); |
| | | redisTemplate.opsForValue().set(numKey, parsed + 1); |
| | | } |
| | | redisTemplate.opsForValue().set(surplusKey, count.decrementAndGet()); |
| | | } |
| | | long end = System.currentTimeMillis(); |
| | | long useTime = (end-start)/1000; |
| | | log.info("线ç¨{}æ¥å审æ¹ç»æï¼èæ¶:{}s",keyPrefix,useTime); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getBatchApprovalProgress() { |
| | | Integer userId = Integer.parseInt(SecurityUtils.getUserId() + ""); |
| | | String key = SYNC_REPORT_KEY_PREFIX + userId; |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("hasProgress",false); |
| | | map.put("hasNum",0); |
| | | map.put("hasCount",0); |
| | | map.put("surplus",0); |
| | | Object o = redisTemplate.opsForValue().get(key); |
| | | if(Objects.nonNull(o)){ |
| | | map.put("hasProgress",true); |
| | | } |
| | | Object o1 = redisTemplate.opsForValue().get(key+"_num"); |
| | | Object o2 = redisTemplate.opsForValue().get(key+"_count"); |
| | | Object surplus = redisTemplate.opsForValue().get(key+"_surplus"); |
| | | Object exception = redisTemplate.opsForValue().get(key+"_exception"); |
| | | if(Objects.nonNull(surplus)){ |
| | | map.put("surplus",surplus); |
| | | } |
| | | if (Objects.nonNull(o1)&&Objects.nonNull(o2)){ |
| | | //å¾å°è¿åº¦ |
| | | BigDecimal multiply = new BigDecimal(String.valueOf(o1)).divide(new BigDecimal(String.valueOf(o2)), 2,BigDecimal.ROUND_DOWN).multiply(BigDecimal.valueOf(100)); |
| | | map.put("hasNum",multiply); |
| | | map.put("hasCount",Long.parseLong(String.valueOf(o2))); |
| | | } |
| | | map.put("hasException",exception); |
| | | return map; |
| | | } |
| | | |
| | | //è§£åæä»¶å¤¹ |
| | | private void unzip(File zipFile, File destDir) throws IOException { |
| | | try (ZipFile zip = new ZipFile(zipFile)) { |
| | | Enumeration<? extends ZipEntry> entries = zip.entries(); |
| | | while (entries.hasMoreElements()) { |
| | | ZipEntry entry = entries.nextElement(); |
| | | File file = new File(destDir, entry.getName()); |
| | | if (entry.isDirectory()) { |
| | | file.mkdirs(); |
| | | } else { |
| | | file.getParentFile().mkdirs(); |
| | | try (InputStream in = zip.getInputStream(entry); |
| | | OutputStream out = new FileOutputStream(file)) { |
| | | byte[] buffer = new byte[1024]; |
| | | int len; |
| | | while ((len = in.read(buffer)) > 0) { |
| | | out.write(buffer, 0, len); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // å缩æä»¶å¤¹ |
| | | public static void zipDirectory(String sourceDirPath, String zipFilePath) throws IOException { |
| | | try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFilePath))) { |
| | | Path sourceDir = Paths.get(sourceDirPath); |
| | | Files.walk(sourceDir) |
| | | .filter(path -> !Files.isDirectory(path)) |
| | | .forEach(path -> { |
| | | ZipEntry zipEntry = new ZipEntry(sourceDir.relativize(path).toString()); |
| | | try { |
| | | zipOut.putNextEntry(zipEntry); |
| | | Files.copy(path, zipOut); |
| | | zipOut.closeEntry(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // å 餿件夹åå
¶å
容 |
| | | public static void deleteDirectory(File directory) throws IOException { |
| | | if (directory.isDirectory()) { |
| | | File[] files = directory.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | | deleteDirectory(file); |
| | | } |
| | | } |
| | | } |
| | | Files.delete(directory.toPath()); |
| | | } |
| | | |
| | | /** |
| | | * word转æ¢pdf |
| | | * @param path |
| | | * @return |
| | | */ |
| | | public String wordToPdfTemp(String path) { |
| | | try { |
| | | return wordToPdf(path, path.replace(".docx", "")); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("转æ¢å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | public String wordToPdf(String wordPath, String pdfPath) { |
| | | FileOutputStream os = null; |
| | | try { |
| | | //åè¯ ä¸ç¶åæ¢åææ°´å° |
| | | InputStream is = Files.newInputStream(new File(licenseUrl).toPath()); |
| | | License license = new License(); |
| | | license.setLicense(is); |
| | | if (!license.getIsLicensed()) { |
| | | System.out.println("Licenseéªè¯ä¸éè¿..."); |
| | | return null; |
| | | } |
| | | //çæä¸ä¸ªç©ºçPDFæä»¶ |
| | | File file; |
| | | //夿æ¯å¦æ¯è¿åæ¥å |
| | | file = File.createTempFile(pdfPath, ".pdf"); |
| | | file.deleteOnExit(); |
| | | 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(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (os != null) { |
| | | try { |
| | | os.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * åå²å¾ç |
| | | * |
| | | * @param Path å¾çè·¯å¾ |
| | | * @param n åå²ä»½æ° |
| | | */ |
| | | public static com.itextpdf.text.Image[] slicingImages(String Path, int n) throws IOException, BadElementException { |
| | | com.itextpdf.text.Image[] nImage = new com.itextpdf.text.Image[n]; |
| | | BufferedImage img = ImageIO.read(new File(Path)); |
| | | |
| | | int h = img.getHeight(); |
| | | int w = img.getWidth(); |
| | | |
| | | int sw = w / n; |
| | | for (int i = 0; i < n; i++) { |
| | | BufferedImage subImg; |
| | | if (i == n - 1) {//æåå©ä½é¨å |
| | | subImg = img.getSubimage(i * sw, 0, w - i * sw, h); |
| | | } else {//ån-1åååå |
| | | subImg = img.getSubimage(i * sw, 0, sw, h); |
| | | } |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | ImageIO.write(subImg, Path.substring(Path.lastIndexOf('.') + 1), out); |
| | | nImage[i] = com.itextpdf.text.Image.getInstance(out.toByteArray()); |
| | | |
| | | } |
| | | return nImage; |
| | | } |
| | | |
| | | /** |
| | | * çéªç¼ç« |
| | | * |
| | | * @param infilePath åPDFè·¯å¾ |
| | | * @param outFilePath è¾åºPDFè·¯å¾ |
| | | */ |
| | | public static void stamperCheckMarkPDF(String infilePath, String outFilePath, String picPath) throws IOException, DocumentException { |
| | | PdfReader reader = new PdfReader(infilePath);//éæ©éè¦å°ç« çpdf |
| | | PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outFilePath));//å å®å°ç« åçpdf |
| | | |
| | | |
| | | com.itextpdf.text.Rectangle pageSize = reader.getPageSize(1);//è·å¾ç¬¬ä¸é¡µ |
| | | float height = pageSize.getHeight(); |
| | | float width = pageSize.getWidth(); |
| | | |
| | | int nums = reader.getNumberOfPages(); |
| | | com.itextpdf.text.Image[] nImage = slicingImages(picPath, nums);//çæéªç¼ç« åå²å¾ç |
| | | |
| | | for (int n = 1; n <= nums; n++) { |
| | | PdfContentByte over = stamp.getOverContent(n);//设置å¨ç¬¬å 页æå°å°ç« |
| | | com.itextpdf.text.Image img = nImage[n - 1];//éæ©å¾ç |
| | | float newHeight = 100f; |
| | | float newWidth = img.getWidth() / (img.getHeight() / 100); |
| | | img.scaleAbsolute(newWidth, newHeight);//æ§å¶å¾çå¤§å° |
| | | img.setAbsolutePosition(width - newWidth, height / 2 - newHeight / 2);//æ§å¶å¾çä½ç½® |
| | | over.addImage(img); |
| | | } |
| | | stamp.close(); |
| | | } |
| | | } |