package com.tofly.feesapi.znbgl.controller;

import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
import com.tofly.feesapi.yhgl.service.YhKhjbxxService;
import com.tofly.feesapi.znbgl.entity.ZnbYhda;
import com.tofly.feesapi.znbgl.entity.dto.ZnbYhdaFilter;
import com.tofly.feesapi.znbgl.entity.vo.ZnbYhdaSelect;
import com.tofly.feesapi.znbgl.service.ZnbYhdaService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;

@RestController
@RequestMapping("/znbyhda")
public class ZnbYhdaController {
    @Autowired
    private ZnbYhdaService znbYhdaService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone<PageResult<ZnbYhdaSelect>> getPage(@ModelAttribute PageDto pageDto, @ModelAttribute ZnbYhdaFilter filter) {
        return ResultRespone.success(znbYhdaService.getPage(pageDto, filter));
    }

    @GetMapping("/page2")
    @ApiOperation(value = "分页查询")
    public ResultRespone<PageResult<ZnbYhdaSelect>> getPage2(@ModelAttribute PageDto pageDto, @ModelAttribute ZnbYhdaFilter filter) {
        return ResultRespone.success(znbYhdaService.getPage(pageDto, filter));
    }

    @GetMapping("/{yhbh}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yhbh", value = "ID", required = true, dataType = "String")
    })
    public ResultRespone getById(@PathVariable("yhbh") String yhbh) {
        return ResultRespone.success(znbYhdaService.getById(yhbh));
    }

    @ApiOperation(value = "新增智能表用户档案")
    @PostMapping
    public ResultRespone save(@RequestBody ZnbYhda znbYhda) {
        return ResultRespone.success(znbYhdaService.save(znbYhda));
    }

    @ApiOperation(value = "修改智能表用户档案")
    @PutMapping
    public ResultRespone updateById(@RequestBody ZnbYhda znbYhda) {
        return ResultRespone.success(znbYhdaService.updateById(znbYhda));
    }

    @ApiOperation(value = "通过ID删除智能表用户档案")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yhbh", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{yhbh}")
    public ResultRespone removeById(@PathVariable String yhbh) {
        return ResultRespone.success(znbYhdaService.removeById(yhbh));
    }

    @ApiOperation(value = "通过ID批量删除智能表用户档案")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(znbYhdaService.removeByIds(Arrays.asList(ids.split(","))));
    }

}
