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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.elephant.framework.galaxy.aroad.module.common.annotation.SysLog;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.dto.EventStatusDto;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.entity.EmergencyEvent;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.service.EmergencyEventService;
import com.elephant.framework.galaxy.aroad.response.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 应急事件表
 *
 * @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.getEventPage(page,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));
  }

  /**
   * 新增应急事件表(路况事件导入，返回ID)
   * @param emergencyEvent 应急事件表
   * @return R
   */
  @SysLog("新增应急事件表")
  @PostMapping("/setemergency")
  public R setEmergency(@RequestBody EmergencyEvent emergencyEvent){
    return new R<>(emergencyEventService.joinEvent(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));
  }


 /**
 * @Description: 更新评估总结文档信息
 * @param: [event]
 * @return: com.elephant.framework.galaxy.aroad.response.R
 * @Author: songwenjie
 * @Date: 2019/5/16
 */
  @PutMapping("/updateFile")
  public R updateFile(@RequestBody EmergencyEvent event){
    return new R<>(emergencyEventService.updateFile(event));
  }

  @PutMapping("/updateStatus")
  public R updateStatus(@RequestBody EventStatusDto event){
    return new R<>(
            emergencyEventService.updateStatus(event.getEventId(),event.getNewStatus(),event.getOldStatus()));
  }
}
