/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.water.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.common.log.annotation.ToFlyAppLog;
import com.tofly.scada.common.BaseController;
import com.tofly.water.entity.TfRegionP;
import com.tofly.water.service.TfRegionPService;
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.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 行政区划
 *
 * @author JF
 * @date Wed Aug 03 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfregionp")
@Api(tags="行政区划接口")
public class TfRegionPController extends BaseController {

    private final TfRegionPService tfRegionPService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param tfRegionP 行政区划
    * @return
    */
    @ToFlyAppLog(title="分页查询" )
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getTfRegionPPage(Page page, @ModelAttribute TfRegionP tfRegionP) {
      return ResultRespone.success(tfRegionPService.page(page, Wrappers.query(tfRegionP)));
    }

    /**
     * 列表查询
     * @param tfRegionP 列表查询
     * @return
     */
    @ToFlyAppLog(title="列表查询" )
    @GetMapping("/list" )
    @ApiOperation(value = "列表查询")
    public ResultRespone getTfRegionPList(@ModelAttribute TfRegionP tfRegionP) {
        return ResultRespone.success(tfRegionPService.list(Wrappers.query(tfRegionP)));
    }

    /**
     * 行政区域树
     * @param tfRegionP 行政区域树
     * @return
     */
    @ToFlyAppLog(title="行政区域树" )
    @GetMapping("/tree" )
    @ApiOperation(value = "行政区域树")
    public ResultRespone getTfRegionPTree(@ModelAttribute TfRegionP tfRegionP) {
        return ResultRespone.success(tfRegionPService.getTfRegionPTree(tfRegionP));
    }


    /**
     * 通过id查询行政区划
     * @param id id
     * @return ResultData
     */
    @ToFlyAppLog(title="通过ID查询" )
    @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(tfRegionPService.getById(id));
    }

    /**
     * 新增行政区划
     * @param tfRegionP 行政区划
     * @return ResultData
     */
    @ToFlyAppLog(title="新增行政区划" )
    @ApiOperation(value = "新增行政区划")
    @PostMapping
    public ResultRespone save(@RequestBody @Valid TfRegionP tfRegionP) {
      return ResultRespone.success(tfRegionPService.save(tfRegionP));
    }

    /**
     * 修改行政区划
     * @param tfRegionP 行政区划
     * @return ResultData
     */
    @ToFlyAppLog(title="修改行政区划" )
    @ApiOperation(value = "修改行政区划")
    @PutMapping
    public ResultRespone updateById(@RequestBody TfRegionP tfRegionP) {
      return ResultRespone.success(tfRegionPService.updateById(tfRegionP));
    }

    /**
     * 通过id删除行政区划
     * @param id id
     * @return ResultData
     */
    @ToFlyAppLog(title="通过id删除行政区划" )
    @ApiOperation(value = "通过ID删除行政区划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(tfRegionPService.removeById(id));
    }

    /**
     * 通过id批量删除行政区划
     * @param ids id
     * @return ResultData
     */
    @ToFlyAppLog(title="通过id批量删除行政区划" )
    @ApiOperation(value = "通过ID批量删除行政区划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(tfRegionPService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
