package com.tofly.feesapi.znbgl.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.znbgl.entity.ZnbDaLog;
import com.tofly.feesapi.znbgl.service.ZnbDaLogService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;

@RestController
@RequestMapping("/znbDaLog")
@Api(tags="智能表用户档案记录日志接口")
public class ZnbDaLogController {

    @Autowired
    private ZnbDaLogService znbDaLogService;

    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getZnbDaLogPage(Page page, @ModelAttribute ZnbDaLog znbDaLog) {
        return ResultRespone.success(znbDaLogService.page(page, Wrappers.query(znbDaLog)));
    }

    @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(znbDaLogService.getById(yhbh));
    }

    @ApiOperation(value = "新增智能表用户档案记录")
    @PostMapping
    public ResultRespone save(@RequestBody ZnbDaLog znbDaLog) {
        return ResultRespone.success(znbDaLogService.save(znbDaLog));
    }

    @ApiOperation(value = "修改智能表用户档案记录")
    @PutMapping
    public ResultRespone updateById(@RequestBody ZnbDaLog znbDaLog) {
        return ResultRespone.success(znbDaLogService.updateById(znbDaLog));
    }

    @ApiOperation(value = "通过ID删除智能表用户档案记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yhbh", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{yhbh}" )
    public ResultRespone removeById(@PathVariable String yhbh) {
        return ResultRespone.success(znbDaLogService.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(znbDaLogService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
