package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.service.EmissionsStatService;
import cn.cecep.talroad.vo.EmissionsStatVo;
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 = "排放量汇总统计controller")
@RestController
@RequestMapping("/emissionsStat")
public class EmissionsStatController {

    @Autowired
    private EmissionsStatService emissionsStatService;

    @ApiOperation(value = "获取监测点排放量统计")
    @GetMapping("/point/list")
    public AjaxResults<IPage<EmissionsStatVo.PointRow>> pointList(EmissionsStatVo.PointSearch search) {
        IPage<EmissionsStatVo.PointRow> page = new Page<>(search.getPageNum(), search.getPageSize());
        List<EmissionsStatVo.PointRow> rows = emissionsStatService.getPointList(page, search);
        page.setRecords(rows);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "导出监测点排放量统计")
    @Log(title = "导出监测点排放量统计", businessType = BusinessType.EXPORT)
    @PostMapping("/point/export")
    public void pointExport(HttpServletResponse response, @RequestBody EmissionsStatVo.PointSearch search) {
        ExcelUtil<EmissionsStatVo.PointRow> util = new ExcelUtil<>(EmissionsStatVo.PointRow.class);
        util.exportExcel(response, pointList(search).getData().getRecords(), "导出监测点排放量统计");
    }

    @ApiOperation(value = "获取企业排放量统计")
    @GetMapping("/factory/list")
    public AjaxResults<IPage<EmissionsStatVo.FactoryRow>> factoryList(EmissionsStatVo.FactorySearch search) {
        IPage<EmissionsStatVo.FactoryRow> page = new Page<>(search.getPageNum(), search.getPageSize());
        List<EmissionsStatVo.FactoryRow> rows = emissionsStatService.getFactoryList(page, search);
        page.setRecords(rows);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "导出企业排放量统计")
    @Log(title = "导出企业排放量统计", businessType = BusinessType.EXPORT)
    @PostMapping("/factory/export")
    public void factoryExport(HttpServletResponse response, @RequestBody EmissionsStatVo.FactorySearch search) {
        ExcelUtil<EmissionsStatVo.FactoryRow> util = new ExcelUtil<>(EmissionsStatVo.FactoryRow.class);
        util.exportExcel(response, factoryList(search).getData().getRecords(), "导出企业排放量统计");
    }

    @ApiOperation(value = "获取区域排放量统计")
    @GetMapping("/region/list")
    public AjaxResults<EmissionsStatVo.Region> regionList(EmissionsStatVo.RegionSearch search) {
        EmissionsStatVo.Region region = emissionsStatService.getRegionStat(search);
        return AjaxResults.success(region);
    }

    @ApiOperation(value = "导出区域排放量统计")
    @Log(title = "导出区域排放量统计", businessType = BusinessType.EXPORT)
    @PostMapping("/region/export")
    public void regionExport(HttpServletResponse response, @RequestBody EmissionsStatVo.RegionSearch search) {
        ExcelUtil<EmissionsStatVo.RegionRow> util = new ExcelUtil<>(EmissionsStatVo.RegionRow.class);
        util.exportExcel(response, regionList(search).getData().getRows(), "导出区域排放量统计");
    }

}
