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


/**
 * 历年数据
 *
 * @author xuzhitu
 * @date 2019-04-16 17:23:38
 */
@RestController
@AllArgsConstructor
@RequestMapping("/zhtj/zhtjzhzslnsj")
public class ZhtjZhzsLnsjController extends BaseController  {

  private final  ZhtjZhzsLnsjService zhtjZhzsLnsjService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param zhtjZhzsLnsj 历年数据
   * @return
   */
  @GetMapping("/page")
  public R getZhtjZhzsLnsjPage(Page page, ZhtjZhzsLnsj zhtjZhzsLnsj) {
    return  new R<>(zhtjZhzsLnsjService.page(page,Wrappers.query(zhtjZhzsLnsj)));
  }

  /**
   * 分页查询
   * @param year 年份
   * @return
   */
  @GetMapping("/getInfoByYear")
  public R getListByYear(String year) {
    return  new R<>(zhtjZhzsLnsjService.getListByYear(year));
  }

  /**
   * 通过id查询历年数据
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(zhtjZhzsLnsjService.getById(id));
  }

  /**
   * 新增历年数据
   * @param zhtjZhzsLnsj 历年数据
   * @return R
   */
  @SysLog("新增历年数据")
  @PostMapping
  public R save(@RequestBody ZhtjZhzsLnsj zhtjZhzsLnsj){
    return new R<>(zhtjZhzsLnsjService.save(zhtjZhzsLnsj));
  }

  /**
   * 修改历年数据
   * @param zhtjZhzsLnsj 历年数据
   * @return R
   */
  @SysLog("修改历年数据")
  @PutMapping
  public R updateById(@RequestBody ZhtjZhzsLnsj zhtjZhzsLnsj){
    return new R<>(zhtjZhzsLnsjService.updateById(zhtjZhzsLnsj));
  }

  /**
   * 通过id删除历年数据
   * @param id id
   * @return R
   */
  @SysLog("删除历年数据")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(zhtjZhzsLnsjService.removeById(id));
  }

}
