模块整理ø
This commit is contained in:
parent
4df82ecdcc
commit
93c1e1c2ca
|
@ -1,79 +1,79 @@
|
|||
//package com.jsl.oa.aspect;
|
||||
//
|
||||
//import com.jsl.oa.utils.ErrorCode;
|
||||
//import com.jsl.oa.utils.ResultUtil;
|
||||
//import org.aspectj.lang.ProceedingJoinPoint;
|
||||
//import org.aspectj.lang.annotation.Around;
|
||||
//import org.aspectj.lang.annotation.Aspect;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.context.request.RequestContextHolder;
|
||||
//import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.util.Objects;
|
||||
//
|
||||
///**
|
||||
// * <h1>用户控制器切面</h1>
|
||||
// * <hr/>
|
||||
// * 用于用户控制器的切面
|
||||
// *
|
||||
// * @since v1.0.0
|
||||
// * @version v1.0.0
|
||||
// * @author 筱锋xiao_lfeng
|
||||
// */
|
||||
//@Aspect
|
||||
//@Component
|
||||
//public class UserControllerAspect {
|
||||
//
|
||||
// /**
|
||||
// * <h1>用户控制器切面</h1>
|
||||
// * <hr/>
|
||||
// * 用于用户控制器的切面
|
||||
// *
|
||||
// * @since v1.0.0
|
||||
// * @param pjp ProceedingJoinPoint对象
|
||||
// * @return {@link Object}
|
||||
// * @throws Throwable 异常
|
||||
// */
|
||||
// @Around("execution(* com.jsl.oa.controllers.UserController.*(..))")
|
||||
// public Object controllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||
// // 获取HttpServletRequest对象
|
||||
// HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
//
|
||||
// // 时间戳检查
|
||||
// if (checkTimestamp(request)) {
|
||||
// // TODO: 2023/12/21 0001 后期固定业务(如:日志处理)
|
||||
// return pjp.proceed();
|
||||
// } else {
|
||||
// return ResultUtil.error(ErrorCode.TIMESTAMP_ERROR);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * <h1>时间戳检查</h1>
|
||||
// * <hr/>
|
||||
// * 用于检查时间戳是否合法,合法时间范围正负5秒
|
||||
// *
|
||||
// * @since v1.0.0
|
||||
// * @param request HttpServletRequest对象
|
||||
// * @return {@link Boolean}
|
||||
// */
|
||||
// public Boolean checkTimestamp(HttpServletRequest request) {
|
||||
// // 获取请求头中的时间戳
|
||||
// String getTimestamp = request.getHeader("Timestamp");
|
||||
// // 判断是否为空
|
||||
// if (getTimestamp == null || getTimestamp.isEmpty()) {
|
||||
// return false;
|
||||
// } else {
|
||||
// if (getTimestamp.length() == 10) {
|
||||
// getTimestamp += "000";
|
||||
// }
|
||||
// }
|
||||
// // 获取当前时间戳
|
||||
// long nowTimestamp = System.currentTimeMillis();
|
||||
//
|
||||
// // 时间误差允许前后五秒钟
|
||||
// return nowTimestamp - Long.parseLong(getTimestamp) <= 5000 && nowTimestamp - Long.parseLong(getTimestamp) >= -5000;
|
||||
// }
|
||||
//}
|
||||
package com.jsl.oa.aspect;
|
||||
|
||||
import com.jsl.oa.utils.ErrorCode;
|
||||
import com.jsl.oa.utils.ResultUtil;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <h1>用户控制器切面</h1>
|
||||
* <hr/>
|
||||
* 用于用户控制器的切面
|
||||
*
|
||||
* @since v1.0.0
|
||||
* @version v1.0.0
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class UserControllerAspect {
|
||||
|
||||
/**
|
||||
* <h1>用户控制器切面</h1>
|
||||
* <hr/>
|
||||
* 用于用户控制器的切面
|
||||
*
|
||||
* @since v1.0.0
|
||||
* @param pjp ProceedingJoinPoint对象
|
||||
* @return {@link Object}
|
||||
* @throws Throwable 异常
|
||||
*/
|
||||
@Around("execution(* com.jsl.oa.controllers.UserController.*(..))")
|
||||
public Object controllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||
// 获取HttpServletRequest对象
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
|
||||
// 时间戳检查
|
||||
if (checkTimestamp(request)) {
|
||||
// TODO: 2023/12/21 0001 后期固定业务(如:日志处理)
|
||||
return pjp.proceed();
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.TIMESTAMP_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>时间戳检查</h1>
|
||||
* <hr/>
|
||||
* 用于检查时间戳是否合法,合法时间范围正负5秒
|
||||
*
|
||||
* @since v1.0.0
|
||||
* @param request HttpServletRequest对象
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
public Boolean checkTimestamp(HttpServletRequest request) {
|
||||
// 获取请求头中的时间戳
|
||||
String getTimestamp = request.getHeader("Timestamp");
|
||||
// 判断是否为空
|
||||
if (getTimestamp == null || getTimestamp.isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
if (getTimestamp.length() == 10) {
|
||||
getTimestamp += "000";
|
||||
}
|
||||
}
|
||||
// 获取当前时间戳
|
||||
long nowTimestamp = System.currentTimeMillis();
|
||||
|
||||
// 时间误差允许前后五秒钟
|
||||
return nowTimestamp - Long.parseLong(getTimestamp) <= 5000 && nowTimestamp - Long.parseLong(getTimestamp) >= -5000;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.jsl.oa.common.doData;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
@ -18,6 +19,7 @@ import java.sql.Date;
|
|||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class UserDO {
|
||||
private Integer id;
|
||||
private String userNum;
|
||||
|
@ -29,5 +31,5 @@ public class UserDO {
|
|||
private String filed;
|
||||
private String hometown;
|
||||
private String kind;
|
||||
private String status;
|
||||
private String state;
|
||||
}
|
||||
|
|
23
src/main/java/com/jsl/oa/common/voData/UserLoginVO.java
Normal file
23
src/main/java/com/jsl/oa/common/voData/UserLoginVO.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package com.jsl.oa.common.voData;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* <h1>用户登陆自定义实体类</h1>
|
||||
* <hr/>
|
||||
* 用于处理用户登陆表单输入的数据
|
||||
*
|
||||
* @author 175yunxuan
|
||||
* @version v1.0.0
|
||||
* @since v1.0.0
|
||||
*/
|
||||
@Getter
|
||||
public class UserLoginVO {
|
||||
@Pattern(regexp = "^[0-9A-Z]+$", message = "工号格式错误")
|
||||
private String userNum;
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
}
|
|
@ -6,7 +6,7 @@ import javax.validation.constraints.NotBlank;
|
|||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* <h1>用户登陆自定义实体类</h1>
|
||||
* <h1>用户注册自定义实体类</h1>
|
||||
* <hr/>
|
||||
* 用于处理用户注册表单输入的数据
|
||||
*
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jsl.oa.controllers;
|
||||
|
||||
import com.jsl.oa.common.doData.UserDO;
|
||||
import com.jsl.oa.common.voData.UserLoginVO;
|
||||
import com.jsl.oa.common.voData.UserRegisterVO;
|
||||
import com.jsl.oa.services.UserService;
|
||||
import com.jsl.oa.utils.BaseResponse;
|
||||
|
@ -44,13 +44,13 @@ public class UserController {
|
|||
* 用户登录接口
|
||||
*
|
||||
* @since v1.0.0
|
||||
* @param userDO 用户登录信息
|
||||
* @param userLoginVO 用户登录信息
|
||||
* @return {@link BaseResponse}
|
||||
* @author 176yunxuan
|
||||
*/
|
||||
@PostMapping("/user/login")
|
||||
public BaseResponse userLogin(@RequestBody UserDO userDO){
|
||||
public BaseResponse userLogin(@RequestBody UserLoginVO userLoginVO){
|
||||
|
||||
return userService.userLogin(userDO);
|
||||
return userService.userLogin(userLoginVO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.jsl.oa.mapper;
|
||||
|
||||
import com.jsl.oa.common.doData.UserDO;
|
||||
import com.jsl.oa.common.voData.UserLoginVO;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
@ -16,12 +17,12 @@ public interface UserMapper {
|
|||
|
||||
@Insert("INSERT INTO organize_oa.users (user_num, username, password, sex, age, unit, field, hometown, kind, state) " +
|
||||
"VALUES " +
|
||||
"(#{userNum}, #{username}, #{password}, #{sex}, #{age}, #{unit}, #{filed}, #{hometown}, #{kind}, #{status})")
|
||||
"(#{userNum}, #{username}, #{password}, #{sex}, #{age}, #{unit}, #{filed}, #{hometown}, #{kind}, #{state})")
|
||||
Boolean insertUser(UserDO userDO);
|
||||
|
||||
@Select("select * from users where user_num = #{userNum} ")
|
||||
UserDO login(UserDO userDO);
|
||||
@Select("select id, user_num, username, sex, age, unit, field, hometown, kind, state from organize_oa.users where user_num = #{userNum} ")
|
||||
UserDO login(UserLoginVO userLoginVO);
|
||||
|
||||
@Select("select password from users where user_num = #{userNum}")
|
||||
String loginPassword(UserDO userDO);
|
||||
@Select("select password from organize_oa.users where user_num = #{userNum}")
|
||||
String loginPassword(UserLoginVO userLoginVO);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jsl.oa.services;
|
||||
|
||||
import com.jsl.oa.common.doData.UserDO;
|
||||
import com.jsl.oa.common.voData.UserLoginVO;
|
||||
import com.jsl.oa.common.voData.UserRegisterVO;
|
||||
import com.jsl.oa.utils.BaseResponse;
|
||||
|
||||
|
@ -9,5 +9,5 @@ import java.text.ParseException;
|
|||
public interface UserService {
|
||||
BaseResponse userRegister(UserRegisterVO userRegisterVO) throws ParseException;
|
||||
|
||||
BaseResponse userLogin(UserDO userDO);
|
||||
BaseResponse userLogin(UserLoginVO userLoginVO);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.jsl.oa.services;
|
||||
|
||||
import com.jsl.oa.common.doData.UserDO;
|
||||
import com.jsl.oa.common.voData.UserLoginVO;
|
||||
import com.jsl.oa.common.voData.UserRegisterVO;
|
||||
import com.jsl.oa.exception.BusinessException;
|
||||
import com.jsl.oa.mapper.UserMapper;
|
||||
|
@ -36,7 +37,7 @@ public class UserServiceImpl implements UserService {
|
|||
UserDO getUserByUsername = userMapper.getUserByUsername(userRegisterVO.getUsername());
|
||||
// 用户名已存在
|
||||
if (getUserByUsername != null) {
|
||||
return ResultUtil.error(ErrorCode.USERNAME_EXIST);
|
||||
return ResultUtil.error(ErrorCode.USER_EXIST);
|
||||
}
|
||||
|
||||
// 生成工号
|
||||
|
@ -57,21 +58,22 @@ public class UserServiceImpl implements UserService {
|
|||
.setFiled(userRegisterVO.getFiled())
|
||||
.setHometown(userRegisterVO.getHometown())
|
||||
.setKind("注册用户")
|
||||
.setStatus("注册状态");
|
||||
.setState("注册状态");
|
||||
// 插入数据
|
||||
if (userMapper.insertUser(userDO)) {
|
||||
return ResultUtil.success("注册成功");
|
||||
userDO.setPassword(null);
|
||||
return ResultUtil.success("注册成功", userDO);
|
||||
} else {
|
||||
throw new BusinessException(ErrorCode.DATABASE_INSERT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse userLogin(UserDO userDO) {
|
||||
String pwd = userDO.getPassword();
|
||||
String encodePwd = userMapper.loginPassword(userDO);
|
||||
public BaseResponse userLogin(UserLoginVO userLoginVO) {
|
||||
String pwd = userLoginVO.getPassword();
|
||||
String encodePwd = userMapper.loginPassword(userLoginVO);
|
||||
if (BCrypt.checkpw(pwd, encodePwd)) {
|
||||
return ResultUtil.success(userMapper.login(userDO));
|
||||
return ResultUtil.success("登陆成功", userMapper.login(userLoginVO));
|
||||
} else return ResultUtil.error(ErrorCode.WRONG_PASSWORD);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ public enum ErrorCode {
|
|||
WRONG_PASSWORD("WrongPassword", 40010, "密码错误"),
|
||||
PARAMETER_ERROR("ParameterError", 40011, "参数错误"),
|
||||
REQUEST_BODY_ERROR("RequestBodyError", 40012, "请求体错误"),
|
||||
USERNAME_EXIST("UsernameExist", 40013, "用户名已存在"),
|
||||
USER_EXIST("UserExist", 40013, "用户名已存在"),
|
||||
TIMESTAMP_ERROR("TimestampError", 40014, "时间戳错误"),
|
||||
USER_NOT_EXIST("UserNotExist", 40015, "用户不存在"),
|
||||
DATABASE_INSERT_ERROR("DatabaseInsertError", 50010, "数据库插入错误"),
|
||||
DATABASE_UPDATE_ERROR("DatabaseUpdateError", 50011, "数据库更新错误"),
|
||||
DATABASE_DELETE_ERROR("DatabaseDeleteError", 50012, "数据库删除错误");
|
||||
|
|
Loading…
Reference in New Issue
Block a user