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.module.attendance.dto.MemberDto;
import com.elephant.framework.galaxy.aroad.module.attendance.dto.SaveAttendanceDto;
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.Attendance;
import com.elephant.framework.galaxy.aroad.module.attendance.service.AttendanceService;
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:46
 */
@RestController
@AllArgsConstructor
@RequestMapping("/attendance")
public class AttendanceController extends BaseController  {

  private final  AttendanceService attendanceService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param attendance 排班表
   * @return
   */
  @GetMapping("/page")
  public R getAttendancePage(Page page, Attendance attendance) {
    return  new R<>(attendanceService.page(page,Wrappers.query(attendance)));
  }


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

  /** 
  * @Description: 查询部门下的排班计划
  * @Param: [deptId] 
  * @return: com.elephant.framework.galaxy.aroad.response.R 
  * @Author: songwenjie 
  * @Date: 2019/4/17
  */ 
  @GetMapping("/list/{deptId}")
  public R getAttance(@PathVariable("deptId") Integer deptId){
    return new R<>(attendanceService.getAttendance(deptId));
  }

  /**
   * 新增排班表
   * @param attendance 排班表
   * @return R
   */
  @SysLog("新增排班表")
  @PostMapping
  public R save(@RequestBody Attendance attendance){
    return new R<>(attendanceService.save(attendance));
  }

  /** 
  * @Description:  系统选择值班人员添加排班
  * @Param: [attendance] 
  * @return: com.elephant.framework.galaxy.aroad.response.R 
  * @Author: songwenjie 
  * @Date: 2019/4/18 
  */ 
  @PostMapping("/autosave")
  public R autoSave(@RequestBody SaveAttendanceDto<Integer> attendance){
    return new R<>(attendanceService.autoSave(attendance));
  }

  /** 
  * @Description: 手动输入
  * @Param: [attendance] 
  * @return: com.elephant.framework.galaxy.aroad.response.R 
  * @Author: songwenjie 
  * @Date: 2019/4/18 
  */ 
  @PostMapping("/manualsave")
  public R manualSave(@RequestBody SaveAttendanceDto<MemberDto> attendance){
    return new R<>(attendanceService.manualSave(attendance));
  }

  /**
   * 修改排班表
   * @param attendance 排班表
   * @return R
   */
  @SysLog("修改排班表")
  @PutMapping
  public R updateById(@RequestBody Attendance attendance){
    return new R<>(attendanceService.updateById(attendance));
  }

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

}
