移除 commons-collections、commons-beanutils 依赖

This commit is contained in:
thinkgem
2023-06-09 14:38:16 +08:00
parent 361baa781b
commit 50466b2556
8 changed files with 379 additions and 376 deletions

View File

@@ -8,7 +8,6 @@ import com.jeesite.common.callback.MethodCallback;
import com.jeesite.common.lang.ObjectUtils; import com.jeesite.common.lang.ObjectUtils;
import com.jeesite.common.lang.StringUtils; import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.reflect.ReflectUtils; import com.jeesite.common.reflect.ReflectUtils;
import org.apache.commons.beanutils.PropertyUtils;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@@ -19,7 +18,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* @version 2015-1-23 * @version 2015-1-23
*/ */
@SuppressWarnings("rawtypes") @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()); 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. // * 提取集合中的对象的个属性(通过Getter函数), 组合成Map.
* @param collection 来源集合. // * @param collection 来源集合.
* @param propertyName 要提取的属性名. // * @param keyPropertyName 要提取为Map中的Key值的属性名.
*/ // * @param valuePropertyName 要提取为Map中的Value值的属性名.
@SuppressWarnings("unchecked") // */
public static <T> List<T> extractToList(final Collection collection, final String propertyName) { // @SuppressWarnings("unchecked")
if (collection == null){ // public static Map extractToMap(final Collection collection, final String keyPropertyName,
return newArrayList(); // final String valuePropertyName) {
} // Map map = new HashMap(collection.size());
List list = new ArrayList(collection.size()); // try {
try { // for (Object obj : collection) {
for (Object obj : collection) { // map.put(ReflectUtils.getFieldValue(obj, keyPropertyName),
list.add(PropertyUtils.getProperty(obj, propertyName)); // ReflectUtils.getFieldValue(obj, valuePropertyName));
} // }
} catch (Exception e) { // } catch (Exception e) {
throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); // throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
} // }
return list; // return map;
} // }
//
/** // /**
* 提取集合中的对象的一个属性(通过Getter函数), 组合成List. // * 提取集合中的对象的一个属性(通过Getter函数), 组合成List.
* @param collection 来源集合. // * @param collection 来源集合.
* @param propertyName 要提取的属性名. // * @param propertyName 要提取的属性名.
* @param prefix 符合前缀的信息(为空则忽略前缀) // */
* @param isNotBlank 仅包含不为空值(空字符串也排除) // @SuppressWarnings("unchecked")
*/ // public static <T> List<T> extractToList(final Collection collection, final String propertyName) {
public static List<String> extractToList(final Collection collection, final String propertyName, // if (collection == null){
final String prefix, final boolean isNotBlank) { // return newArrayList();
List<String> list = new ArrayList<String>(collection.size()); // }
try { // List list = new ArrayList(collection.size());
for (Object obj : collection) { // try {
String value = (String)PropertyUtils.getProperty(obj, propertyName); // for (Object obj : collection) {
if (StringUtils.isBlank(prefix) || StringUtils.startsWith(value, prefix)){ // list.add(ReflectUtils.getFieldValue(obj, propertyName));
if (isNotBlank){ // }
if (StringUtils.isNotBlank(value)){ // } catch (Exception e) {
list.add(value); // throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
} // }
}else{ // return list;
list.add(value); // }
} //
} // /**
} // * 提取集合中的对象的一个属性(通过Getter函数), 组合成List.
} catch (Exception e) { // * @param collection 来源集合.
throw ReflectUtils.convertReflectionExceptionToUnchecked("", e); // * @param propertyName 要提取的属性名.
} // * @param prefix 符合前缀的信息(为空则忽略前缀)
return list; // * @param isNotBlank 仅包含不为空值(空字符串也排除)
} // */
// public static List<String> extractToList(final Collection collection, final String propertyName,
/** // final String prefix, final boolean isNotBlank) {
* 提取集合中的对象的一个属性(通过Getter函数), 组合成由分割符分隔的字符串. // List<String> list = new ArrayList<String>(collection.size());
* // try {
* @param collection 来源集合. // for (Object obj : collection) {
* @param propertyName 要提取的属性名. // String value = ReflectUtils.getFieldValue(obj, propertyName);
* @param separator 分隔符. // if (StringUtils.isBlank(prefix) || StringUtils.startsWith(value, prefix)){
*/ // if (isNotBlank){
public static String extractToString(final Collection collection, final String propertyName, final String separator) { // if (StringUtils.isNotBlank(value)){
List list = extractToList(collection, propertyName); // list.add(value);
return StringUtils.join(list, separator); // }
} // }else{
// list.add(value);
/** // }
* 转换Collection所有元素(通过toString())为String, 中间以 separator分隔。 // }
*/ // }
public static String convertToString(final Collection collection, final String separator) { // } catch (Exception e) {
return StringUtils.join(collection, separator); // throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
} // }
// return list;
/** // }
* 转换Collection所有元素(通过toString())为String, 每个元素的前面加入prefix后面加入postfix如<div>mymessage</div>。 //
*/ // /**
public static String convertToString(final Collection collection, final String prefix, final String postfix) { // * 提取集合中的对象的一个属性(通过Getter函数), 组合成由分割符分隔的字符串.
StringBuilder builder = new StringBuilder(); // *
for (Object o : collection) { // * @param collection 来源集合.
builder.append(prefix).append(o).append(postfix); // * @param propertyName 要提取的属性名.
} // * @param separator 分隔符.
return builder.toString(); // */
} // 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如<div>mymessage</div>。
// */
// 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)); return !(isEmpty(collection));
} }
/** // /**
* 取得Collection的第一个元素如果collection为空返回null. // * 取得Collection的第一个元素如果collection为空返回null.
*/ // */
public static <T> T getFirst(Collection<T> collection) { // public static <T> T getFirst(Collection<T> collection) {
if (isEmpty(collection)) { // if (isEmpty(collection)) {
return null; // return null;
} // }
return collection.iterator().next(); // return collection.iterator().next();
} // }
//
/** // /**
* 获取Collection的最后一个元素 如果collection为空返回null. // * 获取Collection的最后一个元素 如果collection为空返回null.
*/ // */
public static <T> T getLast(Collection<T> collection) { // public static <T> T getLast(Collection<T> collection) {
if (isEmpty(collection)) { // if (isEmpty(collection)) {
return null; // return null;
} // }
//当类型为List时直接取得最后一个元素 。 // //当类型为List时直接取得最后一个元素 。
if (collection instanceof List) { // if (collection instanceof List) {
List<T> list = (List<T>) collection; // List<T> list = (List<T>) collection;
return list.get(list.size() - 1); // return list.get(list.size() - 1);
} // }
//其他类型通过iterator滚动到最后一个元素. // //其他类型通过iterator滚动到最后一个元素.
Iterator<T> iterator = collection.iterator(); // Iterator<T> iterator = collection.iterator();
while (true) { // while (true) {
T current = iterator.next(); // T current = iterator.next();
if (!iterator.hasNext()) { // if (!iterator.hasNext()) {
return current; // return current;
} // }
} // }
} // }
//
/** // /**
* 返回a+b的新List. // * 返回a+b的新List.
*/ // */
public static <T> List<T> union(final Collection<T> a, final Collection<T> b) { // public static <T> List<T> union(final Collection<T> a, final Collection<T> b) {
List<T> result = new ArrayList<T>(a); // List<T> result = new ArrayList<T>(a);
result.addAll(b); // result.addAll(b);
return result; // return result;
} // }
//
/** // /**
* 返回a-b的新List. // * 返回a-b的新List.
*/ // */
public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) { // public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) {
List<T> list = new ArrayList<T>(a); // List<T> list = new ArrayList<T>(a);
for (T element : b) { // for (T element : b) {
list.remove(element); // list.remove(element);
} // }
return list; // return list;
} // }
//
/** // /**
* 返回a与b的交集的新List. // * 返回a与b的交集的新List.
*/ // */
public static <T> List<T> intersection(Collection<T> a, Collection<T> b) { // public static <T> List<T> intersection(Collection<T> a, Collection<T> b) {
List<T> list = new ArrayList<T>(); // List<T> list = new ArrayList<T>();
for (T element : a) { // for (T element : a) {
if (b.contains(element)) { // if (b.contains(element)) {
list.add(element); // list.add(element);
} // }
} // }
return list; // return list;
} // }
// /** // /**
// * 将字符串使用“,”分隔,转换为,多对多中间表列表的转换 // * 将字符串使用“,”分隔,转换为,多对多中间表列表的转换

