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.AttendanceRecords;
import com.elephant.framework.galaxy.aroad.module.attendance.service.AttendanceRecordsService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;


/**
 * 值班通讯录表
 *
 * @author songwenjie
 * @date 2019-04-15 09:34:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("/attendancerecords")
public class AttendanceRecordsController extends BaseController  {

  private final  AttendanceRecordsService attendanceRecordsService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param attendanceRecords 值班通讯录表
   * @return
   */
  @GetMapping("/page")
  public R getAttendanceRecordsPage(Page page, AttendanceRecords attendanceRecords) {
    return  new R<>(attendanceRecordsService.page(page,Wrappers.query(attendanceRecords)));
  }


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

  /**
   * 新增值班通讯录表
   * @param attendanceRecords 值班通讯录表
   * @return R
   */
  @SysLog("新增值班通讯录表")
  @PostMapping
  public R save(@RequestBody AttendanceRecords attendanceRecords){
    return new R<>(attendanceRecordsService.save(attendanceRecords));
  }

  /**
   * 修改值班通讯录表
   * @param attendanceRecords 值班通讯录表
   * @return R
   */
  @SysLog("修改值班通讯录表")
  @PutMapping
  public R updateById(@RequestBody AttendanceRecords attendanceRecords){
    return new R<>(attendanceRecordsService.updateById(attendanceRecords));
  }

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

}
