package com.tofly.feesapi.bjgl.controller;

import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.bjgl.entity.vo.YhHbLogSelect;
import com.tofly.feesapi.bjgl.service.YkHbLogService;
import com.tofly.feesapi.common.Excel.ExcleFileUtil;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
import com.tofly.feesapi.yhgl.entity.dto.YhywLogFilter;
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
@AllArgsConstructor
@RequestMapping("api/yhgl/ykhblog")
@Api(tags = "水表档案-换表（含普表换表）日志接口")
public class YkHbLogController {

    @Autowired
    private YkHbLogService ykHbLogService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone<PageResult<YhHbLogSelect>> getYkHbLogPage(@ModelAttribute PageDto pageDto,@ModelAttribute YhywLogFilter filter) {
        return ResultRespone.success(ykHbLogService.getYkHbLogPage(pageDto, filter));

    }

    @GetMapping("/export")
    @ApiOperation(value = "export导出")
    public void export(HttpServletResponse response,@ModelAttribute YhywLogFilter filter) throws IOException {
        List<YhHbLogSelect> list = ykHbLogService.getYkHbLoglist(filter);
        //导出excle
        ExcleFileUtil.exportExcel(response, list, YhHbLogSelect.class, "用户换表.xlsx", filter.getExportFields());
    }
}
