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.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.service.analysis.ISRaEmissionsOverService;
import cn.cecep.talroad.vo.analysis.SRaEmissionsOverVo;
import cn.cecep.talroad.vo.query.analysis.SRaEmissionsOverQuery;
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("/emissionsOver")
public class SRaEmissionsOverController extends BasesController {
    @Autowired
    private ISRaEmissionsOverService sRaEmissionsOverService;

    @ApiOperation(value = "区域排放量超标分析")
    @GetMapping("/region/list")
    public AjaxResults<IPage<SRaEmissionsOverVo.RegionVo>> regionList(SRaEmissionsOverQuery query) {
        Page<SRaEmissionsOverVo.RegionVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        sRaEmissionsOverService.getRegionEmissions(page, query);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "导出区域排放量超标分析")
    @Log(title = "区域排放量超标分析", businessType = BusinessType.EXPORT)
    @PostMapping("/regionExport")
    public void regionExport(HttpServletResponse response, @RequestBody SRaEmissionsOverQuery query) {
        Page<SRaEmissionsOverVo.RegionVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<SRaEmissionsOverVo.RegionVo> regionEmissions = sRaEmissionsOverService.getRegionEmissions(page, query);

        ExcelUtil<SRaEmissionsOverVo.RegionVo> util = new ExcelUtil<>(SRaEmissionsOverVo.RegionVo.class);
        util.exportExcel(response, regionEmissions, "区域排放量超标分析数据");
    }

    @ApiOperation(value = "行业排放量超标分析")
    @GetMapping("/industry/list")
    public AjaxResults<IPage<SRaEmissionsOverVo.IndustryVo>> industryList(SRaEmissionsOverQuery query) {
        Page<SRaEmissionsOverVo.IndustryVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        sRaEmissionsOverService.getIndustryEmissions(page, query);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "导出行业排放量超标分析")
    @Log(title = "行业排放量超标分析", businessType = BusinessType.EXPORT)
    @PostMapping("/industryExport")
    public void industryExport(HttpServletResponse response, @RequestBody SRaEmissionsOverQuery query) {
        Page<SRaEmissionsOverVo.IndustryVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<SRaEmissionsOverVo.IndustryVo> listVo = sRaEmissionsOverService.getIndustryEmissions(page, query);

        ExcelUtil<SRaEmissionsOverVo.IndustryVo> util = new ExcelUtil<>(SRaEmissionsOverVo.IndustryVo.class);
        util.exportExcel(response, listVo, "行业排放量超标分析数据");
    }

}
