优化代码

This commit is contained in:
TinyAnts 2022-04-02 11:31:11 +08:00
parent 0c20c5ec96
commit 7fb4668c52
12 changed files with 200 additions and 44 deletions

View File

@ -7,6 +7,7 @@ import com.hxkj.common.entity.system.SystemMenu;
import com.hxkj.common.entity.system.SystemRoleMenu; import com.hxkj.common.entity.system.SystemRoleMenu;
import com.hxkj.common.mapper.system.SystemMenuMapper; import com.hxkj.common.mapper.system.SystemMenuMapper;
import com.hxkj.common.mapper.system.SystemRoleMenuMapper; import com.hxkj.common.mapper.system.SystemRoleMenuMapper;
import com.hxkj.common.utils.ArrayUtil;
import com.hxkj.common.utils.RedisUtil; import com.hxkj.common.utils.RedisUtil;
import com.hxkj.common.utils.ToolsUtil; import com.hxkj.common.utils.ToolsUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -113,7 +114,7 @@ public class ISystemRoleMenuServiceImpl implements ISystemRoleMenuService {
} }
} }
RedisUtil.hSet(SystemConfig.backstageRolesKey, String.valueOf(roleId), ToolsUtil.listStrToString(menuArray, ",")); RedisUtil.hSet(SystemConfig.backstageRolesKey, String.valueOf(roleId), ArrayUtil.listStrToString(menuArray, ","));
} }
} }

View File

