Compare commits
No commits in common. "13bd3dc21e305ab202e46ef54ee19833d0eb4f6d" and "71f2b5e30a0bc468da899922f0f2b33cd60138c6" have entirely different histories.
13bd3dc21e
...
71f2b5e30a
|
@ -24,5 +24,4 @@ public class MessageConstant {
|
||||||
public static final String ORDER_STATUS_ERROR = "订单状态错误";
|
public static final String ORDER_STATUS_ERROR = "订单状态错误";
|
||||||
public static final String ORDER_NOT_FOUND = "订单不存在";
|
public static final String ORDER_NOT_FOUND = "订单不存在";
|
||||||
|
|
||||||
public static final String ALREADY_EXISTS = "已存在了";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.sky.dto;
|
package com.sky.dto;
|
||||||
|
|
||||||
import com.sky.entity.Employee;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -16,4 +15,5 @@ public class EmployeePageQueryDTO implements Serializable {
|
||||||
|
|
||||||
//每页显示记录数
|
//每页显示记录数
|
||||||
private int pageSize;
|
private int pageSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.sky.entity;
|
package com.sky.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.*;
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -30,7 +32,7 @@ public class Employee implements Serializable {
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy年MM月dd日 HH:mm:ss")
|
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -39,4 +41,5 @@ public class Employee implements Serializable {
|
||||||
private Long createUser;
|
private Long createUser;
|
||||||
|
|
||||||
private Long updateUser;
|
private Long updateUser;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
package com.sky.config;
|
package com.sky.config;
|
||||||
|
|
||||||
import ch.qos.logback.classic.pattern.MessageConverter;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
||||||
import com.sky.json.JacksonObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
@ -20,9 +15,6 @@ import springfox.documentation.service.ApiInfo;
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置类,注册web层相关组件
|
* 配置类,注册web层相关组件
|
||||||
*/
|
*/
|
||||||
|
@ -30,13 +22,13 @@ import java.util.List;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册自定义拦截器
|
* 注册自定义拦截器
|
||||||
*
|
*
|
||||||
* @param registry InterceptorRegistry
|
* @param registry
|
||||||
*/
|
*/
|
||||||
protected void addInterceptors(InterceptorRegistry registry) {
|
protected void addInterceptors(InterceptorRegistry registry) {
|
||||||
log.info("开始注册自定义拦截器...");
|
log.info("开始注册自定义拦截器...");
|
||||||
|
@ -47,8 +39,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过knife4j生成接口文档
|
* 通过knife4j生成接口文档
|
||||||
*
|
* @return
|
||||||
* @return Docket
|
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public Docket docket() {
|
public Docket docket() {
|
||||||
|
@ -68,25 +59,10 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置静态资源映射
|
* 设置静态资源映射
|
||||||
*
|
* @param registry
|
||||||
* @param registry ResourceHandlerRegistry
|
|
||||||
*/
|
*/
|
||||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 扩展Spring MVC框架转换器
|
|
||||||
*
|
|
||||||
* @param converters List<HttpMessageConverter<?>>
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
||||||
super.extendMessageConverters(converters);
|
|
||||||
log.info("扩展消息转换器...");
|
|
||||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
||||||
converter.setObjectMapper(new JacksonObjectMapper());
|
|
||||||
converters.add(0,converter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,20 @@
|
||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
import com.sky.constant.JwtClaimsConstant;
|
import com.sky.constant.JwtClaimsConstant;
|
||||||
import com.sky.constant.PasswordConstant;
|
|
||||||
import com.sky.constant.StatusConstant;
|
|
||||||
import com.sky.dto.EmployeeDTO;
|
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.properties.JwtProperties;
|
import com.sky.properties.JwtProperties;
|
||||||
import com.sky.result.PageResult;
|
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.EmployeeService;
|
import com.sky.service.EmployeeService;
|
||||||
import com.sky.utils.JwtUtil;
|
import com.sky.utils.JwtUtil;
|
||||||
import com.sky.vo.EmployeeLoginVO;
|
import com.sky.vo.EmployeeLoginVO;
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -33,12 +24,11 @@ import java.util.Map;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/employee")
|
@RequestMapping("/admin/employee")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Api(tags = "员工相关接口")
|
|
||||||
public class EmployeeController {
|
public class EmployeeController {
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private EmployeeService employeeService;
|
private EmployeeService employeeService;
|
||||||
@Resource
|
@Autowired
|
||||||
private JwtProperties jwtProperties;
|
private JwtProperties jwtProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,14 +37,13 @@ public class EmployeeController {
|
||||||
* @param employeeLoginDTO
|
* @param employeeLoginDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "员工登录接口")
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
|
public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
|
||||||
log.info("员工登录:{}", employeeLoginDTO);
|
log.info("员工登录:{}", employeeLoginDTO);
|
||||||
|
|
||||||
Employee employee = employeeService.login(employeeLoginDTO);
|
Employee employee = employeeService.login(employeeLoginDTO);
|
||||||
|
|
||||||
// 登录成功后,生成jwt令牌
|
//登录成功后,生成jwt令牌
|
||||||
Map<String, Object> claims = new HashMap<>();
|
Map<String, Object> claims = new HashMap<>();
|
||||||
claims.put(JwtClaimsConstant.EMP_ID, employee.getId());
|
claims.put(JwtClaimsConstant.EMP_ID, employee.getId());
|
||||||
String token = JwtUtil.createJWT(
|
String token = JwtUtil.createJWT(
|
||||||
|
@ -77,36 +66,9 @@ public class EmployeeController {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "员工退出登录")
|
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
public Result<String> logout() {
|
public Result<String> logout() {
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求新增员工
|
|
||||||
*
|
|
||||||
* @param employeeDTO 请求新增员工参数
|
|
||||||
* @return Result
|
|
||||||
*/
|
|
||||||
@Operation(summary = "新增员工")
|
|
||||||
@PostMapping
|
|
||||||
public Result<String> save(@RequestBody EmployeeDTO employeeDTO) {
|
|
||||||
log.info("新增员工:{}", employeeDTO);
|
|
||||||
employeeService.insert(employeeDTO);
|
|
||||||
return Result.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 员工分页查询
|
|
||||||
*
|
|
||||||
* @return Result<PageResult>
|
|
||||||
*/
|
|
||||||
@Operation(summary = "员工分页查询")
|
|
||||||
@GetMapping("/page")
|
|
||||||
public Result<PageResult> pageResultResult(EmployeePageQueryDTO employeePageQueryDTO) {
|
|
||||||
log.info("员工查找,参数为:{}", employeeService);
|
|
||||||
PageResult pageResult = employeeService.pageQuery(employeePageQueryDTO);
|
|
||||||
return Result.success(pageResult);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package com.sky.handler;
|
package com.sky.handler;
|
||||||
|
|
||||||
import com.sky.constant.MessageConstant;
|
|
||||||
import com.sky.exception.BaseException;
|
import com.sky.exception.BaseException;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
import java.sql.SQLIntegrityConstraintViolationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理器,处理项目中抛出的业务异常
|
* 全局异常处理器,处理项目中抛出的业务异常
|
||||||
*/
|
*/
|
||||||
|
@ -27,21 +24,4 @@ public class GlobalExceptionHandler {
|
||||||
return Result.error(ex.getMessage());
|
return Result.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理SQL异常
|
|
||||||
* @param exception SQLIntegrityConstraintViolationException
|
|
||||||
* @return Result<String>
|
|
||||||
*/
|
|
||||||
@ExceptionHandler
|
|
||||||
public Result<String> exceptionHandler(SQLIntegrityConstraintViolationException exception) {
|
|
||||||
String message = exception.getMessage();
|
|
||||||
if (message.contains("Duplicate entry")) {
|
|
||||||
String[] split = message.split(" ");
|
|
||||||
String username = split[2];
|
|
||||||
String msg = username + MessageConstant.ALREADY_EXISTS;
|
|
||||||
return Result.error(msg);
|
|
||||||
} else {
|
|
||||||
return Result.error(MessageConstant.UNKNOWN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.sky.interceptor;
|
package com.sky.interceptor;
|
||||||
|
|
||||||
import com.sky.constant.JwtClaimsConstant;
|
import com.sky.constant.JwtClaimsConstant;
|
||||||
import com.sky.context.BaseContext;
|
|
||||||
import com.sky.properties.JwtProperties;
|
import com.sky.properties.JwtProperties;
|
||||||
import com.sky.utils.JwtUtil;
|
import com.sky.utils.JwtUtil;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
|
@ -10,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@ -22,17 +19,17 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class JwtTokenAdminInterceptor implements HandlerInterceptor {
|
public class JwtTokenAdminInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private JwtProperties jwtProperties;
|
private JwtProperties jwtProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验jwt
|
* 校验jwt
|
||||||
*
|
*
|
||||||
* @param request HttpServletRequest
|
* @param request
|
||||||
* @param response HttpServletResponse
|
* @param response
|
||||||
* @param handler Object
|
* @param handler
|
||||||
* @return boolean
|
* @return
|
||||||
* @throws Exception Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
//判断当前拦截到的是Controller的方法还是其他资源
|
//判断当前拦截到的是Controller的方法还是其他资源
|
||||||
|
@ -49,8 +46,7 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
|
||||||
log.info("jwt校验:{}", token);
|
log.info("jwt校验:{}", token);
|
||||||
Claims claims = JwtUtil.parseJWT(jwtProperties.getAdminSecretKey(), token);
|
Claims claims = JwtUtil.parseJWT(jwtProperties.getAdminSecretKey(), token);
|
||||||
Long empId = Long.valueOf(claims.get(JwtClaimsConstant.EMP_ID).toString());
|
Long empId = Long.valueOf(claims.get(JwtClaimsConstant.EMP_ID).toString());
|
||||||
log.info("当前员工id:{}", empId);
|
log.info("当前员工id:", empId);
|
||||||
BaseContext.setCurrentId(empId);
|
|
||||||
//3、通过,放行
|
//3、通过,放行
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import org.apache.ibatis.annotations.Insert;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
@ -18,16 +15,4 @@ public interface EmployeeMapper {
|
||||||
@Select("select * from employee where username = #{username}")
|
@Select("select * from employee where username = #{username}")
|
||||||
Employee getByUsername(String username);
|
Employee getByUsername(String username);
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入员工数据
|
|
||||||
* @param employee 员工
|
|
||||||
*/
|
|
||||||
void insert(Employee employee);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 员工分页查询
|
|
||||||
* @param employeePageQueryDTO EmployeePageQueryDTO
|
|
||||||
* @return Page<Employee>
|
|
||||||
*/
|
|
||||||
Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,15 @@
|
||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
import com.sky.dto.EmployeeDTO;
|
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.result.PageResult;
|
|
||||||
|
|
||||||
public interface EmployeeService {
|
public interface EmployeeService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 员工登录
|
* 员工登录
|
||||||
* @param employeeLoginDTO 员工请求
|
* @param employeeLoginDTO
|
||||||
* @return Employee
|
* @return
|
||||||
*/
|
*/
|
||||||
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增员工
|
|
||||||
* @param employeeDTO 请求新增员工参数
|
|
||||||
*/
|
|
||||||
void insert(EmployeeDTO employeeDTO);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 员工分页查询
|
|
||||||
* @param employeeLoginDTO EmployeeService
|
|
||||||
* @return PageResult
|
|
||||||
*/
|
|
||||||
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,115 +1,57 @@
|
||||||
package com.sky.service.impl;
|
package com.sky.service.impl;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
|
||||||
import com.github.pagehelper.PageHelper;
|
|
||||||
import com.sky.constant.MessageConstant;
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.constant.PasswordConstant;
|
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.context.BaseContext;
|
|
||||||
import com.sky.dto.EmployeeDTO;
|
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.exception.AccountLockedException;
|
import com.sky.exception.AccountLockedException;
|
||||||
import com.sky.exception.AccountNotFoundException;
|
import com.sky.exception.AccountNotFoundException;
|
||||||
import com.sky.exception.PasswordErrorException;
|
import com.sky.exception.PasswordErrorException;
|
||||||
import com.sky.mapper.EmployeeMapper;
|
import com.sky.mapper.EmployeeMapper;
|
||||||
import com.sky.result.PageResult;
|
|
||||||
import com.sky.service.EmployeeService;
|
import com.sky.service.EmployeeService;
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EmployeeServiceImpl implements EmployeeService {
|
public class EmployeeServiceImpl implements EmployeeService {
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private EmployeeMapper employeeMapper;
|
private EmployeeMapper employeeMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 员工登录
|
* 员工登录
|
||||||
*
|
*
|
||||||
* @param employeeLoginDTO 登录信息
|
* @param employeeLoginDTO
|
||||||
* @return Employee
|
* @return
|
||||||
*/
|
*/
|
||||||
public Employee login(EmployeeLoginDTO employeeLoginDTO) {
|
public Employee login(EmployeeLoginDTO employeeLoginDTO) {
|
||||||
String username = employeeLoginDTO.getUsername();
|
String username = employeeLoginDTO.getUsername();
|
||||||
String password = employeeLoginDTO.getPassword();
|
String password = employeeLoginDTO.getPassword();
|
||||||
|
|
||||||
// 1、根据用户名查询数据库中的数据
|
//1、根据用户名查询数据库中的数据
|
||||||
Employee employee = employeeMapper.getByUsername(username);
|
Employee employee = employeeMapper.getByUsername(username);
|
||||||
|
|
||||||
// 2、处理各种异常情况(用户名不存在、密码不对、账号被锁定)
|
//2、处理各种异常情况(用户名不存在、密码不对、账号被锁定)
|
||||||
if (employee == null) {
|
if (employee == null) {
|
||||||
// 账号不存在
|
//账号不存在
|
||||||
throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND);
|
throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 密码比对
|
//密码比对
|
||||||
password = DigestUtils.md5DigestAsHex(password.getBytes());// Md5加密
|
// TODO 后期需要进行md5加密,然后再进行比对
|
||||||
if (!password.equals(employee.getPassword())) {
|
if (!password.equals(employee.getPassword())) {
|
||||||
// 密码错误
|
//密码错误
|
||||||
throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
|
throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 账号被锁定
|
|
||||||
if (employee.getStatus() == StatusConstant.DISABLE) {
|
if (employee.getStatus() == StatusConstant.DISABLE) {
|
||||||
|
//账号被锁定
|
||||||
throw new AccountLockedException(MessageConstant.ACCOUNT_LOCKED);
|
throw new AccountLockedException(MessageConstant.ACCOUNT_LOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3、返回实体对象
|
//3、返回实体对象
|
||||||
return employee;
|
return employee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入员工数据
|
|
||||||
*
|
|
||||||
* @param employeeDTO EmployeeDTO
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void insert(EmployeeDTO employeeDTO) {
|
|
||||||
Employee employee = new Employee();
|
|
||||||
// 对象属性拷贝
|
|
||||||
BeanUtils.copyProperties(employeeDTO, employee);
|
|
||||||
|
|
||||||
// 设置状态默认1正常,0表示锁定
|
|
||||||
employee.setStatus(StatusConstant.ENABLE);
|
|
||||||
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
|
||||||
employee.setIdNumber(employeeDTO.getIdNumber());
|
|
||||||
|
|
||||||
// 设置当前时间
|
|
||||||
employee.setCreateTime(LocalDateTime.now());
|
|
||||||
employee.setUpdateTime(LocalDateTime.now());
|
|
||||||
|
|
||||||
// 设置当前记录创建人id
|
|
||||||
employee.setCreateUser(BaseContext.getCurrentId());
|
|
||||||
employee.setUpdateUser(BaseContext.getCurrentId());
|
|
||||||
|
|
||||||
employeeMapper.insert(employee);
|
|
||||||
BaseContext.removeCurrentId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 员工分页查询
|
|
||||||
*
|
|
||||||
* @param employeePageQueryDTO EmployeeService
|
|
||||||
* @return PageResult
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO) {
|
|
||||||
PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize());
|
|
||||||
Page<Employee> page = employeeMapper.pageQuery(employeePageQueryDTO);
|
|
||||||
long total = page.getTotal();
|
|
||||||
List<Employee> result = page.getResult();
|
|
||||||
|
|
||||||
return new PageResult(total, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
sky:
|
sky:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
host: 106.15.251.123
|
host: localhost
|
||||||
port: 3305
|
port: 3306
|
||||||
database: sky_take_out
|
database: sky_take_out
|
||||||
username: root
|
username: root
|
||||||
password: "02120212"
|
password: root
|
||||||
|
|
|
@ -2,23 +2,4 @@
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
||||||
|
|
||||||
<!-- 新增员工 -->
|
|
||||||
<insert id="insert">
|
|
||||||
insert into employee (name, username, password, phone, sex, id, id_number, status, create_time, update_time,
|
|
||||||
create_user, update_user)
|
|
||||||
values (#{name}, #{username}, #{password}, #{phone}, #{sex}, #{id}, #{idNumber}, #{status}, #{createTime},
|
|
||||||
#{updateTime}, #{createUser}, #{updateUser});
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<!-- 员工分页查询 -->
|
|
||||||
<select id="pageQuery" resultType="com.sky.entity.Employee">
|
|
||||||
select * from employee
|
|
||||||
<where>
|
|
||||||
<if test="name!='' and name!=null">
|
|
||||||
and name like concat('%',#{name},'%')
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
order by create_time desc
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue