编辑员工业务代码开发

This commit is contained in:
zvv
2026-03-26 18:41:13 +08:00
parent fe68def5ea
commit 9ac370e8ca
5 changed files with 88 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ import com.sky.result.Result;
import com.sky.service.EmployeeService; import com.sky.service.EmployeeService;
import com.sky.utils.JwtUtil; import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO; import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -120,4 +121,31 @@ public class EmployeeController {
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

@@ -43,4 +43,13 @@ public interface EmployeeMapper {
* @param employee * @param employee
*/ */
void update(Employee employee); void update(Employee employee);
/**
* 根据id查询员工信息
* @param id
* @return
*/
@Select("select * from employee where id = #{id}")
Employee getById(Long id);
} }

View File

@@ -37,4 +37,19 @@ 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

@@ -129,4 +129,31 @@ public class EmployeeServiceImpl implements EmployeeService {
employeeMapper.update(employee); employeeMapper.update(employee);
} }
/**
* 根据id查询员工信息
* @param id
* @return
*/
public Employee getById(Long id) {
Employee employee = employeeMapper.getById(id);
employee.setPassword("******");
return employee;
}
/**
* 编辑员工信息
* @param employeeDTO
*/
public void update(EmployeeDTO employeeDTO) {
Employee employee = new Employee();
BeanUtils.copyProperties(employeeDTO, employee);
employee.setUpdateTime(LocalDateTime.now());
//在拦截器中设置好id
employee.setUpdateUser(BaseContext.getCurrentId());
employeeMapper.update(employee);
}
} }

View File

@@ -19,15 +19,15 @@
<update id="update" parameterType="Employee"> <update id="update" parameterType="Employee">
update employee update employee
<set> <set>
<if test="name != null and name != ''">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">id_number = #{idNumber}</if> <if test="idNumber != null">id_number = #{idNumber},</if>
<if test="updateTime != null">update_time = #{updateTime}</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="createTime != null">create_time = #{createTime}</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>