补丁包

This commit is contained in:
筱锋xiao_lfeng 2023-12-21 11:01:08 +08:00
parent 72090aadd1
commit 4df82ecdcc
No known key found for this signature in database
GPG Key ID: F693AA12AABBFA87
6 changed files with 40 additions and 16 deletions

View File

@ -23,8 +23,7 @@ public class UserRegisterVO {
@NotBlank(message = "密码不能为空") @NotBlank(message = "密码不能为空")
private String password; private String password;
@Pattern(regexp = "^(男|女|保密)$", message = "性别只能为男或女") @Pattern(regexp = "^(男|女|保密)$", message = "性别只能为男、女或保密")
@NotBlank(message = "性别不能为空")
private String sex; private String sex;
@NotBlank(message = "年龄不能为空") @NotBlank(message = "年龄不能为空")

View File

@ -33,15 +33,20 @@ public class UserController {
public BaseResponse userRegister(@RequestBody @Validated UserRegisterVO userRegisterVO, BindingResult bindingResult) throws ParseException { public BaseResponse userRegister(@RequestBody @Validated UserRegisterVO userRegisterVO, BindingResult bindingResult) throws ParseException {
// 判断是否有参数错误 // 判断是否有参数错误
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
return ResultUtil.error(ErrorCode.PARAMETER_ERROR, Processing.getValidatedErrorList(bindingResult)); return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
} }
return userService.userRegister(userRegisterVO); return userService.userRegister(userRegisterVO);
} }
/** /**
* 用户登录 * <h1>用户登录</h1>
* @param userDO * <hr/>
* @return * 用户登录接口
*
* @since v1.0.0
* @param userDO 用户登录信息
* @return {@link BaseResponse}
* @author 176yunxuan
*/ */
@PostMapping("/user/login") @PostMapping("/user/login")
public BaseResponse userLogin(@RequestBody UserDO userDO){ public BaseResponse userLogin(@RequestBody UserDO userDO){

View File

@ -0,0 +1,20 @@
package com.jsl.oa.exception;
import com.jsl.oa.utils.ErrorCode;
/**
* <h1>业务异常类</h1>
* <hr/>
* 用于处理业务异常
*
* @since v1.0.0
* @version v1.0.0
* @author 筱锋xiao_lfeng
* @see RuntimeException
*/
public class BusinessException extends RuntimeException {
public BusinessException(ErrorCode errorCode) {
super(errorCode.getOutput() + "|" + errorCode.getMessage());
}
}

View File

@ -2,6 +2,7 @@ package com.jsl.oa.services;
import com.jsl.oa.common.doData.UserDO; import com.jsl.oa.common.doData.UserDO;
import com.jsl.oa.common.voData.UserRegisterVO; import com.jsl.oa.common.voData.UserRegisterVO;
import com.jsl.oa.exception.BusinessException;
import com.jsl.oa.mapper.UserMapper; import com.jsl.oa.mapper.UserMapper;
import com.jsl.oa.utils.BaseResponse; import com.jsl.oa.utils.BaseResponse;
import com.jsl.oa.utils.ErrorCode; import com.jsl.oa.utils.ErrorCode;
@ -61,7 +62,7 @@ public class UserServiceImpl implements UserService {
if (userMapper.insertUser(userDO)) { if (userMapper.insertUser(userDO)) {
return ResultUtil.success("注册成功"); return ResultUtil.success("注册成功");
} else { } else {
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR); throw new BusinessException(ErrorCode.DATABASE_INSERT_ERROR);
} }
} }
@ -69,11 +70,9 @@ public class UserServiceImpl implements UserService {
public BaseResponse userLogin(UserDO userDO) { public BaseResponse userLogin(UserDO userDO) {
String pwd = userDO.getPassword(); String pwd = userDO.getPassword();
String encodePwd = userMapper.loginPassword(userDO); String encodePwd = userMapper.loginPassword(userDO);
boolean a = BCrypt.checkpw(pwd, encodePwd); if (BCrypt.checkpw(pwd, encodePwd)) {
if(BCrypt.checkpw(pwd, encodePwd))
{
return ResultUtil.success(userMapper.login(userDO)); return ResultUtil.success(userMapper.login(userDO));
}else return ResultUtil.error(ErrorCode.WRONG_PASSWORD); } else return ResultUtil.error(ErrorCode.WRONG_PASSWORD);
} }
} }

View File

@ -6,8 +6,9 @@ import lombok.Getter;
public enum ErrorCode { public enum ErrorCode {
WRONG_PASSWORD("WrongPassword", 40010, "密码错误"), WRONG_PASSWORD("WrongPassword", 40010, "密码错误"),
PARAMETER_ERROR("ParameterError", 40011, "参数错误"), PARAMETER_ERROR("ParameterError", 40011, "参数错误"),
USERNAME_EXIST("UsernameExist", 40012, "用户名已存在"), REQUEST_BODY_ERROR("RequestBodyError", 40012, "请求体错误"),
TIMESTAMP_ERROR("TimestampError", 40013, "时间戳错误"), USERNAME_EXIST("UsernameExist", 40013, "用户名已存在"),
TIMESTAMP_ERROR("TimestampError", 40014, "时间戳错误"),
DATABASE_INSERT_ERROR("DatabaseInsertError", 50010, "数据库插入错误"), DATABASE_INSERT_ERROR("DatabaseInsertError", 50010, "数据库插入错误"),
DATABASE_UPDATE_ERROR("DatabaseUpdateError", 50011, "数据库更新错误"), DATABASE_UPDATE_ERROR("DatabaseUpdateError", 50011, "数据库更新错误"),
DATABASE_DELETE_ERROR("DatabaseDeleteError", 50012, "数据库删除错误"); DATABASE_DELETE_ERROR("DatabaseDeleteError", 50012, "数据库删除错误");

View File

@ -1,8 +1,8 @@
spring: spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306/project url: jdbc:mysql://localhost:3306
username: root username: organize_oa
password: 12345 password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
mybatis: mybatis:
configuration: configuration: