package com.tofly.feesapi.cbgl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.cbgl.entity.dto.ZnbCbDayFilter;
import com.tofly.feesapi.cbgl.entity.vo.ZnbCbDaySelect;
import com.tofly.feesapi.cbgl.service.IZnbCbDayService;
import com.tofly.feesapi.common.Excel.ExcleFileUtil;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/cbgl/znbCbDay")
@Api(tags = "远传抄表明细")
public class ZnbCbDayController {

    @Autowired
    private IZnbCbDayService znbCbDayService;

    @ApiOperationSupport(order = 1)
    @GetMapping("/page")
    @ApiOperation(value = "查询远传抄表明细（分页）")
    public ResultRespone<PageResult<ZnbCbDaySelect>> getPage(@ModelAttribute PageDto pageDto,
                                                             @ModelAttribute ZnbCbDayFilter filter) {
        return ResultRespone.success(znbCbDayService.getPage(pageDto, filter));
    }

    @ApiOperationSupport(order = 2)
    @GetMapping("/export")
    @ApiOperation(value = "导出远传抄表明细")
    public void export(HttpServletResponse response, @ModelAttribute ZnbCbDayFilter filter) throws IOException {
        List<ZnbCbDaySelect> list = znbCbDayService.getList(filter);
        if (!list.isEmpty()) {
            ExcleFileUtil.exportExcel(response, list, ZnbCbDaySelect.class, "远传抄表明细.xlsx",filter.getExportFields());
        }
    }
}