View File

@@ -4,11 +4,6 @@
*/ */
package com.jeesite.common.collect; 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.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@@ -18,7 +13,7 @@ import java.util.concurrent.ConcurrentMap;
* @author ThinkGem * @author ThinkGem
* @version 2015-01-15 * @version 2015-01-15
*/ */
public class MapUtils extends org.apache.commons.collections.MapUtils { public class MapUtils {
public static <K, V> HashMap<K, V> newHashMap() { public static <K, V> HashMap<K, V> newHashMap() {
return new HashMap<K, V>(); return new HashMap<K, V>();
@@ -69,161 +64,161 @@ public class MapUtils extends org.apache.commons.collections.MapUtils {
return new IdentityHashMap<K, V>(); return new IdentityHashMap<K, V>();
} }
/** // /**
* List<Map<String, V>转换为List<T> // * List<Map<String, V>转换为List<T>
* @param clazz // * @param clazz
* @param list // * @param list
*/ // */
public static <T, V> List<T> toObjectList(Class<T> clazz, List<HashMap<String, V>> list) throws Exception { // public static <T, V> List<T> toObjectList(Class<T> clazz, List<HashMap<String, V>> list) throws Exception {
List<T> retList = new ArrayList<T>(); // List<T> retList = new ArrayList<T>();
if (list != null && !list.isEmpty()) { // if (list != null && !list.isEmpty()) {
for (HashMap<String, V> m : list) { // for (HashMap<String, V> m : list) {
retList.add(toObject(clazz, m)); // retList.add(toObject(clazz, m));
} // }
} // }
return retList; // return retList;
} // }
//
/** // /**
* 将Map转换为Object // * 将Map转换为Object
* @param clazz 目标对象的类 // * @param clazz 目标对象的类
* @param map 待转换Map // * @param map 待转换Map
*/ // */
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map) throws Exception { // public static <T, V> T toObject(Class<T> clazz, Map<String, V> map) throws Exception {
T object = clazz.getDeclaredConstructor().newInstance(); // T object = clazz.getDeclaredConstructor().newInstance();
return toObject(object, map); // return toObject(object, map);
} // }
//
/** // /**
* 将Map转换为Object // * 将Map转换为Object
* @param clazz 目标对象的类 // * @param clazz 目标对象的类
* @param map 待转换Map // * @param map 待转换Map
* @param toCamelCase 是否去掉下划线 // * @param toCamelCase 是否去掉下划线
*/ // */
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map, boolean toCamelCase) throws Exception { // public static <T, V> T toObject(Class<T> clazz, Map<String, V> map, boolean toCamelCase) throws Exception {
T object = clazz.getDeclaredConstructor().newInstance(); // T object = clazz.getDeclaredConstructor().newInstance();
return toObject(object, map, toCamelCase); // return toObject(object, map, toCamelCase);
} // }
//
/** // /**
* 将Map转换为Object // * 将Map转换为Object
* @param map 待转换Map // * @param map 待转换Map
*/ // */
public static <T, V> T toObject(T object, Map<String, V> map) throws InstantiationException, IllegalAccessException, InvocationTargetException { // public static <T, V> T toObject(T object, Map<String, V> map) throws InstantiationException, IllegalAccessException, InvocationTargetException {
return toObject(object, map, false); // return toObject(object, map, false);
} // }
//
/** // /**
* 将Map转换为Object // * 将Map转换为Object
* @param object 目标对象的类 // * @param object 目标对象的类
* @param map 待转换Map // * @param map 待转换Map
* @param toCamelCase 是否采用驼峰命名法转换 // * @param toCamelCase 是否采用驼峰命名法转换
*/ // */
public static <T, V> T toObject(T object, Map<String, V> map, boolean toCamelCase) throws InstantiationException, IllegalAccessException, // public static <T, V> T toObject(T object, Map<String, V> map, boolean toCamelCase) throws InstantiationException, IllegalAccessException,
InvocationTargetException { // InvocationTargetException {
if (toCamelCase) { // if (toCamelCase) {
map = toCamelCaseMap(map); // map = toCamelCaseMap(map);
} // }
BeanUtils.populate(object, map); // BeanUtils.populate(object, map);
return object; // return object;
} // }
//
/** // /**
* 对象转Map // * 对象转Map
* @param object 目标对象 // * @param object 目标对象
* @return 转换出来的值都是String // * @return 转换出来的值都是String
*/ // */
public static Map<String, String> toMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { // public static Map<String, String> toMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
return BeanUtils.describe(object); // return BeanUtils.describe(object);
} // }
//
/** // /**
* 对象转Map // * 对象转Map
* @param object 目标对象 // * @param object 目标对象
* @return 转换出来的值类型是原类型 // * @return 转换出来的值类型是原类型
*/ // */
public static Map<String, Object> toNavMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { // public static Map<String, Object> toNavMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
return PropertyUtils.describe(object); // return PropertyUtils.describe(object);
} // }
//
/** // /**
* 转换为Collection<Map<K, V>> // * 转换为Collection<Map<K, V>>
* @param collection 待转换对象集合 // * @param collection 待转换对象集合
* @return 转换后的Collection<Map<K, V>> // * @return 转换后的Collection<Map<K, V>>
* @throws IllegalAccessException // * @throws IllegalAccessException
* @throws InvocationTargetException // * @throws InvocationTargetException
* @throws NoSuchMethodException // * @throws NoSuchMethodException
*/ // */
public static <T> Collection<Map<String, String>> toMapList(Collection<T> collection) throws IllegalAccessException, InvocationTargetException, // public static <T> Collection<Map<String, String>> toMapList(Collection<T> collection) throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException { // NoSuchMethodException {
List<Map<String, String>> retList = new ArrayList<Map<String, String>>(); // List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
if (collection != null && !collection.isEmpty()) { // if (collection != null && !collection.isEmpty()) {
for (Object object : collection) { // for (Object object : collection) {
Map<String, String> map = toMap(object); // Map<String, String> map = toMap(object);
retList.add(map); // retList.add(map);
} // }
} // }
return retList; // return retList;
} // }
//
/** // /**
* 转换为Collection,同时为字段做驼峰转换<Map<K, V>> // * 转换为Collection,同时为字段做驼峰转换<Map<K, V>>
* @param collection 待转换对象集合 // * @param collection 待转换对象集合
* @return 转换后的Collection<Map<K, V>> // * @return 转换后的Collection<Map<K, V>>
* @throws IllegalAccessException // * @throws IllegalAccessException
* @throws InvocationTargetException // * @throws InvocationTargetException
* @throws NoSuchMethodException // * @throws NoSuchMethodException
*/ // */
public static <T> Collection<Map<String, String>> toMapListForFlat(Collection<T> collection) throws IllegalAccessException, // public static <T> Collection<Map<String, String>> toMapListForFlat(Collection<T> collection) throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException { // InvocationTargetException, NoSuchMethodException {
List<Map<String, String>> retList = new ArrayList<Map<String, String>>(); // List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
if (collection != null && !collection.isEmpty()) { // if (collection != null && !collection.isEmpty()) {
for (Object object : collection) { // for (Object object : collection) {
Map<String, String> map = toMapForFlat(object); // Map<String, String> map = toMapForFlat(object);
retList.add(map); // retList.add(map);
} // }
} // }
return retList; // return retList;
} // }
//
/** // /**
* 转换成Map并提供字段命名驼峰转平行 // * 转换成Map并提供字段命名驼峰转平行
* @param object 目标对象 // * @param object 目标对象
* @throws NoSuchMethodException // * @throws NoSuchMethodException
* @throws InvocationTargetException // * @throws InvocationTargetException
* @throws IllegalAccessException // * @throws IllegalAccessException
*/ // */
public static Map<String, String> toMapForFlat(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { // public static Map<String, String> toMapForFlat(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Map<String, String> map = toMap(object); // Map<String, String> map = toMap(object);
return toUnderlineStringMap(map); // return toUnderlineStringMap(map);
} // }
//
/** // /**
* 将Map的Keys去下划线<br> // * 将Map的Keys去下划线<br>
* (例:branch_no -> branchNo )<br> // * (例:branch_no -> branchNo )<br>
* @param map 待转换Map // * @param map 待转换Map
* @return // * @return
*/ // */
public static <V> Map<String, V> toCamelCaseMap(Map<String, V> map) { // public static <V> Map<String, V> toCamelCaseMap(Map<String, V> map) {
Map<String, V> newMap = new HashMap<String, V>(); // Map<String, V> newMap = new HashMap<>();
for (String key : map.keySet()) { // map.forEach((key, value) -> {
safeAddToMap(newMap, StringUtils.camelCase(key), map.get(key)); // map.put(StringUtils.camelCase(key), value);
} // });
return newMap; // return newMap;
} // }
//
/** // /**
* 将Map的Keys转译成下划线格式的<br> // * 将Map的Keys转译成下划线格式的<br>
* (例:branchNo -> branch_no)<br> // * (例:branchNo -> branch_no)<br>
* @param map 待转换Map // * @param map 待转换Map
* @return // * @return
*/ // */
public static <V> Map<String, V> toUnderlineStringMap(Map<String, V> map) { // public static <V> Map<String, V> toUnderlineStringMap(Map<String, V> map) {
Map<String, V> newMap = new HashMap<String, V>(); // Map<String, V> newMap = new HashMap<String, V>();
for (String key : map.keySet()) { // for (String key : map.keySet()) {
newMap.put(StringUtils.uncamelCase(key), map.get(key)); // newMap.put(StringUtils.uncamelCase(key), map.get(key));
} // }
return newMap; // return newMap;
} // }
} }

