diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java index caf1fb217..762649d9d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java @@ -1,21 +1,17 @@ package cn.iocoder.yudao.adminserver.modules.system.service.auth.impl; -import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; -import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; -import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialBindReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; +import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; @@ -45,16 +41,14 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; import javax.annotation.Resource; +import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; -import static java.util.Collections.EMPTY_LIST; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static java.util.Collections.singleton; /** @@ -83,7 +77,8 @@ public class SysAuthServiceImpl implements SysAuthService { @Resource private SysUserSessionCoreService userSessionCoreService; @Resource - private SysPostService sysPostService; + private SysPostService postService; + @Resource private SysSocialService socialService; // TODO @timfruit:静态枚举类,需要都大写,例如说 USER_TYPE_ENUM;静态变量,放在普通变量前面;这个实践不错哈。 @@ -130,11 +125,11 @@ public class SysAuthServiceImpl implements SysAuthService { return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); } - private List getUserPosts(Set postIds) { - return Optional.ofNullable(postIds).map(ids-> - sysPostService.getPosts(ids).stream().map(post -> post.getCode()).collect(Collectors.toList()) - ).orElse(EMPTY_LIST); + if (CollUtil.isEmpty(postIds)) { + return Collections.emptyList(); + } + return convertList(postService.getPosts(postIds), SysPostDO::getCode); } private void verifyCaptcha(String username, String captchaUUID, String captchaCode) { diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java index 6a41c9420..98ec86c81 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java @@ -2,10 +2,10 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; +import cn.iocoder.yudao.adminserver.modules.infra.service.file.impl.InfFileServiceImpl; import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper; import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; -import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import org.junit.jupiter.api.Test; @@ -19,7 +19,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static org.junit.jupiter.api.Assertions.assertEquals; -@Import({InfFileCoreServiceImpl.class, FileProperties.class}) +@Import({InfFileServiceImpl.class, FileProperties.class}) public class InfFileServiceTest extends BaseDbUnitTest { @Resource diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java index c09a194aa..59be97809 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeE import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysAuthServiceImpl; import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; +import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; @@ -67,6 +68,8 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { private SysUserSessionCoreService userSessionCoreService; @MockBean private SysSocialService socialService; + @MockBean + private SysPostService postService; @Test public void testLoadUserByUsername_success() { diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java index e8d601254..0090e6633 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java @@ -63,6 +63,7 @@ public class LoginUser implements UserDetails { /** * group 目前指岗位代替 */ + // TODO jason:这个字段,改成 postCodes 明确更好哈 private List groups; @@ -89,6 +90,7 @@ public class LoginUser implements UserDetails { @JsonIgnore// 避免序列化 public Collection getAuthorities() { List list = new ArrayList<>(1); + // TODO @芋艿:看看有没更优化的方案 list.add(new SimpleGrantedAuthority("ROLE_ACTIVITI_USER")); return list; }