| | |
| | | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | 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); |
| | | |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据条件查询数据 |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param id |
| | | */ |
| | | public void delFile(String id) { |
| | | fileMapper.deleteById(id); |
| | | } |
| | | |
| | | /** |
| | | * 获取出入库文件路径 |
| | | * 根据类型获取文件路径 |
| | | * @param pathTag |
| | | * @return |
| | | */ |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取临时路径 |
| | | * @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 压缩前路径 |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |