| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.igds.service; |
| | | |
| | | 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.ContextUtil; |
| | | import com.ruoyi.common.config.FrameworkConfig; |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.*; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description |
| | | * @Author CZT |
| | | * @Date 2025/12/4 17:36 |
| | | */ |
| | | @Service |
| | | public class FileService { |
| | | |
| | | @Resource |
| | | private FileMapper fileMapper; |
| | | |
| | | /** |
| | | * 弿¥æ§è¡éä»¶ä¿å |
| | | * @param files éä»¶ä¿¡æ¯ |
| | | * @param bizId ä¸å¡id |
| | | * @param bizTag æ ç¾ |
| | | * @param pathTag æä»¶è·¯å¾æ è¯ |
| | | */ |
| | | @Async |
| | | public void saveInoutFiles(List<FileInfo> files, String bizId, String bizTag, String pathTag) { |
| | | |
| | | if (null == files || files.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (FileInfo data : files) { |
| | | // å¦ææ²¡æéä»¶åç§°ï¼åä¸ä¿åéä»¶ä¿¡æ¯ |
| | | if (StringUtils.isBlank(data.getFileName())) { |
| | | continue; |
| | | } |
| | | |
| | | data.setId(ContextUtil.generateId()); |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | |
| | | //æä»¶å
¨è·¯å¾ |
| | | String filePath = getFileSavePath(pathTag) + data.getFileName(); |
| | | filePath = filePath.replace(FrameworkConfig.getProfile(), "/profile/"); |
| | | data.setFilePath(filePath); |
| | | |
| | | if (StringUtils.isNotEmpty(bizId)) { |
| | | data.setBizId(bizId); |
| | | } |
| | | if (StringUtils.isNotEmpty(bizTag)) { |
| | | data.setBizTag(bizTag); |
| | | } |
| | | |
| | | data.setCreateTime(new Date()); |
| | | data.setCreateBy(ContextUtil.getLoginUserName()); |
| | | |
| | | data.setUpdateTime(new Date()); |
| | | data.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | fileMapper.insert(data); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶æ¥è¯¢æ°æ® |
| | | * @param companyId |
| | | * @param deptId |
| | | * @param bizId |
| | | * @return |
| | | */ |
| | | public List<FileInfo> listFile(String companyId, String deptId, String bizId, String bizTag) { |
| | | QueryWrapper<FileInfo> queryWrapper = new QueryWrapper<>(); |
| | | if (StringUtils.isNotBlank(companyId)) { |
| | | queryWrapper.eq("company_id", companyId); |
| | | } |
| | | if (StringUtils.isNotBlank(deptId)) { |
| | | queryWrapper.eq("dept_id", deptId); |
| | | } |
| | | if (StringUtils.isNotBlank(bizId)) { |
| | | queryWrapper.eq("biz_id", bizId); |
| | | } |
| | | if (StringUtils.isNotBlank(bizTag)) { |
| | | queryWrapper.eq("biz_tag", bizTag); |
| | | } |
| | | return fileMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param id |
| | | */ |
| | | public void delFile(String id) { |
| | | fileMapper.deleteById(id); |
| | | } |
| | | |
| | | /** |
| | | * è·ååºå
¥åºæä»¶è·¯å¾ |
| | | * @param pathTag |
| | | * @return |
| | | */ |
| | | public String getFileSavePath(String pathTag) { |
| | | if(StringUtils.isBlank(pathTag)){ |
| | | pathTag = "COMMON"; |
| | | } |
| | | if("INOUT".equals(pathTag)) return getInoutFilePath(); |
| | | if("PATROL".equals(pathTag)) return getPatrolFilePath(); |
| | | if("DEPT".equals(pathTag)) return getDeptFilePath(); |
| | | |
| | | return getCommonFilePath(); |
| | | } |
| | | |
| | | /** |
| | | * è·ååºå
¥åºæä»¶è·¯å¾ |
| | | * @return |
| | | */ |
| | | public String getPatrolFilePath() { |
| | | String basePath = FrameworkConfig.getProfile() + "INOUT/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/"; |
| | | File file = new File(basePath); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | return basePath; |
| | | } |
| | | |
| | | /** |
| | | * è·ååºå
¥åºæä»¶è·¯å¾ |
| | | * @return |
| | | */ |
| | | public String getInoutFilePath() { |
| | | String basePath = FrameworkConfig.getProfile() + "INOUT/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/"; |
| | | File file = new File(basePath); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | return basePath; |
| | | } |
| | | |
| | | /** |
| | | * è·ååºåºè·¯å¾ä¸æä»¶ |
| | | * @return |
| | | */ |
| | | public String getDeptFilePath() { |
| | | |
| | | String basePath = FrameworkConfig.getProfile() + "IMG/"+ FrameworkConfig.getCompanyId() + "/SECURITY/"; |
| | | |
| | | File file = new File(basePath); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | return basePath; |
| | | } |
| | | |
| | | /** |
| | | * è·åå
Œ
±è·¯å¾ |
| | | * @return |
| | | */ |
| | | public String getCommonFilePath() { |
| | | |
| | | String basePath = FrameworkConfig.getProfile() + "COMMON/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/"; |
| | | |
| | | File file = new File(basePath); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | return basePath; |
| | | } |
| | | |
| | | /** |
| | | * å缩å¾ç |
| | | * |
| | | * @param filePath å缩åè·¯å¾ |
| | | * @param scale å缩æ¯ä¾ |
| | | * @param outputPath å缩åè·¯å¾ |
| | | * @throws IOException |
| | | */ |
| | | public void compressedImage(String filePath, double scale, String outputPath) throws IOException { |
| | | BufferedImage bufferedImage = ImageIO.read(new File(filePath)); |
| | | int newWidth = (int) (bufferedImage.getWidth() * scale); |
| | | int newHeight = (int) (bufferedImage.getHeight() * scale); |
| | | |
| | | //å建å缩åçå¾ç |
| | | BufferedImage compressedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); |
| | | Graphics2D graphics2D = compressedImage.createGraphics(); |
| | | |
| | | //ç»å¶åå§å¾çå°å缩åçå¾çä¸ |
| | | graphics2D.drawImage(bufferedImage, 0, 0, newWidth, newHeight, null); |
| | | graphics2D.dispose(); |
| | | |
| | | ImageIO.write(compressedImage, "jpg", new File(outputPath)); |
| | | } |
| | | |
| | | } |