编辑员工

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); employeeService.startOrStop(status,id);
return Result.success(); 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.Insert;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;
@Mapper @Mapper
public interface EmployeeMapper { public interface EmployeeMapper {
@@ -38,4 +39,7 @@ public interface EmployeeMapper {
* @param employee * @param employee
*/ */
void update(Employee 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 * @param id
*/ */
void startOrStop(Integer status, Long 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); 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);
}
} }

View File

@@ -5,15 +5,15 @@
<update id="update" parameterType="Employee"> <update id="update" parameterType="Employee">
update employee update employee
<set> <set>
<if test="name != null">name = #{name}</if> <if test="name != null">name = #{name},</if>
<if test="username != null">username = #{username}</if> <if test="username != null">username = #{username},</if>
<if test="password != null">password = #{password}</if> <if test="password != null">password = #{password},</if>
<if test="phone != null">phone = #{phone}</if> <if test="phone != null">phone = #{phone},</if>
<if test="sex != null">sex = #{sex}</if> <if test="sex != null">sex = #{sex},</if>
<if test="idNumber != null">idNumber = #{idNumber}</if> <if test="idNumber != null">id_number = #{idNumber},</if>
<if test="updateTime != null">updateTime = #{updateTime}</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updateUser != null">updateUser = #{updateUser}</if> <if test="updateUser != null">update_user = #{updateUser},</if>
<if test="status != null">status = #{status}</if> <if test="status != null">status = #{status},</if>
</set> </set>
where id = #{id} where id = #{id}
</update> </update>