package com.tofly.feesapi.sfds.controller;

import com.tofly.common.core.entity.ResultRespone;
import com.tofly.feesapi.common.Excel.ExcleFileUtil;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.sfds.entity.BankDsdzxx;
import com.tofly.feesapi.sfds.entity.dto.BankDsdzxxFilter;
import com.tofly.feesapi.sfds.entity.dto.BankDsdzxxSelect;
import com.tofly.feesapi.sfds.service.BankDsdzxxService;
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.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("api/sfds/bankdsdzxx")
@Api(tags="代收-对账明细信息接口")
public class BankDsdzxxController {

    @Autowired
    private BankDsdzxxService bankDsdzxxService;

    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getPage(@ModelAttribute PageDto pageDto, @ModelAttribute BankDsdzxxFilter filter) {
      return ResultRespone.success(bankDsdzxxService.getPage(pageDto, filter));
    }

    @GetMapping("/exporBankDsdzxx")
    @ApiOperation(value = "导出代收对账明细", tags = {"代收对账明细"})
    public void exporBankDsdzxx(HttpServletResponse response, @ModelAttribute BankDsdzxxFilter filter) throws IOException {
        List<BankDsdzxxSelect> list = bankDsdzxxService.bankDsdzxxList(filter);
        if (!list.isEmpty()) {
            ExcleFileUtil.exportExcel(response, list, BankDsdzxxSelect.class, "代收对账明细.xlsx",filter.getExportFields());
        }
    }

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

    @ApiOperation(value = "新增代收对账信息")
    @PostMapping
    public ResultRespone save(@RequestBody BankDsdzxx bankDsdzxx) {
      return ResultRespone.success(bankDsdzxxService.save(bankDsdzxx));
    }

    @ApiOperation(value = "修改代收对账信息")
    @PutMapping
    public ResultRespone updateById(@RequestBody BankDsdzxx bankDsdzxx) {
      return ResultRespone.success(bankDsdzxxService.updateById(bankDsdzxx));
    }


    @ApiOperation(value = "通过ID删除代收对账信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable String id) {
      return ResultRespone.success(bankDsdzxxService.removeById(id));
    }

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