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


/**
 * 路况事件统计
 *
 * @author Xingyuyang
 * @date 2019-04-23 16:41:06
 */
@RestController
@AllArgsConstructor
@RequestMapping("/roadconditionevent")
public class RoadConditionEventController extends BaseController  {

  private final  RoadConditionEventService roadConditionEventService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param roadConditionEvent 路况事件统计
   * @return
   */
  @GetMapping("/page")
  public R getRoadConditionEventPage(Page page, RoadConditionEvent roadConditionEvent) {
    return  new R<>(roadConditionEventService.page(page,Wrappers.query(roadConditionEvent)));
  }

  /**
   *
   * @description : 根据事件类型统计
   * @author : Xingyuyang
   * @date : 2019/4/23 0023 17:33
   * @param
   * @return : null
   *
   */
  @GetMapping("/eventtype")
  public R staticByEventType(){
    return new R<>(roadConditionEventService.staticByEventType());
  }

  /**
   *
   * @description : 根据影响程度统计
   * @author : Xingyuyang
   * @date : 2019/4/23 0023 17:33
   * @param
   * @return : null
   *
   */
  @GetMapping("/influence")
  public R staticByInfluence(){
    return new R<>(roadConditionEventService.staticByInfluence());
  }

  /**
   *
   * @description : 根据月份统计
   * @author : Xingyuyang
   * @date : 2019-4-24 10:26:49
   * @param
   * @return : null
   *
   */
  @GetMapping("/month")
  public R staticByMonth(){
    return new R<>(roadConditionEventService.staticByMonth());
  }

  /**
   *
   * @description : 根据路段编码统计
   * @author : Xingyuyang
   * @date : 2019-4-24 10:26:49
   * @param
   * @return : null
   *
   */
  @GetMapping("/roadcode")
  public R staticByRoadCode(){
    return new R<>(roadConditionEventService.staticByRoadCode());
  }

  /**
   *
   * @description : 根据路段编码统计
   * @author : Xingyuyang
   * @date : 2019-4-24 10:26:49
   * @param
   * @return : null
   *
   */
  @GetMapping("/city")
  public R staticByCity(){
    return new R<>(roadConditionEventService.staticByCity());
  }

  /**
   * 通过id查询路况事件统计
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(roadConditionEventService.getById(id));
  }

  /**
   * 新增路况事件统计
   * @param roadConditionEvent 路况事件统计
   * @return R
   */
  @SysLog("新增路况事件统计")
  @PostMapping
  public R save(@RequestBody RoadConditionEvent roadConditionEvent){
    return new R<>(roadConditionEventService.save(roadConditionEvent));
  }

  /**
   * 修改路况事件统计
   * @param roadConditionEvent 路况事件统计
   * @return R
   */
  @SysLog("修改路况事件统计")
  @PutMapping
  public R updateById(@RequestBody RoadConditionEvent roadConditionEvent){
    return new R<>(roadConditionEventService.updateById(roadConditionEvent));
  }

  /**
   * 通过id删除路况事件统计
   * @param id id
   * @return R
   */
  @SysLog("删除路况事件统计")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(roadConditionEventService.removeById(id));
  }

}
