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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.zhtj.entity.ZhtjGljsdjqk;
import com.elephant.framework.galaxy.aroad.module.zhtj.entity.ZhtjGllmqk;
import com.elephant.framework.galaxy.aroad.module.zhtj.service.ZhtjGllmqkService;
import com.elephant.framework.galaxy.aroad.response.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 综合统计_公路路面情况
 *
 * @author xuyanqi
 * @date 2019-03-12 11:04:15
 */
@RestController
@AllArgsConstructor
@RequestMapping("/zhtj/zhtjgllmqk")
public class ZhtjGllmqkController extends BaseController  {

  private final  ZhtjGllmqkService zhtjGllmqkService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param zhtjGllmqk 综合统计_公路路面情况
   * @return
   */
  @GetMapping("/page")
  public R getZhtjGllmqkPage(Page page, ZhtjGllmqk zhtjGllmqk) {
    if(zhtjGllmqk.getYear() == null || "".equals(zhtjGllmqk.getYear())){
      // 获取最新的时间
      zhtjGllmqk.setYear(zhtjGllmqkService.newYear(zhtjGllmqk.getType()));
    }
    return  new R<>(zhtjGllmqkService.page(page,Wrappers.query(zhtjGllmqk)));
  }
  /**
   *  获取总体情况柱状图统计信息
   */
  @GetMapping("/barzt")
  public R getBarZtData(@RequestParam("type") String type,@RequestParam("year") String year){

     return  new R <>(zhtjGllmqkService.getBarZtData(type,year));
  }

  @GetMapping("/ordinary")
  public R getOrdinary(@RequestParam("type") String type,@RequestParam("year")String year,@RequestParam("area")String area){
    return  new R <>(zhtjGllmqkService.getOrdinary(type,year,area));
  }
  /**
   * 通过id查询综合统计_公路路面情况
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(zhtjGllmqkService.getById(id));
  }

  /**
   * 新增综合统计_公路路面情况
   * @param zhtjGllmqk 综合统计_公路路面情况
   * @return R
   */
  @SysLog("新增综合统计_公路路面情况")
  @PostMapping
  public R save(@RequestBody ZhtjGllmqk zhtjGllmqk){
    return new R<>(zhtjGllmqkService.save(zhtjGllmqk));
  }

  /**
   * 修改综合统计_公路路面情况
   * @param zhtjGllmqk 综合统计_公路路面情况
   * @return R
   */
  @SysLog("修改综合统计_公路路面情况")
  @PutMapping
  public R updateById(@RequestBody ZhtjGllmqk zhtjGllmqk){
    return new R<>(zhtjGllmqkService.updateById(zhtjGllmqk));
  }

  /**
   * 通过id删除综合统计_公路路面情况
   * @param id id
   * @return R
   */
  @SysLog("删除综合统计_公路路面情况")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(zhtjGllmqkService.removeById(id));
  }
  /**
   * 公路覆蓋情況統計
   */
  @GetMapping("/glfgqktj")
  public R getGlfgqktj(){
    System.out.println("pppppppp");
    return new R<>(zhtjGllmqkService.getGlfgqktj());
  }
}