View File

@@ -20,7 +20,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
* @author ThinkGem * @author ThinkGem
* @version 2015-01-15 * @version 2015-01-15
*/ */
public class SetUtils extends org.apache.commons.collections.SetUtils { public class SetUtils {
public static <E> HashSet<E> newHashSet() { public static <E> HashSet<E> newHashSet() {
return new HashSet<E>(); return new HashSet<E>();

View File

@@ -4,11 +4,8 @@
*/ */
package com.jeesite.common.io; package com.jeesite.common.io;
import java.io.IOException; import com.alibaba.fastjson.parser.ParserConfig;
import java.util.ArrayList; import com.jeesite.common.lang.StringUtils;
import java.util.List;
import java.util.Properties;
import org.springframework.boot.env.OriginTrackedMapPropertySource; import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.boot.env.PropertiesPropertySourceLoader; import org.springframework.boot.env.PropertiesPropertySourceLoader;
import org.springframework.boot.env.YamlPropertySourceLoader; 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.env.PropertySource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import com.alibaba.fastjson.parser.ParserConfig; import java.io.IOException;
import com.jeesite.common.lang.StringUtils; import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/** /**
* 配置文件加载Boot * 配置文件加载Boot
@@ -40,7 +39,11 @@ public class PropertyLoader implements org.springframework.boot.env.PropertySour
List<PropertySource<?>> propertySources = new ArrayList<>(); List<PropertySource<?>> propertySources = new ArrayList<>();
if (!isLoadJeeSitePropertySource) { if (!isLoadJeeSitePropertySource) {
isLoadJeeSitePropertySource = true; isLoadJeeSitePropertySource = true;
ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式 try {
ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式
} catch (Exception ignored) {
// 兼容 fastjson2 的调用,不返回异常
}
Properties properties = PropertiesUtils.getInstance().getProperties(); Properties properties = PropertiesUtils.getInstance().getProperties();
propertySources.add(new OriginTrackedMapPropertySource("jeesite", properties)); propertySources.add(new OriginTrackedMapPropertySource("jeesite", properties));
} else { } else {

View File

@@ -4,15 +4,15 @@
*/ */
package com.jeesite.common.utils.excel.fieldtype; 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.lang.StringUtils;
import com.jeesite.common.utils.SpringUtils; import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.sys.entity.Post; import com.jeesite.modules.sys.entity.Post;
import com.jeesite.modules.sys.service.PostService; import com.jeesite.modules.sys.service.PostService;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 字段类型转换 * 字段类型转换
* @author ThinkGem * @author ThinkGem
@@ -21,7 +21,7 @@ import com.jeesite.modules.sys.service.PostService;
*/ */
public class PostListType implements FieldType { public class PostListType implements FieldType {
private List<Post> postList; private final List<Post> postList;
public PostListType() { public PostListType() {
PostService postService = SpringUtils.getBean(PostService.class); PostService postService = SpringUtils.getBean(PostService.class);
@@ -49,10 +49,11 @@ public class PostListType implements FieldType {
*/ */
@Override @Override
public String setValue(Object val) { public String setValue(Object val) {
if (val != null) { if (val instanceof List) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Post> postList = (List<Post>) val; List<Post> postList = (List<Post>) val;
return ListUtils.extractToString(postList, "postName", ", "); // return ListUtils.extractToString(postList, "postName", ", ");
return postList.stream().map(Post::getPostName).collect(Collectors.joining(", "));
} }
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }

View File

@@ -4,15 +4,15 @@
*/ */
package com.jeesite.common.utils.excel.fieldtype; 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.lang.StringUtils;
import com.jeesite.common.utils.SpringUtils; import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.sys.entity.Role; import com.jeesite.modules.sys.entity.Role;
import com.jeesite.modules.sys.service.RoleService; import com.jeesite.modules.sys.service.RoleService;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 字段类型转换 * 字段类型转换
* @author ThinkGem * @author ThinkGem
@@ -21,7 +21,7 @@ import com.jeesite.modules.sys.service.RoleService;
*/ */
public class RoleListType implements FieldType { public class RoleListType implements FieldType {
private List<Role> roleList; private final List<Role> roleList;
public RoleListType() { public RoleListType() {
RoleService roleService = SpringUtils.getBean(RoleService.class); RoleService roleService = SpringUtils.getBean(RoleService.class);
@@ -49,10 +49,11 @@ public class RoleListType implements FieldType {
*/ */
@Override @Override
public String setValue(Object val) { public String setValue(Object val) {
if (val != null) { if (val instanceof List) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Role> roleList = (List<Role>) val; List<Role> roleList = (List<Role>) val;
return ListUtils.extractToString(roleList, "roleName", ", "); // return ListUtils.extractToString(roleList, "roleName", ", ");
return roleList.stream().map(Role::getRoleName).collect(Collectors.joining(", "));
} }
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }

View File

@@ -18,6 +18,7 @@ import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 员工管理Entity * 员工管理Entity
@@ -148,8 +149,9 @@ public class Employee extends DataEntity<Employee> {
@ApiModelProperty("员工岗位关系") @ApiModelProperty("员工岗位关系")
public String getEmployeePosts() { public String getEmployeePosts() {
List<String> list = ListUtils.extractToList(employeePostList, "postCode"); // List<String> list = ListUtils.extractToList(employeePostList, "postCode");
return StringUtils.join(list, ","); // return StringUtils.join(list, ",");
return employeePostList.stream().map(EmployeePost::getPostCode).collect(Collectors.joining(","));
} }
public void setEmployeePosts(String employeePosts) { public void setEmployeePosts(String employeePosts) {

View File

@@ -4,23 +4,6 @@
*/ */
package com.jeesite.modules.sys.web; 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.ListUtils;
import com.jeesite.common.collect.MapUtils; import com.jeesite.common.collect.MapUtils;
import com.jeesite.common.config.Global; 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.CompanyService;
import com.jeesite.modules.sys.service.OfficeService; import com.jeesite.modules.sys.service.OfficeService;
import com.jeesite.modules.sys.utils.UserUtils; 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 * 公司管理Controller
@@ -113,12 +111,16 @@ public class CompanyController extends BaseController {
company = createNextNode(company); company = createNextNode(company);
// 查询公司所关联的机构信息 // 查询公司所关联的机构信息
if (StringUtils.isNotBlank(company.getCompanyCode())){ if (StringUtils.isNotBlank(company.getCompanyCode())){
Office office = new Office(); Office where = new Office();
office.setCompanyCode(company.getCompanyCode()); where.setCompanyCode(company.getCompanyCode());
List<Office> officeList = officeService.findList(office); List<String> officeCodes = ListUtils.newArrayList();
model.addAttribute("officeList", officeList); List<String> officeNames = ListUtils.newArrayList();
model.addAttribute("officeCodes", ListUtils.extractToString(officeList, "officeCode", ",")); officeService.findList(where).forEach(e -> {
model.addAttribute("officeNames", ListUtils.extractToString(officeList, "officeName", ",")); 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("company", company);
model.addAttribute("ctrlPermi", Global.getConfig("user.adminCtrlPermi", "2")); model.addAttribute("ctrlPermi", Global.getConfig("user.adminCtrlPermi", "2"));