inspect-server/pom.xml
@@ -45,6 +45,11 @@ <groupId>com.ruoyi</groupId> <artifactId>performance-server</artifactId> </dependency> <dependency> <groupId>com.ruoyi</groupId> <artifactId>cnas-process</artifactId> </dependency> <!-- poi-tlå çææ¥å --> <dependency> inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportApproveConfigController.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,39 @@ package com.ruoyi.inspect.controller; import com.ruoyi.common.core.domain.Result; import com.ruoyi.inspect.dto.ApproveConfigDTO; import com.ruoyi.inspect.service.InsReportApproveConfigService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/approveConfig") @Api(tags = "æ¥å审æ¹ç¾åé ç½®") public class InsReportApproveConfigController { @Autowired private InsReportApproveConfigService insReportApproveConfigService; @ApiOperation("审æ¹ç¾åé ç½®æé®") @GetMapping("/getApproveConfigList") public Result getApproveConfigList(){ return Result.success(insReportApproveConfigService.getApproveConfigList()); } @ApiOperation("æ¥è¯¢äººå") @GetMapping("/getUserList") public Result getUserList(){ return Result.success(insReportApproveConfigService.getUserList()); } @ApiOperation("æ´æ°å®¡æ¹ç¾åé ç½®") @PostMapping("/updateApproveConfig") public Result updateApproveConfig(@RequestBody ApproveConfigDTO approveConfigDTO){ return Result.success(insReportApproveConfigService.updateApproveConfig(approveConfigDTO)); } } inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,217 @@ package com.ruoyi.inspect.controller; import cn.hutool.core.io.FileUtil; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.domain.Result; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.JackSonUtil; import com.ruoyi.framework.exception.ErrorException; import com.ruoyi.inspect.dto.BatchApprovalReportDTO; import com.ruoyi.inspect.dto.ReportPageDto; import com.ruoyi.inspect.pojo.InsReport; import com.ruoyi.inspect.service.InsReportService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.logging.log4j.util.Strings; import org.apache.poi.hssf.record.SSTRecord; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Map; import java.util.Objects; import java.util.Scanner; @RestController @RequestMapping("/insReport") @Api(tags = "æ£éªæ¥å") public class InsReportController { @Resource private InsReportService insReportService; @Value("${wordUrl}") private String wordUrl; @ApiOperation(value = "æ¥çæ£éªæ¥åå表") @GetMapping("/pageInsReport") public Result pageInsReport(Page page , ReportPageDto reportPageDto) throws Exception { return Result.success(insReportService.pageInsReport(page, reportPageDto)); } @ApiOperation(value = "ä¸é®å®¡æ¹æé®") @PostMapping("/batchApprovalReport") @Log(title = "æ£éªæ¥å", businessType = BusinessType.UPDATE) public Result batchApprovalReport(@RequestBody BatchApprovalReportDTO batchApprovalReportDTO){ try { insReportService.batchApprovalReport(batchApprovalReportDTO.getIds()); }catch (Exception e){ throw new RuntimeException(e); } return Result.success(); } @ApiOperation(value = "è·å审æ¹è¿åº¦") @GetMapping("/getBatchApprovalProgress") public Result getBatchApprovalProgress(){ return Result.success(insReportService.getBatchApprovalProgress()); } @ApiOperation(value = "æ¥çæ£éªæ¥åæ°éä¿¡æ¯") @GetMapping("/getReportCountInfo") public Result getReportCountInfo(@RequestParam Map<String, Object> params) throws Exception { ReportPageDto reportPageDto = JackSonUtil.unmarshal(JackSonUtil.marshal(params), ReportPageDto.class); return Result.success(insReportService.getReportCountInfo(reportPageDto)); } @ApiOperation(value = "ä¸ä¼ æé®") @PostMapping("/inReport") @Log(title = "æ£éªæ¥å", businessType = BusinessType.IMPORT) public Result inReport(MultipartFile file, Integer id) { String urlString; String pathName; try { String path = wordUrl; File realpath = new File(path); if (!realpath.exists()) { realpath.mkdirs(); } InsReport insReport = insReportService.getById(id); // 妿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 code = insReport.getCode().replace("/", "") + ".docx"; pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + code; urlString = realpath + "/" + pathName; file.transferTo(new File(urlString)); return Result.success(insReportService.inReport("/word/" + pathName, id)); } catch (Exception e) { throw new ErrorException("æä»¶ä¸ä¼ 失败"); } } //ä¸è½½ @GetMapping("/downReport") @Log(title = "æ£éªæ¥å", businessType = BusinessType.EXPORT) public void downReport(@RequestParam("id") Integer id,@RequestParam("type") Integer type, HttpServletResponse response) { insReportService.downReport(id,type, response); } @ApiOperation(value = "è¿åæé®") @PostMapping("/upReportUrl") @Log(title = "æ£éªæ¥å", businessType = BusinessType.UPDATE) public Result upReportUrl(Integer id,Integer type) { insReportService.upReportUrl(id,type); return Result.success(); } @ApiOperation(value = "ç¼å¶æé®") @GetMapping("/upReportFile") @Log(title = "æ£éªæ¥å", businessType = BusinessType.UPDATE) public Result upReportFile() { return Result.success(); } @ApiOperation(value = "æäº¤æé®") @PostMapping("/writeReport") @Log(title = "æ£éªæ¥å", businessType = BusinessType.UPDATE) public Result writeReport(Integer id) { return Result.success(insReportService.writeReport(id)); } @ApiOperation(value = "å®¡æ ¸æé®") @PostMapping("/examineReport") @Log(title = "æ£éªæ¥å", businessType = BusinessType.UPDATE) public Result examineReport(Integer id, Integer isExamine, String examineTell) { return Result.success(insReportService.examineReport(id, isExamine, examineTell)); } @ApiOperation(value = "æ¹åæé®") @PostMapping("/ratifyReport") @Log(title = "æ£éªæ¥å", businessType = BusinessType.UPDATE) public Result ratifyReport(Integer id, Integer isRatify, String ratifyTell) { return Result.success(insReportService.ratifyReport(id, isRatify, ratifyTell)); } @RequestMapping("/onlyOffice/save") @Log(title = "æ£éªæ¥å", businessType = BusinessType.OTHER) public void saveFile(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) { PrintWriter writer = null; try { writer = response.getWriter(); // è·åä¼ è¾çjsonæ°æ® Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A"); String body = scanner.hasNext() ? scanner.next() : ""; JSONObject jsonObject = JSONObject.parseObject(body); if (jsonObject.containsKey("url")) { String jsonArray = jsonObject.get("lastsave").toString(); // æ´æ°æ¶é´ String fileUrl = jsonObject.get("url").toString(); // æ´æ°æä»¶url HttpUtil.downloadFile(fileUrl, FileUtil.file(wordUrl + "/" + fileName)); } } catch (Exception e) { e.printStackTrace(); writer.write("{\"error\":-1}"); return; } /* * status = 1ï¼æä»¬ç»onlyOfficeçæå¡è¿å{"error":"0"}çä¿¡æ¯ã * è¿æ ·onlyOfficeä¼è®¤ä¸ºåè°æ¥å£æ¯æ²¡é®é¢çï¼è¿æ ·å°±å¯ä»¥å¨çº¿ç¼è¾ææ¡£äºï¼å¦åçè¯ä¼å¼¹åºçªå£è¯´æ */ if (Objects.nonNull(writer)) { writer.write("{\"error\":0}"); } } @ApiOperation(value = "æ¹éä¸è½½æé®") @GetMapping("/downAll") @Log(title = "æ£éªæ¥å", businessType = BusinessType.EXPORT) public Result downAll(String ids) { return Result.success(insReportService.downAll(ids)); } @ApiOperation(value = "æ¹éä¸ä¼ æé®") @PostMapping("/upAll") @Log(title = "æ£éªæ¥å", businessType = BusinessType.IMPORT) public Result upAll(MultipartFile file) throws IOException { return Result.success(insReportService.upAll(file)); } @ApiOperation(value = "æ¤åæé®") @PostMapping("/withdraw") @Log(title = "æ£éªæ¥å", businessType = BusinessType.UPDATE) public Result withdraw(@RequestBody Map<String,Object> map) { insReportService.withdraw(map); return Result.success(); } @GetMapping("/getLaboratoryByReportId") public Result getLaboratoryByReportId(Integer id) { return Result.success(insReportService.getLaboratoryByReportId(id)); } } inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportApproveConfigService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,24 @@ package com.ruoyi.inspect.service; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.inspect.dto.ApproveConfigDTO; import com.ruoyi.inspect.pojo.InsReportApproveConfig; import java.util.List; import java.util.Map; /** * @author 27233 * @description é对表ãins_report_approve_config(æ¥å审æ¹ç¾åé ç½®)ãçæ°æ®åºæä½Service * @createDate 2024-12-10 09:36:10 */ public interface InsReportApproveConfigService extends IService<InsReportApproveConfig> { List<InsReportApproveConfig> getApproveConfigList(); InsReportApproveConfig getApproveConfigByLaboratory(String laboratory); Map<String, List<Map<String,Object>>> getUserList(); boolean updateApproveConfig(ApproveConfigDTO approveConfigDTO); } inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,54 @@ package com.ruoyi.inspect.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.inspect.dto.ReportPageDto; import com.ruoyi.inspect.pojo.InsReport; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; import java.util.Map; /** * @author Administrator * @description é对表ãins_report(æ£éªæ¥å)ãçæ°æ®åºæä½Service * @createDate 2024-03-17 22:10:02 */ public interface InsReportService extends IService<InsReport> { IPage<ReportPageDto> pageInsReport(Page page, ReportPageDto reportPageDto); int inReport(String url, Integer id); void upReportUrl(Integer id,Integer type); // ä¸è½½ void downReport(Integer id, Integer type , HttpServletResponse response); //æäº¤ int writeReport(Integer id); //å®¡æ ¸ int examineReport(Integer id, Integer isExamine, String examineTell); //æ¹å int ratifyReport(Integer id, Integer isRatify, String ratifyTell); int wordInsertUrl(Map<String, Object> map, String url); String downAll(String ids); int upAll(MultipartFile file) throws IOException; void withdraw(Map<String,Object> map); List<Map<String,Object>> getLaboratoryByReportId(Integer id); Map<String,Object> getReportCountInfo(ReportPageDto reportPageDto); void batchApprovalReport(List<Integer> ids); Map<String,Object> getBatchApprovalProgress(); } inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportApproveConfigServiceImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,92 @@ package com.ruoyi.inspect.service.impl; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.entity.User; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.inspect.dto.ApproveConfigDTO; import com.ruoyi.inspect.mapper.InsOrderMapper; import com.ruoyi.inspect.mapper.InsReportApproveConfigMapper; import com.ruoyi.inspect.pojo.InsReportApproveConfig; import com.ruoyi.inspect.service.InsReportApproveConfigService; import com.ruoyi.system.mapper.UserMapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author 27233 * @description é对表ãins_report_approve_config(æ¥å审æ¹ç¾åé ç½®)ãçæ°æ®åºæä½Serviceå®ç° * @createDate 2024-12-10 09:36:10 */ @Service public class InsReportApproveConfigServiceImpl extends ServiceImpl<InsReportApproveConfigMapper, InsReportApproveConfig> implements InsReportApproveConfigService { @Autowired private UserMapper userMapper; @Autowired private InsOrderMapper insOrderMapper; @Override public List<InsReportApproveConfig> getApproveConfigList() { Integer userId = Integer.parseInt(SecurityUtils.getUserId()+""); 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; } } return baseMapper.selectList(Wrappers.<InsReportApproveConfig>lambdaQuery() .eq(StringUtils.isNotBlank(laboratory),InsReportApproveConfig::getLaboratory,laboratory)); } @Override public InsReportApproveConfig getApproveConfigByLaboratory(String laboratory) { return baseMapper.selectOne(Wrappers.<InsReportApproveConfig>lambdaQuery() .eq(StringUtils.isNotBlank(laboratory),InsReportApproveConfig::getLaboratory,laboratory)); } @Override public Map<String, List<Map<String,Object>>> getUserList() { //æ¥è¯¢éä¿¡åçµåä¸ç人åä¿¡æ¯ //æ¥è¯¢å½åç»å½äººåçæ¶æ Integer userId = Integer.parseInt(SecurityUtils.getUserId()+""); //å¤æå ¨é¨,个人,ç»ç»çæé User user = userMapper.selectById(userId);//å½åç»å½ç人 //è·åå½å人æå±å®éªå®¤id String laboratory = ""; String departLimsId = user.getDepartLimsId(); if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(departLimsId)) { String[] split = departLimsId.split(","); //æ¥è¯¢å¯¹åºæ¶æåç§°(éä¿¡å®éªå®¤,çµåå®éªå®¤,æ£æµå) String departLims = userMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); if (departLims.contains("å®éªå®¤")) { laboratory = departLims; } } return userMapper.getPersonList(laboratory).stream().collect(Collectors.groupingBy(m->m.get("depName").toString())); } @Override public boolean updateApproveConfig(ApproveConfigDTO approveConfigDTO) { if(!approveConfigDTO.getConfigList().isEmpty()){ approveConfigDTO.getConfigList().forEach(config->baseMapper.updateById(config)); return true; } throw new RuntimeException("æ´æ°å¤±è´¥"); } } inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,876 @@ 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(); } } performance-server/src/main/resources/mapper/PerformanceShiftMapper.xml
@@ -110,8 +110,9 @@ <select id="performanceShiftList" resultMap="performanceShiftPageMap"> SELECT if(u.department is not null and u.department != '', CONCAT(u.name, 'ï¼', u.department, 'ï¼'), u.name) name, GROUP_CONCAT(s.work_time, 'ï¼', s.shift, 'ï¼', s.id order by s.work_time SEPARATOR ';') AS shift_time, u.id user_id, u.department <!--if(u.department is not null and u.department != '', CONCAT(u.name, 'ï¼', u.department, 'ï¼'), u.name) name,--> u.name name, GROUP_CONCAT(s.work_time, 'ï¼', s.shift, 'ï¼', s.id order by s.work_time SEPARATOR ';') AS shift_time, u.id user_id, u.dept_id FROM performance_shift s LEFT JOIN user u on u.id = s.user_id <where> @@ -124,8 +125,8 @@ <if test="laboratory != null and laboratory != ''"> </if> </where> order by s.create_time GROUP BY u.id order by s.create_time </select> <select id="seldepLimsId" resultType="java.lang.String"> ruoyi-common/src/main/java/com/ruoyi/common/config/MinioConfig.java
@@ -17,6 +17,7 @@ private String accessKey; private String secretKey; private Boolean secure; private String bucketName; @Bean public MinioClient getMinioClient() { ruoyi-common/src/main/java/com/ruoyi/common/controller/AttachmentTypeController.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,74 @@ package com.ruoyi.common.controller; import com.ruoyi.common.core.domain.Result; import com.ruoyi.common.service.AttachmentTableService; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; @RestController @RequestMapping("/file/attachmentType") @AllArgsConstructor public class AttachmentTypeController { private AttachmentTableService attachmentTableService; /** * ä¸ä¼ æä»¶ * @param file æä»¶ * @param type æä¸¾ç±»å * @param id ä¸å¡id * @return */ @PostMapping("/upload") public Result upload(@RequestParam("file")MultipartFile file,@RequestParam("type")Integer type,@RequestParam("id")Integer id) { attachmentTableService.upload(file,type,id); return Result.success(); } /** * ä¸è½½æä»¶ * @param id ä¸å¡id * @param type æä¸¾ç±»å * @param code æä»¶åç§° * @param suffix æä»¶åç¼ å¯è½æ¯word æè pdf * @return */ @GetMapping("/downLoad") public void downLoad(Integer id, Integer type , String code,String suffix, HttpServletResponse response) { attachmentTableService.downLoad(id, type,code, suffix,response); } /** * è·åæä»¶çMIME * @param id * @param type * @return */ @GetMapping("/getMIME") public Result getMIME(Integer id, Integer type,String suffix) { return Result.success(attachmentTableService.getAttachmentList(id, type,suffix)); } /** * è·åæä»¶URL * @param id * @param type * @param suffix æä»¶åç¼ å¯è½æ¯word å pdf */ @GetMapping("/getURL") public Result getURL(Integer id, Integer type , String suffix) { return Result.success(attachmentTableService.getURL(id, type , suffix)); } } ruoyi-common/src/main/java/com/ruoyi/common/enums/AttachmentType.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,53 @@ package com.ruoyi.common.enums; public enum AttachmentType { /* * æ¥åç¼å¶ */ INS_REPORT(1, "ins_report"), USER(2, "user"), ; private Integer type; private String value; private AttachmentType(Integer type, String value) { this.type = type; this.value = value; } public Integer getType() { return type; } public void setType(Integer type) { this.type = type; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } public static String getAttachmentValue(Integer type) { for (AttachmentType attachmentType : AttachmentType.values()) { if (attachmentType.getType().equals(type)) { return attachmentType.getValue(); } } return null; } } ruoyi-common/src/main/java/com/ruoyi/common/mapper/AttachmentTableMapper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,10 @@ package com.ruoyi.common.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ruoyi.common.pojo.AttachmentTable; import org.apache.ibatis.annotations.Mapper; @Mapper public interface AttachmentTableMapper extends BaseMapper<AttachmentTable> { } ruoyi-common/src/main/java/com/ruoyi/common/pojo/AttachmentTable.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,36 @@ package com.ruoyi.common.pojo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @TableName("attachment_table") public class AttachmentTable { @TableId(type = IdType.AUTO) private Integer id; @ApiModelProperty("å ¶ä»è¡¨ç»å®id") private Integer subclassId; @ApiModelProperty("æä»¶åç§°") private String fileName; @ApiModelProperty("æä»¶ç±»å") private String fileType; @ApiModelProperty("æä»¶ååç§°") private String originalFileName; @ApiModelProperty("æ¡¶å") private String bucketName; @ApiModelProperty("æå¨æ¨¡ååç§°") private String moduleName; @ApiModelProperty("å ¶ä»è¡¨å") private String otherTableName; } ruoyi-common/src/main/java/com/ruoyi/common/service/AttachmentTableService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,23 @@ package com.ruoyi.common.service; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.common.pojo.AttachmentTable; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.util.Map; public interface AttachmentTableService extends IService<AttachmentTable> { void upload(MultipartFile file, Integer type, Integer id); void downLoad(Integer id, Integer type,String code,String suffix,HttpServletResponse response) ; Map<String, Object> getAttachmentList(Integer id, Integer type,String suffix); String getURL(Integer id, Integer type , String suffix); InputStream getInputStream(Integer id, Integer type , String suffix); } ruoyi-common/src/main/java/com/ruoyi/common/service/impl/AttachmentTableServiceImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,218 @@ package com.ruoyi.common.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.config.MinioConfig; 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.StringUtils; import com.ruoyi.common.utils.uuid.UUID; import io.minio.*; import io.minio.http.Method; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @Service @AllArgsConstructor public class AttachmentTableServiceImpl extends ServiceImpl<AttachmentTableMapper, AttachmentTable> implements AttachmentTableService { private MinioConfig minioConfig; @Override @Transactional(rollbackFor = Exception.class) public void upload(MultipartFile file, Integer type, Integer id) { MinioClient build = MinioClient.builder() .endpoint(minioConfig.getEndpoint(), minioConfig.getPort(), minioConfig.getSecure()) .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey()) .build(); String fileName = UUID.randomUUID() + "_" + file.getOriginalFilename(); try(InputStream inputStream = file.getInputStream()) { build.putObject( PutObjectArgs.builder() .bucket(minioConfig.getBucketName()) .object(fileName) .stream(inputStream, file.getSize(), -1) .contentType("application/octet-stream") .userMetadata(Collections.singletonMap("Content-Disposition", "attachment; filename=\"" + fileName + "\"")) .build() ); // ä¿åå°æ°æ®åº AttachmentTable attachmentTable = new AttachmentTable(); attachmentTable.setSubclassId(id); attachmentTable.setFileName(fileName); attachmentTable.setOriginalFileName(file.getOriginalFilename()); attachmentTable.setFileType(file.getContentType()); attachmentTable.setBucketName(minioConfig.getBucketName()); attachmentTable.setOtherTableName(AttachmentType.getAttachmentValue(type)); baseMapper.insert(attachmentTable); } catch (Exception e) { e.printStackTrace(); } } @Override public void downLoad(Integer id, Integer type,String code,String suffix, HttpServletResponse response) { // æ¥è¯¢æ°æ®åº List<AttachmentTable> list = baseMapper.selectList(new LambdaQueryWrapper<AttachmentTable>() .eq(AttachmentTable::getSubclassId, id) .eq(AttachmentTable::getOtherTableName, AttachmentType.getAttachmentValue(type)) .like(AttachmentTable::getFileName, suffix) .orderByDesc(AttachmentTable::getId)); if(CollectionUtils.isNotEmpty(list)) { AttachmentTable attachmentTable = list.get(0); String fileName = attachmentTable.getFileName(); // æä»¶å MinioClient build = MinioClient.builder() .endpoint(minioConfig.getEndpoint(), minioConfig.getPort(), minioConfig.getSecure()) .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey()) .build(); try( InputStream inputStream = build.getObject(GetObjectArgs.builder().bucket(minioConfig.getBucketName()).object(fileName).build()); ServletOutputStream stream = response.getOutputStream()) { String finalName = ""; String fileNameMinIo = attachmentTable.getFileName(); String suffix1 = fileNameMinIo.substring(fileNameMinIo.lastIndexOf(".")+1); String contentType = getContentType(suffix1); if(StringUtils.isNotEmpty(code)) { finalName = code + "." + suffix1; }else { finalName = fileNameMinIo; } // 设置ååºå¤´ response.setContentType(contentType); response.setHeader("Content-disposition", "attachment;filename=" + finalName); byte[] bytes = new byte[1024]; int len; while ((len = inputStream.read(bytes)) != -1) { stream.write(bytes, 0, len); stream.flush(); } }catch (Exception e) { e.printStackTrace(); } } } @Override public Map<String, Object> getAttachmentList(Integer id, Integer type,String suffix) { HashMap<String, Object> map = new HashMap<>(); // æ¥è¯¢æ°æ®åº List<AttachmentTable> list = baseMapper.selectList(new LambdaQueryWrapper<AttachmentTable>() .eq(AttachmentTable::getSubclassId, id) .eq(AttachmentTable::getOtherTableName, AttachmentType.getAttachmentValue(type)) .like(StringUtils.isNotEmpty(suffix),AttachmentTable::getFileName, suffix) .orderByDesc(AttachmentTable::getId)); if(CollectionUtils.isNotEmpty(list)) { String contentType = getContentType(suffix.replace(".","")); map.put("contentType", contentType); map.put("suffix", suffix); } return map; } @Override public String getURL(Integer id, Integer type , String suffix) { String url = ""; // æ¥è¯¢æ°æ®åº è·åææ°æä»¶å List<AttachmentTable> attachmentTables = baseMapper.selectList(new LambdaQueryWrapper<AttachmentTable>() .eq(AttachmentTable::getSubclassId, id) .eq(AttachmentTable::getOtherTableName, AttachmentType.getAttachmentValue(type)) .like(AttachmentTable::getFileName, suffix) .orderByDesc(AttachmentTable::getId)); if(CollectionUtils.isNotEmpty(attachmentTables)) { AttachmentTable attachmentTable = attachmentTables.get(0); MinioClient build = MinioClient.builder() .endpoint(minioConfig.getEndpoint(), minioConfig.getPort(), minioConfig.getSecure()) .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey()) .build(); try { url = build.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder() .method(Method.GET) .bucket(minioConfig.getBucketName()) .object(attachmentTable.getFileName()) .expiry(60 * 60 * 24) .build()); } catch (Exception e) { throw new RuntimeException(e); } } return url; } public InputStream getInputStream(Integer id, Integer type , String suffix) { InputStream inputStream = null; // æ¥è¯¢æ°æ®åº è·åææ°æä»¶å List<AttachmentTable> attachmentTables = baseMapper.selectList(new LambdaQueryWrapper<AttachmentTable>() .eq(AttachmentTable::getSubclassId, id) .eq(AttachmentTable::getOtherTableName, AttachmentType.getAttachmentValue(type)) .like(StringUtils.isNotEmpty(suffix),AttachmentTable::getFileName, suffix) .orderByDesc(AttachmentTable::getId)); if(CollectionUtils.isNotEmpty(attachmentTables)) { AttachmentTable attachmentTable = attachmentTables.get(0); MinioClient build = MinioClient.builder() .endpoint(minioConfig.getEndpoint(), minioConfig.getPort(), minioConfig.getSecure()) .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey()) .build(); try { inputStream = build.getObject( GetObjectArgs.builder() .bucket(minioConfig.getBucketName()) .object(attachmentTable.getFileName()) .build()); } catch (Exception e) { throw new RuntimeException(e); } } return inputStream; } // æ ¹æ®æä»¶æ©å±åè·å MIME ç±»å private String getContentType(String fileExtension) { switch (fileExtension) { case "jpg": case "jpeg": return "image/jpeg"; case "png": return "image/png"; case "gif": return "image/gif"; case "pdf": return "application/pdf"; case "doc": return "application/msword"; case "docx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; case "xls": return "application/vnd.ms-excel"; case "xlsx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; case "ppt": case "pptx": return "application/vnd.ms-powerpoint"; default: return "application/octet-stream"; // é»è®¤äºè¿å¶æµ } } } ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserMapper.java
@@ -47,5 +47,8 @@ User getUserNow(@Param("userId") int userId); SysUserVO selectUserInfo(Long userId); String seldepLimsId(int depLimsId); List<Map<String, Object>> getPersonList(String laboratory); } ruoyi-system/src/main/resources/mapper/system/UserMapper.xml
@@ -63,4 +63,28 @@ <select id="selectUserInfo" resultType="com.ruoyi.common.core.vo.SysUserVO"> select * from user </select> <select id="seldepLimsId" resultType="java.lang.String"> select name from department_lims where id = #{depLimsId} </select> <select id="getPersonList" resultType="java.util.Map"> select u.id, u.name, dl.name as depName from user u left join department_lims dl on FIND_IN_SET(dl.id,u.depart_lims_id) where dl.name in('é信产åå®éªå®¤','çµå产åå®éªå®¤','æ£æµå') and u.status = 1 and u.is_custom = 0 <if test="laboratory!='' and laboratory!=null"> and (dl.name = #{laboratory} or dl.name='æ£æµå') </if> </select> </mapper>