编辑员工
This commit is contained in:
@@ -115,4 +115,30 @@ public class EmployeeController {
|
||||
employeeService.startOrStop(status,id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询员工
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("根据id查询员工")
|
||||
public Result<Employee> getById(@PathVariable Long id){
|
||||
log.info("根据id查询员工: {}",id);
|
||||
Employee employee = employeeService.getById(id);
|
||||
return Result.success(employee);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑员工信息
|
||||
* @param employeeDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("编辑员工信息")
|
||||
public Result update(@RequestBody EmployeeDTO employeeDTO){
|
||||
log.info("编辑员工信息: {}",employeeDTO);
|
||||
employeeService.update(employeeDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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.springframework.stereotype.Service;
|
||||
|
||||
@Mapper
|
||||
public interface EmployeeMapper {
|
||||
@@ -38,4 +39,7 @@ public interface EmployeeMapper {
|
||||
* @param employee
|
||||
*/
|
||||
void update(Employee employee);
|
||||
|
||||
@Select("select * from employee where id = #{id}")
|
||||
Employee getById(Long id);
|
||||
}
|
||||
|
||||
@@ -34,4 +34,17 @@ public interface EmployeeService {
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
/**
|
||||
* 根据id查询员工
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Employee getById(Long id);
|
||||
|
||||
/**
|
||||
* 编辑员工信息
|
||||
* @param employeeDTO
|
||||
*/
|
||||
void update(EmployeeDTO employeeDTO);
|
||||
}
|
||||
|
||||
@@ -123,4 +123,32 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
employeeMapper.update(employee);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询员工
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Employee getById(Long id) {
|
||||
Employee employee = employeeMapper.getById(id);
|
||||
employee.setPassword("****");
|
||||
return employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑员工信息
|
||||
* @param employeeDTO
|
||||
*/
|
||||
@Override
|
||||
public void update(EmployeeDTO employeeDTO) {
|
||||
Employee employee = new Employee();
|
||||
BeanUtils.copyProperties(employeeDTO, employee);
|
||||
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
BaseContext.removeCurrentId();
|
||||
employeeMapper.update(employee);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user