From 4de4763bafb6fad4f3e219c9b4bcb0e8ac9d1c40 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 Dec 2021 18:32:51 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E8=A7=92=E8=89=B2=E7=BB=84=E3=80=81?= =?UTF-8?q?=E5=B2=97=E4=BD=8D=E7=BB=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SysUserServiceImpl.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 7e8443c..e80e7ae 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -2,6 +2,8 @@ package com.ruoyi.system.service.impl; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +27,7 @@ import com.ruoyi.system.mapper.SysUserPostMapper; import com.ruoyi.system.mapper.SysUserRoleMapper; import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysUserService; +import org.springframework.util.CollectionUtils; /** * 用户 业务层处理 @@ -127,16 +130,11 @@ public class SysUserServiceImpl implements ISysUserService public String selectUserRoleGroup(String userName) { List list = roleMapper.selectRolesByUserName(userName); - StringBuffer idsStr = new StringBuffer(); - for (SysRole role : list) - { - idsStr.append(role.getRoleName()).append(","); - } - if (StringUtils.isNotEmpty(idsStr.toString())) + if (CollectionUtils.isEmpty(list)) { - return idsStr.substring(0, idsStr.length() - 1); + return StringUtils.EMPTY; } - return idsStr.toString(); + return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(",")); } /** @@ -149,16 +147,11 @@ public class SysUserServiceImpl implements ISysUserService public String selectUserPostGroup(String userName) { List list = postMapper.selectPostsByUserName(userName); - StringBuffer idsStr = new StringBuffer(); - for (SysPost post : list) - { - idsStr.append(post.getPostName()).append(","); - } - if (StringUtils.isNotEmpty(idsStr.toString())) + if (CollectionUtils.isEmpty(list)) { - return idsStr.substring(0, idsStr.length() - 1); + return StringUtils.EMPTY; } - return idsStr.toString(); + return list.stream().map(SysPost::getPostName).collect(Collectors.joining(",")); } /**