chenrui
2025-03-13 f0afb2b17f2f6e13925ffe1b6fd8c8ae724aec0e
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
ÎļþÃû´Ó cnas-require/src/main/java/com/ruoyi/require/service/impl/InsReportServiceImpl.java ÐÞ¸Ä
@@ -1,10 +1,8 @@
package com.ruoyi.require.service.impl;
package com.ruoyi.inspect.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.aspose.words.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -33,9 +31,9 @@
import com.ruoyi.inspect.pojo.InsOrder;
import com.ruoyi.inspect.pojo.InsOrderState;
import com.ruoyi.inspect.pojo.InsReport;
import com.ruoyi.inspect.service.InsReportService;
import com.ruoyi.process.mapper.ProcessReportMapper;
import com.ruoyi.process.pojo.ProcessReport;
import com.ruoyi.require.service.InsReportService;
import com.ruoyi.system.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@@ -64,6 +62,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
@@ -80,6 +79,7 @@
@Slf4j
public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport>
        implements InsReportService {
    @Resource
    private UserMapper userMapper;
@@ -118,7 +118,6 @@
    @Override
    public IPage<ReportPageDto> pageInsReport(Page page, ReportPageDto reportPageDto) {
        Map<String, Object> map = new HashMap<>();
        User user = userMapper.selectById(SecurityUtils.getUserId());//当前登录的人
        //获取当前人所属实验室id
        String departLimsId = user.getDepartLimsId();
@@ -136,8 +135,10 @@
            wrapper.gt(reportPageDto.getCreateTimeRange().size()>1,"create_time",reportPageDto.getCreateTimeRange().get(0))
                    .lt(reportPageDto.getCreateTimeRange().size()>1,"create_time",reportPageDto.getCreateTimeRange().get(1));
        }
        return insReportMapper.pageInsReport(page, wrapper ,laboratory);
        IPage<ReportPageDto> iPage = insReportMapper.pageInsReport(page, wrapper, laboratory);
        return iPage;
    }
    @Override
    public int inReport(String url, Integer id) {
@@ -168,7 +169,7 @@
        String url = "";
        // 0 ä¸‹è½½docx 1 ä¸‹è½½pdf
        if(type == 0) {
          url  = Strings.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl();
            url  = Strings.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl();
        }else {
            url = insReport.getTempUrlPdf();
        }
@@ -210,11 +211,11 @@
        insReport.setId(id);
        insReport.setState(1);
        insReport.setWriteTime(LocalDateTime.now());//提交时间
        insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人
        insReport.setWriteUserId(Integer.getInteger(SecurityUtils.getUserId().toString()));//提交人
        //获取提交人的签名地址
        String signatureUrl;
        try {
            signatureUrl = userMapper.selectById(SecurityUtils.getUserId().intValue()).getSignatureUrl();
            signatureUrl = userMapper.selectById(Integer.getInteger(SecurityUtils.getUserId().toString())).getSignatureUrl();
        } catch (Exception e) {
            throw new ErrorException("找不到编制人的签名");
        }
@@ -239,7 +240,7 @@
        if (ObjectUtils.isNotEmpty(examineTell)) {
            insReport.setExamineTell(examineTell);
        }
        insReport.setExamineUserId(SecurityUtils.getUserId().intValue());//审核人
        insReport.setExamineUserId(Integer.getInteger(SecurityUtils.getUserId().toString()));//审核人
        insReport.setExamineTime(LocalDateTime.now());//审核时间
        if (isExamine == 0) {
            //如果审核不通过
@@ -275,7 +276,7 @@
        if (ObjectUtils.isNotEmpty(ratifyTell)) {
            insReport.setRatifyTell(ratifyTell);
        }
        insReport.setRatifyUserId(SecurityUtils.getUserId().intValue());//批准人
        insReport.setRatifyUserId(Integer.getInteger(SecurityUtils.getUserId().toString()));//批准人
        insReport.setRatifyTime(LocalDateTime.now());//批准时间
        if (isRatify == 0) {
            //如果批准不通过
@@ -415,70 +416,6 @@
            }
            inReport("/word/" + pathName, insReport.getId());
        }
//        File tempFile = null;
//        File unzipDir = null;
//        try {
//            tempFile = File.createTempFile(wordUrl, ".zip");
//            file.transferTo(tempFile);
//
//            unzipDir = new File("uploaded_files");
//            if (!unzipDir.exists()) {
//                unzipDir.mkdir();
//            }
//            unzip(tempFile, unzipDir);
//            // å¤„理解压后的文件
//            File[] files = unzipDir.listFiles();
//            if (files != null) {
//                for (File f : files) {
//                    // æ ¹æ®æ–‡ä»¶åæŸ¥è¯¢id
//                    String name = f.getName();
//                    String code = f.getName().replace(".docx", "").replace("JCZX", "JCZX/");
//                    if(f.getName().lastIndexOf("_") != -1) {
//                        code = code.substring(f.getName().lastIndexOf("_") + 1);
//                    }
//                    //InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().eq(InsReport::getCode, f.getName().replace(".docx", "").replace("JCZX", "JCZX/")));
//                    InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().eq(InsReport::getCode, code));
//                    if (ObjectUtils.isEmpty(insReport)) {
//                        throw new ErrorException("没有找到 " + f.getName() + " è¿™ä¸ªæ–‡ä»¶å¯¹åº”的报告数据");
//                    }
//                    // å¦‚æžœ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;
//                    try {
//                        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;
//                        // å¤åˆ¶æ–‡ä»¶åˆ°æŒ‡å®šè·¯å¾„
//                        Files.copy(f.toPath(), new File(urlString).toPath(), StandardCopyOption.REPLACE_EXISTING);
//                        inReport("/word/" + pathName, insReport.getId());
//                    }
//                    catch (IOException e) {
//                        throw new ErrorException("文件上传失败");
//                    }
//                }
//            }
//        } catch (IOException e) {
//            throw new ErrorException("文件处理失败");
//        } finally {
//            if (tempFile != null && tempFile.exists()) {
//                tempFile.delete();
//            }
//            // é€’归删除解压目录及其中的文件
//            if (unzipDir.exists()) {
//                deleteDirectory(unzipDir); // åˆ é™¤æ—§çš„临时文件夹
//            }
//        }
        return 0;
    }
