Commit 2b3d5c13 by levphon

代码优化

1 parent 7cb0d3d5
......@@ -11,7 +11,6 @@ import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -189,14 +188,13 @@ public class UserApiService {
* @return
*/
public Map<String, User> findUserMapByAccount() {
Map<String, User> userMap = new HashedMap();
Map<String, User> userMap = Maps.newHashMap();
List<User> userList = this.findAllUser();
if (userList == null) {
return userMap;
}
for (User user : userList) {
userMap.put(user.getAccount(), user);
}
//要去重,避免以后出现不同租户下允许相同账号名的需求
userMap = userList.stream().collect(Collectors.toMap(User::getAccount, Function.identity(), (o, n) -> n));
return userMap;
}
......@@ -206,14 +204,12 @@ public class UserApiService {
* @return
*/
public Map<Long, User> findUserMapByUserId() {
Map<Long, User> userMap = new HashedMap();
Map<Long, User> userMap = Maps.newHashMap();
List<User> userList = this.findAllUser();
if (userList == null) {
return userMap;
}
for (User user : userList) {
userMap.put(user.getId(), user);
}
userMap = userList.stream().collect(Collectors.toMap(User::getId, Function.identity()));
return userMap;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!