feat(新增): 用户分配部门,用户部门查询实体类修改
This commit is contained in:
parent
d22f2305e5
commit
4778891133
|
@ -2,6 +2,7 @@ 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;
|
||||
|
@ -29,10 +30,6 @@ public class AdminUserAddDto {
|
|||
@Schema(name = "phone", title = "手机号")
|
||||
private String phone;
|
||||
|
||||
@Schema(name = "password", title = "密码")
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
|
||||
@Schema(name = "avatar", title = "头像")
|
||||
private String avatar;
|
||||
|
||||
|
@ -42,6 +39,10 @@ public class AdminUserAddDto {
|
|||
@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 = false;
|
||||
|
||||
|
|
|
@ -40,6 +40,10 @@ 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;
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
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;
|
||||
}
|
|
@ -23,9 +23,9 @@ import lombok.experimental.Accessors;
|
|||
public class UserDept extends BaseEntity {
|
||||
|
||||
@Schema(name = "userId", title = "用户id")
|
||||
private String userId;
|
||||
private Long userId;
|
||||
|
||||
@Schema(name = "deptId", title = "部门id")
|
||||
private String deptId;
|
||||
private Long deptId;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
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.*;
|
||||
|
||||
|
@ -38,6 +41,11 @@ 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;
|
||||
}
|
|
@ -91,7 +91,6 @@ public class UserController {
|
|||
return Result.success(ResultCodeEnum.LOGOUT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "管理员修改管理员用户密码", description = "管理员修改管理员用户密码")
|
||||
@PutMapping("updateUserPasswordByAdmin")
|
||||
public Result<String> updateUserPasswordByAdmin(@Valid @RequestBody UserUpdateWithPasswordDto dto) {
|
||||
|
|
|
@ -2,6 +2,7 @@ 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;
|
||||
|
@ -28,7 +29,7 @@ public interface UserMapper extends BaseMapper<AdminUser> {
|
|||
* @param dto 用户信息查询表单
|
||||
* @return 用户信息分页结果
|
||||
*/
|
||||
IPage<AdminUser> selectListByPage(@Param("page") Page<AdminUser> pageParams, @Param("dto") AdminUserDto dto);
|
||||
IPage<AdminUserAndDept> selectListByPage(@Param("page") Page<AdminUser> pageParams, @Param("dto") AdminUserDto dto);
|
||||
|
||||
/**
|
||||
* 物理删除用户信息
|
||||
|
|
|
@ -7,7 +7,9 @@ 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;
|
||||
|
@ -254,7 +256,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
|||
@Override
|
||||
public PageResult<AdminUserVo> getAdminUserList(Page<AdminUser> pageParams, AdminUserDto dto) {
|
||||
// 分页查询菜单图标
|
||||
IPage<AdminUser> page = baseMapper.selectListByPage(pageParams, dto);
|
||||
IPage<AdminUserAndDept> page = baseMapper.selectListByPage(pageParams, dto);
|
||||
|
||||
List<AdminUserVo> voList = page.getRecords().stream().map(AdminUser -> {
|
||||
// 如果存在用户头像,则设置用户头像
|
||||
|
@ -284,20 +286,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
|||
*/
|
||||
@Override
|
||||
public void addAdminUser(@Valid AdminUserAddDto dto) {
|
||||
// 对密码加密
|
||||
String password = dto.getPassword();
|
||||
|
||||
// 保存数据
|
||||
AdminUser adminUser = new AdminUser();
|
||||
BeanUtils.copyProperties(dto, adminUser);
|
||||
|
||||
// 对密码加密
|
||||
if (StringUtils.hasText(password)) {
|
||||
password = DigestUtils.md5DigestAsHex(password.getBytes());
|
||||
adminUser.setPassword(password);
|
||||
}
|
||||
|
||||
save(adminUser);
|
||||
|
||||
// 插入用户部门关系表
|
||||
Long userId = adminUser.getId();
|
||||
Long deptId = dto.getDeptId();
|
||||
UserDept userDept = new UserDept();
|
||||
userDept.setDeptId(deptId);
|
||||
userDept.setUserId(userId);
|
||||
|
||||
// 插入分配后的用户内容
|
||||
userDeptMapper.insert(userDept);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -307,13 +309,29 @@ 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, dto.getId()));
|
||||
List<AdminUser> adminUserList = list(Wrappers.<AdminUser>lambdaQuery().eq(AdminUser::getId, userId));
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<result column="last_login_ip" property="lastLoginIp"/>
|
||||
<result column="last_login_ip_address" property="lastLoginIpAddress"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="dept_Id" property="deptId"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
|
@ -25,14 +26,14 @@
|
|||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, username, nick_name, email, phone, password, avatar, sex, summary, last_login_ip, last_login_ip_address, status, create_user, create_time, update_time, update_user, is_deleted
|
||||
id, username, nick_name, email, phone, password, avatar, sex, summary, last_login_ip, last_login_ip_address, status, dept_Id, create_user, create_time, update_time, update_user, is_deleted
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询用户信息内容 -->
|
||||
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.AdminUser">
|
||||
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.AdminUserAndDept">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from sys_user
|
||||
user.*,user_dept.dept_id
|
||||
from sys_user user left join sys_user_dept user_dept on user.id = user_dept.user_id
|
||||
<where>
|
||||
<if test="dto.username != null and dto.username != ''">
|
||||
username like CONCAT('%',#{dto.username},'%')
|
||||
|
@ -56,6 +57,7 @@
|
|||
status = #{dto.status}
|
||||
</if>
|
||||
</where>
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 查询用户 -->
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package cn.bunny.service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
class Solution {
|
||||
public List<List<String>> groupAnagrams(String[] strs) {
|
||||
HashMap<String, List<String>> hashMap = new HashMap<>();
|
||||
|
||||
for (String str : strs) {
|
||||
char[] charArray = str.toCharArray();
|
||||
Arrays.sort(charArray);
|
||||
|
||||
String value = String.valueOf(charArray);
|
||||
if (hashMap.containsKey(value)) {
|
||||
hashMap.get(value).add(str);
|
||||
} else {
|
||||
hashMap.put(value, List.of(str));
|
||||
}
|
||||
}
|
||||
|
||||
return hashMap.values().stream().toList();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue