package com.elephant.framework.galaxy.aroad.module.roadcondition.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.roadcondition.entity.RoadConditionEvent;
import com.elephant.framework.galaxy.aroad.module.roadcondition.service.RoadConditionEventService;
import com.elephant.framework.galaxy.aroad.response.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

  private final RoadConditionEventService roadConditionEventService;

  /**
   * 分页查询
   *
   * @param page 分页对象
   * @param roadConditionEvent 路况事件统计
   * @return
   */
  @PostMapping("/page")
  public R getRoadConditionEventPage(
      Page page, @RequestBody RoadConditionEvent roadConditionEvent) {
    //        log.error("接收实体：{}", roadConditionEvent);
    page.setCurrent(roadConditionEvent.getCurrent());
    return new R<>(roadConditionEventService.getRoadConditionEventPage(page, 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("/location")
//  public R locatioinOnMap() {
//    return new R<>(roadConditionEventService.locatioinOnMap());
//  }

  /**
   * @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());
  }

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

  /**
   * @Description: 查询市/局树 @Param: []
   *
   * @return: com.elephant.framework.galaxy.travel.response.R @Author: XingYuyang @Date: 2019/4/10
   */
  @GetMapping("/tree")
  public R getTree() {
    return new R<>(roadConditionEventService.getTree());
  }

  /**
   * 通过id查询路况事件统计
   *
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id) {
//    Integer idi = Integer.parseInt(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));
  }
}
