This commit is contained in:
cuijiawang
2025-09-24 11:51:27 +08:00
parent c54a0db6ab
commit ea37855991
16 changed files with 119 additions and 36 deletions

View File

@@ -139,7 +139,8 @@ public class LoginUser implements Serializable {
* 是否是超级管理员
*/
private Integer isAdmin;
private String clientId;
private Long clientId;
private Integer status;
/**
* 获取登录id

View File

@@ -1,7 +1,13 @@
package com.agileboot.system.client.service;
import com.agileboot.system.client.entity.SysClient;
import com.agileboot.system.client.vo.SysClientVO;
import java.util.List;
public interface ISysClientService {
SysClientVO queryByClientId(String clientId);
SysClientVO queryByClientId(Long clientId);
List<SysClient> list();
}

View File

@@ -9,11 +9,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysClientServiceImpl extends ServiceImpl<SysClientMapper, SysClient> implements ISysClientService {
@Override
public SysClientVO queryByClientId(String clientId) {
SysClient client = super.baseMapper.selectOne(new LambdaQueryWrapper<SysClient>().eq(SysClient::getClientId, clientId));
public SysClientVO queryByClientId(Long clientId) {
SysClient client = super.baseMapper.selectOne(new LambdaQueryWrapper<SysClient>().eq(SysClient::getId, clientId));
return BeanUtil.copyProperties(client, SysClientVO.class);
}
@Override
public List<SysClient> list() {
return super.list();
}
}

View File

@@ -4,6 +4,9 @@ import cn.hutool.core.collection.ListUtil;
import com.agileboot.common.core.core.R;
import com.agileboot.common.core.utils.poi.CustomExcelUtil;
import com.agileboot.common.mybatis.core.page.PageR;
import com.agileboot.system.client.entity.SysClient;
import com.agileboot.system.client.service.ISysClientService;
import com.agileboot.system.client.vo.SysClientVO;
import com.agileboot.system.user.dto.*;
import com.agileboot.system.user.service.ISysUserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -13,8 +16,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 用户信息
@@ -25,11 +28,12 @@ import java.util.List;
public class SysUserController {
private final ISysUserService sysUserService;
private final ISysClientService sysClientService;
/**
* 获取用户列表
*/
@GetMapping
@GetMapping("list")
public PageR<UserInfo> userList(SearchUserQuery dto) {
IPage<UserInfo> page = sysUserService.getUserList(dto);
return new PageR<>(page);
@@ -74,10 +78,20 @@ public class SysUserController {
return R.ok(userDetailInfo);
}
/**
* 获取所有客户端
*/
@GetMapping("/client")
public R<List<SysClientVO>> getClient() {
List<SysClient> list = sysClientService.list();
List<SysClientVO> clientVOS = list.stream().map(SysClientVO::new).toList();
return R.ok(clientVOS);
}
/**
* 新增用户
*/
@PostMapping
@PostMapping("/create")
public R<Void> add(@Validated @RequestBody AddUserCommand command) {
sysUserService.addUser(command);
return R.ok();
@@ -86,8 +100,9 @@ public class SysUserController {
/**
* 修改用户
*/
@PostMapping("/{userId}")
public R<Void> edit(@Validated @RequestBody UpdateUserCommand command) {
@PostMapping("/update/{userId}")
public R<Void> edit(@PathVariable(value = "userId") Long userId, @Validated @RequestBody UpdateUserCommand command) {
command.setUserId(userId);
sysUserService.updateUser(command);
return R.ok();
}
@@ -95,27 +110,36 @@ public class SysUserController {
/**
* 删除用户
*/
@PostMapping("/{userIds}")
public R<Void> remove(@PathVariable List<Long> userIds) {
sysUserService.deleteUsers(new HashSet<>(userIds));
@PostMapping("/del/{userId}")
public R<Void> remove(@PathVariable(value = "userId") Long userId) {
sysUserService.deleteUsers(Set.of(userId));
return R.ok();
}
/**
* 重置密码
* 管理员重置用户密码
*/
@PostMapping("/{userId}/password")
public R<Void> resetPassword(@PathVariable Long userId, @RequestBody ResetPasswordCommand command) {
@PostMapping("/re_pwd_ad/{userId}")
public R<Void> resetPasswordByAdmin(@PathVariable(value = "userId") Long userId, @RequestBody ResetPasswordCommand command) {
command.setUserId(userId);
sysUserService.resetUserPassword(command);
return R.ok();
}
/**
* 重置密码
*/
@PostMapping("/re_pwd")
public R<Void> resetPassword(@RequestBody ResetPasswordCommand command) {
sysUserService.resetUserPasswordByAdmin(command);
return R.ok();
}
/**
* 修改用户状态
*/
@PostMapping("/{userId}/status")
public R<Void> changeStatus(@PathVariable Long userId, @RequestBody ChangeStatusCommand command) {
@PostMapping("/status/{userId}")
public R<Void> changeStatus(@PathVariable(value = "userId") Long userId, @RequestBody ChangeStatusCommand command) {
command.setUserId(userId);
sysUserService.changeUserStatus(command);
return R.ok();

View File

@@ -45,4 +45,6 @@ public interface ISysUserService {
void checkAnyPostIsAssignedToUser(List<Long> ids);
Map<Long, String> geIdNameByIds(Set<Long> userIds);
void resetUserPasswordByAdmin(ResetPasswordCommand command);
}

View File

@@ -2,7 +2,8 @@ package com.agileboot.system.user.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.agileboot.common.core.constant.Constants;
import cn.hutool.crypto.digest.BCrypt;
import com.agileboot.common.core.enums.common.UserStatusEnum;
import com.agileboot.common.core.exception.BizException;
import com.agileboot.common.core.exception.error.ErrorCode;
import com.agileboot.common.mybatis.core.page.PageQuery;
@@ -37,8 +38,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
if (ObjectUtil.isNull(sysUser)) {
throw new BizException("user.not.exists", username);
}
if (Constants.DISABLE.equals(sysUser.getStatus())) {
if (UserStatusEnum.DISABLED.getValue().equals(sysUser.getStatus())) {
throw new BizException("user.blocked", username);
} else if (UserStatusEnum.FROZEN.getValue().equals(sysUser.getStatus())) {
throw new BizException("user.freeze", username);
} else if (!UserStatusEnum.NORMAL.getValue().equals(sysUser.getStatus())) {
throw new BizException("user.status.error", username);
}
LoginUser loginUser = new LoginUser();
loginUser.setUserId(sysUser.getUserId());
@@ -51,6 +56,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
loginUser.setIsAdmin(sysUser.getIsAdmin());
loginUser.setRoleId(sysUser.getRoleId());
loginUser.setClientId(sysUser.getClientId());
loginUser.setStatus(sysUser.getStatus());
return loginUser;
}
@@ -125,6 +131,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
// password encrypt
entity.setPassword(command.getPassword());
entity.setClientId(command.getClientId());
super.baseMapper.insert(entity);
}
@@ -140,17 +147,39 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
public void resetUserPassword(ResetPasswordCommand command) {
// if (!LoginHelper.isSuperAdmin() || !LoginHelper.isTenantAdmin()) {
// throw new BizException("permission.denied");
// }
SysUser sysUser = new SysUser();
String hashpw = BCrypt.hashpw(command.getPassword());
sysUser.setPassword(command.getPassword());
sysUser.setUserId(command.getUserId());
super.updateById(sysUser);
}
@Override
public void resetUserPasswordByAdmin(ResetPasswordCommand command) {
SysUser sysUser = new SysUser();
String hashpw = BCrypt.hashpw(command.getPassword());
sysUser.setPassword(command.getPassword());
sysUser.setUserId(LoginHelper.getUserId());
super.updateById(sysUser);
}
@Override
public void changeUserStatus(ChangeStatusCommand command) {
SysUser sysUser = new SysUser();
sysUser.setStatus(command.getStatus());
sysUser.setUserId(command.getUserId());
super.updateById(sysUser);
}
@Override
public void deleteUsers(Set<Long> longs) {
// if (!LoginHelper.isSuperAdmin() || !LoginHelper.isTenantAdmin()) {
// throw new BizException("permission.denied");
// }
super.removeByIds(longs);
}
@Override

View File

@@ -54,7 +54,7 @@ public class AuthController {
public R<?> login(@RequestBody String body) {
LoginBody loginBody = JSONObject.parseObject(body, LoginBody.class);
ValidatorUtils.validate(loginBody);
String clientId = loginBody.getClientId();
Long clientId = loginBody.getClientId();
String grantType = loginBody.getGrantType();
SysClientVO clientVo = sysClientService.queryByClientId(clientId);

View File

@@ -1,6 +1,7 @@
package com.agileboot.auth.pojo.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.io.Serial;
@@ -21,8 +22,8 @@ public class LoginBody implements Serializable {
/**
* 客户端id
*/
@NotBlank(message = "Auth clientid cannot be blank")
private String clientId;
@NotNull(message = "Auth clientid cannot be blank")
private Long clientId;
/**
* 授权类型

View File

@@ -39,7 +39,7 @@ public class LoginVO {
* 应用id
*/
// @JsonProperty("client_id")
private String clientId;
private Long clientId;
/**
* 令牌权限

View File

@@ -116,6 +116,7 @@ public class SysLoginService {
sysUser.setNickname(username);
sysUser.setPassword(BCrypt.hashpw(password));
sysUser.setUserType(userType);
sysUser.setClientId(registerBody.getClientId());
boolean regFlag = sysUserService.registerUserInfo(sysUser);
if (!regFlag) {

View File

@@ -56,8 +56,9 @@ public class PasswordAuthStrategy implements IAuthStrategy {
}
Long clientId = client.getId();
LoginUser loginUser = userService.getUserInfo(username);
if (!Objects.equals(loginUser.getClientId(), client.getClientId())) {
if (!Objects.equals(loginUser.getClientId(), clientId)) {
throw new BizException("client.not.match");
}
loginService.checkLogin(LoginType.PASSWORD, null, loginUser.getUsername(), () -> false);
@@ -70,14 +71,14 @@ public class PasswordAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
// 生成token
LoginHelper.login(loginUser, model);
LoginVO loginVo = new LoginVO();
loginVo.setAccessToken(StpUtil.getTokenValue());
loginVo.setExpireIn(StpUtil.getTokenTimeout());
loginVo.setClientId(client.getClientId());
loginVo.setClientId(clientId);
RoleVO roleInfo = roleService.getRoleInfo(loginUser.getRoleId());
CurrentLoginUserVO vo = new CurrentLoginUserVO();

View File

@@ -27,9 +27,9 @@ public class SysClient extends BaseEntity {
private Long id;
/**
* 客户端id
* 客户端name
*/
private String clientId;
private String clientName;
/**
* 客户端key

View File

@@ -1,5 +1,6 @@
package com.agileboot.system.client.vo;
import com.agileboot.system.client.entity.SysClient;
import lombok.Data;
import java.io.Serial;
@@ -12,15 +13,23 @@ public class SysClientVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
public SysClientVO() {
}
public SysClientVO(SysClient entity) {
this.setId(entity.getId());
this.setClientName(entity.getClientName());
}
/**
* id
*/
private Long id;
/**
* 客户端id
* clientName
*/
private String clientId;
private String clientName;
/**
* 客户端key

View File

@@ -45,5 +45,7 @@ public class AddUserCommand {
@ExcelColumn(name = "备注")
private String remark;
@ExcelColumn(name = "clientId")
private Long clientId;
}

View File

@@ -9,6 +9,6 @@ import lombok.Data;
public class ChangeStatusCommand {
private Long userId;
private String status;
private Integer status;
}

View File

@@ -79,9 +79,9 @@ public class SysUser extends BaseEntity {
private String password;
/**
* 帐号状态(0正常 1停用)
* 帐号状态(1正常 2停用 3冻结
*/
private String status;
private Integer status;
/**
* 最后登录IP
@@ -112,5 +112,5 @@ public class SysUser extends BaseEntity {
* 超级管理员标志1是0否
*/
private Integer isAdmin;
private String clientId;
private Long clientId;
}