czt
2026-01-07 0c8d20900c14651cb50180ade4ccd0e2074796b4
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/FileService.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzzy.igds.domain.FileInfo;
import com.fzzy.igds.mapper.FileMapper;
import com.fzzy.igds.utils.Base64Util;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.config.FrameworkConfig;
import org.apache.commons.lang3.time.DateFormatUtils;
@@ -98,15 +99,7 @@
    }
    /**
     *
     * @param id
     */
    public void delFile(String id) {
        fileMapper.deleteById(id);
    }
    /**
     * 获取出入库文件路径
     * 根据类型获取文件路径
     * @param pathTag
     * @return
     */
@@ -114,19 +107,51 @@
        if(StringUtils.isBlank(pathTag)){
            pathTag = "COMMON";
        }
        if("EVENT".equals(pathTag)) return getEventFilePath();
        if("SNAP".equals(pathTag)) return getSnapFilePath();
        if("INOUT".equals(pathTag)) return getInoutFilePath();
        if("PATROL".equals(pathTag)) return getPatrolFilePath();
        if("DEPT".equals(pathTag)) return getDeptFilePath();
        if("TEMP".equals(pathTag)) return getTempFilePath();
        if("CONF".equals(pathTag)) return getConfPath();
        if("TEMPLATE".equals(pathTag)) return getTemplateFilePath();
        if("WORD".equals(pathTag)) return getWordPath();
        return getCommonFilePath();
    }
    /**
     * 获取出入库文件路径
     * 获取事件文件路径
     * @return
     */
    public String getEventFilePath() {
        String basePath = FrameworkConfig.getProfile() + "EVENT/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取抓拍文件路径
     * @return
     */
    public String getSnapFilePath() {
        String basePath = FrameworkConfig.getProfile() + "SNAP/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取巡检文件路径
     * @return
     */
    public String getPatrolFilePath() {
        String basePath = FrameworkConfig.getProfile() + "INOUT/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
        String basePath = FrameworkConfig.getProfile() + "PATROL/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
@@ -178,6 +203,70 @@
    }
    /**
     * 获取临时路径
     * @return
     */
    public String getTempFilePath() {
        String basePath = FrameworkConfig.getProfile() + "TEMP/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取模板路径
     * @return
     */
    public String getConfPath() {
        String basePath = FrameworkConfig.getProfile() + "CONF/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取模板路径:所有模板统一放在TEMPLATE/目录下
     * @return
     */
    public String getTemplateFilePath() {
        String basePath = FrameworkConfig.getProfile() + "TEMPLATE/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取word路径
     * @return
     */
    public String getWordPath() {
        String basePath = FrameworkConfig.getProfile()  + "WORD/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * base64转图片保存
     * @param filePath
     * @param imgData
     */
    public void baseImg2Disk(String filePath, String imgData) {
        Base64Util.generateImage(imgData, filePath);
    }
    /**
     * 压缩图片
     *
     * @param filePath   压缩前路径
@@ -201,4 +290,24 @@
        ImageIO.write(compressedImage, "jpg", new File(outputPath));
    }
    /**
     * 判断路径下文件是否存在,不存在则给默认
     * @param imgPath
     * @return
     */
    public String isImgExit(String imgPath, String tag) {
        String path = "/img/img-fail.jpg";
        if(StringUtils.isNotBlank(tag) && "dept".equals(tag)){
            path = "/img/deptImg.jpg";
        }
        if(StringUtils.isNotBlank(imgPath)){
            File file = new File(imgPath.replace("/profile", FrameworkConfig.getProfile()));
            if(file.exists()){
                path = imgPath;
            }
        }
        return path;
    }
}