diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/UserInfoHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/UserInfoHelper.java index b9fc833..a7a5d31 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/UserInfoHelper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/UserInfoHelper.java @@ -1,7 +1,7 @@ package com.ningdatech.pmapi.common.helper; +import com.ningdatech.pmapi.user.entity.UserInfo; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; -import org.springframework.stereotype.Component; /** * @author liuxinxin @@ -9,7 +9,6 @@ import org.springframework.stereotype.Component; * @Description: 用户信息管理工具类 helper */ -@Component public interface UserInfoHelper { /** @@ -22,6 +21,8 @@ public interface UserInfoHelper { UserFullInfoDTO getUserFullInfo(Long userId); + UserFullInfoDTO getUserFullInfo(UserInfo userInfo); + String getUserName(Long userId); /** diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/UserInfoHelperImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/UserInfoHelperImpl.java index 21487ba..2172558 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/UserInfoHelperImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/UserInfoHelperImpl.java @@ -1,14 +1,30 @@ package com.ningdatech.pmapi.common.helper.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; +import com.ningdatech.pmapi.organization.model.entity.DingOrganization; +import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; +import com.ningdatech.pmapi.organization.service.IDingOrganizationService; +import com.ningdatech.pmapi.sys.mapper.RoleMapper; import com.ningdatech.pmapi.sys.model.entity.Role; +import com.ningdatech.pmapi.sys.model.entity.UserRole; +import com.ningdatech.pmapi.sys.service.IUserRoleService; +import com.ningdatech.pmapi.user.entity.UserInfo; import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; -import com.ningdatech.pmapi.user.manage.UserAuthLoginManage; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.service.IUserInfoService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + /** * @author liuxinxin * @date 2023/2/10 下午4:40 @@ -18,36 +34,106 @@ import org.springframework.stereotype.Component; public class UserInfoHelperImpl implements UserInfoHelper { - private final UserAuthLoginManage userAuthLoginManage; + private final IUserInfoService userInfoService; + private final IDingEmployeeInfoService iDingEmployeeInfoService; + private final IDingOrganizationService iDingOrganizationService; + private final IUserRoleService iUserRoleService; + private final RoleMapper roleMapper; @Override public String getOrganizationCode(Long userId) { - UserFullInfoDTO userFullInfo = userAuthLoginManage.getUserFullInfo(userId); - + UserFullInfoDTO userFullInfo = getUserFullInfo(userId); return userFullInfo.getOrganizationCode(); } @Override public UserFullInfoDTO getUserFullInfo(Long userId) { - UserFullInfoDTO userFullInfo = userAuthLoginManage.getUserFullInfo(userId); + UserInfo userInfo = userInfoService.getById(userId); + if (Objects.isNull(userInfo)) { + return null; + } + // 返回用户全量信息 + return getUserFullInfo(userInfo); + } + + @Override + public UserFullInfoDTO getUserFullInfo(UserInfo userInfo) { + UserFullInfoDTO userFullInfo = new UserFullInfoDTO(); + // 获取浙政钉雇员信息 组织信息 + String employeeCode = userInfo.getEmployeeCode(); + if (StringUtils.isNotBlank(employeeCode)) { + List dingEmployeeInfoList = iDingEmployeeInfoService + .list(Wrappers.lambdaQuery(DingEmployeeInfo.class) + .eq(DingEmployeeInfo::getEmployeeCode, employeeCode) + .eq(DingEmployeeInfo::getMainJob, "true")); + DingEmployeeInfo dingEmployeeInfo = dingEmployeeInfoList.get(0); + + + // 装配用户任职所在单位 + String empPosUnitCode = dingEmployeeInfo.getEmpPosUnitCode(); + if (StringUtils.isNotBlank(empPosUnitCode)) { + DingOrganization dingOrganization = iDingOrganizationService.getByOrgCode(empPosUnitCode); + if (Objects.nonNull(dingOrganization)) { + userFullInfo.setEmpPosUnitCode(empPosUnitCode); + userFullInfo.setEmpPosUnitName(dingOrganization.getOrganizationName()); + } + } + + // 装配用户所在orgCode + String organizationCode = dingEmployeeInfo.getOrganizationCode(); + List dingOrganizationList = iDingOrganizationService.list(Wrappers + .lambdaQuery(DingOrganization.class) + .eq(DingOrganization::getOrganizationCode, organizationCode)); + if (CollectionUtil.isNotEmpty(dingOrganizationList)) { + DingOrganization dingOrganization = dingOrganizationList.get(0); + userFullInfo.setOrganizationCode(dingOrganization.getOrganizationCode()); + userFullInfo.setOrganizationName(dingOrganization.getOrganizationName()); + userFullInfo.setRegionCode(dingOrganization.getDivisionCode()); + // 测试使用 + userFullInfo.setRegionLevel(3); + } + } + + List roleList = new ArrayList<>(); + // 获取用户角色列表信息 + List userRoleList = iUserRoleService + .list(Wrappers.lambdaQuery(UserRole.class) + .eq(UserRole::getUserId, userInfo.getId())); + if (CollectionUtil.isNotEmpty(userRoleList)) { + List roleIdList = userRoleList.stream() + .map(UserRole::getRoleId).distinct() + .collect(Collectors.toList()); + roleList = roleMapper.selectBatchIds(roleIdList); + } + userFullInfo.setUserRoleList(roleList); + + // 装配用户任职所在单位 + + // 装配返回 + userFullInfo.setUserId(userInfo.getId()); + userFullInfo.setIdentifier(userInfo.getRealName()); + userFullInfo.setRealName(userInfo.getRealName()); + userFullInfo.setEmployeeCode(employeeCode); + userFullInfo.setUsername(userInfo.getRealName()); + userFullInfo.setMobile(userInfo.getMobile()); + userFullInfo.setAccountId(userInfo.getAccountId()); return userFullInfo; } @Override public String getUserName(Long userId) { - UserFullInfoDTO userFullInfo = userAuthLoginManage.getUserFullInfo(userId); - String realName = userFullInfo.getRealName(); - return realName; + UserFullInfoDTO userFullInfo = getUserFullInfo(userId); + return userFullInfo.getRealName(); } @Override public boolean isSuperOrRegionAdmin(Long userId) { - UserFullInfoDTO userFullInfo = userAuthLoginManage.getUserFullInfo(userId); - if(CollUtil.isNotEmpty(userFullInfo.getUserRoleList())){ - for(Role role : userFullInfo.getUserRoleList()){ - if(RoleEnum.SUPER_ADMIN.name().equals(role.getCode()) || - RoleEnum.REGION_MANAGER.name().equals(role.getCode()) ){ + UserFullInfoDTO userFullInfo = getUserFullInfo(userId); + if (CollUtil.isNotEmpty(userFullInfo.getUserRoleList())) { + for (Role role : userFullInfo.getUserRoleList()) { + if (RoleEnum.SUPER_ADMIN.name().equals(role.getCode()) || + RoleEnum.REGION_MANAGER.name().equals(role.getCode())) { return Boolean.TRUE; } } @@ -57,13 +143,12 @@ public class UserInfoHelperImpl implements UserInfoHelper { @Override public UserFullInfoDTO getUserFullInfoByEmployeeCode(String employeeCode) { - UserFullInfoDTO userFullInfo = userAuthLoginManage.getUserFullInfoByEmployeeCode(employeeCode); - return userFullInfo; + return getUserFullInfoByEmployeeCode(employeeCode); } @Override public String getUserEmpPosUnitCode(Long userId) { - UserFullInfoDTO userFullInfo = userAuthLoginManage.getUserFullInfo(userId); + UserFullInfoDTO userFullInfo = getUserFullInfo(userId); return userFullInfo.getEmpPosUnitCode(); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java index ce7953f..56e2464 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java @@ -19,7 +19,7 @@ import com.ningdatech.pmapi.sys.model.dto.RoleUpdateDTO; import com.ningdatech.pmapi.sys.model.entity.*; import com.ningdatech.pmapi.sys.service.*; import com.ningdatech.pmapi.sys.utils.AuthCacheKeyUtils; -import com.ningdatech.pmapi.user.manage.UserAuthLoginManage; +import com.ningdatech.pmapi.user.manage.UserAuthManage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -48,7 +48,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR private final CachePlusOps cachePlusOps; private final IRoleMenuService roleMenuService; private final IMenuService menuService; - private final UserAuthLoginManage userAuthLoginManage; + private final UserAuthManage userAuthManage; /** * 删除角色时,需要级联删除跟角色相关的一切资源: @@ -161,7 +161,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR List userIdList = userRoleService.listUserIdByRoleId(role.getId()); userIdList.forEach(w -> { cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(w)); - userAuthLoginManage.refreshSession(w); + userAuthManage.refreshSession(w); }); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthLoginManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthLoginManage.java deleted file mode 100644 index bedf486..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthLoginManage.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.ningdatech.pmapi.user.manage; - -import cn.hutool.core.collection.CollectionUtil; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.ningdatech.pmapi.common.util.StrUtils; -import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; -import com.ningdatech.pmapi.organization.model.entity.DingOrganization; -import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; -import com.ningdatech.pmapi.organization.service.IDingOrganizationService; -import com.ningdatech.pmapi.sys.model.entity.Role; -import com.ningdatech.pmapi.sys.model.entity.UserRole; -import com.ningdatech.pmapi.sys.service.IRoleService; -import com.ningdatech.pmapi.sys.service.IUserRoleService; -import com.ningdatech.pmapi.user.convert.UserInfoConvertor; -import com.ningdatech.pmapi.user.entity.UserInfo; -import com.ningdatech.pmapi.user.security.auth.credential.CredentialAuthToken; -import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; -import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; -import com.ningdatech.pmapi.user.service.IUserInfoService; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.context.SecurityContextImpl; -import org.springframework.session.Session; -import org.springframework.session.SessionRepository; -import org.springframework.session.data.redis.RedisIndexedSessionRepository; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * @author liuxinxin - * @date 2023/1/3 上午10:57 - */ - -@Component -@RequiredArgsConstructor -public class UserAuthLoginManage { - - private final IUserInfoService iUserInfoService; - private final IRoleService iRoleService; - private final IDingOrganizationService iDingOrganizationService; - private final IDingEmployeeInfoService iDingEmployeeInfoService; - private final IUserRoleService iUserRoleService; - private final RedisIndexedSessionRepository redisIndexedSessionRepository; - - /** - * 根据用户id 获取用户全量信息 - * - * @param userId / - * @return / - */ - public UserFullInfoDTO getUserFullInfo(Long userId) { - UserInfo userInfo = iUserInfoService.getById(userId); - if (Objects.isNull(userInfo)) { - return null; - } - // 返回用户全量信息 - UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); - userFullInfoAssembler(userInfo, userFullInfoDTO); - return userFullInfoDTO; - } - - /** - * 根据用户名获取 - * - * @param username / - * @return / - */ - public UserFullInfoDTO queryUserInfoInPasswordAuth(String username) { - // TODO 目前账号密码登陆测试使用 强制用户登录 userId 1L - UserInfo userInfo = iUserInfoService.getById(username); - if (Objects.isNull(userInfo)) { - return null; - } - // 返回用户全量信息 - UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); - userFullInfoAssembler(userInfo, userFullInfoDTO); - return userFullInfoDTO; - } - - /** - * 根据手机号获取 - * - * @param phoneNo / - * @return / - */ - public UserFullInfoDTO queryUserInfoInPhoneNoAuth(String phoneNo) { - UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) - .eq(UserInfo::getMobile, phoneNo)); - if (Objects.isNull(userInfo)) { - return null; - } - // 返回用户全量信息 - UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); - userFullInfoAssembler(userInfo, userFullInfoDTO); - return userFullInfoDTO; - } - - /** - * 根据accountId(浙政钉扫码登陆) - * - * @param accountId / - * @return / - */ - public UserFullInfoDTO queryUserInfoInAccountIdAuth(String accountId) { - - // 获取用户信息 - UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) - .eq(UserInfo::getAccountId, accountId)); - if (Objects.isNull(userInfo)) { - return null; - } - // 返回用户全量信息 - UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); - userFullInfoAssembler(userInfo, userFullInfoDTO); - return userFullInfoDTO; - } - - - private void userFullInfoAssembler(UserInfo userInfo, UserFullInfoDTO userFullInfoDTO) { - // 获取浙政钉雇员信息 组织信息 - String employeeCode = userInfo.getEmployeeCode(); - if (StringUtils.isNotBlank(employeeCode)) { - List dingEmployeeInfoList = iDingEmployeeInfoService - .list(Wrappers.lambdaQuery(DingEmployeeInfo.class) - .eq(DingEmployeeInfo::getEmployeeCode, employeeCode) - .eq(DingEmployeeInfo::getMainJob, "true")); - DingEmployeeInfo dingEmployeeInfo = dingEmployeeInfoList.get(0); - - - // 装配用户任职所在单位 - String empPosUnitCode = dingEmployeeInfo.getEmpPosUnitCode(); - if (StringUtils.isNotBlank(empPosUnitCode)) { - DingOrganization dingOrganization = iDingOrganizationService.getByOrgCode(empPosUnitCode); - if (Objects.nonNull(dingOrganization)) { - userFullInfoDTO.setEmpPosUnitCode(empPosUnitCode); - userFullInfoDTO.setEmpPosUnitName(dingOrganization.getOrganizationName()); - } - } - - // 装配用户所在orgCode - String organizationCode = dingEmployeeInfo.getOrganizationCode(); - List dingOrganizationList = iDingOrganizationService.list(Wrappers - .lambdaQuery(DingOrganization.class) - .eq(DingOrganization::getOrganizationCode, organizationCode)); - if (CollectionUtil.isNotEmpty(dingOrganizationList)) { - DingOrganization dingOrganization = dingOrganizationList.get(0); - userFullInfoDTO.setOrganizationCode(dingOrganization.getOrganizationCode()); - userFullInfoDTO.setOrganizationName(dingOrganization.getOrganizationName()); - userFullInfoDTO.setRegionCode(dingOrganization.getDivisionCode()); - // 测试使用 - userFullInfoDTO.setRegionLevel(3); - } - } - - List roleList = new ArrayList<>(); - // 获取用户角色列表信息 - List userRoleList = iUserRoleService - .list(Wrappers.lambdaQuery(UserRole.class) - .eq(UserRole::getUserId, userInfo.getId())); - if (CollectionUtil.isNotEmpty(userRoleList)) { - List roleIdList = userRoleList.stream() - .map(UserRole::getRoleId).distinct() - .collect(Collectors.toList()); - roleList = iRoleService.list(Wrappers.lambdaQuery(Role.class).in(Role::getId, roleIdList)); - } - userFullInfoDTO.setUserRoleList(roleList); - - // 装配用户任职所在单位 - - // 装配返回 - userFullInfoDTO.setUserId(userInfo.getId()); - userFullInfoDTO.setIdentifier(userInfo.getRealName()); - userFullInfoDTO.setRealName(userInfo.getRealName()); - userFullInfoDTO.setEmployeeCode(employeeCode); - userFullInfoDTO.setUsername(userInfo.getRealName()); - userFullInfoDTO.setMobile(userInfo.getMobile()); - userFullInfoDTO.setAccountId(userInfo.getAccountId()); - } - - public UserFullInfoDTO getUserFullInfoByEmployeeCode(String employeeCode) { - UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) - .eq(UserInfo::getEmployeeCode, employeeCode).last("limit 1")); - if (Objects.isNull(userInfo)) { - return null; - } - // 返回用户全量信息 - UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); - userFullInfoAssembler(userInfo, userFullInfoDTO); - return userFullInfoDTO; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public void refreshSession(Long userId) { - UserFullInfoDTO userFullInfo = getUserFullInfo(userId); - List sessionIds = getSessionIds(userFullInfo); - if (sessionIds.isEmpty()) { - return; - } - SessionRepository redisSessionRepository = redisIndexedSessionRepository; - UserInfoDetails details = UserInfoConvertor.toUserInfoDetails(userFullInfo); - CredentialAuthToken cat = new CredentialAuthToken(details, details.getPassword(), details.getAuthorities()); - sessionIds.forEach(sessionId -> { - Session session = redisIndexedSessionRepository.findById(sessionId); - SecurityContextImpl context = session.getAttribute("SPRING_SECURITY_CONTEXT"); - context.setAuthentication(cat); - session.setAttribute("SPRING_SECURITY_CONTEXT", context); - redisSessionRepository.save(session); - }); - } - - private List getSessionIds(UserFullInfoDTO userFullInfo) { - List sessionIds = new ArrayList<>(); - String identifier = userFullInfo.getIdentifier(); - if (StrUtils.isNotBlank(identifier)) { - sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(identifier).keySet()); - } - String mobile = userFullInfo.getMobile(); - if (StrUtils.isNotBlank(mobile)) { - sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(mobile).keySet()); - } - Long accountId = userFullInfo.getAccountId(); - if (accountId != null) { - sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(accountId.toString()).keySet()); - } - return sessionIds; - } - - public void kickOff(Long userId) { - UserFullInfoDTO userFullInfo = getUserFullInfo(userId); - List sessionIds = getSessionIds(userFullInfo); - sessionIds.forEach(redisIndexedSessionRepository::deleteById); - } - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthManage.java new file mode 100644 index 0000000..0d6a3ad --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthManage.java @@ -0,0 +1,76 @@ +package com.ningdatech.pmapi.user.manage; + +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.common.util.StrUtils; +import com.ningdatech.pmapi.user.convert.UserInfoConvertor; +import com.ningdatech.pmapi.user.security.auth.credential.CredentialAuthToken; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import lombok.AllArgsConstructor; +import org.springframework.security.core.context.SecurityContextImpl; +import org.springframework.session.Session; +import org.springframework.session.SessionRepository; +import org.springframework.session.data.redis.RedisIndexedSessionRepository; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +/** + *

+ * UserAuthHelper + *

+ * + * @author WendyYang + * @since 2023/5/5 + **/ +@Component +@AllArgsConstructor +public class UserAuthManage { + + private final UserInfoHelper userInfoHelper; + private final RedisIndexedSessionRepository redisSessionRepository; + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void refreshSession(Long userId) { + UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); + List sessionIds = getSessionIds(userFullInfo); + if (sessionIds.isEmpty()) { + return; + } + SessionRepository sessionRepository = redisSessionRepository; + UserInfoDetails details = UserInfoConvertor.toUserInfoDetails(userFullInfo); + CredentialAuthToken cat = new CredentialAuthToken(details, details.getPassword(), details.getAuthorities()); + sessionIds.forEach(sessionId -> { + Session session = redisSessionRepository.findById(sessionId); + SecurityContextImpl context = session.getAttribute("SPRING_SECURITY_CONTEXT"); + context.setAuthentication(cat); + session.setAttribute("SPRING_SECURITY_CONTEXT", context); + sessionRepository.save(session); + }); + } + + private List getSessionIds(UserFullInfoDTO userFullInfo) { + List sessionIds = new ArrayList<>(); + String identifier = userFullInfo.getIdentifier(); + if (StrUtils.isNotBlank(identifier)) { + sessionIds.addAll(redisSessionRepository.findByPrincipalName(identifier).keySet()); + } + String mobile = userFullInfo.getMobile(); + if (StrUtils.isNotBlank(mobile)) { + sessionIds.addAll(redisSessionRepository.findByPrincipalName(mobile).keySet()); + } + Long accountId = userFullInfo.getAccountId(); + if (accountId != null) { + sessionIds.addAll(redisSessionRepository.findByPrincipalName(accountId.toString()).keySet()); + } + return sessionIds; + } + + public void kickOff(Long userId) { + UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); + List sessionIds = getSessionIds(userFullInfo); + sessionIds.forEach(redisSessionRepository::deleteById); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java index d974830..77d6b3d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java @@ -1,6 +1,7 @@ package com.ningdatech.pmapi.user.manage; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -48,14 +49,14 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class UserInfoManage { + private final UserAuthManage userAuthManage; + private final IUserInfoService iUserInfoService; + private final IRoleService iRoleService; private final IDingOrganizationService iDingOrganizationService; private final IDingEmployeeInfoService iDingEmployeeInfoService; - private final IUserInfoService iUserInfoService; private final IUserRoleService iUserRoleService; - private final IRoleService iRoleService; private final UserInfoHelper userInfoHelper; private final RegionCacheHelper regionCacheHelper; - private final UserAuthLoginManage userAuthLoginManage; public PageVo list(ReqUserInfoListPO req) { PageVo pageVo = new PageVo<>(); @@ -261,7 +262,7 @@ public class UserInfoManage { userInfo.setAvailable(reqUserDisableOrEnablePO.getOperation()); iUserInfoService.updateById(userInfo); if (userInfo.getAvailable().equals("DISABLE")) { - userAuthLoginManage.kickOff(userId); + userAuthManage.kickOff(userId); } } @@ -337,7 +338,7 @@ public class UserInfoManage { iUserRoleService.saveBatch(userRoleList); } // 刷新用户权限 - userAuthLoginManage.refreshSession(userId); + userAuthManage.refreshSession(userId); } /** @@ -536,4 +537,64 @@ public class UserInfoManage { return controlledRoleVOList; } + /** + * 根据用户名获取 + * + * @param username / + * @return / + */ + public UserFullInfoDTO queryUserInfoInPasswordAuth(String username) { + // TODO 目前账号密码登陆测试使用 强制用户登录 userId 1L + UserInfo userInfo = iUserInfoService.getById(username); + if (Objects.isNull(userInfo)) { + return null; + } + // 返回用户全量信息 + return userInfoHelper.getUserFullInfo(userInfo); + } + + /** + * 根据手机号获取 + * + * @param phoneNo / + * @return / + */ + public UserFullInfoDTO queryUserInfoInPhoneNoAuth(String phoneNo) { + UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) + .eq(UserInfo::getMobile, phoneNo)); + if (Objects.isNull(userInfo)) { + return null; + } + // 返回用户全量信息 + return userInfoHelper.getUserFullInfo(userInfo); + } + + /** + * 根据accountId(浙政钉扫码登陆) + * + * @param accountId / + * @return / + */ + public UserFullInfoDTO queryUserInfoInAccountIdAuth(String accountId) { + + // 获取用户信息 + UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) + .eq(UserInfo::getAccountId, accountId)); + if (Objects.isNull(userInfo)) { + return null; + } + // 返回用户全量信息 + return userInfoHelper.getUserFullInfo(userInfo); + } + + public UserFullInfoDTO getUserFullInfoByEmployeeCode(String employeeCode) { + UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) + .eq(UserInfo::getEmployeeCode, employeeCode).last("limit 1")); + if (Objects.isNull(userInfo)) { + return null; + } + // 返回用户全量信息 + return userInfoHelper.getUserFullInfo(userInfo); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentLoginUserDetailService.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentLoginUserDetailService.java index b4134ef..cce479d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentLoginUserDetailService.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentLoginUserDetailService.java @@ -1,7 +1,7 @@ package com.ningdatech.pmapi.user.security.auth.agent; -import com.ningdatech.pmapi.user.manage.UserAuthLoginManage; +import com.ningdatech.pmapi.common.helper.UserInfoHelper; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; import lombok.RequiredArgsConstructor; @@ -20,14 +20,14 @@ import java.util.Objects; @RequiredArgsConstructor public class AgentLoginUserDetailService implements UserDetailsService { - private final UserAuthLoginManage userAuthLoginManage; + private final UserInfoHelper userInfoHelper; @Override public UserInfoDetails loadUserByUsername(String username) throws UsernameNotFoundException { final Long userId = Long.parseLong(username); - UserFullInfoDTO userFullInfoDTO = userAuthLoginManage.getUserFullInfo(userId); + UserFullInfoDTO userFullInfoDTO = userInfoHelper.getUserFullInfo(userId); if (Objects.isNull(userFullInfoDTO)) { throw new UsernameNotFoundException(String.format("%s user not exist", username)); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/common/CommonLoginUserDetailService.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/common/CommonLoginUserDetailService.java index 3766f7a..9878d4a 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/common/CommonLoginUserDetailService.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/common/CommonLoginUserDetailService.java @@ -1,7 +1,7 @@ package com.ningdatech.pmapi.user.security.auth.common; -import com.ningdatech.pmapi.user.manage.UserAuthLoginManage; +import com.ningdatech.pmapi.user.manage.UserInfoManage; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; import lombok.RequiredArgsConstructor; @@ -20,12 +20,12 @@ import java.util.Objects; @RequiredArgsConstructor public class CommonLoginUserDetailService implements UserDetailsService { - private final UserAuthLoginManage userAuthLoginManage; + private final UserInfoManage userInfoManage; @Override public UserInfoDetails loadUserByUsername(String username) throws UsernameNotFoundException { final String employeeCode = username; - UserFullInfoDTO userFullInfoDTO = userAuthLoginManage.getUserFullInfoByEmployeeCode(employeeCode); + UserFullInfoDTO userFullInfoDTO = userInfoManage.getUserFullInfoByEmployeeCode(employeeCode); if (Objects.isNull(userFullInfoDTO)) { throw new UsernameNotFoundException(String.format("%s user not exist", username)); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java index 455c0b9..fd1e859 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java @@ -3,7 +3,7 @@ package com.ningdatech.pmapi.user.security.auth.credential; import com.ningdatech.pmapi.user.constant.LoginTypeEnum; import com.ningdatech.pmapi.user.convert.UserInfoConvertor; -import com.ningdatech.pmapi.user.manage.UserAuthLoginManage; +import com.ningdatech.pmapi.user.manage.UserInfoManage; import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; @@ -24,7 +24,7 @@ import java.util.Objects; @RequiredArgsConstructor public class CredentialLoginUserDetailService implements UserDetailsService { - private final UserAuthLoginManage userAuthLoginManage; + private final UserInfoManage userInfoManage; @Override public UserInfoDetails loadUserByUsername(String username) throws UsernameNotFoundException { @@ -36,21 +36,21 @@ public class CredentialLoginUserDetailService implements UserDetailsService { UserFullInfoDTO userFullInfo; switch (loginTypeEnum) { case PHONE_VERIFICATION_CODE_LOGIN: { - userFullInfo = userAuthLoginManage.queryUserInfoInPhoneNoAuth(username); + userFullInfo = userInfoManage.queryUserInfoInPhoneNoAuth(username); if (Objects.isNull(userFullInfo)) { throw new CommonLoginException("改手机号未绑定用户"); } } break; case USERNAME_PASSWORD_LOGIN: { - userFullInfo = userAuthLoginManage.queryUserInfoInPasswordAuth(username); + userFullInfo = userInfoManage.queryUserInfoInPasswordAuth(username); if (Objects.isNull(userFullInfo)) { throw new UsernameNotFoundException(String.format("%s user not exist", username)); } } break; case DING_QR_LOGIN: { - userFullInfo = userAuthLoginManage.queryUserInfoInAccountIdAuth(username); + userFullInfo = userInfoManage.queryUserInfoInAccountIdAuth(username); if (Objects.isNull(userFullInfo)) { throw new CommonLoginException("浙政钉账号无法登陆"); }