新增用户白名单

new
cyl 1 year ago
parent 32d52702bd
commit 11d8b5a275

@ -86,6 +86,15 @@ public class UserController {
return success(true); return success(true);
} }
@PutMapping("/update-whiteList")
@Operation(summary = "修改用户状态")
@PreAuthorize("@ss.hasPermission('system:user:updatewhiteList')")
public CommonResult<Boolean> updateUserWhiteList(@Valid @RequestBody UserUpdateWhiteListReqVo reqVO) {
userService.updateUserWhiteList(reqVO.getId(), reqVO.getWhiteList());
return success(true);
}
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "获得用户分页列表") @Operation(summary = "获得用户分页列表")
@PreAuthorize("@ss.hasPermission('system:user:list')") @PreAuthorize("@ss.hasPermission('system:user:list')")

@ -51,4 +51,7 @@ public class UserBaseVO {
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
private String avatar; private String avatar;
@Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer whiteList;
} }

@ -35,4 +35,7 @@ public class UserPageReqVO extends PageParam {
@Schema(description = "部门编号,同时筛选子部门", example = "1024") @Schema(description = "部门编号,同时筛选子部门", example = "1024")
private Long deptId; private Long deptId;
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
private Integer whiteList;
} }

@ -18,4 +18,11 @@ public class UserUpdateStatusReqVO {
// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") // @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status; private Integer status;
// @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
// @NotNull(message = "状态不能为空")
// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
// @Schema(description = "白名单")
// @NotNull(message = "状态不能为空")
// private Integer whiteList;
} }

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author: cyl
* @Description:
* @create: 2023/11/10 12:48
*/
@Schema(description = "管理后台 - 用户更新白名单状态 Request VO")
@Data
public class UserUpdateWhiteListReqVo {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "角色编号不能为空")
private Long id;
@Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer whiteList;
}

@ -93,4 +93,10 @@ public class AdminUserDO extends TenantBaseDO {
*/ */
private LocalDateTime loginDate; private LocalDateTime loginDate;
/**
*
*
*/
private Integer whiteList;
} }

@ -33,6 +33,7 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
.likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername()) .likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
.likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile()) .likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
.eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus()) .eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
.eqIfPresent(AdminUserDO::getWhiteList, reqVO.getWhiteList())
.betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())
.inIfPresent(AdminUserDO::getDeptId, deptIds) .inIfPresent(AdminUserDO::getDeptId, deptIds)
.orderByDesc(AdminUserDO::getId)); .orderByDesc(AdminUserDO::getId));

@ -20,7 +20,7 @@ public interface RedisKeyConstants {
RedisKeyDefine OAUTH2_ACCESS_TOKEN = new RedisKeyDefine("访问令牌的缓存", RedisKeyDefine OAUTH2_ACCESS_TOKEN = new RedisKeyDefine("访问令牌的缓存",
"oauth2_access_token:%s", // 参数为访问令牌 token "oauth2_access_token:%s", // 参数为访问令牌 token
STRING, OAuth2AccessTokenDO.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); STRING, OAuth2AccessTokenDO.class, RedisKeyDefine.TimeoutTypeEnum.FOREVER);
RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交登陆的 state", // 注意,它是被 JustAuth 的 justauth.type.prefix 使用到 RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交登陆的 state", // 注意,它是被 JustAuth 的 justauth.type.prefix 使用到
"social_auth_state:%s", // 参数为 state "social_auth_state:%s", // 参数为 state

@ -8,17 +8,21 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserBaseVO;
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2RefreshTokenDO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2RefreshTokenDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2AccessTokenMapper; import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2AccessTokenMapper;
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2RefreshTokenMapper; import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2RefreshTokenMapper;
import cn.iocoder.yudao.module.system.dal.redis.oauth2.OAuth2AccessTokenRedisDAO; import cn.iocoder.yudao.module.system.dal.redis.oauth2.OAuth2AccessTokenRedisDAO;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
@ -44,6 +48,9 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
@Resource @Resource
private OAuth2ClientService oauth2ClientService; private OAuth2ClientService oauth2ClientService;
@Resource
private AdminUserService adminUserService;
@Override @Override
@Transactional @Transactional
public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes) { public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes) {
@ -139,7 +146,16 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
.setClientId(clientDO.getClientId()).setScopes(refreshTokenDO.getScopes()) .setClientId(clientDO.getClientId()).setScopes(refreshTokenDO.getScopes())
.setRefreshToken(refreshTokenDO.getRefreshToken()) .setRefreshToken(refreshTokenDO.getRefreshToken())
.setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getAccessTokenValiditySeconds())); .setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getAccessTokenValiditySeconds()));
accessTokenDO.setTenantId(TenantContextHolder.getTenantId()); // 手动设置租户编号,避免缓存到 Redis 的时候,无对应的租户编号 // 手动设置租户编号,避免缓存到 Redis 的时候,无对应的租户编号
accessTokenDO.setTenantId(TenantContextHolder.getTenantId());
Long userId = accessTokenDO.getUserId();
AdminUserDO user = adminUserService.getUser(userId);
System.out.println(user);
Integer whiteList = user.getWhiteList();
if (whiteList == 0){
accessTokenDO.setExpiresTime(LocalDateTime.now().plus(1, ChronoUnit.YEARS));
}
oauth2AccessTokenMapper.insert(accessTokenDO); oauth2AccessTokenMapper.insert(accessTokenDO);
// 记录到 Redis 中 // 记录到 Redis 中
oauth2AccessTokenRedisDAO.set(accessTokenDO); oauth2AccessTokenRedisDAO.set(accessTokenDO);

@ -82,6 +82,16 @@ public interface AdminUserService {
*/ */
void updateUserStatus(Long id, Integer status); void updateUserStatus(Long id, Integer status);
/**
*
*
* @param id
* @param whiteList
*/
void updateUserWhiteList(Long id, Integer whiteList);
/** /**
* *
* *

@ -90,6 +90,7 @@ public class AdminUserServiceImpl implements AdminUserService {
// 插入用户 // 插入用户
AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); AdminUserDO user = UserConvert.INSTANCE.convert(reqVO);
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
user.setWhiteList(CommonStatusEnum.ENABLE.getStatus());// 默认开启
user.setPassword(encodePassword(reqVO.getPassword())); // 加密密码 user.setPassword(encodePassword(reqVO.getPassword())); // 加密密码
userMapper.insert(user); userMapper.insert(user);
// 插入关联岗位 // 插入关联岗位
@ -190,6 +191,18 @@ public class AdminUserServiceImpl implements AdminUserService {
userMapper.updateById(updateObj); userMapper.updateById(updateObj);
} }
@Override
public void updateUserWhiteList(Long id, Integer whiteList) {
// 校验用户存在
validateUserExists(id);
// 更新状态
AdminUserDO updateObj = new AdminUserDO();
updateObj.setId(id);
updateObj.setWhiteList(whiteList);
userMapper.updateById(updateObj);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteUser(Long id) { public void deleteUser(Long id) {

Loading…
Cancel
Save