feat: 修改用户信息查看用户登录日志完成
This commit is contained in:
parent
17afe7ba5e
commit
f226f4ad98
|
@ -1,5 +1,6 @@
|
|||
package cn.bunny.dao.dto.system.user;
|
||||
|
||||
import cn.bunny.dao.pojo.constant.UserConstant;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
@ -45,7 +46,7 @@ public class AdminUserAddDto {
|
|||
private Byte sex = 1;
|
||||
|
||||
@Schema(name = "summary", title = "个人描述")
|
||||
private String summary = "这个人很懒,没有介绍";
|
||||
private String summary = UserConstant.PERSON_DESCRIPTION;
|
||||
|
||||
@Schema(name = "deptId", title = "部门")
|
||||
@NotNull(message = "部门不能为空")
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package cn.bunny.dao.dto.system.user;
|
||||
|
||||
import cn.bunny.dao.pojo.constant.UserConstant;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Schema(name = "AdminUserUpdateByLocalUserDto对象", title = "更新本地用户信息", description = "更新本地用户信息")
|
||||
public class AdminUserUpdateByLocalUserDto {
|
||||
|
||||
@Schema(name = "username", title = "用户名")
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
@NotNull(message = "用户名不能为空")
|
||||
private String username;
|
||||
|
||||
@Schema(name = "nickName", title = "昵称")
|
||||
@NotBlank(message = "昵称不能为空")
|
||||
@NotNull(message = "昵称不能为空")
|
||||
private String nickName;
|
||||
|
||||
@Schema(name = "email", title = "邮箱")
|
||||
@NotBlank(message = "邮箱不能为空")
|
||||
@NotNull(message = "邮箱不能为空")
|
||||
private String email;
|
||||
|
||||
@Schema(name = "avatar", title = "头像")
|
||||
private String avatar = UserConstant.USER_AVATAR;
|
||||
|
||||
@Schema(name = "phone", title = "手机号")
|
||||
private String phone;
|
||||
|
||||
@Schema(name = "sex", title = "性别", description = "0:女 1:男")
|
||||
private Byte sex = 1;
|
||||
|
||||
@Schema(name = "summary", title = "个人描述")
|
||||
private String summary = UserConstant.PERSON_DESCRIPTION;
|
||||
|
||||
}
|
|
@ -51,3 +51,4 @@ public class AdminUserUpdateDto {
|
|||
private Boolean status;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ public class UserVo extends BaseVo {
|
|||
private Byte sex;
|
||||
|
||||
@Schema(name = "personDescription", title = "个人描述")
|
||||
private String personDescription;
|
||||
private String summary;
|
||||
|
||||
@Schema(name = "status", title = "1:禁用 0:正常")
|
||||
private Byte status;
|
||||
private Boolean status;
|
||||
|
||||
}
|
||||
|
|
|
@ -70,6 +70,13 @@ public class UserController {
|
|||
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新本地用户信息", description = "更新本地用户信息")
|
||||
@PutMapping("noManage/updateAdminUserByLocalUser")
|
||||
public Result<String> updateAdminUserByLocalUser(@Valid @RequestBody AdminUserUpdateByLocalUserDto dto) {
|
||||
userService.updateAdminUserByLocalUser(dto);
|
||||
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改用户状态", description = "管理员修改用户状态")
|
||||
@PutMapping("updateUserStatusByAdmin")
|
||||
public Result<String> updateUserStatusByAdmin(@Valid @RequestBody AdminUserUpdateUserStatusDto dto) {
|
||||
|
|
|
@ -31,6 +31,8 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Component
|
||||
@Transactional
|
||||
|
@ -139,6 +141,25 @@ public class UserFactory {
|
|||
userMapper.updateById(updateUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户头像是否合规
|
||||
*
|
||||
* @param avatar 头像字符串
|
||||
* @return 整理好的头像内容
|
||||
*/
|
||||
public String checkUserAvatar(String avatar) {
|
||||
if (!StringUtils.hasText(avatar)) return null;
|
||||
String regex = "https?://.*?/(.*)";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(avatar);
|
||||
|
||||
// 如果没有匹配
|
||||
if (!matcher.matches()) return null;
|
||||
|
||||
// 匹配后返回内容
|
||||
return "/" + matcher.group(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 设置用户登录日志内容
|
||||
*/
|
||||
|
|
|
@ -122,4 +122,11 @@ public interface UserService extends IService<AdminUser> {
|
|||
* @return 用户信息
|
||||
*/
|
||||
UserVo getUserinfo();
|
||||
|
||||
/**
|
||||
* * 更新本地用户信息
|
||||
*
|
||||
* @param dto 用户信息
|
||||
*/
|
||||
void updateAdminUserByLocalUser(AdminUserUpdateByLocalUserDto dto);
|
||||
}
|
||||
|
|
|
@ -171,13 +171,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
|||
*/
|
||||
@Override
|
||||
public UserVo getUserinfoById(Long id) {
|
||||
// 判断请求Id是否为空
|
||||
if (id == null) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
|
||||
AdminUser user = getById(id);
|
||||
|
||||
// 用户是否存在
|
||||
if (user == null) throw new BunnyException(ResultCodeEnum.DATA_NOT_EXIST);
|
||||
|
||||
// 用户头像
|
||||
String avatar = user.getAvatar();
|
||||
|
||||
UserVo userVo = new UserVo();
|
||||
BeanUtils.copyProperties(user, userVo);
|
||||
|
||||
|
@ -290,7 +292,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
|||
/**
|
||||
* * 修改用户状态
|
||||
*
|
||||
* @param dto 管理员用户修改密码
|
||||
* @param dto 管理员用户修改状态
|
||||
*/
|
||||
@Override
|
||||
public void updateUserStatusByAdmin(AdminUserUpdateUserStatusDto dto) {
|
||||
|
@ -322,6 +324,30 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
|||
return userVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 更新本地用户信息
|
||||
*
|
||||
* @param dto 用户信息
|
||||
*/
|
||||
@Override
|
||||
public void updateAdminUserByLocalUser(AdminUserUpdateByLocalUserDto dto) {
|
||||
Long userId = BaseContext.getUserId();
|
||||
|
||||
// 判断是否存在这个用户
|
||||
AdminUser adminUser = getOne(Wrappers.<AdminUser>lambdaQuery().eq(AdminUser::getId, userId));
|
||||
if (adminUser == null) throw new BunnyException(ResultCodeEnum.USER_IS_EMPTY);
|
||||
|
||||
// 检查用户头像
|
||||
dto.setAvatar(userFactory.checkUserAvatar(dto.getAvatar()));
|
||||
|
||||
// 更新用户
|
||||
adminUser = new AdminUser();
|
||||
adminUser.setId(userId);
|
||||
BeanUtils.copyProperties(dto, adminUser);
|
||||
|
||||
updateById(adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 用户信息 服务实现类
|
||||
*
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package cn.bunny.services.service.impl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class UserServiceImplTest {
|
||||
|
||||
@Test
|
||||
void updateAdminUserByLocalUser() {
|
||||
String url1 = "http://192.168.3.98:9000/auth-admin/avatar/2024/10-22/a9f1794e-610a-471d-8f4f-75c8c738ef46";
|
||||
|
||||
String regex = "https?://.*?/(.*)";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(url1);
|
||||
if (matcher.matches()) {
|
||||
System.out.println(matcher.group(1));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue