sgj
2026-03-26 26220601f74874186865626c051ea08373ea44bb
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/FileService.java
@@ -2,7 +2,9 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzzy.igds.domain.FileInfo;
import com.fzzy.igds.domain.Quantity;
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;
@@ -30,6 +32,29 @@
    private FileMapper fileMapper;
    /**
     * 根据条件获取附件信息
     * @param companyId
     * @param bizId
     * @return
     */
    public List<FileInfo> listFile(String companyId, String bizId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        if (StringUtils.isEmpty(bizId)){
            return null;
        }
        QueryWrapper<FileInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id", companyId);
        queryWrapper.eq("biz_id", bizId);
        queryWrapper.orderByAsc("create_time");
        return fileMapper.selectList(queryWrapper);
    }
    /**
     * 异步执行附件保存
     * @param files     附件信息
     * @param bizId     业务id
@@ -50,10 +75,13 @@
            }
            data.setId(ContextUtil.generateId());
            data.setCreateTime(new Date());
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCompanyId(ContextUtil.getCompanyId());
            //文件全路径
            String filePath = getFileSavePath(pathTag) + data.getFileName();
            filePath = filePath.replace(FrameworkConfig.getProfile(), "/profile/");
            data.setFilePath(filePath);
@@ -64,14 +92,28 @@
                data.setBizTag(bizTag);
            }
            data.setCreateTime(new Date());
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setUpdateTime(new Date());
            data.setUpdateBy(ContextUtil.getLoginUserName());
            fileMapper.insert(data);
            saveFile(data);
        }
    }
    /**
     *
     * @param data
     */
    public void saveFile(FileInfo data) {
        data.setUpdateTime(new Date());
        data.setUpdateBy(ContextUtil.getLoginUserName());
        if(StringUtils.isBlank(data.getId())){
            data.setId(ContextUtil.UUID());
            data.setCreateTime(new Date());
            data.setCreateBy(ContextUtil.getLoginUserName());
        }
        fileMapper.insert(data);
    }
    /**
     * 根据条件查询数据
@@ -98,15 +140,7 @@
    }
    /**
     *
     * @param id
     */
    public void delFile(String id) {
        fileMapper.deleteById(id);
    }
    /**
     * 获取出入库文件路径
     * 根据类型获取文件路径
     * @param pathTag
     * @return
     */
@@ -114,19 +148,79 @@
        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("QUANTITY".equals(pathTag)) return getQuantityPath();
        if("WORD".equals(pathTag)) return getWordPath();
        if("WEIGHTNAP".equals(pathTag)) return getWeightSnapPath();
        return getCommonFilePath();
    }
    /**
     * 获取出入库文件路径
     * 获取事件文件路径
     * @return
     */
    public String getQuantityPath() {
        String basePath = FrameworkConfig.getProfile() + "QUANTITY/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取事件文件路径
     * @return
     */
    public String getWeightSnapPath() {
        String basePath = FrameworkConfig.getProfile() + "WEIGHTNAP/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取事件文件路径
     * @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();
@@ -179,15 +273,11 @@
    /**
     * 获取临时路径
     * @param companyId
     * @return
     */
    public String getTempFilePath(String companyId) {
    public String getTempFilePath() {
        String basePath = FrameworkConfig.getProfile() + "TEMP/";
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(companyId)) {
            basePath += companyId + "/";
        }
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
@@ -207,6 +297,42 @@
            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);
    }
    /**
@@ -252,33 +378,5 @@
        return path;
    }
    /**
     * 获取模板路径:所有模板统一放在TEMPLATE/目录下
     * @return
     */
    public String getTemplateFilePath() {
        String basePath = FrameworkConfig.getProfile() + "TEMPLATE/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
    /**
     * 获取word路径
     * @param deptId
     * @return
     */
    public String getWordPath(String deptId) {
        if(StringUtils.isBlank(deptId)){
            deptId = "0000";
        }
        String basePath = FrameworkConfig.getProfile() + deptId + "/WORD/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
}