三.启用禁用员工账号
- controller
@PostMapping("/status/{status}")
@ApiOperation("修改员工状态")
public Result startOrStop(Long id, @PathVariable Integer status) {
log.info("修改员工状态:id={},status={}", id, status);
employeeService.startOrStop(id, status);
return Result.success();
}
- service
void startOrStop(Long id, Integer status);
- impl
@Override
public void startOrStop(Long id, Integer status) {
Employee employee = Employee.builder()
.id(id)
.status(status)
.updateTime(LocalDateTime.now())
.updateUser(BaseContext.getCurrentId())
.build();
employeeMapper.updateById(employee);
}
四.编辑员工
- controller
@GetMapping("/{id}")
@ApiOperation("根据id查询员工")
public Result<Employee> getById(@PathVariable Long id) {
log.info("根据id查询员工:id={}", id);
Employee employee = employeeService.getById(id);
return Result.success(employee);
}
@PutMapping()
@ApiOperation("修改员工")
public Result update(@RequestBody EmployeeDTO employeeDTO) {
log.info("修改员工:{}", employeeDTO);
employeeService.update(employeeDTO);
return Result.success();
}
- service
Employee getById(Long id);
void update(EmployeeDTO employeeDTO);
- impl
@Override
public Employee getById(Long id) {
Employee employee = employeeMapper.selectById(id);
employee.setPassword("********");
return employee;
}
@Override
public void update(EmployeeDTO employeeDTO) {
Employee employee = new Employee();
BeanUtils.copyProperties(employeeDTO, employee);
employee.setUpdateTime(LocalDateTime.now());
employee.setUpdateUser(BaseContext.getCurrentId());
employeeMapper.updateById(employee);
}