From 50466b25566efe7d9761169e07ccd06b80e876bf Mon Sep 17 00:00:00 2001 From: thinkgem Date: Fri, 9 Jun 2023 14:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20commons-collections?= =?UTF-8?q?=E3=80=81commons-beanutils=20=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jeesite/common/collect/ListUtils.java | 331 +++++++++--------- .../com/jeesite/common/collect/MapUtils.java | 319 +++++++++-------- .../com/jeesite/common/collect/SetUtils.java | 2 +- .../com/jeesite/common/io/PropertyLoader.java | 19 +- .../utils/excel/fieldtype/PostListType.java | 15 +- .../utils/excel/fieldtype/RoleListType.java | 15 +- .../jeesite/modules/sys/entity/Employee.java | 6 +- .../modules/sys/web/CompanyController.java | 48 +-- 8 files changed, 379 insertions(+), 376 deletions(-) diff --git a/common/src/main/java/com/jeesite/common/collect/ListUtils.java b/common/src/main/java/com/jeesite/common/collect/ListUtils.java index 5408391b..d70634f8 100644 --- a/common/src/main/java/com/jeesite/common/collect/ListUtils.java +++ b/common/src/main/java/com/jeesite/common/collect/ListUtils.java @@ -8,7 +8,6 @@ import com.jeesite.common.callback.MethodCallback; import com.jeesite.common.lang.ObjectUtils; import com.jeesite.common.lang.StringUtils; import com.jeesite.common.reflect.ReflectUtils; -import org.apache.commons.beanutils.PropertyUtils; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; @@ -19,7 +18,7 @@ import java.util.concurrent.CopyOnWriteArrayList; * @version 2015-1-23 */ @SuppressWarnings("rawtypes") -public class ListUtils extends org.apache.commons.collections.ListUtils { +public class ListUtils { /** * 是否包含字符串 @@ -141,107 +140,107 @@ public class ListUtils extends org.apache.commons.collections.ListUtils { } return addAll(addTo, elementsToAdd.iterator()); } - - /** - * 提取集合中的对象的两个属性(通过Getter函数), 组合成Map. - * @param collection 来源集合. - * @param keyPropertyName 要提取为Map中的Key值的属性名. - * @param valuePropertyName 要提取为Map中的Value值的属性名. - */ - @SuppressWarnings("unchecked") - public static Map extractToMap(final Collection collection, final String keyPropertyName, - final String valuePropertyName) { - Map map = new HashMap(collection.size()); - try { - for (Object obj : collection) { - map.put(PropertyUtils.getProperty(obj, keyPropertyName), - PropertyUtils.getProperty(obj, valuePropertyName)); - } - } catch (Exception e) { - throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); - } - return map; - } - /** - * 提取集合中的对象的一个属性(通过Getter函数), 组合成List. - * @param collection 来源集合. - * @param propertyName 要提取的属性名. - */ - @SuppressWarnings("unchecked") - public static List extractToList(final Collection collection, final String propertyName) { - if (collection == null){ - return newArrayList(); - } - List list = new ArrayList(collection.size()); - try { - for (Object obj : collection) { - list.add(PropertyUtils.getProperty(obj, propertyName)); - } - } catch (Exception e) { - throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); - } - return list; - } - - /** - * 提取集合中的对象的一个属性(通过Getter函数), 组合成List. - * @param collection 来源集合. - * @param propertyName 要提取的属性名. - * @param prefix 符合前缀的信息(为空则忽略前缀) - * @param isNotBlank 仅包含不为空值(空字符串也排除) - */ - public static List extractToList(final Collection collection, final String propertyName, - final String prefix, final boolean isNotBlank) { - List list = new ArrayList(collection.size()); - try { - for (Object obj : collection) { - String value = (String)PropertyUtils.getProperty(obj, propertyName); - if (StringUtils.isBlank(prefix) || StringUtils.startsWith(value, prefix)){ - if (isNotBlank){ - if (StringUtils.isNotBlank(value)){ - list.add(value); - } - }else{ - list.add(value); - } - } - } - } catch (Exception e) { - throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); - } - return list; - } - - /** - * 提取集合中的对象的一个属性(通过Getter函数), 组合成由分割符分隔的字符串. - * - * @param collection 来源集合. - * @param propertyName 要提取的属性名. - * @param separator 分隔符. - */ - public static String extractToString(final Collection collection, final String propertyName, final String separator) { - List list = extractToList(collection, propertyName); - return StringUtils.join(list, separator); - } - - /** - * 转换Collection所有元素(通过toString())为String, 中间以 separator分隔。 - */ - public static String convertToString(final Collection collection, final String separator) { - return StringUtils.join(collection, separator); - } - - /** - * 转换Collection所有元素(通过toString())为String, 每个元素的前面加入prefix,后面加入postfix,如
mymessage
。 - */ - public static String convertToString(final Collection collection, final String prefix, final String postfix) { - StringBuilder builder = new StringBuilder(); - for (Object o : collection) { - builder.append(prefix).append(o).append(postfix); - } - return builder.toString(); - } +// /** +// * 提取集合中的对象的两个属性(通过Getter函数), 组合成Map. +// * @param collection 来源集合. +// * @param keyPropertyName 要提取为Map中的Key值的属性名. +// * @param valuePropertyName 要提取为Map中的Value值的属性名. +// */ +// @SuppressWarnings("unchecked") +// public static Map extractToMap(final Collection collection, final String keyPropertyName, +// final String valuePropertyName) { +// Map map = new HashMap(collection.size()); +// try { +// for (Object obj : collection) { +// map.put(ReflectUtils.getFieldValue(obj, keyPropertyName), +// ReflectUtils.getFieldValue(obj, valuePropertyName)); +// } +// } catch (Exception e) { +// throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); +// } +// return map; +// } +// +// /** +// * 提取集合中的对象的一个属性(通过Getter函数), 组合成List. +// * @param collection 来源集合. +// * @param propertyName 要提取的属性名. +// */ +// @SuppressWarnings("unchecked") +// public static List extractToList(final Collection collection, final String propertyName) { +// if (collection == null){ +// return newArrayList(); +// } +// List list = new ArrayList(collection.size()); +// try { +// for (Object obj : collection) { +// list.add(ReflectUtils.getFieldValue(obj, propertyName)); +// } +// } catch (Exception e) { +// throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); +// } +// return list; +// } +// +// /** +// * 提取集合中的对象的一个属性(通过Getter函数), 组合成List. +// * @param collection 来源集合. +// * @param propertyName 要提取的属性名. +// * @param prefix 符合前缀的信息(为空则忽略前缀) +// * @param isNotBlank 仅包含不为空值(空字符串也排除) +// */ +// public static List extractToList(final Collection collection, final String propertyName, +// final String prefix, final boolean isNotBlank) { +// List list = new ArrayList(collection.size()); +// try { +// for (Object obj : collection) { +// String value = ReflectUtils.getFieldValue(obj, propertyName); +// if (StringUtils.isBlank(prefix) || StringUtils.startsWith(value, prefix)){ +// if (isNotBlank){ +// if (StringUtils.isNotBlank(value)){ +// list.add(value); +// } +// }else{ +// list.add(value); +// } +// } +// } +// } catch (Exception e) { +// throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); +// } +// return list; +// } +// +// /** +// * 提取集合中的对象的一个属性(通过Getter函数), 组合成由分割符分隔的字符串. +// * +// * @param collection 来源集合. +// * @param propertyName 要提取的属性名. +// * @param separator 分隔符. +// */ +// public static String extractToString(final Collection collection, final String propertyName, final String separator) { +// List list = extractToList(collection, propertyName); +// return StringUtils.join(list, separator); +// } +// +// /** +// * 转换Collection所有元素(通过toString())为String, 中间以 separator分隔。 +// */ +// public static String convertToString(final Collection collection, final String separator) { +// return StringUtils.join(collection, separator); +// } +// +// /** +// * 转换Collection所有元素(通过toString())为String, 每个元素的前面加入prefix,后面加入postfix,如
mymessage
。 +// */ +// public static String convertToString(final Collection collection, final String prefix, final String postfix) { +// StringBuilder builder = new StringBuilder(); +// for (Object o : collection) { +// builder.append(prefix).append(o).append(postfix); +// } +// return builder.toString(); +// } /** * 判断是否为空. @@ -257,70 +256,70 @@ public class ListUtils extends org.apache.commons.collections.ListUtils { return !(isEmpty(collection)); } - /** - * 取得Collection的第一个元素,如果collection为空返回null. - */ - public static T getFirst(Collection collection) { - if (isEmpty(collection)) { - return null; - } - return collection.iterator().next(); - } - - /** - * 获取Collection的最后一个元素 ,如果collection为空返回null. - */ - public static T getLast(Collection collection) { - if (isEmpty(collection)) { - return null; - } - //当类型为List时,直接取得最后一个元素 。 - if (collection instanceof List) { - List list = (List) collection; - return list.get(list.size() - 1); - } - //其他类型通过iterator滚动到最后一个元素. - Iterator iterator = collection.iterator(); - while (true) { - T current = iterator.next(); - if (!iterator.hasNext()) { - return current; - } - } - } - - /** - * 返回a+b的新List. - */ - public static List union(final Collection a, final Collection b) { - List result = new ArrayList(a); - result.addAll(b); - return result; - } - - /** - * 返回a-b的新List. - */ - public static List subtract(final Collection a, final Collection b) { - List list = new ArrayList(a); - for (T element : b) { - list.remove(element); - } - return list; - } - - /** - * 返回a与b的交集的新List. - */ - public static List intersection(Collection a, Collection b) { - List list = new ArrayList(); - for (T element : a) { - if (b.contains(element)) { - list.add(element); - } - } - return list; - } +// /** +// * 取得Collection的第一个元素,如果collection为空返回null. +// */ +// public static T getFirst(Collection collection) { +// if (isEmpty(collection)) { +// return null; +// } +// return collection.iterator().next(); +// } +// +// /** +// * 获取Collection的最后一个元素 ,如果collection为空返回null. +// */ +// public static T getLast(Collection collection) { +// if (isEmpty(collection)) { +// return null; +// } +// //当类型为List时,直接取得最后一个元素 。 +// if (collection instanceof List) { +// List list = (List) collection; +// return list.get(list.size() - 1); +// } +// //其他类型通过iterator滚动到最后一个元素. +// Iterator iterator = collection.iterator(); +// while (true) { +// T current = iterator.next(); +// if (!iterator.hasNext()) { +// return current; +// } +// } +// } +// +// /** +// * 返回a+b的新List. +// */ +// public static List union(final Collection a, final Collection b) { +// List result = new ArrayList(a); +// result.addAll(b); +// return result; +// } +// +// /** +// * 返回a-b的新List. +// */ +// public static List subtract(final Collection a, final Collection b) { +// List list = new ArrayList(a); +// for (T element : b) { +// list.remove(element); +// } +// return list; +// } +// +// /** +// * 返回a与b的交集的新List. +// */ +// public static List intersection(Collection a, Collection b) { +// List list = new ArrayList(); +// for (T element : a) { +// if (b.contains(element)) { +// list.add(element); +// } +// } +// return list; +// } // /** // * 将字符串使用“,”分隔,转换为,多对多中间表列表的转换 diff --git a/common/src/main/java/com/jeesite/common/collect/MapUtils.java b/common/src/main/java/com/jeesite/common/collect/MapUtils.java index b30f134c..7e75d5bf 100644 --- a/common/src/main/java/com/jeesite/common/collect/MapUtils.java +++ b/common/src/main/java/com/jeesite/common/collect/MapUtils.java @@ -4,11 +4,6 @@ */ package com.jeesite.common.collect; -import com.jeesite.common.lang.StringUtils; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.beanutils.PropertyUtils; - -import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -18,7 +13,7 @@ import java.util.concurrent.ConcurrentMap; * @author ThinkGem * @version 2015-01-15 */ -public class MapUtils extends org.apache.commons.collections.MapUtils { +public class MapUtils { public static HashMap newHashMap() { return new HashMap(); @@ -69,161 +64,161 @@ public class MapUtils extends org.apache.commons.collections.MapUtils { return new IdentityHashMap(); } - /** - * List转换为List - * @param clazz - * @param list - */ - public static List toObjectList(Class clazz, List> list) throws Exception { - List retList = new ArrayList(); - if (list != null && !list.isEmpty()) { - for (HashMap m : list) { - retList.add(toObject(clazz, m)); - } - } - return retList; - } - - /** - * 将Map转换为Object - * @param clazz 目标对象的类 - * @param map 待转换Map - */ - public static T toObject(Class clazz, Map map) throws Exception { - T object = clazz.getDeclaredConstructor().newInstance(); - return toObject(object, map); - } - - /** - * 将Map转换为Object - * @param clazz 目标对象的类 - * @param map 待转换Map - * @param toCamelCase 是否去掉下划线 - */ - public static T toObject(Class clazz, Map map, boolean toCamelCase) throws Exception { - T object = clazz.getDeclaredConstructor().newInstance(); - return toObject(object, map, toCamelCase); - } - - /** - * 将Map转换为Object - * @param map 待转换Map - */ - public static T toObject(T object, Map map) throws InstantiationException, IllegalAccessException, InvocationTargetException { - return toObject(object, map, false); - } - - /** - * 将Map转换为Object - * @param object 目标对象的类 - * @param map 待转换Map - * @param toCamelCase 是否采用驼峰命名法转换 - */ - public static T toObject(T object, Map map, boolean toCamelCase) throws InstantiationException, IllegalAccessException, - InvocationTargetException { - if (toCamelCase) { - map = toCamelCaseMap(map); - } - BeanUtils.populate(object, map); - return object; - } - - /** - * 对象转Map - * @param object 目标对象 - * @return 转换出来的值都是String - */ - public static Map toMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { - return BeanUtils.describe(object); - } - - /** - * 对象转Map - * @param object 目标对象 - * @return 转换出来的值类型是原类型 - */ - public static Map toNavMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { - return PropertyUtils.describe(object); - } - - /** - * 转换为Collection> - * @param collection 待转换对象集合 - * @return 转换后的Collection> - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws NoSuchMethodException - */ - public static Collection> toMapList(Collection collection) throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - List> retList = new ArrayList>(); - if (collection != null && !collection.isEmpty()) { - for (Object object : collection) { - Map map = toMap(object); - retList.add(map); - } - } - return retList; - } - - /** - * 转换为Collection,同时为字段做驼峰转换> - * @param collection 待转换对象集合 - * @return 转换后的Collection> - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws NoSuchMethodException - */ - public static Collection> toMapListForFlat(Collection collection) throws IllegalAccessException, - InvocationTargetException, NoSuchMethodException { - List> retList = new ArrayList>(); - if (collection != null && !collection.isEmpty()) { - for (Object object : collection) { - Map map = toMapForFlat(object); - retList.add(map); - } - } - return retList; - } - - /** - * 转换成Map并提供字段命名驼峰转平行 - * @param object 目标对象 - * @throws NoSuchMethodException - * @throws InvocationTargetException - * @throws IllegalAccessException - */ - public static Map toMapForFlat(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { - Map map = toMap(object); - return toUnderlineStringMap(map); - } - - /** - * 将Map的Keys去下划线
- * (例:branch_no -> branchNo )
- * @param map 待转换Map - * @return - */ - public static Map toCamelCaseMap(Map map) { - Map newMap = new HashMap(); - for (String key : map.keySet()) { - safeAddToMap(newMap, StringUtils.camelCase(key), map.get(key)); - } - return newMap; - } - - /** - * 将Map的Keys转译成下划线格式的
- * (例:branchNo -> branch_no)
- * @param map 待转换Map - * @return - */ - public static Map toUnderlineStringMap(Map map) { - Map newMap = new HashMap(); - for (String key : map.keySet()) { - newMap.put(StringUtils.uncamelCase(key), map.get(key)); - } - return newMap; - } +// /** +// * List转换为List +// * @param clazz +// * @param list +// */ +// public static List toObjectList(Class clazz, List> list) throws Exception { +// List retList = new ArrayList(); +// if (list != null && !list.isEmpty()) { +// for (HashMap m : list) { +// retList.add(toObject(clazz, m)); +// } +// } +// return retList; +// } +// +// /** +// * 将Map转换为Object +// * @param clazz 目标对象的类 +// * @param map 待转换Map +// */ +// public static T toObject(Class clazz, Map map) throws Exception { +// T object = clazz.getDeclaredConstructor().newInstance(); +// return toObject(object, map); +// } +// +// /** +// * 将Map转换为Object +// * @param clazz 目标对象的类 +// * @param map 待转换Map +// * @param toCamelCase 是否去掉下划线 +// */ +// public static T toObject(Class clazz, Map map, boolean toCamelCase) throws Exception { +// T object = clazz.getDeclaredConstructor().newInstance(); +// return toObject(object, map, toCamelCase); +// } +// +// /** +// * 将Map转换为Object +// * @param map 待转换Map +// */ +// public static T toObject(T object, Map map) throws InstantiationException, IllegalAccessException, InvocationTargetException { +// return toObject(object, map, false); +// } +// +// /** +// * 将Map转换为Object +// * @param object 目标对象的类 +// * @param map 待转换Map +// * @param toCamelCase 是否采用驼峰命名法转换 +// */ +// public static T toObject(T object, Map map, boolean toCamelCase) throws InstantiationException, IllegalAccessException, +// InvocationTargetException { +// if (toCamelCase) { +// map = toCamelCaseMap(map); +// } +// BeanUtils.populate(object, map); +// return object; +// } +// +// /** +// * 对象转Map +// * @param object 目标对象 +// * @return 转换出来的值都是String +// */ +// public static Map toMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { +// return BeanUtils.describe(object); +// } +// +// /** +// * 对象转Map +// * @param object 目标对象 +// * @return 转换出来的值类型是原类型 +// */ +// public static Map toNavMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { +// return PropertyUtils.describe(object); +// } +// +// /** +// * 转换为Collection> +// * @param collection 待转换对象集合 +// * @return 转换后的Collection> +// * @throws IllegalAccessException +// * @throws InvocationTargetException +// * @throws NoSuchMethodException +// */ +// public static Collection> toMapList(Collection collection) throws IllegalAccessException, InvocationTargetException, +// NoSuchMethodException { +// List> retList = new ArrayList>(); +// if (collection != null && !collection.isEmpty()) { +// for (Object object : collection) { +// Map map = toMap(object); +// retList.add(map); +// } +// } +// return retList; +// } +// +// /** +// * 转换为Collection,同时为字段做驼峰转换> +// * @param collection 待转换对象集合 +// * @return 转换后的Collection> +// * @throws IllegalAccessException +// * @throws InvocationTargetException +// * @throws NoSuchMethodException +// */ +// public static Collection> toMapListForFlat(Collection collection) throws IllegalAccessException, +// InvocationTargetException, NoSuchMethodException { +// List> retList = new ArrayList>(); +// if (collection != null && !collection.isEmpty()) { +// for (Object object : collection) { +// Map map = toMapForFlat(object); +// retList.add(map); +// } +// } +// return retList; +// } +// +// /** +// * 转换成Map并提供字段命名驼峰转平行 +// * @param object 目标对象 +// * @throws NoSuchMethodException +// * @throws InvocationTargetException +// * @throws IllegalAccessException +// */ +// public static Map toMapForFlat(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { +// Map map = toMap(object); +// return toUnderlineStringMap(map); +// } +// +// /** +// * 将Map的Keys去下划线
+// * (例:branch_no -> branchNo )
+// * @param map 待转换Map +// * @return +// */ +// public static Map toCamelCaseMap(Map map) { +// Map newMap = new HashMap<>(); +// map.forEach((key, value) -> { +// map.put(StringUtils.camelCase(key), value); +// }); +// return newMap; +// } +// +// /** +// * 将Map的Keys转译成下划线格式的
+// * (例:branchNo -> branch_no)
+// * @param map 待转换Map +// * @return +// */ +// public static Map toUnderlineStringMap(Map map) { +// Map newMap = new HashMap(); +// for (String key : map.keySet()) { +// newMap.put(StringUtils.uncamelCase(key), map.get(key)); +// } +// return newMap; +// } } diff --git a/common/src/main/java/com/jeesite/common/collect/SetUtils.java b/common/src/main/java/com/jeesite/common/collect/SetUtils.java index ab1284fe..2872213e 100644 --- a/common/src/main/java/com/jeesite/common/collect/SetUtils.java +++ b/common/src/main/java/com/jeesite/common/collect/SetUtils.java @@ -20,7 +20,7 @@ import java.util.concurrent.CopyOnWriteArraySet; * @author ThinkGem * @version 2015-01-15 */ -public class SetUtils extends org.apache.commons.collections.SetUtils { +public class SetUtils { public static HashSet newHashSet() { return new HashSet(); diff --git a/common/src/main/java/com/jeesite/common/io/PropertyLoader.java b/common/src/main/java/com/jeesite/common/io/PropertyLoader.java index 984d8ad3..f2e01951 100644 --- a/common/src/main/java/com/jeesite/common/io/PropertyLoader.java +++ b/common/src/main/java/com/jeesite/common/io/PropertyLoader.java @@ -4,11 +4,8 @@ */ package com.jeesite.common.io; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - +import com.alibaba.fastjson.parser.ParserConfig; +import com.jeesite.common.lang.StringUtils; import org.springframework.boot.env.OriginTrackedMapPropertySource; import org.springframework.boot.env.PropertiesPropertySourceLoader; import org.springframework.boot.env.YamlPropertySourceLoader; @@ -16,8 +13,10 @@ import org.springframework.core.Ordered; import org.springframework.core.env.PropertySource; import org.springframework.core.io.Resource; -import com.alibaba.fastjson.parser.ParserConfig; -import com.jeesite.common.lang.StringUtils; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; /** * 配置文件加载(Boot) @@ -40,7 +39,11 @@ public class PropertyLoader implements org.springframework.boot.env.PropertySour List> propertySources = new ArrayList<>(); if (!isLoadJeeSitePropertySource) { isLoadJeeSitePropertySource = true; - ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式 + try { + ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式 + } catch (Exception ignored) { + // 兼容 fastjson2 的调用,不返回异常 + } Properties properties = PropertiesUtils.getInstance().getProperties(); propertySources.add(new OriginTrackedMapPropertySource("jeesite", properties)); } else { diff --git a/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/PostListType.java b/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/PostListType.java index f627b828..a43cba73 100644 --- a/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/PostListType.java +++ b/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/PostListType.java @@ -4,15 +4,15 @@ */ package com.jeesite.common.utils.excel.fieldtype; -import java.util.ArrayList; -import java.util.List; - -import com.jeesite.common.collect.ListUtils; import com.jeesite.common.lang.StringUtils; import com.jeesite.common.utils.SpringUtils; import com.jeesite.modules.sys.entity.Post; import com.jeesite.modules.sys.service.PostService; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + /** * 字段类型转换 * @author ThinkGem @@ -21,7 +21,7 @@ import com.jeesite.modules.sys.service.PostService; */ public class PostListType implements FieldType { - private List postList; + private final List postList; public PostListType() { PostService postService = SpringUtils.getBean(PostService.class); @@ -49,10 +49,11 @@ public class PostListType implements FieldType { */ @Override public String setValue(Object val) { - if (val != null) { + if (val instanceof List) { @SuppressWarnings("unchecked") List postList = (List) val; - return ListUtils.extractToString(postList, "postName", ", "); +// return ListUtils.extractToString(postList, "postName", ", "); + return postList.stream().map(Post::getPostName).collect(Collectors.joining(", ")); } return StringUtils.EMPTY; } diff --git a/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/RoleListType.java b/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/RoleListType.java index 6285658f..9513e256 100644 --- a/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/RoleListType.java +++ b/modules/core/src/main/java/com/jeesite/common/utils/excel/fieldtype/RoleListType.java @@ -4,15 +4,15 @@ */ package com.jeesite.common.utils.excel.fieldtype; -import java.util.ArrayList; -import java.util.List; - -import com.jeesite.common.collect.ListUtils; import com.jeesite.common.lang.StringUtils; import com.jeesite.common.utils.SpringUtils; import com.jeesite.modules.sys.entity.Role; import com.jeesite.modules.sys.service.RoleService; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + /** * 字段类型转换 * @author ThinkGem @@ -21,7 +21,7 @@ import com.jeesite.modules.sys.service.RoleService; */ public class RoleListType implements FieldType { - private List roleList; + private final List roleList; public RoleListType() { RoleService roleService = SpringUtils.getBean(RoleService.class); @@ -49,10 +49,11 @@ public class RoleListType implements FieldType { */ @Override public String setValue(Object val) { - if (val != null) { + if (val instanceof List) { @SuppressWarnings("unchecked") List roleList = (List) val; - return ListUtils.extractToString(roleList, "roleName", ", "); +// return ListUtils.extractToString(roleList, "roleName", ", "); + return roleList.stream().map(Role::getRoleName).collect(Collectors.joining(", ")); } return StringUtils.EMPTY; } diff --git a/modules/core/src/main/java/com/jeesite/modules/sys/entity/Employee.java b/modules/core/src/main/java/com/jeesite/modules/sys/entity/Employee.java index 9f77f782..8ffe954f 100644 --- a/modules/core/src/main/java/com/jeesite/modules/sys/entity/Employee.java +++ b/modules/core/src/main/java/com/jeesite/modules/sys/entity/Employee.java @@ -18,6 +18,7 @@ import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; +import java.util.stream.Collectors; /** * 员工管理Entity @@ -148,8 +149,9 @@ public class Employee extends DataEntity { @ApiModelProperty("员工岗位关系") public String getEmployeePosts() { - List list = ListUtils.extractToList(employeePostList, "postCode"); - return StringUtils.join(list, ","); +// List list = ListUtils.extractToList(employeePostList, "postCode"); +// return StringUtils.join(list, ","); + return employeePostList.stream().map(EmployeePost::getPostCode).collect(Collectors.joining(",")); } public void setEmployeePosts(String employeePosts) { diff --git a/modules/core/src/main/java/com/jeesite/modules/sys/web/CompanyController.java b/modules/core/src/main/java/com/jeesite/modules/sys/web/CompanyController.java index 64a65274..5e045ff7 100644 --- a/modules/core/src/main/java/com/jeesite/modules/sys/web/CompanyController.java +++ b/modules/core/src/main/java/com/jeesite/modules/sys/web/CompanyController.java @@ -4,23 +4,6 @@ */ package com.jeesite.modules.sys.web; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import io.swagger.annotations.Api; -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - import com.jeesite.common.collect.ListUtils; import com.jeesite.common.collect.MapUtils; import com.jeesite.common.config.Global; @@ -32,6 +15,21 @@ import com.jeesite.modules.sys.entity.Office; import com.jeesite.modules.sys.service.CompanyService; import com.jeesite.modules.sys.service.OfficeService; import com.jeesite.modules.sys.utils.UserUtils; +import io.swagger.annotations.Api; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.Map; /** * 公司管理Controller @@ -113,12 +111,16 @@ public class CompanyController extends BaseController { company = createNextNode(company); // 查询公司所关联的机构信息 if (StringUtils.isNotBlank(company.getCompanyCode())){ - Office office = new Office(); - office.setCompanyCode(company.getCompanyCode()); - List officeList = officeService.findList(office); - model.addAttribute("officeList", officeList); - model.addAttribute("officeCodes", ListUtils.extractToString(officeList, "officeCode", ",")); - model.addAttribute("officeNames", ListUtils.extractToString(officeList, "officeName", ",")); + Office where = new Office(); + where.setCompanyCode(company.getCompanyCode()); + List officeCodes = ListUtils.newArrayList(); + List officeNames = ListUtils.newArrayList(); + officeService.findList(where).forEach(e -> { + officeCodes.add(e.getOfficeCode()); + officeNames.add(e.getOfficeCode()); + }); + model.addAttribute("officeCodes", StringUtils.join(officeCodes, ",")); + model.addAttribute("officeNames", StringUtils.join(officeNames, ",")); } model.addAttribute("company", company); model.addAttribute("ctrlPermi", Global.getConfig("user.adminCtrlPermi", "2"));