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.AttendanceTemplateDto;
import com.elephant.framework.galaxy.aroad.module.attendance.vo.AttendanceTemplateVo;
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.AttendanceTemplates;
import com.elephant.framework.galaxy.aroad.module.attendance.service.AttendanceTemplatesService;
import com.elephant.framework.galaxy.aroad.util.JsonUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;

import java.util.List;


/**
 * 班次表
 *
 * @author songwenjie
 * @date 2019-04-11 10:09:35
 */
@RestController
@AllArgsConstructor
@RequestMapping("/attendancetemplates")
public class AttendanceTemplatesController extends BaseController  {

  private final  AttendanceTemplatesService attendanceTemplatesService;

  /**
   * 分页查询
   * @param page 分页对象
   * @return
   */
  @GetMapping("/page")
  public R getAttendanceTemplatesPage(Page page,Integer unitId) {
    return  new R<>(attendanceTemplatesService.getShiftPage(page,unitId));
  }


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


  /** 
  * @Description: 查询值班班次信息（用于下拉列表）
  * @Param: [] 
  * @return: com.elephant.framework.galaxy.aroad.response.R 
  * @Author: songwenjie 
  * @Date: 2019/4/15 
  */
  @GetMapping("/shiftselection/{unitId}")
  public R getShiftSelection(@PathVariable("unitId") Integer unitId){
    return new R<>(attendanceTemplatesService.getShiftSelection(unitId));
  }
  

  /**
   * 新增班次表
   * @param template 班次表
   * @return R
   */
  @SysLog("新增班次表")
  @PostMapping
  public R save(@RequestBody AttendanceTemplates template) throws Exception {
    return new R<>(attendanceTemplatesService.save(template));
  }

  /**
   * 修改班次表
   * @param template 班次表
   * @return R
   */
  @SysLog("修改班次表")
  @PutMapping
  public R updateById(@RequestBody AttendanceTemplates template) throws Exception{
    return new R<>(attendanceTemplatesService.updateById(template));
  }

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

}
