2025.4.15 员工管理
This commit is contained in:
parent
6fd41837ae
commit
21626b0663
@ -6,6 +6,7 @@ package com.sky.constant;
|
|||||||
public class MessageConstant {
|
public class MessageConstant {
|
||||||
|
|
||||||
public static final String PASSWORD_ERROR = "密码错误";
|
public static final String PASSWORD_ERROR = "密码错误";
|
||||||
|
public static final String CHANGE_PASSWORD_ERROR="原始密码错误";
|
||||||
public static final String ACCOUNT_NOT_FOUND = "账号不存在";
|
public static final String ACCOUNT_NOT_FOUND = "账号不存在";
|
||||||
public static final String ACCOUNT_LOCKED = "账号被锁定";
|
public static final String ACCOUNT_LOCKED = "账号被锁定";
|
||||||
public static final String UNKNOWN_ERROR = "未知错误";
|
public static final String UNKNOWN_ERROR = "未知错误";
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.sky.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EmployeeChangePasswordDTO {
|
||||||
|
private Integer empId;
|
||||||
|
private String newPassword;
|
||||||
|
private String oldPassword;
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
package com.sky.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class StartOrStopDTO {
|
|
||||||
private int status;
|
|
||||||
private Long id;
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
import com.sky.constant.JwtClaimsConstant;
|
import com.sky.constant.JwtClaimsConstant;
|
||||||
|
import com.sky.dto.EmployeeChangePasswordDTO;
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.dto.StartOrStopDTO;
|
|
||||||
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.PageResult;
|
||||||
@ -65,8 +65,7 @@ public class EmployeeController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出
|
* 退出
|
||||||
*
|
* 后端不做操作,前端删除token
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
public Result<String> logout() {
|
public Result<String> logout() {
|
||||||
@ -93,28 +92,44 @@ public class EmployeeController {
|
|||||||
PageResult pageResult=employeeService.pageQuery(employeePageQueryDTO);
|
PageResult pageResult=employeeService.pageQuery(employeePageQueryDTO);
|
||||||
return Result.success(pageResult);
|
return Result.success(pageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 禁用/启动员工
|
* 禁用/启动员工
|
||||||
*/
|
*/
|
||||||
@PutMapping("/status")
|
@PostMapping("/status/{status}")
|
||||||
@ApiOperation("禁用/启用")
|
@ApiOperation("禁用/启用")
|
||||||
public Result startOrStop(@RequestBody StartOrStopDTO startOrStopDTO){
|
public Result startOrStop(@PathVariable Integer status, Long id){
|
||||||
employeeService.startOrStop(startOrStopDTO);
|
log.info("启用禁用员工账号:{},{}",status,id);
|
||||||
|
employeeService.startOrStop(status,id);//后绪步骤定义
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 查询用户id信息
|
* 查询员工id信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@ApiOperation("查询用户信息")
|
@ApiOperation("查询员工信息")
|
||||||
public Result<Employee> queryById(@PathVariable Integer id){
|
public Result<Employee> queryById(@PathVariable Long id){
|
||||||
Employee employee=employeeService.queryById(id);
|
Employee employee=employeeService.queryById(id);
|
||||||
return Result.success(employee);
|
return Result.success(employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新员工信息
|
||||||
|
*/
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ApiOperation("修改用户信息")
|
@ApiOperation("修改用户信息")
|
||||||
public Result update(@RequestBody EmployeeDTO employeeDTO){
|
public Result update(@RequestBody EmployeeDTO employeeDTO){
|
||||||
employeeService.update(employeeDTO);
|
employeeService.update(employeeDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*/
|
||||||
|
@PutMapping("/editPassword")
|
||||||
|
@ApiOperation("修改密码")
|
||||||
|
public Result changePassword(@RequestBody EmployeeChangePasswordDTO employeeChangePasswordDTO){
|
||||||
|
employeeService.changePassword(employeeChangePasswordDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,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);
|
BaseContext.setCurrentId(empId);
|
||||||
//3、通过,放行
|
//3、通过,放行
|
||||||
return true;
|
return true;
|
||||||
|
@ -2,7 +2,6 @@ package com.sky.mapper;
|
|||||||
|
|
||||||
import com.sky.annotation.AutoFill;
|
import com.sky.annotation.AutoFill;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.dto.StartOrStopDTO;
|
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.enumeration.OperationType;
|
import com.sky.enumeration.OperationType;
|
||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
@ -34,12 +33,17 @@ public interface EmployeeMapper {
|
|||||||
void save(Employee employee);
|
void save(Employee employee);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页条件查询
|
* 分页+条件查询
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Employee> list(EmployeePageQueryDTO employeePageQueryDTO);
|
List<Employee> list(EmployeePageQueryDTO employeePageQueryDTO);
|
||||||
|
|
||||||
@Select("select * from employee where id=#{id};")
|
@Select("select * from employee where id=#{id};")
|
||||||
Employee queryById(Integer id);
|
Employee queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑员工信息
|
||||||
|
*/
|
||||||
@AutoFill(OperationType.UPDATE)
|
@AutoFill(OperationType.UPDATE)
|
||||||
void update(Employee employee);
|
void update(Employee employee);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.EmployeeChangePasswordDTO;
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.dto.StartOrStopDTO;
|
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
|
|
||||||
@ -20,9 +20,11 @@ public interface EmployeeService {
|
|||||||
|
|
||||||
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||||
|
|
||||||
void startOrStop(StartOrStopDTO startOrStopDTO);
|
void startOrStop(Integer status, Long id);
|
||||||
|
|
||||||
Employee queryById(Integer id);
|
Employee queryById(Long id);
|
||||||
|
|
||||||
void update(EmployeeDTO employeeDTO);
|
void update(EmployeeDTO employeeDTO);
|
||||||
|
|
||||||
|
void changePassword(EmployeeChangePasswordDTO employeeChangePasswordDTO);
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ import com.sky.constant.MessageConstant;
|
|||||||
import com.sky.constant.PasswordConstant;
|
import com.sky.constant.PasswordConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.context.BaseContext;
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.dto.EmployeeChangePasswordDTO;
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.dto.StartOrStopDTO;
|
|
||||||
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;
|
||||||
@ -17,15 +17,16 @@ import com.sky.exception.PasswordErrorException;
|
|||||||
import com.sky.mapper.EmployeeMapper;
|
import com.sky.mapper.EmployeeMapper;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.service.EmployeeService;
|
import com.sky.service.EmployeeService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class EmployeeServiceImpl implements EmployeeService {
|
public class EmployeeServiceImpl implements EmployeeService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -72,10 +73,6 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
Employee employee = new Employee();
|
Employee employee = new Employee();
|
||||||
//对象属性拷贝
|
//对象属性拷贝
|
||||||
BeanUtils.copyProperties(employeeDTO, 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);
|
String encodedPassword=bCryptPasswordEncoder.encode(PasswordConstant.DEFAULT_PASSWORD);
|
||||||
employee.setPassword(encodedPassword);
|
employee.setPassword(encodedPassword);
|
||||||
employee.setStatus(StatusConstant.ENABLE);
|
employee.setStatus(StatusConstant.ENABLE);
|
||||||
@ -87,18 +84,20 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize());
|
PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize());
|
||||||
List<Employee> employeeList=employeeMapper.list(employeePageQueryDTO);
|
List<Employee> employeeList=employeeMapper.list(employeePageQueryDTO);
|
||||||
Page<Employee> p= (Page<Employee>) employeeList;
|
Page<Employee> p= (Page<Employee>) employeeList;
|
||||||
PageResult pageResult=new PageResult(p.getTotal(),p.getResult());
|
return new PageResult(p.getTotal(),p.getResult());
|
||||||
return pageResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startOrStop(StartOrStopDTO startOrStopDTO) {
|
public void startOrStop(Integer status, Long id) {
|
||||||
Employee employee=Employee.builder().status(startOrStopDTO.getStatus()).id(startOrStopDTO.getId()).build();
|
Employee employee = Employee.builder()
|
||||||
|
.status(status)
|
||||||
|
.id(id)
|
||||||
|
.build();
|
||||||
employeeMapper.update(employee);
|
employeeMapper.update(employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Employee queryById(Integer id) {
|
public Employee queryById(Long id) {
|
||||||
Employee employee=employeeMapper.queryById(id);
|
Employee employee=employeeMapper.queryById(id);
|
||||||
return employee;
|
return employee;
|
||||||
}
|
}
|
||||||
@ -108,9 +107,17 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
Employee employee = new Employee();
|
Employee employee = new Employee();
|
||||||
BeanUtils.copyProperties(employeeDTO, employee);
|
BeanUtils.copyProperties(employeeDTO, employee);
|
||||||
|
|
||||||
// employee.setUpdateTime(LocalDateTime.now());
|
|
||||||
// employee.setUpdateUser(BaseContext.getCurrentId());
|
|
||||||
|
|
||||||
employeeMapper.update(employee);
|
employeeMapper.update(employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changePassword(EmployeeChangePasswordDTO employeeChangePasswordDTO) {
|
||||||
|
Employee employee=employeeMapper.queryById(BaseContext.getCurrentId());
|
||||||
|
if(bCryptPasswordEncoder.matches(employeeChangePasswordDTO.getOldPassword(),employee.getPassword())){
|
||||||
|
String encodedPassword = bCryptPasswordEncoder.encode(employeeChangePasswordDTO.getNewPassword());
|
||||||
|
employee.setPassword(encodedPassword);
|
||||||
|
employeeMapper.update(employee);
|
||||||
|
}else
|
||||||
|
throw new PasswordErrorException(MessageConstant.CHANGE_PASSWORD_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user