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.ZhtjGljbxxXxctdqk;
import com.elephant.framework.galaxy.aroad.module.zhtj.service.ZhtjGljbxxXxctdqkService;
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 xuzhitu
 * @date 2019-03-12 21:59:39
 */
@RestController
@AllArgsConstructor
@RequestMapping("/zhtj/zhtjgljbxxxxctdqk")
public class ZhtjGljbxxXxctdqkController extends BaseController  {

  private final ZhtjGljbxxXxctdqkService zhtjGljbxxXxctdqkService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param zhtjGljbxxXxctdqk 县乡村通达情况
   * @return
   */
  @GetMapping("/page")
  public R getZhtjGljbxxXxctdqkPage(Page page, ZhtjGljbxxXxctdqk zhtjGljbxxXxctdqk) {
    if(zhtjGljbxxXxctdqk.getYear() == null){
      zhtjGljbxxXxctdqk.setYear("2018");
    }
    return  new R<>(zhtjGljbxxXxctdqkService.page(page,Wrappers.query(zhtjGljbxxXxctdqk)));
  }

  /**
   * 通过id查询县乡村通达情况
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(zhtjGljbxxXxctdqkService.getById(id));
  }

  /**
   * 新增县乡村通达情况
   * @param zhtjGljbxxXxctdqk 县乡村通达情况
   * @return R
   */
  @SysLog("新增县乡村通达情况")
  @PostMapping
  public R save(@RequestBody ZhtjGljbxxXxctdqk zhtjGljbxxXxctdqk){
    return new R<>(zhtjGljbxxXxctdqkService.save(zhtjGljbxxXxctdqk));
  }

  /**
   * 修改县乡村通达情况
   * @param zhtjGljbxxXxctdqk 县乡村通达情况
   * @return R
   */
  @SysLog("修改县乡村通达情况")
  @PutMapping
  public R updateById(@RequestBody ZhtjGljbxxXxctdqk zhtjGljbxxXxctdqk){
    return new R<>(zhtjGljbxxXxctdqkService.updateById(zhtjGljbxxXxctdqk));
  }

  /**
   * 通过id删除县乡村通达情况
   * @param id id
   * @return R
   */
  @SysLog("删除县乡村通达情况")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(zhtjGljbxxXxctdqkService.removeById(id));
  }

}
