Compare commits

..

No commits in common. "73f8f42dd7112e6b8289505191a61b0d0c8f4da5" and "d22f2305e51fdf9d0806728ffc5f3903ae9b7306" have entirely different histories.

14 changed files with 50 additions and 214 deletions

View File

@ -2,7 +2,6 @@ package cn.bunny.dao.dto.system.user;
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;
@ -32,7 +31,7 @@ public class AdminUserAddDto {
@Schema(name = "password", title = "密码")
@NotBlank(message = "密码不能为空")
private String password = "123456";
private String password;
@Schema(name = "avatar", title = "头像")
private String avatar;
@ -41,11 +40,7 @@ public class AdminUserAddDto {
private Byte sex = 1;
@Schema(name = "summary", title = "个人描述")
private String summary = "这个人很懒,没有介绍";
@Schema(name = "deptId", title = "部门")
@NotNull(message = "部门不能为空")
private Long deptId;
private String summary;
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
private Boolean status = false;

View File

@ -6,8 +6,6 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ -36,7 +34,4 @@ public class AdminUserDto {
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
private Boolean status;
@Schema(name = "deptId", title = "部门")
private List<Long> deptIds;
}

View File

@ -40,10 +40,6 @@ public class AdminUserUpdateDto {
@Schema(name = "summary", title = "个人描述")
private String summary;
@Schema(name = "deptId", title = "部门")
@NotNull(message = "部门不能为空")
private Long deptId;
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
private Boolean status;

View File

@ -1,25 +0,0 @@
package cn.bunny.dao.dto.system.user;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "UserUpdateWithPasswordDto对象", title = "管理员用户修改密码", description = "管理员用户修改密码")
public class AdminUserUpdateUserStatusDto {
@Schema(name = "userId", title = "用户ID")
@NotNull(message = "用户ID不能为空")
private Long userId;
@Schema(name = "status", title = "用户状态")
@NotNull(message = "用户状态不能为空")
private Boolean status;
}

View File

@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Builder
@Schema(name = "UserUpdateWithPasswordDto对象", title = "管理员用户修改密码", description = "管理员用户修改密码")
public class AdminUserUpdateWithPasswordDto {
public class UserUpdateWithPasswordDto {
@Schema(name = "userId", title = "用户ID")
@NotNull(message = "用户ID不能为空")

View File

@ -1,60 +0,0 @@
package cn.bunny.dao.entity.system;
import cn.bunny.dao.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
* 管理员用户信息
* </p>
*
* @author Bunny
* @since 2024-06-26
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@TableName("sys_user")
@Schema(name = "AdminUserAndDept对象", title = "用户信息和部门Id", description = "用户信息和部门Id")
public class AdminUserAndDept extends BaseEntity {
@Schema(name = "username", title = "用户名")
private String username;
@Schema(name = "nickName", title = "昵称")
private String nickName;
@Schema(name = "email", title = "邮箱")
private String email;
@Schema(name = "phone", title = "手机号")
private String phone;
@Schema(name = "password", title = "密码")
private String password;
@Schema(name = "avatar", title = "头像")
private String avatar;
@Schema(name = "sex", title = "性别", description = "0:女 1:男")
private Byte sex;
@Schema(name = "summary", title = "个人描述")
private String summary;
@Schema(name = "lastLoginIp", title = "最后登录IP")
private String lastLoginIp;
@Schema(name = "lastLoginIpAddress", title = "最后登录ip归属地")
private String lastLoginIpAddress;
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
private Boolean status;
@Schema(name = "deptId", title = "部门")
private Long deptId;
}

View File

@ -23,9 +23,9 @@ import lombok.experimental.Accessors;
public class UserDept extends BaseEntity {
@Schema(name = "userId", title = "用户id")
private Long userId;
private String userId;
@Schema(name = "deptId", title = "部门id")
private Long deptId;
private String deptId;
}

View File

@ -1,9 +1,6 @@
package cn.bunny.dao.vo.system.user;
import cn.bunny.dao.vo.BaseVo;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@ -41,11 +38,6 @@ public class AdminUserVo extends BaseVo {
@Schema(name = "lastLoginIpAddress", title = "最后登录ip归属地")
private String lastLoginIpAddress;
@Schema(name = "deptId", title = "部门")
@JsonFormat(shape = JsonFormat.Shape.STRING)
@JSONField(serializeUsing = ToStringSerializer.class)
private Long deptId;
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
private Boolean status;
}

View File

@ -49,7 +49,7 @@ public class UserController {
return Mono.just(Result.success(vo));
}
@Operation(summary = "多条件查询用户", description = "多条件查询用户")
@Operation(summary = "查询用户", description = "查询用户")
@GetMapping("queryUser")
public Mono<Result<List<AdminUserVo>>> queryUser(String keyword) {
List<AdminUserVo> voList = userService.queryUser(keyword);
@ -58,37 +58,9 @@ public class UserController {
@Operation(summary = "更新用户信息", description = "更新用户信息")
@PutMapping("updateAdminUser")
public Result<String> updateAdminUser(@Valid @RequestBody AdminUserUpdateDto dto) {
public Mono<Result<String>> updateAdminUser(@Valid @RequestBody AdminUserUpdateDto dto) {
userService.updateAdminUser(dto);
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
}
@Operation(summary = "修改用户状态", description = "管理员修改用户状态")
@PutMapping("updateUserStatusByAdmin")
public Result<String> updateUserStatusByAdmin(@Valid @RequestBody AdminUserUpdateUserStatusDto dto) {
userService.updateUserStatusByAdmin(dto);
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
}
@Operation(summary = "修改管理员用户密码", description = "管理员修改管理员用户密码")
@PutMapping("updateUserPasswordByAdmin")
public Result<String> updateUserPasswordByAdmin(@Valid @RequestBody AdminUserUpdateWithPasswordDto dto) {
userService.updateUserPasswordByAdmin(dto);
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
}
@Operation(summary = "修改用户头像", description = "管理员修改用户头像")
@PutMapping("uploadAvatarByAdmin")
public Result<String> uploadAvatarByAdmin(@Valid UserUpdateWithAvatarDto dto) {
userService.uploadAvatarByAdmin(dto);
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
}
@Operation(summary = "强制退出", description = "强制退出")
@PutMapping("forcedOffline")
public Result<String> forcedOffline(@RequestBody Long id) {
userService.forcedOffline(id);
return Result.success();
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
}
@Operation(summary = "登录发送邮件验证码", description = "登录发送邮件验证码")
@ -107,9 +79,9 @@ public class UserController {
@Operation(summary = "添加用户信息", description = "添加用户信息")
@PostMapping("addAdminUser")
public Result<Object> addAdminUser(@Valid @RequestBody AdminUserAddDto dto) {
public Mono<Result<String>> addAdminUser(@Valid @RequestBody AdminUserAddDto dto) {
userService.addAdminUser(dto);
return Result.success(ResultCodeEnum.ADD_SUCCESS);
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
}
@Operation(summary = "退出登录", description = "退出登录")
@ -119,6 +91,28 @@ public class UserController {
return Result.success(ResultCodeEnum.LOGOUT_SUCCESS);
}
@Operation(summary = "管理员修改管理员用户密码", description = "管理员修改管理员用户密码")
@PutMapping("updateUserPasswordByAdmin")
public Result<String> updateUserPasswordByAdmin(@Valid @RequestBody UserUpdateWithPasswordDto dto) {
userService.updateUserPasswordByAdmin(dto);
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
}
@Operation(summary = "管理员上传用户头像", description = "管理员上传用户头像")
@PutMapping("uploadAvatarByAdmin")
public Result<String> uploadAvatarByAdmin(@Valid UserUpdateWithAvatarDto dto) {
userService.uploadAvatarByAdmin(dto);
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
}
@Operation(summary = "强制退出", description = "强制退出")
@PutMapping("forcedOffline")
public Result<String> forcedOffline(@RequestBody Long id) {
userService.forcedOffline(id);
return Result.success();
}
@Operation(summary = "删除用户信息", description = "删除用户信息")
@DeleteMapping("deleteAdminUser")
public Mono<Result<String>> deleteAdminUser(@RequestBody List<Long> ids) {

View File

@ -2,7 +2,6 @@ package cn.bunny.services.mapper;
import cn.bunny.dao.dto.system.user.AdminUserDto;
import cn.bunny.dao.entity.system.AdminUser;
import cn.bunny.dao.entity.system.AdminUserAndDept;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -29,7 +28,7 @@ public interface UserMapper extends BaseMapper<AdminUser> {
* @param dto 用户信息查询表单
* @return 用户信息分页结果
*/
IPage<AdminUserAndDept> selectListByPage(@Param("page") Page<AdminUser> pageParams, @Param("dto") AdminUserDto dto);
IPage<AdminUser> selectListByPage(@Param("page") Page<AdminUser> pageParams, @Param("dto") AdminUserDto dto);
/**
* 物理删除用户信息

View File

@ -85,7 +85,7 @@ public interface UserService extends IService<AdminUser> {
*
* @param dto 管理员用户修改密码
*/
void updateUserPasswordByAdmin(AdminUserUpdateWithPasswordDto dto);
void updateUserPasswordByAdmin(UserUpdateWithPasswordDto dto);
/**
* * 管理员上传用户头像
@ -108,11 +108,4 @@ public interface UserService extends IService<AdminUser> {
* @return 用户信息列表
*/
List<AdminUserVo> queryUser(String keyword);
/**
* * 修改用户状态
*
* @param dto 管理员用户修改密码
*/
void updateUserStatusByAdmin(AdminUserUpdateUserStatusDto dto);
}

View File

@ -7,9 +7,7 @@ import cn.bunny.common.service.utils.minio.MinioUtil;
import cn.bunny.dao.dto.system.files.FileUploadDto;
import cn.bunny.dao.dto.system.user.*;
import cn.bunny.dao.entity.system.AdminUser;
import cn.bunny.dao.entity.system.AdminUserAndDept;
import cn.bunny.dao.entity.system.EmailUsers;
import cn.bunny.dao.entity.system.UserDept;
import cn.bunny.dao.pojo.common.EmailSendInit;
import cn.bunny.dao.pojo.constant.MinioConstant;
import cn.bunny.dao.pojo.constant.RedisUserConstant;
@ -160,7 +158,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
* @param dto 管理员用户修改密码
*/
@Override
public void updateUserPasswordByAdmin(AdminUserUpdateWithPasswordDto dto) {
public void updateUserPasswordByAdmin(UserUpdateWithPasswordDto dto) {
Long userId = dto.getUserId();
String password = dto.getPassword();
@ -246,20 +244,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
}).toList();
}
/**
* * 修改用户状态
*
* @param dto 管理员用户修改密码
*/
@Override
public void updateUserStatusByAdmin(AdminUserUpdateUserStatusDto dto) {
AdminUser adminUser = new AdminUser();
adminUser.setId(dto.getUserId());
adminUser.setStatus(dto.getStatus());
updateById(adminUser);
}
/**
* * 用户信息 服务实现类
*
@ -270,7 +254,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
@Override
public PageResult<AdminUserVo> getAdminUserList(Page<AdminUser> pageParams, AdminUserDto dto) {
// 分页查询菜单图标
IPage<AdminUserAndDept> page = baseMapper.selectListByPage(pageParams, dto);
IPage<AdminUser> page = baseMapper.selectListByPage(pageParams, dto);
List<AdminUserVo> voList = page.getRecords().stream().map(AdminUser -> {
// 如果存在用户头像则设置用户头像
@ -301,23 +285,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
@Override
public void addAdminUser(@Valid AdminUserAddDto dto) {
// 对密码加密
String md5Password = DigestUtils.md5DigestAsHex(dto.getPassword().getBytes());
String password = dto.getPassword();
// 保存数据
AdminUser adminUser = new AdminUser();
BeanUtils.copyProperties(dto, adminUser);
adminUser.setPassword(md5Password);
save(adminUser);
// 插入用户部门关系表
Long userId = adminUser.getId();
Long deptId = dto.getDeptId();
UserDept userDept = new UserDept();
userDept.setDeptId(deptId);
userDept.setUserId(userId);
// 插入分配后的用户内容
userDeptMapper.insert(userDept);
// 对密码加密
if (StringUtils.hasText(password)) {
password = DigestUtils.md5DigestAsHex(password.getBytes());
adminUser.setPassword(password);
}
save(adminUser);
}
/**
@ -327,29 +307,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
*/
@Override
public void updateAdminUser(AdminUserUpdateDto dto) {
// 部门Id
Long deptId = dto.getDeptId();
Long userId = dto.getId();
// 判断更新内容是否存在
List<AdminUser> adminUserList = list(Wrappers.<AdminUser>lambdaQuery().eq(AdminUser::getId, userId));
List<AdminUser> adminUserList = list(Wrappers.<AdminUser>lambdaQuery().eq(AdminUser::getId, dto.getId()));
if (adminUserList.isEmpty()) throw new BunnyException(ResultCodeEnum.DATA_NOT_EXIST);
// 更新用户
AdminUser adminUser = new AdminUser();
BeanUtils.copyProperties(dto, adminUser);
updateById(adminUser);
// 更新用户部门
UserDept userDept = new UserDept();
userDept.setDeptId(deptId);
userDept.setUserId(userId);
// 删除这个用户部门关系下所有
userDeptMapper.deleteBatchIdsByUserIdWithPhysics(List.of(userId));
// 插入分配后的用户内容
userDeptMapper.insert(userDept);
}
/**

View File

@ -77,8 +77,8 @@ mybatis-plus:
global-config:
db-config:
logic-delete-field: isDelete
# configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
logging:
level:

View File

@ -29,10 +29,10 @@
</sql>
<!-- 分页查询用户信息内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.AdminUserAndDept">
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.AdminUser">
select
user.*,user_dept.dept_id
from sys_user user left join sys_user_dept user_dept on user.id = user_dept.user_id
<include refid="Base_Column_List"/>
from sys_user
<where>
<if test="dto.username != null and dto.username != ''">
username like CONCAT('%',#{dto.username},'%')
@ -55,14 +55,7 @@
<if test="dto.status != null and dto.status != ''">
status = #{dto.status}
</if>
<if test="dto.deptIds != null and dto.deptIds.size() > 0">
user_dept.dept_id in
<foreach collection="dto.deptIds" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</if>
</where>
</select>
<!-- 查询用户 -->