上传文件按日期存储及部分文件路径位置

master
RuoYi 6 years ago committed by Limy
parent fdbf6d3ebf
commit 1cdc1129f1

@ -53,12 +53,18 @@
<dependencies>
<!--Spring框架基本的核心工具-->
<!-- Spring框架基本的核心工具 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- SpringWeb模块 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- SpringBoot集成mybatis框架 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>

@ -14,9 +14,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.framework.util.FileUploadUtils;
/**
*

@ -11,8 +11,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.framework.web.base.BaseController;
/**

@ -16,8 +16,8 @@ import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.framework.shiro.service.SysPasswordService;
import com.ruoyi.framework.util.FileUploadUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysDictDataService;

@ -22,13 +22,10 @@ user.notfound=请重新登录
user.forcelogout=管理员强制退出,请重新登录
user.unknown.error=未知错误,请重新登录
#批量插入用户错误信息
user.import.excel.null=Excel数据为空请按照导入模板填写数据
user.import.excel.data.null=Excel数据为空只有标题行请按照导入模板填写数据
user.import.excel.filetype.error=文件不是Excel文件
user.import.excel.file.error=文件名为空,文件为空
user.import.excel.fileinput.error=获取Excel2003流错误
user.import.excel.fileinputx.error=获取Excel2007流错误
##文件上传消息
upload.exceed.maxSize=上传的文件大小超出限制的文件大小!<br/>允许的文件最大大小是:{0}MB
upload.filename.exceed.length=上传的文件名最长{0}个字符
##权限
no.permission=您没有数据的权限,请联系管理员添加权限 [{0}]
no.create.permission=您没有创建数据的权限,请联系管理员添加权限 [{0}]

@ -15,7 +15,7 @@
// 判断是否 iphone
var isIPhone = function () {
let browserName = navigator.userAgent.toLowerCase();
var browserName = navigator.userAgent.toLowerCase();
return /(iPhone|iPad|iPod|iOS)/i.test(browserName);
};

@ -1,7 +1,7 @@
package com.ruoyi.framework.web.exception.base;
package com.ruoyi.common.exception.base;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.util.MessageUtils;
/**
*

@ -0,0 +1,19 @@
package com.ruoyi.common.exception.file;
import com.ruoyi.common.exception.base.BaseException;
/**
*
*
* @author ruoyi
*/
public class FileException extends BaseException
{
private static final long serialVersionUID = 1L;
public FileException(String code, Object[] args)
{
super("file", code, args, null);
}
}

@ -1,39 +1,16 @@
package com.ruoyi.common.exception.file;
import org.apache.commons.fileupload.FileUploadException;
/**
*
*
*
* @author ruoyi
*/
public class FileNameLengthLimitExceededException extends FileUploadException
public class FileNameLengthLimitExceededException extends FileException
{
private static final long serialVersionUID = 1L;
private int length;
private int maxLength;
private String filename;
public FileNameLengthLimitExceededException(String filename, int length, int maxLength)
{
super("file name : [" + filename + "], length : [" + length + "], max length : [" + maxLength + "]");
this.length = length;
this.maxLength = maxLength;
this.filename = filename;
}
public String getFilename()
{
return filename;
}
public int getLength()
{
return length;
}
public int getMaxLength()
public FileNameLengthLimitExceededException(int defaultFileNameLength)
{
return maxLength;
super("upload.filename.exceed.length", new Object[] { defaultFileNameLength });
}
}

@ -0,0 +1,16 @@
package com.ruoyi.common.exception.file;
/**
*
*
* @author ruoyi
*/
public class FileSizeLimitExceededException extends FileException
{
private static final long serialVersionUID = 1L;
public FileSizeLimitExceededException(long defaultMaxSize)
{
super("upload.exceed.maxSize", new Object[] { defaultMaxSize });
}
}

