From 2039aa4cb4e1f2949cafeae94531b94a424e7b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Mon, 6 Feb 2023 15:50:32 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=96=B0=E5=A2=9E=20StringUtils=20splitT?= =?UTF-8?q?o=20=E4=B8=8E=20splitList=20=E6=96=B9=E6=B3=95=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=B8=9A=E5=8A=A1=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/service/DictService.java | 11 +- .../ruoyi/common/core/utils/ServletUtils.java | 2 +- .../ruoyi/common/core/utils/StreamUtils.java | 2 +- .../ruoyi/common/core/utils/StringUtils.java | 454 ++++++++++-------- .../excel/annotation/ExcelDictFormat.java | 4 +- .../ruoyi/common/excel/utils/ExcelUtil.java | 4 +- .../common/mybatis/core/page/PageQuery.java | 4 +- .../common/sms/core/TencentSmsTemplate.java | 2 +- .../com/ruoyi/gen/domain/GenTableColumn.java | 2 +- .../java/com/ruoyi/gen/util/GenUtils.java | 6 +- .../com/ruoyi/gen/util/VelocityUtils.java | 4 +- .../service/impl/SysOssServiceImpl.java | 5 +- .../system/controller/SysDeptController.java | 5 +- .../service/impl/SysDeptServiceImpl.java | 9 +- .../service/impl/SysMenuServiceImpl.java | 4 +- .../service/impl/SysRoleServiceImpl.java | 4 +- 16 files changed, 287 insertions(+), 235 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/DictService.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/DictService.java index 2b649fcf..4b426776 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/DictService.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/DictService.java @@ -1,5 +1,7 @@ package com.ruoyi.common.core.service; +import com.ruoyi.common.core.utils.StringUtils; + /** * 字典服务服务 * @@ -7,11 +9,6 @@ package com.ruoyi.common.core.service; */ public interface DictService { - /** - * 分隔符 - */ - String SEPARATOR = ","; - /** * 根据字典类型和字典值获取字典标签 * @@ -20,7 +17,7 @@ public interface DictService { * @return 字典标签 */ default String getDictLabel(String dictType, String dictValue) { - return getDictLabel(dictType, dictValue, SEPARATOR); + return getDictLabel(dictType, dictValue, StringUtils.SEPARATOR); } /** @@ -31,7 +28,7 @@ public interface DictService { * @return 字典值 */ default String getDictValue(String dictType, String dictLabel) { - return getDictValue(dictType, dictLabel, SEPARATOR); + return getDictValue(dictType, dictLabel, StringUtils.SEPARATOR); } /** diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java index 4ae00a29..1c5662c2 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java @@ -96,7 +96,7 @@ public class ServletUtils extends ServletUtil { public static Map getParamMap(ServletRequest request) { Map params = new HashMap<>(); for (Map.Entry entry : getParams(request).entrySet()) { - params.put(entry.getKey(), StringUtils.join(entry.getValue(), ",")); + params.put(entry.getKey(), StringUtils.join(entry.getValue(), StringUtils.SEPARATOR)); } return params; } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java index 8a9a5561..27fd0573 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java @@ -42,7 +42,7 @@ public class StreamUtils { * @return 拼接后的list */ public static String join(Collection collection, Function function) { - return join(collection, function, ","); + return join(collection, function, StringUtils.SEPARATOR); } /** diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java index e2bbbb2c..3f0c1b46 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java @@ -1,16 +1,16 @@ package com.ruoyi.common.core.utils; 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.springframework.util.AntPathMatcher; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 字符串工具类 @@ -20,237 +20,238 @@ import java.util.Set; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class StringUtils extends org.apache.commons.lang3.StringUtils { - /** - * 获取参数不为空值 - * - * @param str defaultValue 要判断的value - * @return value 返回值 - */ - public static String blankToDefault(String str, String defaultValue) { - return StrUtil.blankToDefault(str, defaultValue); - } + public static final String SEPARATOR = ","; - /** - * * 判断一个字符串是否为空串 - * - * @param str String - * @return true:为空 false:非空 - */ - public static boolean isEmpty(String str) { - return StrUtil.isEmpty(str); - } + /** + * 获取参数不为空值 + * + * @param str defaultValue 要判断的value + * @return value 返回值 + */ + public static String blankToDefault(String str, String defaultValue) { + return StrUtil.blankToDefault(str, defaultValue); + } - /** - * * 判断一个字符串是否为非空串 - * - * @param str String - * @return true:非空串 false:空串 - */ - public static boolean isNotEmpty(String str) { - return !isEmpty(str); - } + /** + * * 判断一个字符串是否为空串 + * + * @param str String + * @return true:为空 false:非空 + */ + public static boolean isEmpty(String str) { + return StrUtil.isEmpty(str); + } - /** - * 去空格 - */ - public static String trim(String str) { - return StrUtil.trim(str); - } + /** + * * 判断一个字符串是否为非空串 + * + * @param str String + * @return true:非空串 false:空串 + */ + public static boolean isNotEmpty(String str) { + return !isEmpty(str); + } - /** - * 截取字符串 - * - * @param str 字符串 - * @param start 开始 - * @return 结果 - */ - public static String substring(final String str, int start) { - return substring(str, start, str.length()); - } + /** + * 去空格 + */ + public static String trim(String str) { + return StrUtil.trim(str); + } - /** - * 截取字符串 - * - * @param str 字符串 - * @param start 开始 - * @param end 结束 - * @return 结果 - */ - public static String substring(final String str, int start, int end) { - return StrUtil.sub(str, start, end); - } + /** + * 截取字符串 + * + * @param str 字符串 + * @param start 开始 + * @return 结果 + */ + public static String substring(final String str, int start) { + return substring(str, start, str.length()); + } - /** - * 格式化文本, {} 表示占位符
- * 此方法只是简单将占位符 {} 按照顺序替换为参数
- * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可
- * 例:
- * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b
- * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a
- * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b
- * - * @param template 文本模板,被替换的部分用 {} 表示 - * @param params 参数值 - * @return 格式化后的文本 - */ - public static String format(String template, Object... params) { - return StrUtil.format(template, params); - } + /** + * 截取字符串 + * + * @param str 字符串 + * @param start 开始 + * @param end 结束 + * @return 结果 + */ + public static String substring(final String str, int start, int end) { + return StrUtil.sub(str, start, end); + } - /** - * 是否为http(s)://开头 - * - * @param link 链接 - * @return 结果 - */ - public static boolean ishttp(String link) { - return Validator.isUrl(link); - } + /** + * 格式化文本, {} 表示占位符
+ * 此方法只是简单将占位符 {} 按照顺序替换为参数
+ * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可
+ * 例:
+ * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b
+ * 转义{}: format("this is \\{} for {}", "a", "b") -> this is {} for a
+ * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b
+ * + * @param template 文本模板,被替换的部分用 {} 表示 + * @param params 参数值 + * @return 格式化后的文本 + */ + public static String format(String template, Object... params) { + return StrUtil.format(template, params); + } - /** - * 字符串转set - * - * @param str 字符串 - * @param sep 分隔符 - * @return set集合 - */ - public static Set str2Set(String str, String sep) { - return new HashSet<>(str2List(str, sep, true, false)); - } + /** + * 是否为http(s)://开头 + * + * @param link 链接 + * @return 结果 + */ + public static boolean ishttp(String link) { + return Validator.isUrl(link); + } - /** - * 字符串转list - * - * @param str 字符串 - * @param sep 分隔符 - * @param filterBlank 过滤纯空白 - * @param trim 去掉首尾空白 - * @return list集合 - */ - public static List str2List(String str, String sep, boolean filterBlank, boolean trim) { - List list = new ArrayList<>(); - if (isEmpty(str)) { - return list; - } + /** + * 字符串转set + * + * @param str 字符串 + * @param sep 分隔符 + * @return set集合 + */ + public static Set str2Set(String str, String sep) { + return new HashSet<>(str2List(str, sep, true, false)); + } - // 过滤空白字符串 - if (filterBlank && isBlank(str)) { - return list; - } - String[] split = str.split(sep); - for (String string : split) { - if (filterBlank && isBlank(string)) { - continue; - } - if (trim) { - string = trim(string); - } - list.add(string); - } + /** + * 字符串转list + * + * @param str 字符串 + * @param sep 分隔符 + * @param filterBlank 过滤纯空白 + * @param trim 去掉首尾空白 + * @return list集合 + */ + public static List str2List(String str, String sep, boolean filterBlank, boolean trim) { + List list = new ArrayList<>(); + if (isEmpty(str)) { + return list; + } - return list; - } + // 过滤空白字符串 + if (filterBlank && isBlank(str)) { + return list; + } + String[] split = str.split(sep); + for (String string : split) { + if (filterBlank && isBlank(string)) { + continue; + } + if (trim) { + string = trim(string); + } + list.add(string); + } - /** - * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写 - * - * @param cs 指定字符串 - * @param searchCharSequences 需要检查的字符串数组 - * @return 是否包含任意一个字符串 - */ - public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) { - return StrUtil.containsAnyIgnoreCase(cs, searchCharSequences); - } + return list; + } - /** - * 驼峰转下划线命名 - */ - public static String toUnderScoreCase(String str) { - return StrUtil.toUnderlineCase(str); - } + /** + * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写 + * + * @param cs 指定字符串 + * @param searchCharSequences 需要检查的字符串数组 + * @return 是否包含任意一个字符串 + */ + public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) { + return StrUtil.containsAnyIgnoreCase(cs, searchCharSequences); + } - /** - * 是否包含字符串 - * - * @param str 验证字符串 - * @param strs 字符串组 - * @return 包含返回true - */ - public static boolean inStringIgnoreCase(String str, String... strs) { - return StrUtil.equalsAnyIgnoreCase(str, strs); - } + /** + * 驼峰转下划线命名 + */ + public static String toUnderScoreCase(String str) { + return StrUtil.toUnderlineCase(str); + } - /** - * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld - * - * @param name 转换前的下划线大写方式命名的字符串 - * @return 转换后的驼峰式命名的字符串 - */ - public static String convertToCamelCase(String name) { - return StrUtil.upperFirst(StrUtil.toCamelCase(name)); - } + /** + * 是否包含字符串 + * + * @param str 验证字符串 + * @param strs 字符串组 + * @return 包含返回true + */ + public static boolean inStringIgnoreCase(String str, String... strs) { + return StrUtil.equalsAnyIgnoreCase(str, strs); + } - /** - * 驼峰式命名法 例如:user_name->userName - */ - public static String toCamelCase(String s) { - return StrUtil.toCamelCase(s); - } + /** + * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld + * + * @param name 转换前的下划线大写方式命名的字符串 + * @return 转换后的驼峰式命名的字符串 + */ + public static String convertToCamelCase(String name) { + return StrUtil.upperFirst(StrUtil.toCamelCase(name)); + } - /** - * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 - * - * @param str 指定字符串 - * @param strs 需要检查的字符串数组 - * @return 是否匹配 - */ - public static boolean matches(String str, List strs) { - if (isEmpty(str) || CollUtil.isEmpty(strs)) { - return false; - } - for (String pattern : strs) { - if (isMatch(pattern, str)) { - return true; - } - } - return false; - } + /** + * 驼峰式命名法 例如:user_name->userName + */ + public static String toCamelCase(String s) { + return StrUtil.toCamelCase(s); + } - /** - * 判断url是否与规则配置: - * ? 表示单个字符; - * * 表示一层路径内的任意字符串,不可跨层级; - * ** 表示任意层路径; - * - * @param pattern 匹配规则 - * @param url 需要匹配的url - * @return - */ - public static boolean isMatch(String pattern, String url) { - AntPathMatcher matcher = new AntPathMatcher(); - return matcher.match(pattern, url); - } + /** + * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 + * + * @param str 指定字符串 + * @param strs 需要检查的字符串数组 + * @return 是否匹配 + */ + public static boolean matches(String str, List strs) { + if (isEmpty(str) || CollUtil.isEmpty(strs)) { + return false; + } + for (String pattern : strs) { + if (isMatch(pattern, str)) { + return true; + } + } + return false; + } + + /** + * 判断url是否与规则配置: + * ? 表示单个字符; + * * 表示一层路径内的任意字符串,不可跨层级; + * ** 表示任意层路径; + * + * @param pattern 匹配规则 + * @param url 需要匹配的url + */ + public static boolean isMatch(String pattern, String url) { + AntPathMatcher matcher = new AntPathMatcher(); + return matcher.match(pattern, url); + } /** * 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。 * - * @param num 数字对象 + * @param num 数字对象 * @param size 字符串指定长度 * @return 返回数字的字符串格式,该字符串为指定长度。 */ - public static final String padl(final Number num, final int size) { + public static String padl(final Number num, final int size) { return padl(num.toString(), size, '0'); } /** * 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。 * - * @param s 原始字符串 + * @param s 原始字符串 * @param size 字符串指定长度 - * @param c 用于补齐的字符 + * @param c 用于补齐的字符 * @return 返回指定长度的字符串,由原字符串左补齐或截取得到。 */ - public static final String padl(final String s, final int size, final char c) { + public static String padl(final String s, final int size, final char c) { final StringBuilder sb = new StringBuilder(size); if (s != null) { final int len = s.length(); @@ -270,4 +271,55 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { return sb.toString(); } + /** + * 切分字符串(分隔符默认逗号) + * + * @param str 被切分的字符串 + * @return 分割后的数据列表 + */ + public static List splitList(String str) { + return splitTo(str, Convert::toStr); + } + + /** + * 切分字符串 + * + * @param str 被切分的字符串 + * @param separator 分隔符 + * @return 分割后的数据列表 + */ + public static List splitList(String str, String separator) { + return splitTo(str, separator, Convert::toStr); + } + + /** + * 切分字符串自定义转换(分隔符默认逗号) + * + * @param str 被切分的字符串 + * @param mapper 自定义转换 + * @return 分割后的数据列表 + */ + public static List splitTo(String str, Function mapper) { + return splitTo(str, SEPARATOR, mapper); + } + + /** + * 切分字符串自定义转换 + * + * @param str 被切分的字符串 + * @param separator 分隔符 + * @param mapper 自定义转换 + * @return 分割后的数据列表 + */ + public static List splitTo(String str, String separator, Function mapper) { + if (isBlank(str)) { + return new ArrayList<>(0); + } + return StrUtil.split(str, separator) + .stream() + .filter(Objects::nonNull) + .map(mapper) + .collect(Collectors.toList()); + } + } diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/annotation/ExcelDictFormat.java b/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/annotation/ExcelDictFormat.java index a9671fb6..162dc796 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/annotation/ExcelDictFormat.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/annotation/ExcelDictFormat.java @@ -1,5 +1,7 @@ package com.ruoyi.common.excel.annotation; +import com.ruoyi.common.core.utils.StringUtils; + import java.lang.annotation.*; /** @@ -25,6 +27,6 @@ public @interface ExcelDictFormat { /** * 分隔符,读取字符串组内容 */ - String separator() default ","; + String separator() default StringUtils.SEPARATOR; } diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/utils/ExcelUtil.java b/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/utils/ExcelUtil.java index 4fa8c080..95563e1d 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/utils/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/utils/ExcelUtil.java @@ -270,7 +270,7 @@ public class ExcelUtil { */ public static String convertByExp(String propertyValue, String converterExp, String separator) { StringBuilder propertyString = new StringBuilder(); - String[] convertSource = converterExp.split(","); + String[] convertSource = converterExp.split(StringUtils.SEPARATOR); for (String item : convertSource) { String[] itemArray = item.split("="); if (StringUtils.containsAny(propertyValue, separator)) { @@ -299,7 +299,7 @@ public class ExcelUtil { */ public static String reverseByExp(String propertyValue, String converterExp, String separator) { StringBuilder propertyString = new StringBuilder(); - String[] convertSource = converterExp.split(","); + String[] convertSource = converterExp.split(StringUtils.SEPARATOR); for (String item : convertSource) { String[] itemArray = item.split("="); if (StringUtils.containsAny(propertyValue, separator)) { diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/core/page/PageQuery.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/core/page/PageQuery.java index 91396cb4..3f5764f5 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/core/page/PageQuery.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/core/page/PageQuery.java @@ -87,8 +87,8 @@ public class PageQuery implements Serializable { // 兼容前端排序类型 isAsc = StringUtils.replaceEach(isAsc, new String[]{"ascending", "descending"}, new String[]{"asc", "desc"}); - String[] orderByArr = orderBy.split(","); - String[] isAscArr = isAsc.split(","); + String[] orderByArr = orderBy.split(StringUtils.SEPARATOR); + String[] isAscArr = isAsc.split(StringUtils.SEPARATOR); if (isAscArr.length != 1 && isAscArr.length != orderByArr.length) { throw new ServiceException("排序参数有误"); } diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/core/TencentSmsTemplate.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/core/TencentSmsTemplate.java index f4a3e069..9449a961 100644 --- a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/core/TencentSmsTemplate.java +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/core/TencentSmsTemplate.java @@ -52,7 +52,7 @@ public class TencentSmsTemplate implements SmsTemplate { throw new SmsException("模板ID不能为空"); } SendSmsRequest req = new SendSmsRequest(); - Set set = Arrays.stream(phones.split(",")).map(p -> "+86" + p).collect(Collectors.toSet()); + Set set = Arrays.stream(phones.split(StringUtils.SEPARATOR)).map(p -> "+86" + p).collect(Collectors.toSet()); req.setPhoneNumberSet(ArrayUtil.toArray(set, String.class)); if (CollUtil.isNotEmpty(param)) { req.setTemplateParamSet(ArrayUtil.toArray(param.values(), String.class)); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java index 06226dbc..a9137002 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java @@ -212,7 +212,7 @@ public class GenTableColumn extends BaseEntity { if (StringUtils.isNotEmpty(value)) { Object startStr = value.subSequence(0, 1); String endStr = value.substring(1); - sb.append("").append(startStr).append("=").append(endStr).append(","); + sb.append(StringUtils.EMPTY).append(startStr).append("=").append(endStr).append(StringUtils.SEPARATOR); } } return sb.deleteCharAt(sb.length() - 1).toString(); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java index b3120473..42cb278e 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java @@ -57,7 +57,7 @@ public class GenUtils { column.setHtmlType(GenConstants.HTML_INPUT); // 如果是浮点型 统一用BigDecimal - String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); + String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), StringUtils.SEPARATOR); if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) { column.setJavaType(GenConstants.TYPE_BIGDECIMAL); } @@ -166,7 +166,7 @@ public class GenUtils { boolean autoRemovePre = GenConfig.getAutoRemovePre(); String tablePrefix = GenConfig.getTablePrefix(); if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) { - String[] searchList = StringUtils.split(tablePrefix, ","); + String[] searchList = StringUtils.split(tablePrefix, StringUtils.SEPARATOR); tableName = replaceFirst(tableName, searchList); } return StringUtils.convertToCamelCase(tableName); @@ -183,7 +183,7 @@ public class GenUtils { String text = replacementm; for (String searchString : searchList) { if (replacementm.startsWith(searchString)) { - text = replacementm.replaceFirst(searchString, ""); + text = replacementm.replaceFirst(searchString, StringUtils.EMPTY); break; } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java index 8a23cf15..bfc46e75 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java @@ -230,7 +230,7 @@ public class VelocityUtils { public static HashSet getImportList(GenTable genTable) { List columns = genTable.getColumns(); GenTable subGenTable = genTable.getSubTable(); - HashSet importList = new HashSet(); + HashSet importList = new HashSet<>(); if (ObjectUtil.isNotNull(subGenTable)) { importList.add("java.util.List"); } @@ -252,7 +252,7 @@ public class VelocityUtils { */ public static String getDicts(GenTable genTable) { List columns = genTable.getColumns(); - Set dicts = new HashSet(); + Set dicts = new HashSet<>(); addDicts(dicts, columns); if (ObjectUtil.isNotNull(genTable.getSubTable())) { List subColumns = genTable.getSubTable().getColumns(); diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java index 988eceeb..b649598d 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.resource.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -70,13 +71,13 @@ public class SysOssServiceImpl implements ISysOssService { @Override public String selectUrlByIds(String ossIds) { List list = new ArrayList<>(); - for (Long id : Arrays.stream(ossIds.split(",")).map(Long::parseLong).collect(Collectors.toList())) { + for (Long id : StringUtils.splitTo(ossIds, Convert::toLong)) { SysOssVo vo = SpringUtils.getAopProxy(this).getById(id); if (ObjectUtil.isNotNull(vo)) { list.add(this.matchingUrl(vo).getUrl()); } } - return String.join(",", list); + return String.join(StringUtils.SEPARATOR, list); } private LambdaQueryWrapper buildQueryWrapper(SysOssBo bo) { diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java index b2bda6b2..a9a37af9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java @@ -1,7 +1,7 @@ package com.ruoyi.system.controller; import cn.dev33.satoken.annotation.SaCheckPermission; -import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.convert.Convert; import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.StringUtils; @@ -48,7 +48,8 @@ public class SysDeptController extends BaseController { @GetMapping("/list/exclude/{deptId}") public R> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) { List depts = deptService.selectDeptList(new SysDept()); - depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtil.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); + depts.removeIf(d -> d.getDeptId().intValue() == deptId + || StringUtils.splitList(d.getAncestors()).contains(Convert.toStr(deptId))); return R.ok(depts); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 2967967b..b6736ec7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -30,7 +30,6 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; /** * 部门管理 服务实现 @@ -131,13 +130,13 @@ public class SysDeptServiceImpl implements ISysDeptService { @Override public String selectDeptNameByIds(String deptIds) { List list = new ArrayList<>(); - for (Long id : Arrays.stream(deptIds.split(",")).map(Long::parseLong).collect(Collectors.toList())) { + for (Long id : StringUtils.splitTo(deptIds, Convert::toLong)) { SysDept dept = SpringUtils.getAopProxy(this).selectDeptById(id); if (ObjectUtil.isNotNull(dept)) { list.add(dept.getDeptName()); } } - return String.join(",", list); + return String.join(StringUtils.SEPARATOR, list); } /** @@ -225,7 +224,7 @@ public class SysDeptServiceImpl implements ISysDeptService { if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { throw new ServiceException("部门停用,不允许新增"); } - dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId()); return baseMapper.insert(dept); } @@ -241,7 +240,7 @@ public class SysDeptServiceImpl implements ISysDeptService { SysDept newParentDept = baseMapper.selectById(dept.getParentId()); SysDept oldDept = baseMapper.selectById(dept.getDeptId()); if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) { - String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); + String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getDeptId(); String oldAncestors = oldDept.getAncestors(); dept.setAncestors(newAncestors); updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index e5c829f3..c9056bb3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -92,7 +92,7 @@ public class SysMenuServiceImpl implements ISysMenuService { Set permsSet = new HashSet<>(); for (String perm : perms) { if (StringUtils.isNotEmpty(perm)) { - permsSet.addAll(Arrays.asList(perm.trim().split(","))); + permsSet.addAll(StringUtils.splitList(perm.trim())); } } return permsSet; @@ -110,7 +110,7 @@ public class SysMenuServiceImpl implements ISysMenuService { Set permsSet = new HashSet<>(); for (String perm : perms) { if (StringUtils.isNotEmpty(perm)) { - permsSet.addAll(Arrays.asList(perm.trim().split(","))); + permsSet.addAll(StringUtils.splitList(perm.trim())); } } return permsSet; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index ceab4137..27b2b6af 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -5,11 +5,11 @@ import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.mybatis.core.page.PageQuery; import com.ruoyi.common.mybatis.core.page.TableDataInfo; import com.ruoyi.common.satoken.utils.LoginHelper; @@ -106,7 +106,7 @@ public class SysRoleServiceImpl implements ISysRoleService { Set permsSet = new HashSet<>(); for (SysRole perm : perms) { if (ObjectUtil.isNotNull(perm)) { - permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); + permsSet.addAll(StringUtils.splitList(perm.getRoleKey().trim())); } } return permsSet;