修改
This commit is contained in:
parent
2e4b16b188
commit
2d541308e5
|
@ -10,10 +10,7 @@ import com.jsl.oa.utils.ResultUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -23,31 +20,29 @@ public class RoleController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户权限授予
|
* 用户权限授予
|
||||||
* @param roleAddUserVO
|
*
|
||||||
* @param bindingResult
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("role/user/add")
|
@PostMapping("role/user/add")
|
||||||
public BaseResponse roleAddUser(@RequestBody @Validated RoleAddUserVO roleAddUserVO, BindingResult bindingResult){
|
public BaseResponse roleAddUser(@RequestParam Long uid,@RequestParam Long rid){
|
||||||
// 判断是否有参数错误
|
// 判断是否有参数错误
|
||||||
if (bindingResult.hasErrors()) {
|
if (uid == null || rid == null) {
|
||||||
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
|
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||||
}
|
}
|
||||||
return roleService.roleAddUser(roleAddUserVO);
|
return roleService.roleAddUser(uid,rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户权限删除
|
* 用户权限删除
|
||||||
* @param roleRemoveUserVO
|
*
|
||||||
* @param bindingResult
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("role/user/remove")
|
@DeleteMapping("role/user/remove")
|
||||||
public BaseResponse roleRemoveUser(@RequestBody @Validated RoleRemoveUserVO roleRemoveUserVO, BindingResult bindingResult){
|
public BaseResponse roleRemoveUser(@RequestParam Long uid){
|
||||||
// 判断是否有参数错误
|
// 判断是否有参数错误
|
||||||
if (bindingResult.hasErrors()) {
|
if (uid==null) {
|
||||||
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
|
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||||
}
|
}
|
||||||
return roleService.roleRemoveUser(roleRemoveUserVO);
|
return roleService.roleRemoveUser(uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ import org.springframework.stereotype.Component;
|
||||||
public class RoleDAO {
|
public class RoleDAO {
|
||||||
private final RoleMapper roleMapper;
|
private final RoleMapper roleMapper;
|
||||||
|
|
||||||
public void roleAddUser(RoleAddUserVO roleAddUserVO) {
|
public void roleAddUser(Long uid,Long rid) {
|
||||||
roleMapper.roleAddUser(roleAddUserVO);
|
roleMapper.roleAddUser(uid,rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void roleRemoveUser(RoleRemoveUserVO roleRemoveUserVO) {
|
public void roleRemoveUser(Long uid) {
|
||||||
roleMapper.roleRemoveUser(roleRemoveUserVO);
|
roleMapper.roleRemoveUser(uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
public interface RoleMapper {
|
public interface RoleMapper {
|
||||||
|
|
||||||
@Insert("insert into organize_oa.oa_role_user (uid, rid) VALUE (#{uid},#{rid})")
|
@Insert("insert into organize_oa.oa_role_user (uid, rid) VALUE (#{uid},#{rid})")
|
||||||
void roleAddUser(RoleAddUserVO roleAddUserVO);
|
void roleAddUser(Long uid,Long rid);
|
||||||
|
|
||||||
@Delete("delete from organize_oa.oa_role_user where uid=#{uid}")
|
@Delete("delete from organize_oa.oa_role_user where uid=#{uid}")
|
||||||
void roleRemoveUser(RoleRemoveUserVO roleRemoveUserVO);
|
void roleRemoveUser(Long uid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import javax.validation.constraints.Pattern;
|
||||||
public class UserLoginVO {
|
public class UserLoginVO {
|
||||||
@Pattern(regexp = "^[0-9A-Za-z_]+$", message = "支持用户名/手机号/工号登陆")
|
@Pattern(regexp = "^[0-9A-Za-z_]+$", message = "支持用户名/手机号/工号登陆")
|
||||||
@NotBlank(message = "用户名不能为空")
|
@NotBlank(message = "用户名不能为空")
|
||||||
private String user;
|
private String username;
|
||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
private String password;
|
private String password;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import com.jsl.oa.model.voData.RoleRemoveUserVO;
|
||||||
import com.jsl.oa.utils.BaseResponse;
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
|
||||||
public interface RoleService {
|
public interface RoleService {
|
||||||
BaseResponse roleAddUser(RoleAddUserVO roleAddUserVO);
|
BaseResponse roleAddUser(Long uid,Long rid);
|
||||||
|
|
||||||
BaseResponse roleRemoveUser(RoleRemoveUserVO roleRemoveUserVO);
|
BaseResponse roleRemoveUser(Long uid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,18 +71,18 @@ public class AuthServiceImpl implements AuthService {
|
||||||
public BaseResponse authLogin(@NotNull UserLoginVO userLoginVO) {
|
public BaseResponse authLogin(@NotNull UserLoginVO userLoginVO) {
|
||||||
// 检查用户是否存在
|
// 检查用户是否存在
|
||||||
UserDO userDO;
|
UserDO userDO;
|
||||||
if (Pattern.matches("^[0-9A-Za-z_]{3,40}$", userLoginVO.getUser())) {
|
if (Pattern.matches("^[0-9A-Za-z_]{3,40}$", userLoginVO.getUsername())) {
|
||||||
// 是否为用户名
|
// 是否为用户名
|
||||||
userDO = userMapper.getUserInfoByUsername(userLoginVO.getUser());
|
userDO = userMapper.getUserInfoByUsername(userLoginVO.getUsername());
|
||||||
} else if (Pattern.matches("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", userLoginVO.getUser())) {
|
} else if (Pattern.matches("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", userLoginVO.getUsername())) {
|
||||||
// 是否为手机号
|
// 是否为手机号
|
||||||
userDO = userMapper.getUserInfoByPhone(userLoginVO.getUser());
|
userDO = userMapper.getUserInfoByPhone(userLoginVO.getUsername());
|
||||||
} else if (Pattern.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", userLoginVO.getUser())) {
|
} else if (Pattern.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", userLoginVO.getUsername())) {
|
||||||
// 是否为邮箱
|
// 是否为邮箱
|
||||||
return ResultUtil.error(ErrorCode.EMAIL_LOGIN_NOT_SUPPORT);
|
return ResultUtil.error(ErrorCode.EMAIL_LOGIN_NOT_SUPPORT);
|
||||||
} else {
|
} else {
|
||||||
// 工号
|
// 工号
|
||||||
userDO = userMapper.getUserByJobId(userLoginVO.getUser());
|
userDO = userMapper.getUserByJobId(userLoginVO.getUsername());
|
||||||
}
|
}
|
||||||
if (userDO != null) {
|
if (userDO != null) {
|
||||||
// 获取用户并登陆
|
// 获取用户并登陆
|
||||||
|
|
|
@ -19,17 +19,17 @@ public class RoleServiceImpl implements RoleService {
|
||||||
private final UserDAO userDAO;
|
private final UserDAO userDAO;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse roleAddUser(RoleAddUserVO roleAddUserVO) {
|
public BaseResponse roleAddUser(Long uid,Long rid) {
|
||||||
if(userDAO.isExistUser(roleAddUserVO.getUid())) {
|
if(userDAO.isExistUser(uid)) {
|
||||||
roleDAO.roleAddUser(roleAddUserVO);
|
roleDAO.roleAddUser(uid,rid);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse roleRemoveUser(RoleRemoveUserVO roleRemoveUserVO) {
|
public BaseResponse roleRemoveUser(Long uid) {
|
||||||
if(userDAO.isExistUser(roleRemoveUserVO.getUid())) {
|
if(userDAO.isExistUser(uid)) {
|
||||||
roleDAO.roleRemoveUser(roleRemoveUserVO);
|
roleDAO.roleRemoveUser(uid);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
} else return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user