From ca5445257b1fdeceddf3fcc2dea18c442023aeb7 Mon Sep 17 00:00:00 2001 From: kongzy <kongzy> Date: 星期五, 08 十二月 2023 09:30:36 +0800 Subject: [PATCH] 新街口 --- assess-system/src/main/java/com/gkhy/assess/system/service/impl/SysCommonServiceImpl.java | 29 ++++++++++++++--------------- 1 files changed, 14 insertions(+), 15 deletions(-) diff --git a/assess-system/src/main/java/com/gkhy/assess/system/service/impl/SysCommonServiceImpl.java b/assess-system/src/main/java/com/gkhy/assess/system/service/impl/SysCommonServiceImpl.java index e126d7e..25f68bd 100644 --- a/assess-system/src/main/java/com/gkhy/assess/system/service/impl/SysCommonServiceImpl.java +++ b/assess-system/src/main/java/com/gkhy/assess/system/service/impl/SysCommonServiceImpl.java @@ -1,5 +1,6 @@ package com.gkhy.assess.system.service.impl; +import cn.hutool.core.date.DateUtil; import com.gkhy.assess.common.exception.ApiException; import com.gkhy.assess.system.domain.vo.UploadObjectVO; import com.gkhy.assess.system.service.SysCommonService; @@ -10,16 +11,14 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.util.Date; import java.util.UUID; @Service public class SysCommonServiceImpl implements SysCommonService { - @Value("${image.upload_file}") - private String uploadFilePath; - - @Value("${image.upload_image}") - private String uploadImagePath; + @Value("${image.upload_path}") + private String uploadPath; @Override public UploadObjectVO uploadFile(MultipartFile file) { @@ -32,11 +31,11 @@ String systemDir=System.getProperty("user.dir"); String filePath=systemDir+File.separator+path; File dirFile=new File(filePath); - if(!dirFile.isFile()){ - throw new ApiException("非文件,不能删除"); - } if(!dirFile.exists()){ throw new ApiException("文件不存在"); + } + if(!dirFile.isFile()){ + throw new ApiException("非文件,不能删除"); } dirFile.delete(); return true; @@ -47,12 +46,8 @@ String subfix=filename.substring(filename.lastIndexOf(".")); filename= UUID.randomUUID().toString().replace("-","")+subfix; String systemDir=System.getProperty("user.dir"); - String filePath=""; - if(checkImageType(subfix)){ - filePath=uploadImagePath; - }else{ - filePath=uploadFilePath; - } + String dateStr= DateUtil.format(new Date(),"yyyyMMdd"); + String filePath=uploadPath+File.separator+dateStr; File dirFile=new File(filePath); if(!dirFile.exists()){ dirFile.mkdirs(); @@ -65,6 +60,7 @@ } catch (IOException e) { throw new ApiException("发生错误,请联系管理员"); } + filePath=filePath.replace("\\","/"); UploadObjectVO uploadObjectVO=new UploadObjectVO().setFilename(filename) .setPath(filePath); return uploadObjectVO; @@ -76,7 +72,10 @@ ".jpeg".equalsIgnoreCase(subfix)|| ".png".equalsIgnoreCase(subfix)|| ".bmp".equalsIgnoreCase(subfix)|| - ".tif".equalsIgnoreCase(subfix) + ".tif".equalsIgnoreCase(subfix)|| + ".jfif".equalsIgnoreCase(subfix)|| + ".webp".equalsIgnoreCase(subfix)|| + ".gif".equalsIgnoreCase(subfix) ){ return true; } -- Gitblit v1.9.2