second_commit
This commit is contained in:
parent
c3933a36e9
commit
4e69f59a56
@ -23,5 +23,5 @@ public class MessageConstant {
|
||||
public static final String DISH_BE_RELATED_BY_SETMEAL = "当前菜品关联了套餐,不能删除";
|
||||
public static final String ORDER_STATUS_ERROR = "订单状态错误";
|
||||
public static final String ORDER_NOT_FOUND = "订单不存在";
|
||||
|
||||
public static final String ALREADY_EXISTS = "已存在";
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKN
|
||||
public class JacksonObjectMapper extends ObjectMapper {
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
||||
//public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm";
|
||||
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
// public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm";
|
||||
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
|
||||
|
||||
public JacksonObjectMapper() {
|
||||
|
9
sky-pojo/src/main/java/com/sky/dto/StartOrStopDTO.java
Normal file
9
sky-pojo/src/main/java/com/sky/dto/StartOrStopDTO.java
Normal file
@ -0,0 +1,9 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StartOrStopDTO {
|
||||
private int status;
|
||||
private int id;
|
||||
}
|
@ -95,7 +95,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
@ -115,6 +114,15 @@
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.4.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.sky.config;
|
||||
|
||||
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
||||
import com.sky.json.JacksonObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
@ -15,6 +18,8 @@ import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配置类,注册web层相关组件
|
||||
*/
|
||||
@ -65,4 +70,19 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
|
||||
/**
|
||||
*扩展spring mvc消息转化器
|
||||
* @param converters
|
||||
*/
|
||||
@Override
|
||||
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
log.info("扩展消息转换器...");
|
||||
//创建一个消息转换器对象
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
//需要为消息转换器设置一个对象转换器,对象转换器可以将Java对象序列化为json数据
|
||||
converter.setObjectMapper(new JacksonObjectMapper());
|
||||
//将自己的消息转化器加入容器中
|
||||
converters.add(0,converter);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.sky.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests()
|
||||
.anyRequest().permitAll() // 允许所有请求
|
||||
.and()
|
||||
.csrf().disable(); // 禁用CSRF保护
|
||||
}
|
||||
@Bean
|
||||
public BCryptPasswordEncoder encoder(){
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
@ -1,19 +1,21 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.dto.StartOrStopDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.EmployeeService;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import com.sky.vo.EmployeeLoginVO;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -71,4 +73,33 @@ public class EmployeeController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增员工
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增员工")
|
||||
public Result save(@RequestBody EmployeeDTO employeeDTO){
|
||||
log.info("新增员工:{}",employeeDTO);
|
||||
employeeService.save(employeeDTO);
|
||||
return Result.success();
|
||||
}
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页查询")
|
||||
public Result<PageResult> list(EmployeePageQueryDTO employeePageQueryDTO){
|
||||
log.info("分页查询:{}",employeePageQueryDTO);
|
||||
PageResult pageResult=employeeService.pageQuery(employeePageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
/**
|
||||
* 禁用/启动员工
|
||||
*/
|
||||
@PutMapping("/status")
|
||||
@ApiOperation("禁用/启用")
|
||||
public Result startOrStop(@RequestBody StartOrStopDTO startOrStopDTO){
|
||||
employeeService.startOrStop(startOrStopDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.sky.handler;
|
||||
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.exception.BaseException;
|
||||
import com.sky.result.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
|
||||
/**
|
||||
* 全局异常处理器,处理项目中抛出的业务异常
|
||||
*/
|
||||
@ -23,5 +26,18 @@ public class GlobalExceptionHandler {
|
||||
log.error("异常信息:{}", ex.getMessage());
|
||||
return Result.error(ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
public Result exceptionHandler(SQLIntegrityConstraintViolationException ex){
|
||||
//Duplicate entry 'zhangsan' for key 'employee.idx_username'
|
||||
String message = ex.getMessage();
|
||||
log.info(message);
|
||||
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,6 +1,7 @@
|
||||
package com.sky.interceptor;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
@ -47,6 +48,7 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
|
||||
Claims claims = JwtUtil.parseJWT(jwtProperties.getAdminSecretKey(), token);
|
||||
Long empId = Long.valueOf(claims.get(JwtClaimsConstant.EMP_ID).toString());
|
||||
log.info("当前员工id:", empId);
|
||||
BaseContext.setCurrentId(empId);
|
||||
//3、通过,放行
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
|
@ -1,8 +1,14 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.dto.StartOrStopDTO;
|
||||
import com.sky.entity.Employee;
|
||||
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 EmployeeMapper {
|
||||
@ -15,4 +21,20 @@ public interface EmployeeMapper {
|
||||
@Select("select * from employee where username = #{username}")
|
||||
Employee getByUsername(String username);
|
||||
|
||||
/**
|
||||
* 新增员工
|
||||
* @param employee
|
||||
*/
|
||||
@Insert("insert into employee (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user,status) " +
|
||||
"values " +
|
||||
"(#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})")
|
||||
void save(Employee employee);
|
||||
|
||||
/**
|
||||
* 分页条件查询
|
||||
* @return
|
||||
*/
|
||||
List<Employee> list(EmployeePageQueryDTO employeePageQueryDTO);
|
||||
@Update("update employee set status=#{status} where id=#{id}")
|
||||
void startOrStop(StartOrStopDTO startOrStopDTO);
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.dto.StartOrStopDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.result.PageResult;
|
||||
|
||||
public interface EmployeeService {
|
||||
|
||||
@ -12,4 +16,9 @@ public interface EmployeeService {
|
||||
*/
|
||||
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
||||
|
||||
void save(EmployeeDTO employeeDTO);
|
||||
|
||||
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||
|
||||
void startOrStop(StartOrStopDTO startOrStopDTO);
|
||||
}
|
||||
|
@ -1,23 +1,37 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.PasswordConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.dto.StartOrStopDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.exception.AccountLockedException;
|
||||
import com.sky.exception.AccountNotFoundException;
|
||||
import com.sky.exception.PasswordErrorException;
|
||||
import com.sky.mapper.EmployeeMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.EmployeeService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@Autowired
|
||||
private EmployeeMapper employeeMapper;
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
/**
|
||||
* 员工登录
|
||||
@ -40,7 +54,7 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
//密码比对
|
||||
// TODO 后期需要进行md5加密,然后再进行比对
|
||||
if (!password.equals(employee.getPassword())) {
|
||||
if (!bCryptPasswordEncoder.matches(password,employee.getPassword())) {
|
||||
//密码错误
|
||||
throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
|
||||
}
|
||||
@ -54,4 +68,32 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
return employee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(EmployeeDTO employeeDTO) {
|
||||
Employee employee = new Employee();
|
||||
//对象属性拷贝
|
||||
BeanUtils.copyProperties(employeeDTO, employee);
|
||||
employee.setCreateTime(LocalDateTime.now());
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
employee.setCreateUser(BaseContext.getCurrentId());
|
||||
String encodedPassword=bCryptPasswordEncoder.encode(PasswordConstant.DEFAULT_PASSWORD);
|
||||
employee.setPassword(encodedPassword);
|
||||
employee.setStatus(StatusConstant.ENABLE);
|
||||
employeeMapper.save(employee);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO) {
|
||||
PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize());
|
||||
List<Employee> employeeList=employeeMapper.list(employeePageQueryDTO);
|
||||
Page<Employee> p= (Page<Employee>) employeeList;
|
||||
PageResult pageResult=new PageResult(p.getTotal(),p.getResult());
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startOrStop(StartOrStopDTO startOrStopDTO) {
|
||||
employeeMapper.startOrStop(startOrStopDTO);
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,4 @@ sky:
|
||||
port: 3306
|
||||
database: sky_take_out
|
||||
username: root
|
||||
password: root
|
||||
password: 123456
|
||||
|
@ -2,4 +2,13 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
||||
<select id="list" resultType="com.sky.entity.Employee">
|
||||
select * from employee
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
and name like concat('%',#{name},'%')
|
||||
</if>
|
||||
</where>
|
||||
order by update_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user