Bootstrap

苍穹外卖学习笔记(三)

三.启用禁用员工账号

  1. controller
  /**
     * 修改员工状态
     *
     * @param id
     * @param status
     * @return
     */
    @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();
    }
  1. service
 /**
     * 修改员工状态
     * @param
     * @return
     */
    void startOrStop(Long id, Integer status);
  1. impl
   /**
     * 修改员工状态
     *
     * @param id
     * @param status
     * @return
     */
    @Override
    public void startOrStop(Long id, Integer status) {
//        Employee employee = new Employee();
//        employee.setId(id);
//        employee.setStatus(status);
//        employee.setUpdateTime(LocalDateTime.now());
//        employee.setUpdateUser(BaseContext.getCurrentId());
        Employee employee = Employee.builder()
                .id(id)
                .status(status)
                .updateTime(LocalDateTime.now())
                .updateUser(BaseContext.getCurrentId())
                .build();
        employeeMapper.updateById(employee);
    }

四.编辑员工

  1. controller
/**
     * 根据id查询员工
     *
     * @param id
     * @return
     */
    @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);
    }

    /**
     * 修改员工
     *
     * @param employeeDTO
     */
    @PutMapping()
    @ApiOperation("修改员工")
    public Result update(@RequestBody EmployeeDTO employeeDTO) {
        log.info("修改员工:{}", employeeDTO);
        employeeService.update(employeeDTO);
        return Result.success();
    }
  1. service
   /**
     * 根据id查询员工
     * @param id
     * @return
     */
    Employee getById(Long id);

    /**
     * 修改员工
     * @param employeeDTO
     */
    void update(EmployeeDTO employeeDTO);
  1. impl
/**
     * 根据id查询员工
     *
     * @param id
     * @return
     */
    @Override
    public Employee getById(Long id) {
        Employee employee = employeeMapper.selectById(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());
        employeeMapper.updateById(employee);
    }
;