package com.tofly.feesapi.sfgl.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.sfgl.entity.YyQfmxCzls;
import com.tofly.feesapi.sfgl.service.YyQfmxCzlsService;
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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Arrays;

@RestController
@RequestMapping("api/sfgl/yyqfmxczls")
@Api(tags="应收明细(欠费明细)历史记录")
public class YyQfmxCzlsController {

    @Autowired
    private  YyQfmxCzlsService yyQfmxCzlsService;

    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getYyQfmxCzlsPage(Page page, @ModelAttribute YyQfmxCzls yyQfmxCzls) {
      return ResultRespone.success(yyQfmxCzlsService.page(page, Wrappers.query(yyQfmxCzls)));
    }

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

    @ApiOperation(value = "新增")
    @PostMapping
    public ResultRespone save(@RequestBody YyQfmxCzls yyQfmxCzls) {
      return ResultRespone.success(yyQfmxCzlsService.save(yyQfmxCzls));
    }

    @ApiOperation(value = "修改")
    @PutMapping
    public ResultRespone updateById(@RequestBody YyQfmxCzls yyQfmxCzls) {
      return ResultRespone.success(yyQfmxCzlsService.updateById(yyQfmxCzls));
    }

    /**
     * 通过id删除
     * @param yswsf id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yswsf", value = "ID", required = true, dataType = "BigDecimal")
    })
    @DeleteMapping("/{yswsf}" )
    public ResultRespone removeById(@PathVariable BigDecimal yswsf) {
      return ResultRespone.success(yyQfmxCzlsService.removeById(yswsf));
    }

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