编辑员工

This commit is contained in:
slhaf
2024-09-10 13:25:41 +08:00
parent 46491d98a7
commit f9f2a66022
5 changed files with 80 additions and 9 deletions

View File

@@ -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();
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}
}