用户管理
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package com.njcn.gather.user.pojo.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2024/11/11
|
||||||
|
*/
|
||||||
|
public interface UserState {
|
||||||
|
Integer DELETED = 0;
|
||||||
|
Integer ENABLED = 1;
|
||||||
|
Integer LOCKED = 2;
|
||||||
|
Integer WAITING_FOR_APPROVAL = 3;
|
||||||
|
Integer SLEEPING = 4;
|
||||||
|
Integer PASSWORD_EXPIRED = 5;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.njcn.gather.user.pojo.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2024/11/8
|
||||||
|
*/
|
||||||
|
public interface UserValidMessage {
|
||||||
|
|
||||||
|
String ID_NOT_BLANK = "id不能为空,请检查id参数";
|
||||||
|
|
||||||
|
String ID_FORMAT_ERROR = "id格式错误,请检查id参数";
|
||||||
|
|
||||||
|
String DEPT_ID_FORMAT_ERROR = "部门id格式错误,请检查deptId参数";
|
||||||
|
|
||||||
|
String NAME_NOT_BLANK = "名称不能为空,请检查name参数";
|
||||||
|
|
||||||
|
String NAME_FORMAT_ERROR = "名称格式错误,请检查name参数";
|
||||||
|
|
||||||
|
String CODE_NOT_BLANK="编码不能为空,请检查code参数";
|
||||||
|
|
||||||
|
String LOGIN_NAME_NOT_BLANK = "登录名不能为空,请检查loginName参数";
|
||||||
|
|
||||||
|
String LOGIN_NAME_FORMAT_ERROR = "登录名格式错误,需3-16位的英文字母或数字,请检查loginName参数";
|
||||||
|
|
||||||
|
String PASSWORD_NOT_BLANK = "密码不能为空,请检查password参数";
|
||||||
|
|
||||||
|
String PASSWORD_FORMAT_ERROR = "密码格式错误,需要包含特殊字符字母数字8-16位";
|
||||||
|
|
||||||
|
String PHONE_FORMAT_ERROR = "电话号码格式错误,请检查phone参数";
|
||||||
|
|
||||||
|
//String LOGIN_ERROR_TIMES_NOT_NULL = "登录错误次数不能为空,请检查loginErrorTimes参数";
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.njcn.gather.user.pojo.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2024/11/9
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum UserResponseEnum {
|
||||||
|
LOGIN_NAME_REPEAT("A010001", "登录名重复,请检查loginName参数"),
|
||||||
|
REGISTER_PHONE_FAIL("A010002", "该号码已被注册"),
|
||||||
|
USER_NAME_REPEAT("A010003", "用户名重复,请检查name参数"),
|
||||||
|
REGISTER_EMAIL_FAIL("A010004", "该邮箱已被注册"),
|
||||||
|
ROLE_NAME_REPEAT("A010005", "角色名称重复");
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
UserResponseEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package com.njcn.gather.user.user.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.constant.OperateType;
|
||||||
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.LogUtil;
|
||||||
|
import com.njcn.gather.user.user.pojo.param.SysUserParam;
|
||||||
|
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||||
|
import com.njcn.gather.user.user.service.ISysUserService;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @since 2024-11-08
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("sysUser")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysUserController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysUserService sysUserService;
|
||||||
|
|
||||||
|
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
// @PostMapping("/login")
|
||||||
|
// @ApiOperation("登录")
|
||||||
|
// public HttpResult<Object> login(@RequestBody SysUserParam.UserLoginParam loginParam) {}
|
||||||
|
|
||||||
|
// @OperateInfo(info = LogEnum.SYSTEM_SERIOUS, operateType = OperateType.LOGOUT)
|
||||||
|
// @ApiOperation("注销登录")
|
||||||
|
// @DeleteMapping("/logout")
|
||||||
|
// public HttpResult<Object> logout() {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ApiOperation("分页查询用户列表")
|
||||||
|
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||||
|
public HttpResult<Page<SysUser>> list(@RequestBody @Validated SysUserParam.SysUserQueryParam queryParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("list");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||||
|
Page<SysUser> result = sysUserService.listUser(queryParam);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@GetMapping("/listUserByDeptId")
|
||||||
|
@ApiOperation("查询部门下的用户")
|
||||||
|
@ApiImplicitParam(name = "deptId", value = "部门id", required = true)
|
||||||
|
public HttpResult<List<SysUser>> listUserByDeptId(String deptId) {
|
||||||
|
String methodDescribe = getMethodDescribe("listAllUserByDeptId");
|
||||||
|
List<SysUser> list = sysUserService.listUserByDeptId(deptId);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||||
|
@PostMapping("/add")
|
||||||
|
@ApiOperation("新增用户")
|
||||||
|
@ApiImplicitParam(name = "addUserParam", value = "新增用户", required = true)
|
||||||
|
public HttpResult<Boolean> add(@RequestBody @Validated SysUserParam.SysUserAddParam addUserParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("add");
|
||||||
|
LogUtil.njcnDebug(log, "{},用户数据为:{}", methodDescribe, addUserParam);
|
||||||
|
boolean result = sysUserService.addUser(addUserParam);
|
||||||
|
//更新redis数据
|
||||||
|
//sysUserService.userRoleList();
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@ApiOperation("批量删除用户")
|
||||||
|
@ApiImplicitParam(name = "ids", value = "用户id", required = true)
|
||||||
|
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
|
||||||
|
String methodDescribe = getMethodDescribe("delete");
|
||||||
|
LogUtil.njcnDebug(log, "{},用户id为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||||
|
boolean result = sysUserService.deleteUser(ids);
|
||||||
|
//更新redis数据
|
||||||
|
//sysUserService.userRoleList();
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
|
||||||
|
@PutMapping("/update")
|
||||||
|
@ApiOperation("修改用户")
|
||||||
|
@ApiImplicitParam(name = "updateUserParam", value = "修改用户", required = true)
|
||||||
|
public HttpResult<Boolean> update(@RequestBody @Validated SysUserParam.SysUserUpdateParam updateUserParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("update");
|
||||||
|
LogUtil.njcnDebug(log, "{},用户数据为:{}", methodDescribe, updateUserParam);
|
||||||
|
boolean result = sysUserService.updateUser(updateUserParam);
|
||||||
|
//更新redis数据
|
||||||
|
//userService.userRoleList();
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DOWNLOAD)
|
||||||
|
// @PostMapping("/export")
|
||||||
|
// @ApiOperation("导出用户数据")
|
||||||
|
// @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||||
|
// public void export(@RequestBody @Validated SysUserParam.UserQueryParam queryParam) {
|
||||||
|
// sysUserService.exportUserData(queryParam);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.njcn.gather.user.user.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @since 2024-11-08
|
||||||
|
*/
|
||||||
|
public interface SysUserMapper extends MPJBaseMapper<SysUser> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.njcn.gather.user.user.mapper.SysUserMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.njcn.gather.user.user.pojo.param;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.constant.PatternRegex;
|
||||||
|
import com.njcn.gather.user.pojo.constant.UserValidMessage;
|
||||||
|
import com.njcn.web.pojo.annotation.DateTimeStrValid;
|
||||||
|
import com.njcn.web.pojo.param.BaseParam;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.hibernate.validator.constraints.Range;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2024/11/8
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SysUserParam {
|
||||||
|
|
||||||
|
@ApiModelProperty("用户名(别名)")
|
||||||
|
@NotBlank(message = UserValidMessage.NAME_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.DEPT_NAME_REGEX, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("部门Id")
|
||||||
|
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.DEPT_ID_FORMAT_ERROR)
|
||||||
|
private String deptId;
|
||||||
|
|
||||||
|
@ApiModelProperty("电话号码")
|
||||||
|
@Pattern(regexp = PatternRegex.PHONE_REGEX_OR_NULL, message = UserValidMessage.PHONE_FORMAT_ERROR)
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@ApiModelProperty("邮箱")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
// @ApiModelProperty("最后一次登录时间")
|
||||||
|
// private LocalDateTime loginTime;
|
||||||
|
|
||||||
|
// @ApiModelProperty("密码错误次数")
|
||||||
|
// @NotNull(message = UserValidMessage.LOGIN_ERROR_TIMES_NOT_NULL)
|
||||||
|
// private Integer loginErrorTimes;
|
||||||
|
|
||||||
|
// @ApiModelProperty("密码错误锁定时间")
|
||||||
|
// @DateTimeStrValid(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
// private String lockTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class SysUserAddParam extends SysUserParam {
|
||||||
|
|
||||||
|
@ApiModelProperty("登录名")
|
||||||
|
@NotBlank(message = UserValidMessage.LOGIN_NAME_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.LOGIN_NAME_REGEX, message = UserValidMessage.LOGIN_NAME_FORMAT_ERROR)
|
||||||
|
private String loginName;
|
||||||
|
|
||||||
|
@ApiModelProperty("密码")
|
||||||
|
@NotBlank(message = UserValidMessage.PASSWORD_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class SysUserUpdateParam extends SysUserParam {
|
||||||
|
|
||||||
|
@ApiModelProperty("用户表Id")
|
||||||
|
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class SysUserQueryParam extends BaseParam {
|
||||||
|
@ApiModelProperty("用户名(别名)")
|
||||||
|
@Pattern(regexp = PatternRegex.USERNAME_REGEX, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.njcn.gather.user.user.pojo.po;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @since 2024-11-08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("sys_user")
|
||||||
|
public class SysUser extends BaseEntity implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -54771740356521149L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户表Id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名(别名)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录名
|
||||||
|
*/
|
||||||
|
private String loginName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门Id
|
||||||
|
*/
|
||||||
|
private String deptId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电话号码
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后一次登录时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime loginTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码错误次数
|
||||||
|
*/
|
||||||
|
private Integer loginErrorTimes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码错误锁定时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime lockTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户状态 0-删除;1-正常;2-锁定;3-待审核;4-休眠;5-密码过期
|
||||||
|
*/
|
||||||
|
private Integer state;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -15,34 +15,76 @@ public interface ISysUserService extends IService<SysUser> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询用户列表
|
* 分页查询用户列表
|
||||||
|
*
|
||||||
* @param queryParam 分页查询参数
|
* @param queryParam 分页查询参数
|
||||||
* @return 分页查询结果
|
* @return 分页查询结果
|
||||||
*/
|
*/
|
||||||
Page<SysUser> listUser(SysUserParam.UserQueryParam queryParam);
|
Page<SysUser> listUser(SysUserParam.SysUserQueryParam queryParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据部门ID查询用户列表
|
* 根据部门ID查询用户列表
|
||||||
|
*
|
||||||
* @param deptId 部门ID
|
* @param deptId 部门ID
|
||||||
* @return 用户列表
|
* @return 用户列表
|
||||||
*/
|
*/
|
||||||
List<SysUser> listUserByDeptId(String deptId);
|
List<SysUser> listUserByDeptId(String deptId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据登录名查询用户
|
||||||
|
*
|
||||||
|
* @param loginName
|
||||||
|
* @return 用户对象,如果没有查询到则返回null
|
||||||
|
*/
|
||||||
|
SysUser getUserByLoginName(String loginName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询用户
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
* @param isExcludeSelf 是否排除自己
|
||||||
|
* @param id 排除自己时需要传入自己的ID
|
||||||
|
* @return 用户对象,如果没有查询到则返回null
|
||||||
|
*/
|
||||||
|
SysUser getUserByPhone(String phone, boolean isExcludeSelf, String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名(别名)查询用户
|
||||||
|
*
|
||||||
|
* @param name 用户名(别名)
|
||||||
|
* @param isExcludeSelf 是否排除自己
|
||||||
|
* @param id 排除自己时需要传入自己的ID
|
||||||
|
* @return 用户对象,如果没有查询到则返回null
|
||||||
|
*/
|
||||||
|
SysUser getUserByName(String name, boolean isExcludeSelf, String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据邮箱查询用户
|
||||||
|
* @param email 邮箱
|
||||||
|
* @param isExcludeSelf 是否排除自己
|
||||||
|
* @param id 排除自己时需要传入自己的ID
|
||||||
|
* @return 用户对象,如果没有查询到则返回null
|
||||||
|
*/
|
||||||
|
SysUser getUserByEmail(String email, boolean isExcludeSelf, String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增用户
|
* 新增用户
|
||||||
|
*
|
||||||
* @param addUserParam 新增用户参数
|
* @param addUserParam 新增用户参数
|
||||||
* @return 结果,true表示新增成功,false表示新增失败
|
* @return 结果,true表示新增成功,false表示新增失败
|
||||||
*/
|
*/
|
||||||
boolean addUser(SysUserParam.UserAddParam addUserParam);
|
boolean addUser(SysUserParam.SysUserAddParam addUserParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户
|
* 更新用户
|
||||||
|
*
|
||||||
* @param updateUserParam 更新用户参数
|
* @param updateUserParam 更新用户参数
|
||||||
* @return 结果,true表示更新成功,false表示更新失败
|
* @return 结果,true表示更新成功,false表示更新失败
|
||||||
*/
|
*/
|
||||||
boolean updateUser(SysUserParam.UserUpdateParam updateUserParam);
|
boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除用户
|
* 批量删除用户
|
||||||
|
*
|
||||||
* @param ids 用户ID列表
|
* @param ids 用户ID列表
|
||||||
* @return 结果,true表示删除成功,false表示删除失败
|
* @return 结果,true表示删除成功,false表示删除失败
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
package com.njcn.gather.user.user.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.common.utils.sm.Sm4Utils;
|
||||||
|
import com.njcn.db.mybatisplus.constant.DbConstant;
|
||||||
|
import com.njcn.gather.user.pojo.constant.UserState;
|
||||||
|
import com.njcn.gather.user.pojo.enums.UserResponseEnum;
|
||||||
|
import com.njcn.gather.user.user.mapper.SysUserMapper;
|
||||||
|
import com.njcn.gather.user.user.pojo.param.SysUserParam;
|
||||||
|
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||||
|
import com.njcn.gather.user.user.service.ISysUserService;
|
||||||
|
import com.njcn.web.factory.PageFactory;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2024-11-08
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<SysUser> listUser(SysUserParam.SysUserQueryParam queryParam) {
|
||||||
|
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
||||||
|
if (ObjectUtil.isNotNull(queryParam)) {
|
||||||
|
queryWrapper.like(StrUtil.isNotBlank(queryParam.getName()), "sys_user.name", queryParam.getName())
|
||||||
|
.between(ObjectUtil.isAllNotEmpty(queryParam.getSearchBeginTime(), queryParam.getSearchEndTime()), "sys_user.Login_Time", queryParam.getSearchBeginTime(), queryParam.getSearchEndTime());
|
||||||
|
//排序
|
||||||
|
if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) {
|
||||||
|
queryWrapper.orderBy(true, queryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy()));
|
||||||
|
} else {
|
||||||
|
queryWrapper.orderByDesc("sys_user.update_time");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
queryWrapper.orderByDesc("sys_user.update_time");
|
||||||
|
}
|
||||||
|
queryWrapper.ne("sys_user.state", UserState.DELETED);
|
||||||
|
return this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysUser> listUserByDeptId(String deptId) {
|
||||||
|
if (StrUtil.isNotBlank(deptId)) {
|
||||||
|
return this.lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getDeptId, deptId).orderByAsc(SysUser::getCreateTime).list();
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser getUserByLoginName(String loginName) {
|
||||||
|
return this.lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getLoginName, loginName).one();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser getUserByPhone(String phone, boolean isExcludeSelf, String id) {
|
||||||
|
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQuery.eq(SysUser::getPhone, phone).ne(SysUser::getState, UserState.DELETED);
|
||||||
|
if (isExcludeSelf) {
|
||||||
|
lambdaQuery.ne(SysUser::getId, id);
|
||||||
|
}
|
||||||
|
return this.baseMapper.selectOne(lambdaQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser getUserByName(String name, boolean isExcludeSelf, String id) {
|
||||||
|
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQuery.eq(SysUser::getName, name).ne(SysUser::getState, UserState.DELETED);
|
||||||
|
if (isExcludeSelf) {
|
||||||
|
lambdaQuery.ne(SysUser::getId, id);
|
||||||
|
}
|
||||||
|
return this.baseMapper.selectOne(lambdaQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser getUserByEmail(String email, boolean isExcludeSelf, String id) {
|
||||||
|
LambdaQueryWrapper<SysUser> lambdaQuery = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQuery.eq(SysUser::getEmail, email).ne(SysUser::getState, UserState.DELETED);
|
||||||
|
if (isExcludeSelf) {
|
||||||
|
lambdaQuery.ne(SysUser::getId, id);
|
||||||
|
}
|
||||||
|
return this.baseMapper.selectOne(lambdaQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addUser(SysUserParam.SysUserAddParam addUserParam) {
|
||||||
|
if (!Objects.isNull(getUserByLoginName(addUserParam.getLoginName()))) {
|
||||||
|
throw new BusinessException(UserResponseEnum.LOGIN_NAME_REPEAT);
|
||||||
|
}
|
||||||
|
checkRepeat(addUserParam, false, null);
|
||||||
|
SysUser sysUser = new SysUser();
|
||||||
|
BeanUtils.copyProperties(addUserParam, sysUser);
|
||||||
|
String secretkey = Sm4Utils.globalSecretKey;
|
||||||
|
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||||
|
sysUser.setPassword(sm4.encryptData_ECB(sysUser.getPassword()));
|
||||||
|
sysUser.setLoginErrorTimes(0);
|
||||||
|
sysUser.setState(UserState.ENABLED);
|
||||||
|
return this.save(sysUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam) {
|
||||||
|
checkRepeat(updateUserParam, true, updateUserParam.getId());
|
||||||
|
SysUser sysUser = new SysUser();
|
||||||
|
BeanUtils.copyProperties(updateUserParam, sysUser);
|
||||||
|
return this.updateById(sysUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteUser(List<String> ids) {
|
||||||
|
UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.set("sys_user.state", UserState.DELETED).in("sys_user.id", ids);
|
||||||
|
return this.update(updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验重复
|
||||||
|
*
|
||||||
|
* @param sysUserParam 检查对象
|
||||||
|
* @param isExcludeSelf 是否排除自己
|
||||||
|
* @param id 排除自己id
|
||||||
|
*/
|
||||||
|
private void checkRepeat(SysUserParam sysUserParam, boolean isExcludeSelf, String id) {
|
||||||
|
if (!Objects.isNull(getUserByName(sysUserParam.getName(), isExcludeSelf, id))) {
|
||||||
|
throw new BusinessException(UserResponseEnum.USER_NAME_REPEAT);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(sysUserParam.getPhone()) && !Objects.isNull(getUserByPhone(sysUserParam.getPhone(), isExcludeSelf, id))) {
|
||||||
|
throw new BusinessException(UserResponseEnum.REGISTER_PHONE_FAIL);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(sysUserParam.getEmail()) && !Objects.isNull(getUserByEmail(sysUserParam.getEmail(), isExcludeSelf, id))) {
|
||||||
|
throw new BusinessException(UserResponseEnum.REGISTER_EMAIL_FAIL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user