Преглед изворни кода

代理登陆请求

tags/24080901
liuxinxin пре 1 година
родитељ
комит
559ff9c141
4 измењених фајлова са 100 додато и 13 уклоњено
  1. +8
    -4
      pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java
  2. +70
    -6
      pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java
  3. +21
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqGenerationLoginPO.java
  4. +1
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java

+ 8
- 4
pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java Прегледај датотеку

@@ -3,10 +3,7 @@ package com.ningdatech.pmapi.user.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.pmapi.user.manage.UserInfoManage;
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 io.swagger.annotations.Api;
@@ -17,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
@@ -61,4 +59,10 @@ public class UserInfoController {
return userInfoManage.currentUserInfo();
}

@ApiOperation(value = "代登陆", notes = "代登陆")
@PostMapping("/generation-login")
public void generationLogin(@Valid @RequestBody ReqGenerationLoginPO reqGenerationLoginPO, HttpServletRequest httpServletRequest) {
userInfoManage.generationLogin(reqGenerationLoginPO);
}

}

+ 70
- 6
pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java Прегледај датотеку

@@ -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);
// }
// }


}

+ 21
- 0
pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqGenerationLoginPO.java Прегледај датотеку

@@ -0,0 +1,21 @@
package com.ningdatech.pmapi.user.model.po;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
* @author liuxinxin
* @date 2023/2/21 下午3:39
*/
@Data
@ApiModel("代登陆请求PO")
public class ReqGenerationLoginPO {

@NotNull(message = "用户id 不能为空")
@ApiModelProperty("用户id")
private Long userId;

}

+ 1
- 3
pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java Прегледај датотеку

@@ -1,6 +1,5 @@
package com.ningdatech.pmapi.user.model.vo;

import com.ningdatech.pmapi.sys.model.entity.Role;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -38,7 +37,7 @@ public class ResUserInfoListVO {
private Long regionId;

@ApiModelProperty("用户角色")
private List<Role> userRoleList;
private List<UserRoleVO> userRoleList;

@ApiModelProperty("状态")
private String status;
@@ -46,5 +45,4 @@ public class ResUserInfoListVO {
@ApiModelProperty("更新时间")
private LocalDateTime updateTime;


}

Loading…
Откажи
Сачувај