package com.elephant.framework.galaxy.aroad.module.attendance.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.elephant.framework.galaxy.aroad.response.R;
import com.elephant.framework.galaxy.aroad.module.common.annotation.SysLog;
import com.elephant.framework.galaxy.aroad.module.attendance.entity.AttendanceMembers;
import com.elephant.framework.galaxy.aroad.module.attendance.service.AttendanceMembersService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;


/**
 * 值班人员表
 *
 * @author songwenjie
 * @date 2019-04-11 10:09:42
 */
@RestController
@AllArgsConstructor
@RequestMapping("/attendancemembers")
public class AttendanceMembersController extends BaseController  {

  private final  AttendanceMembersService attendanceMembersService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param attendanceMembers 值班人员表
   * @return
   */
  @GetMapping("/page")
  public R getAttendanceMembersPage(Page page, AttendanceMembers attendanceMembers) {
    return  new R<>(attendanceMembersService.page(page,Wrappers.query(attendanceMembers)));
  }


  /**
   * 通过id查询值班人员表
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(attendanceMembersService.getById(id));
  }


  /** 
  * @Description:  获取一次排班中的值班人员信息
  * @Param: [attendanceId] 
  * @return: com.elephant.framework.galaxy.aroad.response.R 
  * @Author: songwenjie 
  * @Date: 2019/4/17 
  */ 
  @GetMapping("/byattendance/{attendanceId}")
  public R getMembers(@PathVariable("attendanceId") int attendanceId){
    return new  R<>(attendanceMembersService.getMembers(attendanceId));
  }


  /**
   * 新增值班人员表
   * @param attendanceMembers 值班人员表
   * @return R
   */
  @SysLog("新增值班人员表")
  @PostMapping
  public R save(@RequestBody AttendanceMembers attendanceMembers){
    return new R<>(attendanceMembersService.save(attendanceMembers));
  }

  /**
   * 修改值班人员表
   * @param attendanceMembers 值班人员表
   * @return R
   */
  @SysLog("修改值班人员表")
  @PutMapping
  public R updateById(@RequestBody AttendanceMembers attendanceMembers){
    return new R<>(attendanceMembersService.updateById(attendanceMembers));
  }

  /**
   * 通过id删除值班人员表
   * @param id id
   * @return R
   */
  @SysLog("删除值班人员表")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(attendanceMembersService.removeById(id));
  }

}