@ -4,6 +4,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/**
* 相册分类Vo
*/
@Data @Data
public class AlbumCateVo implements Serializable { public class AlbumCateVo implements Serializable {

View File

@ -4,6 +4,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/**
* 相册Vo
*/
@Data @Data
public class AlbumVo implements Serializable { public class AlbumVo implements Serializable {

View File

@ -4,6 +4,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/**
* 登录日志Vo
*/
@Data @Data
public class LogLoginVo implements Serializable { public class LogLoginVo implements Serializable {

View File

@ -4,6 +4,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/**
* 操作日志Vo
*/
@Data @Data
public class LogOperateVo implements Serializable { public class LogOperateVo implements Serializable {

View File

@ -4,6 +4,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/**
* 管理员Vo
*/
@Data @Data
public class SystemAdminVo implements Serializable { public class SystemAdminVo implements Serializable {

View File

@ -4,6 +4,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/**
* 系统菜单Vo
*/
@Data @Data
public class SystemMenuVo implements Serializable { public class SystemMenuVo implements Serializable {

View File

@ -4,6 +4,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/**
* 系统角色Vo
*/
@Data @Data
public class SystemRoleVo implements Serializable { public class SystemRoleVo implements Serializable {

View File

@ -0,0 +1,10 @@
Spring Boot Version: ${spring-boot.version}
///////////////////////////////////////////////////////
// _ _ _ _ _ _ //
// | | (_) | __ / \ __| |_ __ ___ (_)_ __ //
// | | | | |/ / / _ \ / _` | '_ ` _ \| | '_ \ //
// | |___| | < / ___ \ (_| | | | | | | | | | | //
// |_____|_|_|\_\/_/ \_\__,_|_| |_| |_|_|_| |_| //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //
///////////////////////////////////////////////////////

View File

@ -3,6 +3,11 @@ package com.hxkj.common.utils;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** /**
* 数组工具类 * 数组工具类
*/ */
@ -53,5 +58,140 @@ public class ArrayUtil {
return r; return r;
} }
/**
* List去重,不打乱原来顺序,泛型list对象
* 对象重写hashCode和equals
*
* @author fzr
* @param <T> 泛型
* @param list 列表
* @return List
*/
public static <T> List<T> uniqueBySetOrder(List<T> list){
Set<T> set = new HashSet<T>();
List<T> newList = new ArrayList<T>();
for(T t: list){
if(set.add(t)){
newList.add(t);
}
}
return newList;
}
/**
* List去重,可能打乱原来顺序,泛型list对象
* 对象重写hashCode和equals
*
* @author fzr
* @param list 列表
* @return List
*/
public static <T> List<T> uniqueBySet(List<T> list){
return new ArrayList<T>(new HashSet<T>(list));
}
/**
* 列表转字符串
*
* @author fzr
* @param list 列表 [1, 2, 4] -> 1,2,3
* @param separator 分割符号
* @return String
*/
public static String listToString(List<Long> list, String separator) {
StringBuilder sb = new StringBuilder();
for (Object o : list) {
sb.append(o).append(separator);
}
return list.isEmpty() ? "" : sb.substring(0, sb.toString().length() - 1);
}
/**
* 列表转字符串
*
* @author fzr
* @param list 列表 ["1", "2", "3"] -> 1,2,3
* @param separator 分割符号
* @return String
*/
public static String listStrToString(List<String> list, String separator) {
StringBuilder sb = new StringBuilder();
for (Object o : list) {
sb.append(o).append(separator);
}
return list.isEmpty() ? "" : sb.substring(0, sb.toString().length() - 1);
}
/**
* 字符串分割,转化为数组
*
* @author fzr
* @param str 字符串
* @return List<Integer>
*/
public static List<Integer> stringToArray(String str){
return stringToArrayByRegex(str, ",");
}
/**
* 字符串分割转化为数组
*
* @author fzr
* @param str 字符串
* @return List<String>
*/
public static List<String> stringToArrayStr(String str){
return stringToArrayStrRegex(str, ",");
}
/**
* 字符串分割,转化为数组
*
* @author fzr
* @param str 字符串
* @param regex 分隔符
* @return List<Integer>
*/
public static List<Integer> stringToArrayByRegex(String str, String regex){
List<Integer> list = new ArrayList<>();
if (str.contains(regex)){
String[] split = str.split(regex);
for (String value : split) {
if(!StringUtil.isBlank(value)){
list.add(Integer.parseInt(value.trim()));
}
}
}else {
list.add(Integer.parseInt(str));
}
return list;
}
/**
* 字符串分割转化为数组
*
* @author fzr
* @param str 字符串
* @param regex 分隔符
* @return List<String>
*/
public static List<String> stringToArrayStrRegex(String str, String regex ){
List<String> list = new ArrayList<>();
if (str.contains(regex)){
String[] split = str.split(regex);
for (String value : split) {
if(!StringUtil.isBlank(value)){
list.add(value);
}
}
}else {
list.add(str);
}
return list;
}
} }

View File

@ -7,13 +7,15 @@ import java.util.*;
/** /**
* 字符串工具类 * 字符串工具类
*/ */
public class StringUtil extends org.apache.commons.lang3.StringUtils public class StringUtil extends org.apache.commons.lang3.StringUtils {
{ /**
* 空字符串
/** 空字符串 */ */
private static final String NULL_STR = ""; private static final String NULL_STR = "";
/** 下划线 */ /**
* 下划线
*/
private static final char SEPARATOR = '_'; private static final char SEPARATOR = '_';
/** /**
@ -27,10 +29,10 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
} }
/** /**
* 判断一个Collection是否为空, 包含List, Set, Queue * 判断一个Collection是否为空,包含List, Set, Queue
* *
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true为空 false非空 * @return true=为空, false=非空
*/ */
public static boolean isEmpty(Collection<?> coll) { public static boolean isEmpty(Collection<?> coll) {
return isNull(coll) || coll.isEmpty(); return isNull(coll) || coll.isEmpty();
@ -40,7 +42,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个Collection是否非空,包含List, Set, Queue * 判断一个Collection是否非空,包含List, Set, Queue
* *
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true非空 false * @return true=非空, false=
*/ */
public static boolean isNotEmpty(Collection<?> coll) { public static boolean isNotEmpty(Collection<?> coll) {
return !isEmpty(coll); return !isEmpty(coll);
@ -50,7 +52,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个对象数组是否为空 * 判断一个对象数组是否为空
* *
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
* @return true为空 false非空 * @return true=为空, false=非空
*/ */
public static boolean isEmpty(Object[] objects) { public static boolean isEmpty(Object[] objects) {
return isNull(objects) || (objects.length == 0); return isNull(objects) || (objects.length == 0);
@ -60,7 +62,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个对象数组是否非空 * 判断一个对象数组是否非空
* *
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
* @return true非空 false * @return true=非空, false=
*/ */
public static boolean isNotEmpty(Object[] objects) { public static boolean isNotEmpty(Object[] objects) {
return !isEmpty(objects); return !isEmpty(objects);
@ -70,7 +72,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个Map是否为空 * 判断一个Map是否为空
* *
* @param map 要判断的Map * @param map 要判断的Map
* @return true为空 false非空 * @return true=为空, false=非空
*/ */
public static boolean isEmpty(Map<?, ?> map) { public static boolean isEmpty(Map<?, ?> map) {
return isNull(map) || map.isEmpty(); return isNull(map) || map.isEmpty();
@ -80,7 +82,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个Map是否为空 * 判断一个Map是否为空
* *
* @param map 要判断的Map * @param map 要判断的Map
* @return true非空 false * @return true=非空, false=
*/ */
public static boolean isNotEmpty(Map<?, ?> map) { public static boolean isNotEmpty(Map<?, ?> map) {
return !isEmpty(map); return !isEmpty(map);
@ -90,7 +92,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个字符串是否为空串 * 判断一个字符串是否为空串
* *
* @param str String * @param str String
* @return true为空 false非空 * @return true=为空, false=非空
*/ */
public static boolean isEmpty(String str) { public static boolean isEmpty(String str) {
return isNull(str) || NULL_STR.equals(str.trim()); return isNull(str) || NULL_STR.equals(str.trim());
@ -100,7 +102,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个字符串是否为非空串 * 判断一个字符串是否为非空串
* *
* @param str String * @param str String
* @return true非空串 false空串 * @return true=非空串, false=空串
*/ */
public static boolean isNotEmpty(String str) { public static boolean isNotEmpty(String str) {
return !isEmpty(str); return !isEmpty(str);
@ -110,7 +112,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个对象是否为空 * 判断一个对象是否为空
* *
* @param object Object * @param object Object
* @return true为空 false非空 * @return true=为空, false=非空
*/ */
public static boolean isNull(Object object) { public static boolean isNull(Object object) {
return object == null; return object == null;
@ -120,7 +122,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个对象是否非空 * 判断一个对象是否非空
* *
* @param object Object * @param object Object
* @return true非空 false * @return true=非空, false=
*/ */
public static boolean isNotNull(Object object) { public static boolean isNotNull(Object object) {
return !isNull(object); return !isNull(object);
@ -130,7 +132,7 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils
* 判断一个对象是否是数组类型Java基本型别的数组 * 判断一个对象是否是数组类型Java基本型别的数组
* *
* @param object 对象 * @param object 对象
* @return true是数组 false不是数组 * @return true=是数组, false=不是数组
*/ */
public static boolean isArray(Object object) { public static boolean isArray(Object object) {
return isNotNull(object) && object.getClass().isArray(); return isNotNull(object) && object.getClass().isArray();

View File

@ -157,35 +157,17 @@ public class ToolsUtil {
} }
/** /**
* 列表转字符串 * map合并
* *
* @author fzr * @author fzr
* @param list 列表 [1, 2, 4] -> 1,2,3 * @param map 对象
* @param separator 分割符号 * @return Object
* @return String
*/ */
public static String listToString(List<Long> list, String separator) { public static Map<String, Object> mergeMap(Map<String, Object> map, Map<String, Object> map1){
StringBuilder sb = new StringBuilder(); HashMap<String, Object> map2 = new HashMap<>();
for (Object o : list) { map2.putAll(map);
sb.append(o).append(separator); map2.putAll(map1);
} return map2;
return list.isEmpty() ? "" : sb.substring(0, sb.toString().length() - 1);
}
/**
* 列表转字符串
*
* @author fzr
* @param list 列表 ["1", "2", "3"] -> 1,2,3
* @param separator 分割符号
* @return String
*/
public static String listStrToString(List<String> list, String separator) {
StringBuilder sb = new StringBuilder();
for (Object o : list) {
sb.append(o).append(separator);
}
return list.isEmpty() ? "" : sb.substring(0, sb.toString().length() - 1);
} }
} }