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.BankDsdzhz;
import com.tofly.feesapi.sfds.entity.dto.BankDsdzhzFilter;
import com.tofly.feesapi.sfds.entity.dto.BankDsdzhzSelect;
import com.tofly.feesapi.sfds.service.BankDsdzhzService;
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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("api/sfds/bankdsdzhz")
@Api(tags="代收-对账汇总信息接口")
public class BankDsdzhzController {

    @Autowired
    private BankDsdzhzService bankDsdzhzService;

    @GetMapping("/page" )
    @ApiOperation(value = "代收总账分页查询")
    public ResultRespone getPage(@ModelAttribute PageDto pageDto, @ModelAttribute BankDsdzhzFilter filter) {
      return ResultRespone.success(bankDsdzhzService.getPage(pageDto, filter));
    }

    @GetMapping("/exporBankDsdzhz")
    @ApiOperation(value = "导出代收总账", tags = {"代收总账查询"})
    public void exporBankDsdzhz(HttpServletResponse response, @ModelAttribute BankDsdzhzFilter filter) throws IOException {
        List<BankDsdzhzSelect> list = bankDsdzhzService.bankDsdzhzList(filter);
        if (!list.isEmpty()) {
            ExcleFileUtil.exportExcel(response, list, BankDsdzhzSelect.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(bankDsdzhzService.getById(id));
    }


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

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


    @ApiOperation(value = "通过ID删除代收对账信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable String id) {
      return ResultRespone.success(bankDsdzhzService.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(bankDsdzhzService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
