UserAllCurrent
This commit is contained in:
parent
e71c10348f
commit
955bdc5552
@ -41,7 +41,7 @@ public class AuthControllerAspect {
|
||||
* @throws Throwable 异常
|
||||
* @since v1.0.0
|
||||
*/
|
||||
@Around("execution(* com.jsl.oa.controllers.AuthController.*(..))")
|
||||
@Around("execution(* com.jsl.oa.controllers.*.*(..))")
|
||||
public Object controllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||
// 获取HttpServletRequest对象
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
|
@ -25,7 +25,7 @@ public class ShiroConfiguration {
|
||||
|
||||
// 配置过滤器规则
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
||||
filterChainDefinitionMap.put("/auth/**", "anon"); // 登录接口允许匿名访问
|
||||
filterChainDefinitionMap.put("/auth/**/**", "anon"); // 登录接口允许匿名访问
|
||||
filterChainDefinitionMap.put("/unauthorized", "anon"); // 未授权接口允许匿名访问
|
||||
filterChainDefinitionMap.put("/", "jwt"); // 首页允许匿名访问
|
||||
filterChainDefinitionMap.put("/**/**", "jwt"); // 其他接口一律拦截(需要Token)
|
||||
|
@ -86,8 +86,8 @@ public class AuthController {
|
||||
* @author 筱锋xiao_lfeng
|
||||
* @since v1.1.0
|
||||
*/
|
||||
@GetMapping("/auth/login/email/code")
|
||||
public BaseResponse authLoginSendEmailCode(@RequestParam String email) {
|
||||
@GetMapping("/auth/email/code")
|
||||
public BaseResponse authSendEmailCode(@RequestParam String email) {
|
||||
if (email != null) {
|
||||
if (Pattern.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", email)) {
|
||||
return authService.authLoginSendEmailCode(email);
|
||||
|
@ -1,16 +1,30 @@
|
||||
package com.jsl.oa.controllers;
|
||||
|
||||
import com.jsl.oa.model.voData.*;
|
||||
import com.jsl.oa.model.voData.UserAllCurrentVO;
|
||||
import com.jsl.oa.model.voData.UserEditProfileVO;
|
||||
import com.jsl.oa.services.UserService;
|
||||
import com.jsl.oa.utils.BaseResponse;
|
||||
import com.jsl.oa.utils.ErrorCode;
|
||||
import com.jsl.oa.utils.Processing;
|
||||
import com.jsl.oa.utils.ResultUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <h1>用户控制器</h1>
|
||||
* <hr/>
|
||||
* 用户控制器,包含用户账号删除、用户账号锁定、用户编辑自己的信息接口
|
||||
*
|
||||
* @version v1.1.0
|
||||
* @see UserService
|
||||
* @see UserEditProfileVO
|
||||
* @since v1.0.0
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
@ -18,25 +32,26 @@ public class UserController {
|
||||
|
||||
/**
|
||||
* 用户账号删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/user/delete")
|
||||
public BaseResponse userDelete(@RequestParam Long id){
|
||||
public BaseResponse userDelete(@RequestParam Long id) {
|
||||
// 判断是否有参数错误
|
||||
if (id == null) {
|
||||
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||
}
|
||||
else return userService.userDelete(id);
|
||||
} else return userService.userDelete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户账号锁定
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/user/lock")
|
||||
public BaseResponse userLock(@RequestParam Long id){
|
||||
public BaseResponse userLock(@RequestParam Long id) {
|
||||
// 判断是否有参数错误
|
||||
if (id == null) {
|
||||
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||
@ -46,12 +61,13 @@ public class UserController {
|
||||
|
||||
/**
|
||||
* 用户编辑自己的信息
|
||||
*
|
||||
* @param userEditProfileVO
|
||||
* @param bindingResult
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/user/profile/edit")
|
||||
public BaseResponse userEditProfile(@RequestBody @Validated UserEditProfileVO userEditProfileVO, BindingResult bindingResult){
|
||||
public BaseResponse userEditProfile(@RequestBody @Validated UserEditProfileVO userEditProfileVO, BindingResult bindingResult) {
|
||||
// 判断是否有参数错误
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
|
||||
@ -59,5 +75,22 @@ public class UserController {
|
||||
return userService.userEditProfile(userEditProfileVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取全部的用户信息</h2>
|
||||
* <hr/>
|
||||
* 获取全部的用户信息接口<br/>
|
||||
* Admin接口
|
||||
*
|
||||
* @return {@link BaseResponse}
|
||||
*/
|
||||
@GetMapping("/user/current/all")
|
||||
public BaseResponse userCurrentAll(@RequestBody @Validated UserAllCurrentVO userAllCurrentVO,
|
||||
HttpServletRequest request, @NotNull BindingResult bindingResult) {
|
||||
// 判断是否有参数错误
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
|
||||
}
|
||||
return userService.userCurrentAll(request, userAllCurrentVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,26 @@
|
||||
package com.jsl.oa.dao;
|
||||
|
||||
import com.jsl.oa.mapper.RoleMapper;
|
||||
import com.jsl.oa.mapper.UserMapper;
|
||||
import com.jsl.oa.model.doData.RoleUserDO;
|
||||
import com.jsl.oa.model.doData.UserCurrentDO;
|
||||
import com.jsl.oa.model.doData.UserDO;
|
||||
import com.jsl.oa.model.voData.UserAllCurrentVO;
|
||||
import com.jsl.oa.model.voData.UserEditProfileVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class UserDAO {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final RoleMapper roleMapper;
|
||||
|
||||
/**
|
||||
* <h2>用户名获取用户信息</h2>
|
||||
@ -61,4 +71,30 @@ public class UserDAO {
|
||||
public void userEditProfile(UserEditProfileVO userEditProfileVO) {
|
||||
userMapper.userEditProfile(userEditProfileVO);
|
||||
}
|
||||
|
||||
public List<UserCurrentDO> userCurrentAll(UserAllCurrentVO userAllCurrentVO) {
|
||||
List<UserCurrentDO> userCurrentDO = userMapper.getAllUser(userAllCurrentVO);
|
||||
return this.userCurrentAll(userCurrentDO);
|
||||
|
||||
}
|
||||
|
||||
public List<UserCurrentDO> userCurrentAllLike(UserAllCurrentVO userAllCurrentVO) {
|
||||
List<UserCurrentDO> userCurrentDO = userMapper.getAllUserBySearch(userAllCurrentVO);
|
||||
return this.userCurrentAll(userCurrentDO);
|
||||
}
|
||||
|
||||
@Contract("_ -> param1")
|
||||
private @NotNull List<UserCurrentDO> userCurrentAll(@NotNull List<UserCurrentDO> userCurrentDO) {
|
||||
userCurrentDO.forEach(it -> {
|
||||
it.setRole(roleMapper.getRoleUserByUid(it.getId()));
|
||||
if (it.getRole() == null) {
|
||||
RoleUserDO newRoleUserDO = new RoleUserDO();
|
||||
newRoleUserDO.setRid(0L)
|
||||
.setUid(it.getId())
|
||||
.setCreatedAt(new Timestamp(System.currentTimeMillis()));
|
||||
it.setRole(newRoleUserDO);
|
||||
}
|
||||
});
|
||||
return userCurrentDO;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.jsl.oa.mapper;
|
||||
|
||||
import com.jsl.oa.model.doData.RoleDO;
|
||||
import com.jsl.oa.model.doData.RoleUserDO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
@ -16,5 +17,8 @@ public interface RoleMapper {
|
||||
void roleRemoveUser(Long uid);
|
||||
|
||||
@Select("SELECT * FROM organize_oa.oa_role_user WHERE uid=#{uid}")
|
||||
RoleUserDO getRoleByUid(Long uid);
|
||||
RoleUserDO getRoleUserByUid(Long uid);
|
||||
|
||||
@Select("SELECT * FROM organize_oa.oa_role WHERE role_name=#{roleName}")
|
||||
RoleDO getRoleByRoleName(String roleName);
|
||||
}
|
||||
|
@ -1,12 +1,16 @@
|
||||
package com.jsl.oa.mapper;
|
||||
|
||||
import com.jsl.oa.model.doData.UserCurrentDO;
|
||||
import com.jsl.oa.model.doData.UserDO;
|
||||
import com.jsl.oa.model.voData.UserAllCurrentVO;
|
||||
import com.jsl.oa.model.voData.UserEditProfileVO;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
@ -43,4 +47,14 @@ public interface UserMapper {
|
||||
|
||||
@Update("UPDATE organize_oa.oa_user SET password = #{newPassword} WHERE id = #{id}")
|
||||
boolean updateUserPassword(Long id, String newPassword);
|
||||
|
||||
@Select("SELECT * FROM organize_oa.oa_user ORDER BY `id` DESC LIMIT #{page},#{limit}")
|
||||
List<UserCurrentDO> getAllUser(UserAllCurrentVO userAllCurrentVO);
|
||||
|
||||
@Select("SELECT * FROM organize_oa.oa_user " +
|
||||
"WHERE username LIKE CONCAT('%',#{search},'%') " +
|
||||
"OR email LIKE CONCAT('%',#{search},'%') " +
|
||||
"OR phone LIKE CONCAT('%',#{search},'%') " +
|
||||
"ORDER BY `id` LIMIT #{page},#{limit}")
|
||||
List<UserCurrentDO> getAllUserBySearch(UserAllCurrentVO userAllCurrentVO);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.jsl.oa.model.doData;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ -17,7 +16,6 @@ import java.sql.Timestamp;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class RoleUserDO {
|
||||
private Long uid;
|
||||
private Long rid;
|
||||
|
31
src/main/java/com/jsl/oa/model/doData/UserCurrentDO.java
Normal file
31
src/main/java/com/jsl/oa/model/doData/UserCurrentDO.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.jsl.oa.model.doData;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserCurrentDO {
|
||||
private Long id;
|
||||
private String jobId;
|
||||
private String username;
|
||||
private String address;
|
||||
private String phone;
|
||||
private String email;
|
||||
private Short age;
|
||||
private String signature;
|
||||
private String avatar;
|
||||
private String nickname;
|
||||
private Short sex;
|
||||
private Boolean enabled;
|
||||
private Boolean accountNoExpired;
|
||||
private Boolean credentialsNoExpired;
|
||||
private Boolean recommend;
|
||||
private Boolean accountNoLocked;
|
||||
private String description;
|
||||
private RoleUserDO role;
|
||||
private Timestamp createdAt;
|
||||
private Timestamp updatedAt;
|
||||
}
|
13
src/main/java/com/jsl/oa/model/voData/UserAllCurrentVO.java
Normal file
13
src/main/java/com/jsl/oa/model/voData/UserAllCurrentVO.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.jsl.oa.model.voData;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserAllCurrentVO {
|
||||
private Long page;
|
||||
private Long limit;
|
||||
private String search;
|
||||
private Long role;
|
||||
}
|
@ -1,32 +1,34 @@
|
||||
package com.jsl.oa.services;
|
||||
|
||||
import com.jsl.oa.model.doData.UserDO;
|
||||
import com.jsl.oa.model.voData.UserAllCurrentVO;
|
||||
import com.jsl.oa.model.voData.UserEditProfileVO;
|
||||
import com.jsl.oa.utils.BaseResponse;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <h1>用户控制器接口</h1>
|
||||
* <hr/>
|
||||
*
|
||||
* <p>该接口用于定义用户控制器的方法</p>
|
||||
* 该接口用于定义用户控制器的方法
|
||||
*
|
||||
* @version 1.1.0
|
||||
* @since v1.1.0
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
public interface UserService {
|
||||
/**
|
||||
* <h2>根据用户名获取用户信息</h2>
|
||||
*
|
||||
* <p>该方法用于根据用户名获取用户信息</p>
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserDO getUserInfoByUsername(String username);
|
||||
/**
|
||||
* <h2>根据用户名获取用户信息</h2>
|
||||
*
|
||||
* <p>该方法用于根据用户名获取用户信息</p>
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserDO getUserInfoByUsername(String username);
|
||||
|
||||
/**
|
||||
* 用户账号删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ -34,10 +36,22 @@ public interface UserService {
|
||||
|
||||
/**
|
||||
* 用户账号锁定
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
BaseResponse userLock(Long id);
|
||||
|
||||
BaseResponse userEditProfile(UserEditProfileVO userEditProfileVO);
|
||||
|
||||
/**
|
||||
* <h2>获取全部的用户信息</h2>
|
||||
* <hr/>
|
||||
* 该方法用于获取全部的用户信息
|
||||
*
|
||||
* @param request 请求
|
||||
* @param userAllCurrentVO 输入信息
|
||||
* @return {@link BaseResponse}
|
||||
*/
|
||||
BaseResponse userCurrentAll(HttpServletRequest request, UserAllCurrentVO userAllCurrentVO);
|
||||
}
|
||||
|
@ -91,11 +91,16 @@ public class AuthServiceImpl implements AuthService {
|
||||
userDO = userMapper.getUserByJobId(userLoginVO.getUser());
|
||||
}
|
||||
if (userDO != null) {
|
||||
// 获取用户并登陆
|
||||
if (BCrypt.checkpw(userLoginVO.getPassword(), userDO.getPassword())) {
|
||||
return this.encapsulateDisplayContent(userDO);
|
||||
// 账户是否有效
|
||||
if (userDO.getEnabled()) {
|
||||
// 获取用户并登陆
|
||||
if (BCrypt.checkpw(userLoginVO.getPassword(), userDO.getPassword())) {
|
||||
return this.encapsulateDisplayContent(userDO);
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.WRONG_PASSWORD);
|
||||
}
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.WRONG_PASSWORD);
|
||||
return ResultUtil.error(ErrorCode.USER_IS_DEACTIVATED);
|
||||
}
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
@ -126,18 +131,23 @@ public class AuthServiceImpl implements AuthService {
|
||||
// 获取用户信息
|
||||
UserDO userDO = userMapper.getUserInfoByEmail(email);
|
||||
if (userDO != null) {
|
||||
// 生成验证码
|
||||
Integer code = Processing.createCode(null);
|
||||
// 存储验证码
|
||||
if (emailRedisUtil.setData(BusinessConstants.BUSINESS_LOGIN, email, code, 5)) {
|
||||
// 发送邮件
|
||||
if (mailService.sendMailAboutUserLogin(email, code)) {
|
||||
return ResultUtil.success("验证码已发送");
|
||||
// 账户是否有效
|
||||
if (userDO.getEnabled()) {
|
||||
// 生成验证码
|
||||
Integer code = Processing.createCode(null);
|
||||
// 存储验证码
|
||||
if (emailRedisUtil.setData(BusinessConstants.BUSINESS_LOGIN, email, code, 5)) {
|
||||
// 发送邮件
|
||||
if (mailService.sendMailAboutUserLogin(email, code)) {
|
||||
return ResultUtil.success("验证码已发送");
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.EMAIL_LOGIN_NOT_SUPPORT);
|
||||
}
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.EMAIL_LOGIN_NOT_SUPPORT);
|
||||
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR);
|
||||
}
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR);
|
||||
return ResultUtil.error(ErrorCode.USER_IS_DEACTIVATED);
|
||||
}
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
@ -151,7 +161,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
return ResultUtil.error(ErrorCode.PASSWORD_NOT_SAME);
|
||||
}
|
||||
// 检查用户
|
||||
UserDO userDO = userMapper.getUserById(Processing.getAuthHeader(request));
|
||||
UserDO userDO = userMapper.getUserById(Processing.getAuthHeaderToUserId(request));
|
||||
if (userDO != null) {
|
||||
// 检查旧密码
|
||||
if (BCrypt.checkpw(userChangePasswordVO.getOldPassword(), userDO.getPassword())) {
|
||||
@ -172,7 +182,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Override
|
||||
public BaseResponse authLogout(HttpServletRequest request) {
|
||||
// 获取用户
|
||||
UserDO userDO = userMapper.getUserById(Processing.getAuthHeader(request));
|
||||
UserDO userDO = userMapper.getUserById(Processing.getAuthHeaderToUserId(request));
|
||||
// 删除Token
|
||||
if (tokenRedisUtil.delData(BusinessConstants.BUSINESS_LOGIN, userDO.getId().toString())) {
|
||||
return ResultUtil.success("登出成功");
|
||||
@ -196,7 +206,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
return ResultUtil.success("修改成功");
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.DATABASE_UPDATE_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,7 +228,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
// Token 上传到 Redis
|
||||
tokenRedisUtil.setData(BusinessConstants.BUSINESS_LOGIN, userDO.getId().toString(), token, 1440);
|
||||
// 获取用户角色
|
||||
RoleUserDO getUserRole = roleMapper.getRoleByUid(userDO.getId());
|
||||
RoleUserDO getUserRole = roleMapper.getRoleUserByUid(userDO.getId());
|
||||
if (getUserRole == null) {
|
||||
getUserRole = new RoleUserDO();
|
||||
getUserRole.setRid(0L)
|
||||
|
@ -1,21 +1,34 @@
|
||||
package com.jsl.oa.services.impl;
|
||||
|
||||
import com.jsl.oa.dao.UserDAO;
|
||||
import com.jsl.oa.mapper.RoleMapper;
|
||||
import com.jsl.oa.model.doData.RoleDO;
|
||||
import com.jsl.oa.model.doData.RoleUserDO;
|
||||
import com.jsl.oa.model.doData.UserCurrentDO;
|
||||
import com.jsl.oa.model.doData.UserDO;
|
||||
import com.jsl.oa.model.voData.UserAllCurrentVO;
|
||||
import com.jsl.oa.model.voData.UserEditProfileVO;
|
||||
import com.jsl.oa.services.UserService;
|
||||
import com.jsl.oa.utils.BaseResponse;
|
||||
import com.jsl.oa.utils.ErrorCode;
|
||||
import com.jsl.oa.utils.Processing;
|
||||
import com.jsl.oa.utils.ResultUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
private final UserDAO userDAO;
|
||||
private final RoleMapper roleMapper;
|
||||
|
||||
@Override
|
||||
public UserDO getUserInfoByUsername(String username) {
|
||||
@ -25,29 +38,72 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public BaseResponse userDelete(Long id) {
|
||||
//判断用户是否存在
|
||||
if(userDAO.isExistUser(id)){
|
||||
if (userDAO.isExistUser(id)) {
|
||||
userDAO.userDelete(id);
|
||||
return ResultUtil.success("删除成功");
|
||||
}else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse userLock(Long id) {
|
||||
//判断用户是否存在
|
||||
if(userDAO.isExistUser(id)) {
|
||||
if (userDAO.isExistUser(id)) {
|
||||
userDAO.userLock(id);
|
||||
return ResultUtil.success("锁定成功");
|
||||
}else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse userEditProfile(UserEditProfileVO userEditProfileVO) {
|
||||
if(userDAO.isExistUser(userEditProfileVO.getId())) {
|
||||
if(userEditProfileVO.getPassword()!=null) {
|
||||
public BaseResponse userEditProfile(@NotNull UserEditProfileVO userEditProfileVO) {
|
||||
if (userDAO.isExistUser(userEditProfileVO.getId())) {
|
||||
if (userEditProfileVO.getPassword() != null) {
|
||||
userEditProfileVO.setPassword(BCrypt.hashpw(userEditProfileVO.getPassword(), BCrypt.gensalt()));
|
||||
}
|
||||
userDAO.userEditProfile(userEditProfileVO);
|
||||
return ResultUtil.success("修改成功");
|
||||
}else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse userCurrentAll(HttpServletRequest request, @NotNull UserAllCurrentVO userAllCurrentVO) {
|
||||
// 检查是否是管理员用户
|
||||
RoleUserDO roleUserDO = roleMapper.getRoleUserByUid(Processing.getAuthHeaderToUserId(request));
|
||||
if (roleUserDO != null) {
|
||||
RoleDO roleDO = roleMapper.getRoleByRoleName("admin");
|
||||
if (!roleUserDO.getRid().equals(roleDO.getId())) {
|
||||
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
||||
}
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
||||
}
|
||||
// 检查数据
|
||||
if (userAllCurrentVO.getPage() == null || userAllCurrentVO.getPage() < 1) {
|
||||
userAllCurrentVO.setPage(1L);
|
||||
}
|
||||
if (userAllCurrentVO.getLimit() == null || userAllCurrentVO.getLimit() < 1) {
|
||||
userAllCurrentVO.setLimit(20L);
|
||||
}
|
||||
// 页码转换
|
||||
if (userAllCurrentVO.getPage() > 0) {
|
||||
userAllCurrentVO.setPage((userAllCurrentVO.getPage() - 1) * userAllCurrentVO.getLimit());
|
||||
}
|
||||
// 检查是否处于模糊查询
|
||||
List<UserCurrentDO> userAllCurrentVOList;
|
||||
if (userAllCurrentVO.getSearch() != null && !userAllCurrentVO.getSearch().isEmpty()) {
|
||||
if (Pattern.matches("^[0-9A-Za-z_@]+$", userAllCurrentVO.getSearch())) {
|
||||
userAllCurrentVOList = userDAO.userCurrentAllLike(userAllCurrentVO);
|
||||
} else {
|
||||
ArrayList<String> arrayList = new ArrayList<>();
|
||||
arrayList.add("只允许 0-9、A-Z、a-z、_和@进行查询");
|
||||
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, arrayList);
|
||||
}
|
||||
} else {
|
||||
userAllCurrentVOList = userDAO.userCurrentAll(userAllCurrentVO);
|
||||
}
|
||||
// 检查是否存在 Role 筛选
|
||||
if (userAllCurrentVO.getRole() != null) {
|
||||
userAllCurrentVOList.removeIf(it -> !userAllCurrentVO.getRole().equals(it.getRole().getRid()));
|
||||
}
|
||||
return ResultUtil.success(userAllCurrentVOList);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ public enum ErrorCode {
|
||||
TOKEN_EXPIRED("TokenExpired", 40101, "Token已过期"),
|
||||
VERIFICATION_INVALID("VerificationInvalid", 40102, "验证码无效"),
|
||||
TOKEN_NOT_EXIST("TokenNotExist", 40103, "Token不存在"),
|
||||
USER_IS_DEACTIVATED("UserIsDeactivated", 40300, "用户已被禁用"),
|
||||
NOT_ADMIN("NotAdmin", 40300, "不是管理员"),
|
||||
EMAIL_LOGIN_NOT_SUPPORT("EmailLoginNotSupport", 40300, "请使用邮箱登陆"),
|
||||
PASSWORD_NOT_SAME("PasswordNotSame", 40301, "两次密码不一致"),
|
||||
DATABASE_INSERT_ERROR("DatabaseInsertError", 50010, "数据库插入错误"),
|
||||
|
@ -135,7 +135,7 @@ public class Processing {
|
||||
*
|
||||
* @param request 请求
|
||||
*/
|
||||
public static @Nullable Long getAuthHeader(@NotNull HttpServletRequest request) {
|
||||
public static @Nullable Long getAuthHeaderToUserId(@NotNull HttpServletRequest request) {
|
||||
String token = request.getHeader("Authorization");
|
||||
if (token == null || token.isEmpty()) {
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user