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.ZhtjGlqsqkQlqk;
import com.elephant.framework.galaxy.aroad.module.zhtj.service.ZhtjGlqsqkQlqkService;
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-12 08:57:24
 */
@RestController
@AllArgsConstructor
@RequestMapping("/zhtj/zhtjglqsqkqlqk")
public class ZhtjGlqsqkQlqkController extends BaseController  {

  private final ZhtjGlqsqkQlqkService zhtjGlqsqkQlqkService;

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


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

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

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

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

}
