user part
This commit is contained in:
parent
fb81670776
commit
d7b36d9f59
@ -1,8 +1,20 @@
|
||||
package com.agileboot.system.user.controller;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.agileboot.common.core.core.R;
|
||||
import com.agileboot.common.core.utils.poi.CustomExcelUtil;
|
||||
import com.agileboot.system.user.pojo.dto.*;
|
||||
import com.agileboot.system.user.pojo.entity.SearchUserDO;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
@ -12,4 +24,101 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequiredArgsConstructor
|
||||
public class SysUserController {
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*/
|
||||
@GetMapping
|
||||
public R<IPage<UserDTO>> userList(SearchUserDO query) {
|
||||
IPage<UserDTO> page = sysUserService.getUserList(query);
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户列表导出
|
||||
*/
|
||||
@GetMapping("/excel")
|
||||
public void exportUserByExcel(HttpServletResponse response, SearchUserDO query) {
|
||||
IPage<UserDTO> page = sysUserService.getUserList(query);
|
||||
CustomExcelUtil.writeToResponse(page.getRecords(), UserDTO.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户列表导入
|
||||
*/
|
||||
@PostMapping("/excel")
|
||||
public R<Void> importUserByExcel(MultipartFile file) {
|
||||
List<AddUserCommand> commands = CustomExcelUtil.readFromRequest(AddUserCommand.class, file);
|
||||
|
||||
for (AddUserCommand command : commands) {
|
||||
sysUserService.addUser(command);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载批量导入模板
|
||||
*/
|
||||
@GetMapping("/excelTemplate")
|
||||
public void downloadExcelTemplate(HttpServletResponse response) {
|
||||
CustomExcelUtil.writeToResponse(ListUtil.toList(new AddUserCommand()), AddUserCommand.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户编号获取详细信息
|
||||
*/
|
||||
@GetMapping("/{userId}")
|
||||
public R<UserDetailDTO> getUserDetailInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||
UserDetailDTO userDetailInfo = sysUserService.getUserDetailInfo(userId);
|
||||
return R.ok(userDetailInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
*/
|
||||
@PostMapping
|
||||
public R<Void> add(@Validated @RequestBody AddUserCommand command) {
|
||||
sysUserService.addUser(command);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@PostMapping("/{userId}")
|
||||
public R<Void> edit(@Validated @RequestBody UpdateUserCommand command) {
|
||||
sysUserService.updateUser(command);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@PostMapping("/{userIds}")
|
||||
public R<Void> remove(@PathVariable List<Long> userIds) {
|
||||
sysUserService.deleteUsers(new HashSet<>(userIds));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
@PostMapping("/{userId}/password")
|
||||
public R<Void> resetPassword(@PathVariable Long userId, @RequestBody ResetPasswordCommand command) {
|
||||
command.setUserId(userId);
|
||||
sysUserService.resetUserPassword(command);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*/
|
||||
@PostMapping("/{userId}/status")
|
||||
public R<Void> changeStatus(@PathVariable Long userId, @RequestBody ChangeStatusCommand command) {
|
||||
command.setUserId(userId);
|
||||
sysUserService.changeUserStatus(command);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package com.agileboot.system.user.pojo.dto;
|
||||
|
||||
import com.agileboot.common.core.annotation.ExcelColumn;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class AddUserCommand {
|
||||
|
||||
@ExcelColumn(name = "部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@ExcelColumn(name = "用户名")
|
||||
private String username;
|
||||
|
||||
@ExcelColumn(name = "昵称")
|
||||
private String nickname;
|
||||
|
||||
@ExcelColumn(name = "邮件")
|
||||
private String email;
|
||||
|
||||
@ExcelColumn(name = "电话号码")
|
||||
private String phoneNumber;
|
||||
|
||||
@ExcelColumn(name = "性别")
|
||||
private Integer sex;
|
||||
|
||||
@ExcelColumn(name = "头像")
|
||||
private String avatar;
|
||||
|
||||
@ExcelColumn(name = "密码")
|
||||
private String password;
|
||||
|
||||
@ExcelColumn(name = "状态")
|
||||
private Integer status;
|
||||
|
||||
@ExcelColumn(name = "角色ID")
|
||||
private Long roleId;
|
||||
|
||||
@ExcelColumn(name = "职位ID")
|
||||
private Long postId;
|
||||
|
||||
@ExcelColumn(name = "备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.agileboot.system.user.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class ChangeStatusCommand {
|
||||
|
||||
private Long userId;
|
||||
private String status;
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.agileboot.system.user.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class ResetPasswordCommand {
|
||||
|
||||
private Long userId;
|
||||
private String password;
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.agileboot.system.user.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdateUserCommand extends AddUserCommand {
|
||||
|
||||
private Long userId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.agileboot.system.user.pojo.dto;
|
||||
|
||||
import com.agileboot.common.core.annotation.ExcelColumn;
|
||||
import com.agileboot.common.core.annotation.ExcelSheet;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@ExcelSheet(name = "用户列表")
|
||||
@Data
|
||||
public class UserDTO {
|
||||
|
||||
|
||||
@ExcelColumn(name = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ExcelColumn(name = "职位ID")
|
||||
private Long postId;
|
||||
|
||||
@ExcelColumn(name = "职位名称")
|
||||
private String postName;
|
||||
|
||||
@ExcelColumn(name = "角色ID")
|
||||
private Long roleId;
|
||||
|
||||
@ExcelColumn(name = "角色名称")
|
||||
private String roleName;
|
||||
|
||||
@ExcelColumn(name = "部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@ExcelColumn(name = "部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ExcelColumn(name = "用户名")
|
||||
private String username;
|
||||
|
||||
@ExcelColumn(name = "用户昵称")
|
||||
private String nickname;
|
||||
|
||||
@ExcelColumn(name = "用户类型")
|
||||
private Integer userType;
|
||||
|
||||
@ExcelColumn(name = "邮件")
|
||||
private String email;
|
||||
|
||||
@ExcelColumn(name = "号码")
|
||||
private String phoneNumber;
|
||||
|
||||
@ExcelColumn(name = "性别")
|
||||
private Integer sex;
|
||||
|
||||
@ExcelColumn(name = "用户头像")
|
||||
private String avatar;
|
||||
|
||||
@ExcelColumn(name = "状态")
|
||||
private Integer status;
|
||||
|
||||
@ExcelColumn(name = "IP")
|
||||
private String loginIp;
|
||||
|
||||
@ExcelColumn(name = "登录时间")
|
||||
private Date loginDate;
|
||||
|
||||
@ExcelColumn(name = "创建者ID")
|
||||
private Long creatorId;
|
||||
|
||||
@ExcelColumn(name = "创建者")
|
||||
private String creatorName;
|
||||
|
||||
@ExcelColumn(name = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ExcelColumn(name = "修改者ID")
|
||||
private Long updaterId;
|
||||
|
||||
@ExcelColumn(name = "修改者")
|
||||
private String updaterName;
|
||||
|
||||
@ExcelColumn(name = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@ExcelColumn(name = "备注")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.agileboot.system.user.pojo.dto;
|
||||
|
||||
import com.agileboot.common.satoken.pojo.PostDTO;
|
||||
import com.agileboot.common.satoken.pojo.RoleDTO;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class UserDetailDTO {
|
||||
|
||||
private UserDTO user;
|
||||
|
||||
/**
|
||||
* 返回所有role
|
||||
*/
|
||||
private List<RoleDTO> roleOptions;
|
||||
|
||||
/**
|
||||
* 返回所有posts
|
||||
*/
|
||||
private List<PostDTO> postOptions;
|
||||
|
||||
private Long postId;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Set<String> permissions;
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.agileboot.system.user.pojo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 如果Entity的字段和复杂查询不匹配时 自定义类来接收
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SearchUserDO extends SysUser {
|
||||
|
||||
private String deptName;
|
||||
private String deptLeader;
|
||||
|
||||
}
|
||||
@ -1,10 +1,29 @@
|
||||
package com.agileboot.system.user.service;
|
||||
|
||||
import com.agileboot.common.satoken.pojo.LoginUser;
|
||||
import com.agileboot.system.user.pojo.dto.*;
|
||||
import com.agileboot.system.user.pojo.entity.SearchUserDO;
|
||||
import com.agileboot.system.user.pojo.entity.SysUser;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface ISysUserService {
|
||||
LoginUser getUserInfo(String username);
|
||||
|
||||
boolean registerUserInfo(SysUser sysUser);
|
||||
|
||||
IPage<UserDTO> getUserList(SearchUserDO query);
|
||||
|
||||
void addUser(AddUserCommand command);
|
||||
|
||||
UserDetailDTO getUserDetailInfo(Long userId);
|
||||
|
||||
void updateUser(UpdateUserCommand command);
|
||||
|
||||
void resetUserPassword(ResetPasswordCommand command);
|
||||
|
||||
void changeUserStatus(ChangeStatusCommand command);
|
||||
|
||||
void deleteUsers(Set<Long> longs);
|
||||
}
|
||||
|
||||
@ -1,16 +1,26 @@
|
||||
package com.agileboot.system.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.agileboot.system.user.mapper.SysUserMapper;
|
||||
import com.agileboot.system.user.pojo.entity.SysUser;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.agileboot.common.core.constant.Constants;
|
||||
import com.agileboot.common.core.exception.BizException;
|
||||
import com.agileboot.common.core.exception.error.ErrorCode;
|
||||
import com.agileboot.common.satoken.pojo.LoginUser;
|
||||
import com.agileboot.common.satoken.utils.LoginHelper;
|
||||
import com.agileboot.system.user.mapper.SysUserMapper;
|
||||
import com.agileboot.system.user.pojo.dto.*;
|
||||
import com.agileboot.system.user.pojo.entity.SearchUserDO;
|
||||
import com.agileboot.system.user.pojo.entity.SysUser;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
|
||||
@ -47,4 +57,68 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
sysUser.setUpdateBy(0L);
|
||||
return baseMapper.insert(sysUser) > 0;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------
|
||||
|
||||
@Override
|
||||
public IPage<UserDTO> getUserList(SearchUserDO query) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUser(AddUserCommand command) {
|
||||
SysUser entity = new SysUser();
|
||||
if (command == null) {
|
||||
throw new BizException("user is null");
|
||||
}
|
||||
BeanUtils.copyProperties(command, entity, "userId");
|
||||
|
||||
LambdaQueryWrapper<SysUser> isUserNameDuplicated = Wrappers.lambdaQuery(SysUser.class)
|
||||
.eq(SysUser::getUsername, command.getUsername());
|
||||
if (this.baseMapper.exists(isUserNameDuplicated)) {
|
||||
throw new BizException(ErrorCode.Business.USER_NAME_IS_NOT_UNIQUE);
|
||||
}
|
||||
Long userId = LoginHelper.getUserId();
|
||||
LambdaQueryWrapper<SysUser> isPhoneDuplicated = Wrappers.lambdaQuery(SysUser.class)
|
||||
.ne(userId != null, SysUser::getUserId, userId)
|
||||
.eq(SysUser::getPhoneNumber, command.getPhoneNumber());
|
||||
if (StringUtils.isNotBlank(command.getPhoneNumber()) && baseMapper.exists(isPhoneDuplicated)) {
|
||||
throw new BizException(ErrorCode.Business.USER_PHONE_NUMBER_IS_NOT_UNIQUE);
|
||||
}
|
||||
LambdaQueryWrapper<SysUser> isEmailDuplicated = Wrappers.lambdaQuery(SysUser.class)
|
||||
.ne(userId != null, SysUser::getUserId, userId)
|
||||
.eq(SysUser::getEmail, command.getEmail());
|
||||
if (StringUtils.isNotBlank(command.getEmail()) && baseMapper.exists(isEmailDuplicated)) {
|
||||
throw new BizException(ErrorCode.Business.USER_EMAIL_IS_NOT_UNIQUE);
|
||||
}
|
||||
// password encrypt
|
||||
entity.setPassword(command.getPassword());
|
||||
super.baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetailDTO getUserDetailInfo(Long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(UpdateUserCommand command) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetUserPassword(ResetPasswordCommand command) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeUserStatus(ChangeStatusCommand command) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUsers(Set<Long> longs) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user