|
|
@@ -15,19 +15,24 @@ 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.constant.LoginTypeEnum; |
|
|
|
import com.ningdatech.pmapi.user.constant.UserAvailableEnum; |
|
|
|
import com.ningdatech.pmapi.user.entity.UserInfo; |
|
|
|
import com.ningdatech.pmapi.user.model.po.ReqUserDetailEditPO; |
|
|
|
import com.ningdatech.pmapi.user.model.po.ReqUserDetailPO; |
|
|
|
import com.ningdatech.pmapi.user.model.po.ReqUserDisableOrEnablePO; |
|
|
|
import com.ningdatech.pmapi.user.model.po.ReqUserInfoListPO; |
|
|
|
import com.ningdatech.pmapi.user.model.po.*; |
|
|
|
import com.ningdatech.pmapi.user.model.vo.ResUserDetailVO; |
|
|
|
import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; |
|
|
|
import com.ningdatech.pmapi.user.model.vo.UserRoleVO; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.credential.CredentialAuthToken; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; |
|
|
|
import com.ningdatech.pmapi.user.service.IUserInfoService; |
|
|
|
import com.ningdatech.pmapi.user.util.LoginUserUtil; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.security.core.AuthenticationException; |
|
|
|
import org.springframework.security.core.context.SecurityContextHolder; |
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService; |
|
|
|
import org.springframework.security.web.authentication.WebAuthenticationDetails; |
|
|
|
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
@@ -50,6 +55,7 @@ public class UserInfoManage { |
|
|
|
private final IUserRoleService iUserRoleService; |
|
|
|
private final IRoleService iRoleService; |
|
|
|
private final UserInfoHelper userInfoHelper; |
|
|
|
private final UserDetailsService userDetailsService; |
|
|
|
|
|
|
|
public PageVo<ResUserInfoListVO> list(ReqUserInfoListPO reqUserInfoListPO) { |
|
|
|
LambdaQueryWrapper<DingEmployeeInfo> wrapper = Wrappers.lambdaQuery(DingEmployeeInfo.class) |
|
|
@@ -100,7 +106,7 @@ public class UserInfoManage { |
|
|
|
resListVO.setUpdateTime(r.getUpdateOn()); |
|
|
|
// 从用户信息中获取 |
|
|
|
resListVO.setEmployeeCode(r.getEmployeeCode()); |
|
|
|
resListVO.setUserRoleList(new ArrayList<>()); |
|
|
|
resListVO.setUserRoleList(getUserRoleVOList(resListVO.getUserId())); |
|
|
|
return resListVO; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
@@ -111,6 +117,27 @@ public class UserInfoManage { |
|
|
|
return pageVo; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<UserRoleVO> getUserRoleVOList(Long userId) { |
|
|
|
List<UserRoleVO> userRoleInfoList = new ArrayList<>(); |
|
|
|
if (Objects.isNull(userId)) { |
|
|
|
return userRoleInfoList; |
|
|
|
} |
|
|
|
List<UserRole> userRoleList = iUserRoleService.list(Wrappers.lambdaQuery(UserRole.class) |
|
|
|
.eq(UserRole::getUserId, userId)); |
|
|
|
if (CollUtil.isNotEmpty(userRoleList)) { |
|
|
|
List<Long> roleIdList = userRoleList.stream().map(UserRole::getRoleId).collect(Collectors.toList()); |
|
|
|
List<Role> roleList = iRoleService.list(Wrappers.lambdaQuery(Role.class).in(Role::getId, roleIdList)); |
|
|
|
userRoleInfoList = roleList.stream().map(r -> { |
|
|
|
UserRoleVO userRoleVO = new UserRoleVO(); |
|
|
|
userRoleVO.setId(r.getId()); |
|
|
|
userRoleVO.setName(r.getName()); |
|
|
|
return userRoleVO; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
return userRoleInfoList; |
|
|
|
} |
|
|
|
|
|
|
|
public void disableOrEnable(ReqUserDisableOrEnablePO reqUserDisableOrEnablePO) { |
|
|
|
Long userId = generateUserId(reqUserDisableOrEnablePO.getEmployeeCode()); |
|
|
|
UserInfo userInfo = iUserInfoService.getById(userId); |
|
|
@@ -131,7 +158,8 @@ public class UserInfoManage { |
|
|
|
resUserDetailVO.setStatus(userInfo.getAvailable()); |
|
|
|
|
|
|
|
// 装配用户角色信息列表 |
|
|
|
List<UserRole> userRoleList = iUserRoleService.list(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getUserId, userId)); |
|
|
|
List<UserRole> userRoleList = iUserRoleService.list(Wrappers.lambdaQuery(UserRole.class) |
|
|
|
.eq(UserRole::getUserId, userId)); |
|
|
|
List<UserRoleVO> userRoleInfoList = new ArrayList<>(); |
|
|
|
if (CollUtil.isNotEmpty(userRoleList)) { |
|
|
|
List<Long> roleIdList = userRoleList.stream().map(UserRole::getRoleId).collect(Collectors.toList()); |
|
|
@@ -208,4 +236,40 @@ public class UserInfoManage { |
|
|
|
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public void generationLogin(ReqGenerationLoginPO reqGenerationLoginPO) { |
|
|
|
Long userId = reqGenerationLoginPO.getUserId(); |
|
|
|
UserInfo userInfo = iUserInfoService.getById(userId); |
|
|
|
if (Objects.isNull(userInfo)) { |
|
|
|
throw new BizException("该员工账号处于禁用状态中,无法使用"); |
|
|
|
} |
|
|
|
if (!UserAvailableEnum.ENABLE.name().equals(userInfo.getAvailable())) { |
|
|
|
throw new BizException("该员工账号处于禁用状态中,无法使用"); |
|
|
|
} |
|
|
|
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); |
|
|
|
|
|
|
|
|
|
|
|
// ReqGenerationLoginPO reqGenerationLoginPO |
|
|
|
} |
|
|
|
|
|
|
|
// public void autoLogin(Long userId){ |
|
|
|
// userDetailsService.loadUserByUsername(userId + UserDeatilsServiceConstant.USER_DETAILS_SERVICE_SEPARATOR + LoginTypeEnum.USERNAME_PASSWORD_LOGIN.name()); |
|
|
|
// |
|
|
|
// CredentialAuthToken token = new CredentialAuthToken(email, password); |
|
|
|
// try { |
|
|
|
// token.setDetails(new WebAuthenticationDetails(httpServletRequest)); |
|
|
|
// UsernamePasswordAuthToken authenticatedUser = (UsernamePasswordAuthToken)usernamePasswordAuthSecurityConfig |
|
|
|
// .getAuthenticationManager().authenticate(token); |
|
|
|
// SecurityContextHolder.getContext().setAuthentication(authenticatedUser); |
|
|
|
// httpServletRequest.getSession().setAttribute( |
|
|
|
// HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext()); |
|
|
|
// String sessionId = httpServletRequest.getSession().getId(); |
|
|
|
// putSessionIdToCache(LoginUserUtil.getUserId(), sessionId); |
|
|
|
// } catch ( |
|
|
|
// AuthenticationException e) { |
|
|
|
// throw new RuntimeException("autoLogIn Authentication failed!", e); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
} |