package cn.cecep.talroad.controller.analysis;

import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.service.analysis.ISRaWaterFlagService;
import cn.cecep.talroad.vo.analysis.SRaWaterFlagVo;
import cn.cecep.talroad.vo.query.analysis.SRaWaterFlagQuery;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@Api(tags = "废水在线监测标记汇总")
@RestController
@RequestMapping("/sraWaterFlag")
public class SRaWaterFlagController extends BasesController {
    @Autowired
    private ISRaWaterFlagService waterFlagService;

    @ApiOperation(value = "废水在线监测标记汇总")
    @GetMapping("/list")
    public AjaxResults<IPage<SRaWaterFlagVo.Row>> list(SRaWaterFlagQuery query) {
        Page<SRaWaterFlagVo.Row> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<SRaWaterFlagVo.Row> list = waterFlagService.getWaterFlagList(page, query);
        page.setRecords(list);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "导出废水在线监测标记汇总")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody SRaWaterFlagQuery query) {
        Page<SRaWaterFlagVo.Row> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<SRaWaterFlagVo.Row> list = waterFlagService.getWaterFlagList(page, query);

        ExcelUtil<SRaWaterFlagVo.Row> util = new ExcelUtil<>(SRaWaterFlagVo.Row.class);
        util.exportExcel(response, list, "废水在线监测标记汇总数据");
    }

    @ApiOperation(value = "废水在线监测标记明细")
    @GetMapping("/detail/list")
    public AjaxResults<IPage<SRaWaterFlagVo.DetailRow>> detailList(SRaWaterFlagQuery query) {
        Page<SRaWaterFlagVo.DetailRow> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<SRaWaterFlagVo.DetailRow> list = waterFlagService.getWaterFlagDetailList(page, query);
        page.setRecords(list);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "导出废水在线监测标记明细")
    @PostMapping("/detail/export")
    public void detailExport(HttpServletResponse response, @RequestBody SRaWaterFlagQuery query) {
        Page<SRaWaterFlagVo.DetailRow> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<SRaWaterFlagVo.DetailRow> list = waterFlagService.getWaterFlagDetailList(page, query);

        ExcelUtil<SRaWaterFlagVo.DetailRow> util = new ExcelUtil<>(SRaWaterFlagVo.DetailRow.class);
        util.exportExcel(response, list, "废水在线监测标记汇总数据");
    }

}
