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


/**
 * 路段交通量
 *
 * @author Xingyuyang
 * @date 2019-04-30 10:48:34
 */
@RestController
@AllArgsConstructor
@RequestMapping("/trafficroadsection")
public class TrafficRoadsectionController extends BaseController  {

  private final  TrafficRoadsectionService trafficRoadsectionService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param trafficRoadsection 路段交通量
   * @return
   */
  @GetMapping("/page")
  public R getTrafficRoadsectionPage(Page page, TrafficRoadsection trafficRoadsection) {
    return  new R<>(trafficRoadsectionService.page(page,Wrappers.query(trafficRoadsection)));
  }


  /**
   * 通过id查询路段交通量
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(trafficRoadsectionService.getById(id));
  }

  /**
   * 新增路段交通量
   * @param trafficRoadsection 路段交通量
   * @return R
   */
  @SysLog("新增路段交通量")
  @PostMapping
  public R save(@RequestBody TrafficRoadsection trafficRoadsection){
    return new R<>(trafficRoadsectionService.save(trafficRoadsection));
  }

  /**
   * 修改路段交通量
   * @param trafficRoadsection 路段交通量
   * @return R
   */
  @SysLog("修改路段交通量")
  @PutMapping
  public R updateById(@RequestBody TrafficRoadsection trafficRoadsection){
    return new R<>(trafficRoadsectionService.updateById(trafficRoadsection));
  }

  /**
   * 通过id删除路段交通量
   * @param id id
   * @return R
   */
  @SysLog("删除路段交通量")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(trafficRoadsectionService.removeById(id));
  }

}
