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.ZnbCbLogFilter;
import com.tofly.feesapi.cbgl.entity.vo.ZnbCbLogSelect;
import com.tofly.feesapi.cbgl.service.IZnbCbLogService;
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("/api/cbgl/znbCbLog")
@Api(tags = "智能表抄表明细")
public class ZnbCbLogController {

    @Autowired
    private IZnbCbLogService znbCbLogService;

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

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