@@ -506,7 +443,7 @@
        List<Map<String, Object>> list = new ArrayList<>();
        Integer insOrderId = insReportMapper.selectById(id).getInsOrderId();
        insOrderStateMapper.selectList(new LambdaQueryWrapper<InsOrderState>()
                .eq(InsOrderState::getInsOrderId,insOrderId))
                        .eq(InsOrderState::getInsOrderId,insOrderId))
                .forEach(insOrderState -> {
                    Map<String, Object> map = new HashMap<>();
                    map.put("label",insOrderState.getLaboratory());
@@ -547,7 +484,7 @@
    @Transactional(rollbackFor = Exception.class)
    public void batchApprovalReport(List<Integer> ids) {
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        Integer userId = SecurityUtils.getUserId().intValue();
        Integer userId = Integer.parseInt(SecurityUtils.getUserId().toString());
        String key = SYNC_REPORT_KEY_PREFIX+userId;
        //执行前删除之前的keys
        deleteRedisKeys(key);
@@ -676,7 +613,7 @@
    @Override
    public Map<String, Object> getBatchApprovalProgress() {
        Integer userId = SecurityUtils.getUserId().intValue();
        Integer userId = Integer.parseInt(SecurityUtils.getUserId().toString());
        String key = SYNC_REPORT_KEY_PREFIX + userId;
        Map<String, Object> map = new HashMap<>();
        map.put("hasProgress",false);
@@ -790,7 +727,7 @@
            file = new File(pdfPath);
            os = new FileOutputStream(file);
            //要转换的word文件
            Document doc = new Document(wordPath);
            com.aspose.words.Document doc = new com.aspose.words.Document(wordPath);
            doc.save(os, SaveFormat.PDF);
            String name = file.getName();
            return file.getName();