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.zhtj.entity.ZhtjGlqsqkSdqk;
import com.elephant.framework.galaxy.aroad.module.zhtj.service.ZhtjGlqsqkSdqkService;
import com.elephant.framework.galaxy.aroad.response.R;
import com.elephant.framework.galaxy.aroad.module.common.annotation.SysLog;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;


/**
 * 综合统计_公路桥隧情况_隧道情况
 *
 * @author xuyanqi
 * @date 2019-03-11 20:53:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/zhtj/zhtjglqsqksdqk")
public class ZhtjGlqsqkSdqkController extends BaseController  {

  private final ZhtjGlqsqkSdqkService zhtjGlqsqkSdqkService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param zhtjGlqsqkSdqk 综合统计_公路桥隧情况_隧道情况
   * @return
   */
  @GetMapping("/page")
  public R getZhtjGlqsqkSdqkPage(Page page, ZhtjGlqsqkSdqk zhtjGlqsqkSdqk) {
    if(zhtjGlqsqkSdqk.getYear() == null || "".equals(zhtjGlqsqkSdqk.getYear())){
      // 获取最新的时间
      zhtjGlqsqkSdqk.setYear(zhtjGlqsqkSdqkService.newYear());
    }
    return  new R<>(zhtjGlqsqkSdqkService.page(page,Wrappers.query(zhtjGlqsqkSdqk)));
  }


  /**
   * 通过id查询综合统计_公路桥隧情况_隧道情况
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(zhtjGlqsqkSdqkService.getById(id));
  }

  /**
   * 新增综合统计_公路桥隧情况_隧道情况
   * @param zhtjGlqsqkSdqk 综合统计_公路桥隧情况_隧道情况
   * @return R
   */
  @SysLog("新增综合统计_公路桥隧情况_隧道情况")
  @PostMapping
  public R save(@RequestBody ZhtjGlqsqkSdqk zhtjGlqsqkSdqk){
    return new R<>(zhtjGlqsqkSdqkService.save(zhtjGlqsqkSdqk));
  }

  /**
   * 修改综合统计_公路桥隧情况_隧道情况
   * @param zhtjGlqsqkSdqk 综合统计_公路桥隧情况_隧道情况
   * @return R
   */
  @SysLog("修改综合统计_公路桥隧情况_隧道情况")
  @PutMapping
  public R updateById(@RequestBody ZhtjGlqsqkSdqk zhtjGlqsqkSdqk){
    return new R<>(zhtjGlqsqkSdqkService.updateById(zhtjGlqsqkSdqk));
  }

  /**
   * 通过id删除综合统计_公路桥隧情况_隧道情况
   * @param id id
   * @return R
   */
  @SysLog("删除综合统计_公路桥隧情况_隧道情况")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(zhtjGlqsqkSdqkService.removeById(id));
  }

}