@ -1,4 +1,4 @@
package com.ruoyi.framework.web.exception.user;
package com.ruoyi.common.exception.user;
/**
*

@ -1,4 +1,4 @@
package com.ruoyi.framework.web.exception.user;
package com.ruoyi.common.exception.user;
/**
*

@ -1,4 +1,4 @@
package com.ruoyi.framework.web.exception.user;
package com.ruoyi.common.exception.user;
/**
*

@ -1,4 +1,4 @@
package com.ruoyi.framework.web.exception.user;
package com.ruoyi.common.exception.user;
/**
*

@ -1,6 +1,6 @@
package com.ruoyi.framework.web.exception.user;
package com.ruoyi.common.exception.user;
import com.ruoyi.framework.web.exception.base.BaseException;
import com.ruoyi.common.exception.base.BaseException;
/**
*

@ -1,4 +1,4 @@
package com.ruoyi.framework.web.exception.user;
package com.ruoyi.common.exception.user;
/**
*

@ -1,4 +1,4 @@
package com.ruoyi.framework.web.exception.user;
package com.ruoyi.common.exception.user;
/**
*

@ -1,8 +1,7 @@
package com.ruoyi.framework.web.page;
package com.ruoyi.common.page;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.page.PageDomain;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.common.utils.ServletUtils;
/**
*

@ -1,4 +1,4 @@
package com.ruoyi.framework.util;
package com.ruoyi.common.utils;
import org.springframework.context.MessageSource;
import com.ruoyi.common.utils.spring.SpringUtils;

@ -1,4 +1,4 @@
package com.ruoyi.framework.util;
package com.ruoyi.common.utils;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
@ -8,7 +8,6 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.StringUtils;
/**
*

@ -1,11 +1,12 @@
package com.ruoyi.framework.util;
package com.ruoyi.common.utils.file;
import java.io.File;
import java.io.IOException;
import org.apache.tomcat.util.http.fileupload.FileUploadBase.FileSizeLimitExceededException;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException;
import com.ruoyi.common.exception.file.FileSizeLimitExceededException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.Md5Utils;
/**
@ -18,17 +19,17 @@ public class FileUploadUtils
/**
* 50M
*/
public static final long DEFAULT_MAX_SIZE = 52428800;
public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
/**
*
* 100
*/
private static String defaultBaseDir = Global.getProfile();
public static final int DEFAULT_FILE_NAME_LENGTH = 100;
/**
*
*
*/
public static final int DEFAULT_FILE_NAME_LENGTH = 200;
private static String defaultBaseDir = Global.getProfile();
/**
* jpg
@ -62,7 +63,7 @@ public class FileUploadUtils
}
catch (Exception e)
{
throw new IOException(e);
throw new IOException(e.getMessage(), e);
}
}
@ -82,7 +83,7 @@ public class FileUploadUtils
}
catch (Exception e)
{
throw new IOException(e);
throw new IOException(e.getMessage(), e);
}
}
@ -104,19 +105,25 @@ public class FileUploadUtils
int fileNamelength = file.getOriginalFilename().length();
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
{
throw new FileNameLengthLimitExceededException(file.getOriginalFilename(), fileNamelength,
FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
}
assertAllowed(file);
String fileName = encodingFilename(file.getOriginalFilename(), extension);
String fileName = extractFilename(file, extension);
File desc = getAbsoluteFile(baseDir, baseDir + fileName);
file.transferTo(desc);
return fileName;
}
public static final String extractFilename(MultipartFile file, String extension)
{
String filename = file.getOriginalFilename();
filename = DateUtils.datePath() + "/" + encodingFilename(filename) + extension;
return filename;
}
private static final File getAbsoluteFile(String uploadDir, String filename) throws IOException
{
File desc = new File(File.separator + filename);
@ -135,10 +142,10 @@ public class FileUploadUtils
/**
*
*/
private static final String encodingFilename(String filename, String extension)
private static final String encodingFilename(String filename)
{
filename = filename.replace("_", " ");
filename = Md5Utils.hash(filename + System.nanoTime() + counter++) + extension;
filename = Md5Utils.hash(filename + System.nanoTime() + counter++);
return filename;
}
@ -154,7 +161,7 @@ public class FileUploadUtils
long size = file.getSize();
if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE)
{
throw new FileSizeLimitExceededException("not allowed upload upload", size, DEFAULT_MAX_SIZE);
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
}
}
}

