package com.elephant.framework.galaxy.aroad.module.emergencyevent.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.emergencyevent.entity.EmergencyEvent;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.service.EmergencyEventService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;


/**
 * 应急事件表
 *
 * @author songwenjie
 * @date 2019-05-08 14:43:42
 */
@RestController
@AllArgsConstructor
@RequestMapping("/emergencyevent")
public class EmergencyEventController extends BaseController  {

  private final  EmergencyEventService emergencyEventService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param emergencyEvent 应急事件表
   * @return
   */
  @GetMapping("/page")
  public R getEmergencyEventPage(Page page, EmergencyEvent emergencyEvent) {
    return  new R<>(emergencyEventService.page(page,Wrappers.query(emergencyEvent)));
  }


  /**
   * 通过id查询应急事件表
   * @param eventId id
   * @return R
   */
  @GetMapping("/{eventId}")
  public R getById(@PathVariable("eventId") Integer eventId){
    return new R<>(emergencyEventService.getById(eventId));
  }

  /**
   * 新增应急事件表
   * @param emergencyEvent 应急事件表
   * @return R
   */
  @SysLog("新增应急事件表")
  @PostMapping
  public R save(@RequestBody EmergencyEvent emergencyEvent){
    return new R<>(emergencyEventService.saveEvent(emergencyEvent));
  }

  /**
   * 修改应急事件表
   * @param emergencyEvent 应急事件表
   * @return R
   */
  @SysLog("修改应急事件表")
  @PutMapping
  public R updateById(@RequestBody EmergencyEvent emergencyEvent){
    return new R<>(emergencyEventService.updateById(emergencyEvent));
  }

  /**
   * 通过id删除应急事件表
   * @param eventId id
   * @return R
   */
  @SysLog("删除应急事件表")
  @DeleteMapping("/{eventId}")
  public R removeById(@PathVariable Integer eventId){
    return new R<>(emergencyEventService.removeById(eventId));
  }

}
