mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2026-06-13 01:06:24 +00:00
update 优化媒体工具类,添加私有构造函数以防止实例化
This commit is contained in:
@@ -2,6 +2,8 @@ package org.dromara.common.core.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.dromara.common.core.enums.FormatsType;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
@@ -19,21 +21,16 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
/**
|
||||
* 日期解析格式集合。
|
||||
*/
|
||||
private static final String[] PARSE_PATTERNS = {
|
||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
||||
|
||||
/**
|
||||
* 工具类不允许实例化。
|
||||
*/
|
||||
@Deprecated
|
||||
private DateUtils() {
|
||||
}
|
||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取当前日期和时间
|
||||
@@ -414,7 +411,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
// 本周
|
||||
if (DateUtil.isSameWeek(date, now, true)) {
|
||||
return DateUtil.dayOfWeekEnum(date).toChinese("周")
|
||||
+ " " + DateUtil.format(date, "HH:mm");
|
||||
+ " " + DateUtil.format(date, "HH:mm");
|
||||
}
|
||||
|
||||
// 今年内其它时间
|
||||
|
||||
@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.Strings;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
@@ -17,6 +19,7 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
|
||||
public static final String SEPARATOR = ",";
|
||||
@@ -25,10 +28,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
|
||||
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
||||
|
||||
@Deprecated
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
@@ -318,11 +317,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
return StrUtil.split(str, separator)
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(mapper)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(mapper)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,6 +362,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将可迭代对象中的元素使用逗号拼接成字符串
|
||||
*
|
||||
@@ -397,7 +397,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断字符串是否在指定的字符串列表中
|
||||
*
|
||||
* @param string 字符串
|
||||
* @param string 字符串
|
||||
* @param searchStrings 字符串列表
|
||||
* @return 是否在列表中
|
||||
*/
|
||||
@@ -408,7 +408,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 忽略大小写判断字符串是否在指定的字符串列表中
|
||||
*
|
||||
* @param string 字符串
|
||||
* @param string 字符串
|
||||
* @param searchStrings 字符串列表
|
||||
* @return 是否在列表中
|
||||
*/
|
||||
@@ -499,8 +499,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 移除字符串中的指定字符序列。
|
||||
*
|
||||
* @param str 要处理的字符串,不能为null
|
||||
* @param remove 要移除的字符序列,不能为null
|
||||
* @param str 要处理的字符串,不能为null
|
||||
* @param remove 要移除的字符序列,不能为null
|
||||
* @return 处理后的字符串
|
||||
*/
|
||||
public static String remove(final String str, final String remove) {
|
||||
|
||||
@@ -1,71 +1,116 @@
|
||||
package org.dromara.common.core.utils.file;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 媒体类型工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class MimeTypeUtils {
|
||||
|
||||
/**
|
||||
* PNG 图片 MIME 类型。
|
||||
* PNG 图片 MIME 类型
|
||||
*/
|
||||
public static final String IMAGE_PNG = "image/png";
|
||||
|
||||
/**
|
||||
* JPG 图片 MIME 类型。
|
||||
* JPG 图片 MIME 类型
|
||||
*/
|
||||
public static final String IMAGE_JPG = "image/jpg";
|
||||
|
||||
/**
|
||||
* JPEG 图片 MIME 类型。
|
||||
* JPEG 图片 MIME 类型
|
||||
*/
|
||||
public static final String IMAGE_JPEG = "image/jpeg";
|
||||
|
||||
/**
|
||||
* BMP 图片 MIME 类型。
|
||||
* BMP 图片 MIME 类型
|
||||
*/
|
||||
public static final String IMAGE_BMP = "image/bmp";
|
||||
|
||||
/**
|
||||
* GIF 图片 MIME 类型。
|
||||
* GIF 图片 MIME 类型
|
||||
*/
|
||||
public static final String IMAGE_GIF = "image/gif";
|
||||
|
||||
/**
|
||||
* 图片扩展名集合。
|
||||
* 图片扩展名数组
|
||||
*/
|
||||
public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"};
|
||||
|
||||
/**
|
||||
* Flash 扩展名集合。
|
||||
* Flash 文件扩展名数组
|
||||
*/
|
||||
public static final String[] FLASH_EXTENSION = {"swf", "flv"};
|
||||
|
||||
/**
|
||||
* 媒体扩展名集合。
|
||||
*/
|
||||
public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
|
||||
"asf", "rm", "rmvb"};
|
||||
|
||||
/**
|
||||
* 视频扩展名集合。
|
||||
* 视频文件扩展名数组
|
||||
*/
|
||||
public static final String[] VIDEO_EXTENSION = {"mp4", "avi", "rmvb"};
|
||||
|
||||
/**
|
||||
* 默认允许上传扩展名集合。
|
||||
* 媒体文件扩展名数组(音频+视频+Flash)
|
||||
*/
|
||||
public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", "asf", "rm", "rmvb"};
|
||||
|
||||
/**
|
||||
* 默认允许上传的文件扩展名数组
|
||||
*/
|
||||
public static final String[] DEFAULT_ALLOWED_EXTENSION = {
|
||||
// 图片
|
||||
"bmp", "gif", "jpg", "jpeg", "png",
|
||||
// word excel powerpoint
|
||||
"doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
|
||||
// 压缩文件
|
||||
"rar", "zip", "gz", "bz2",
|
||||
// 视频格式
|
||||
"mp4", "avi", "rmvb",
|
||||
// pdf
|
||||
"pdf"};
|
||||
// 图片
|
||||
"bmp", "gif", "jpg", "jpeg", "png",
|
||||
// word excel powerpoint
|
||||
"doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
|
||||
// 压缩文件
|
||||
"rar", "zip", "gz", "bz2",
|
||||
// 视频格式
|
||||
"mp4", "avi", "rmvb",
|
||||
// pdf
|
||||
"pdf"
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断文件扩展名是否为图片格式(忽略大小写)
|
||||
*
|
||||
* @param extension 文件扩展名
|
||||
* @return 是图片返回 true,否则返回 false
|
||||
*/
|
||||
public static boolean isImage(String extension) {
|
||||
return StrUtil.equalsAnyIgnoreCase(extension, IMAGE_EXTENSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件扩展名是否为视频格式(忽略大小写)
|
||||
*
|
||||
* @param extension 文件扩展名
|
||||
* @return 是视频返回 true,否则返回 false
|
||||
*/
|
||||
public static boolean isVideo(String extension) {
|
||||
return StrUtil.equalsAnyIgnoreCase(extension, VIDEO_EXTENSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件扩展名是否为媒体格式(忽略大小写)
|
||||
*
|
||||
* @param extension 文件扩展名
|
||||
* @return 是媒体返回 true,否则返回 false
|
||||
*/
|
||||
public static boolean isMedia(String extension) {
|
||||
return StrUtil.equalsAnyIgnoreCase(extension, MEDIA_EXTENSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件扩展名是否在默认允许上传范围内(忽略大小写)
|
||||
*
|
||||
* @param extension 文件扩展名
|
||||
* @return 允许返回 true,不允许返回 false
|
||||
*/
|
||||
public static boolean isDefaultAllowed(String extension) {
|
||||
return StrUtil.equalsAnyIgnoreCase(extension, DEFAULT_ALLOWED_EXTENSION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.dromara.common.core.utils.ip;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
@@ -19,6 +21,7 @@ import java.time.Duration;
|
||||
* @author 秋辞未寒
|
||||
*/
|
||||
@Slf4j
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class RegionUtils {
|
||||
|
||||
// 默认IPv4地址库文件路径
|
||||
@@ -52,12 +55,12 @@ public class RegionUtils {
|
||||
|
||||
// IPv4配置
|
||||
Config v4Config = Config.custom()
|
||||
.setCachePolicy(Config.BufferCache)
|
||||
//.setXdbFile(v4TempXdb)
|
||||
.setXdbInputStream(v4InputStream)
|
||||
//
|
||||
.setCacheSliceBytes(DEFAULT_CACHE_SLICE_BYTES)
|
||||
.asV4();
|
||||
.setCachePolicy(Config.BufferCache)
|
||||
//.setXdbFile(v4TempXdb)
|
||||
.setXdbInputStream(v4InputStream)
|
||||
//
|
||||
.setCacheSliceBytes(DEFAULT_CACHE_SLICE_BYTES)
|
||||
.asV4();
|
||||
|
||||
// IPv6配置
|
||||
Config v6Config = null;
|
||||
@@ -66,11 +69,11 @@ public class RegionUtils {
|
||||
log.warn("未加载 IPv6 地址库:未在类路径下找到文件 {}。当前仅启用 IPv4 查询。如需启用 IPv6,请将 ip2region_v6.xdb 放置到 resources 目录", DEFAULT_IPV6_XDB_PATH);
|
||||
} else {
|
||||
v6Config = Config.custom()
|
||||
.setCachePolicy(Config.BufferCache)
|
||||
//.setXdbFile(v6TempXdb)
|
||||
.setXdbInputStream(v6XdbInputStream)
|
||||
.setCacheSliceBytes(DEFAULT_CACHE_SLICE_BYTES)
|
||||
.asV6();
|
||||
.setCachePolicy(Config.BufferCache)
|
||||
//.setXdbFile(v6TempXdb)
|
||||
.setXdbInputStream(v6XdbInputStream)
|
||||
.setCacheSliceBytes(DEFAULT_CACHE_SLICE_BYTES)
|
||||
.asV6();
|
||||
}
|
||||
|
||||
// 初始化Ip2Region实例
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.dromara.common.core.utils.regex;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.constant.RegexConstants;
|
||||
|
||||
/**
|
||||
@@ -9,6 +11,7 @@ import org.dromara.common.core.constant.RegexConstants;
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class RegexUtils extends ReUtil {
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.dromara.common.core.utils.regex;
|
||||
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.factory.RegexPatternPoolFactory;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@@ -12,6 +14,7 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class RegexValidator extends Validator {
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.LambdaMeta;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.ibatis.reflection.property.PropertyNamer;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@@ -14,6 +16,7 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class AggregateSelectUtils {
|
||||
|
||||
/**
|
||||
@@ -21,12 +24,6 @@ public final class AggregateSelectUtils {
|
||||
*/
|
||||
private static final Pattern ALIAS_PATTERN = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*");
|
||||
|
||||
/**
|
||||
* 工具类不允许实例化。
|
||||
*/
|
||||
private AggregateSelectUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加查询字段 SQL。
|
||||
*
|
||||
@@ -83,7 +80,7 @@ public final class AggregateSelectUtils {
|
||||
*/
|
||||
public static String checkAlias(String alias) {
|
||||
Assert.isTrue(StringUtils.isNotBlank(alias) && ALIAS_PATTERN.matcher(alias).matches(),
|
||||
"查询别名只能包含字母、数字、下划线且不能以数字开头: %s", alias);
|
||||
"查询别名只能包含字母、数字、下划线且不能以数字开头: %s", alias);
|
||||
return alias;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ public class SysProfileController extends BaseController {
|
||||
public R<AvatarVo> avatar(@RequestPart("avatarfile") MultipartFile avatarfile) {
|
||||
if (ObjectUtil.isNotNull(avatarfile) && !avatarfile.isEmpty()) {
|
||||
String extension = FileUtil.extName(avatarfile.getOriginalFilename());
|
||||
if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) {
|
||||
if (!MimeTypeUtils.isImage(extension)) {
|
||||
return R.fail("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "格式");
|
||||
}
|
||||
SysOssVo oss = ossService.upload(avatarfile);
|
||||
@@ -142,7 +142,8 @@ public class SysProfileController extends BaseController {
|
||||
*
|
||||
* @param imgUrl 头像地址
|
||||
*/
|
||||
public record AvatarVo(String imgUrl) {}
|
||||
public record AvatarVo(String imgUrl) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户个人信息
|
||||
@@ -151,7 +152,8 @@ public class SysProfileController extends BaseController {
|
||||
* @param roleGroup 用户所属角色组
|
||||
* @param postGroup 用户所属岗位组
|
||||
*/
|
||||
public record ProfileVo(ProfileUserVo user, String roleGroup, String postGroup) {}
|
||||
public record ProfileVo(ProfileUserVo user, String roleGroup, String postGroup) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户密码修改
|
||||
@@ -160,8 +162,8 @@ public class SysProfileController extends BaseController {
|
||||
* @param newPassword 新密码
|
||||
*/
|
||||
public record SysUserPasswordBo(
|
||||
@NotBlank(message = "旧密码不能为空") String oldPassword,
|
||||
@NotBlank(message = "新密码不能为空") String newPassword) {
|
||||
@NotBlank(message = "旧密码不能为空") String oldPassword,
|
||||
@NotBlank(message = "新密码不能为空") String newPassword) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user