@ -15,10 +15,10 @@ import org.springframework.stereotype.Component;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessStatus;
import com.ruoyi.common.json.JSON;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysOperLog;
import com.ruoyi.system.domain.SysUser;

@ -2,7 +2,8 @@ package com.ruoyi.framework.config;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.common.utils.ServletUtils;
/**
*

@ -5,10 +5,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.AddressUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.shiro.session.OnlineSession;
import com.ruoyi.framework.util.LogUtils;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysLogininfor;
import com.ruoyi.system.domain.SysOperLog;

@ -19,14 +19,15 @@ import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.RoleBlockedException;
import com.ruoyi.common.exception.user.UserBlockedException;
import com.ruoyi.common.exception.user.UserNotExistsException;
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
import com.ruoyi.common.exception.user.UserPasswordRetryLimitExceedException;
import com.ruoyi.framework.shiro.service.SysLoginService;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.framework.web.exception.user.CaptchaException;
import com.ruoyi.framework.web.exception.user.RoleBlockedException;
import com.ruoyi.framework.web.exception.user.UserBlockedException;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import com.ruoyi.framework.web.exception.user.UserPasswordNotMatchException;
import com.ruoyi.framework.web.exception.user.UserPasswordRetryLimitExceedException;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysMenuService;
import com.ruoyi.system.service.ISysRoleService;

@ -7,17 +7,17 @@ import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.ShiroConstants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.enums.UserStatus;
import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.UserBlockedException;
import com.ruoyi.common.exception.user.UserDeleteException;
import com.ruoyi.common.exception.user.UserNotExistsException;
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.util.MessageUtils;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.framework.web.exception.user.CaptchaException;
import com.ruoyi.framework.web.exception.user.UserBlockedException;
import com.ruoyi.framework.web.exception.user.UserDeleteException;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import com.ruoyi.framework.web.exception.user.UserPasswordNotMatchException;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysUserService;

@ -9,11 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
import com.ruoyi.common.exception.user.UserPasswordRetryLimitExceedException;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.util.MessageUtils;
import com.ruoyi.framework.web.exception.user.UserPasswordNotMatchException;
import com.ruoyi.framework.web.exception.user.UserPasswordRetryLimitExceedException;
import com.ruoyi.system.domain.SysUser;
/**

@ -7,7 +7,8 @@ import org.apache.shiro.session.mgt.SessionFactory;
import org.apache.shiro.web.session.mgt.WebSessionContext;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.IpUtils;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.common.utils.ServletUtils;
import eu.bitwalker.useragentutils.UserAgent;
/**

@ -7,10 +7,10 @@ import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.util.MessageUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;

@ -2,6 +2,7 @@ package com.ruoyi.framework.util;
import org.apache.commons.lang3.StringUtils;
import com.ruoyi.common.constant.PermissionConstants;
import com.ruoyi.common.utils.MessageUtils;
/**
* permission

@ -10,10 +10,10 @@ import com.github.pagehelper.PageInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.page.PageDomain;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.page.TableSupport;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.framework.web.page.TableSupport;
import com.ruoyi.system.domain.SysUser;
/**

@ -219,6 +219,7 @@ public class GenUtils
javaTypeMap.put("smallint", "Integer");
javaTypeMap.put("mediumint", "Integer");
javaTypeMap.put("int", "Integer");
javaTypeMap.put("number", "Integer");
javaTypeMap.put("integer", "integer");
javaTypeMap.put("bigint", "Long");
javaTypeMap.put("float", "Float");
@ -227,6 +228,7 @@ public class GenUtils
javaTypeMap.put("bit", "Boolean");
javaTypeMap.put("char", "String");
javaTypeMap.put("varchar", "String");
javaTypeMap.put("varchar2", "String");
javaTypeMap.put("tinytext", "String");
javaTypeMap.put("text", "String");
javaTypeMap.put("mediumtext", "String");

Loading…
Cancel
Save