/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.xrtygis.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.xrtygis.entity.Rivermanage;
import com.tofly.xrtygis.service.RivermanageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 河流管理配置表
 *
 * @author admin
 * @date Thu Sep 09 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/rivermanage")
@Api(tags = "河流管理配置表接口")
public class RivermanageController {

    private final RivermanageService rivermanageService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return ResultRespone
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getRivermanagePage(Page page) {
        return ResultRespone.success(rivermanageService.page(page, Wrappers.<Rivermanage>lambdaQuery()
                .orderByAsc(Rivermanage::getName)));
    }


    /**
     * 通过id查询河流管理配置表
     *
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id") Long id) {
        return ResultRespone.success(rivermanageService.getById(id));
    }

    /**
     * 新增河流管理配置表
     *
     * @param rivermanage 河流管理配置表
     * @return ResultRespone
     */

    @ApiOperation(value = "新增河流管理配置表")
    @PostMapping
    public ResultRespone save(@RequestBody Rivermanage rivermanage) {
        return ResultRespone.success(rivermanageService.insertRiver(rivermanage));
    }

    /**
     * 修改河流管理配置表
     *
     * @param rivermanage 河流管理配置表
     * @return ResultRespone
     */
    @ApiOperation(value = "修改河流管理配置表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Rivermanage rivermanage) {
        return ResultRespone.success(rivermanageService.updateById(rivermanage));
    }

    /**
     * 通过id删除河流管理配置表
     *
     * @param id id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID删除河流管理配置表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "多个id‘.’分割", required = true, dataType = "string")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable String id) {
        return ResultRespone.success(rivermanageService.deleteRiver(id));
    }

    @GetMapping("/getCodeInfo")
    @ApiOperation("获取编码表信息")
    public ResultRespone getCodeInfo(){
        return ResultRespone.success(rivermanageService.getCodeInfo());
    }
}
