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.domain.analysis.SRaEmissionsOverFactory;
import cn.cecep.talroad.service.analysis.ISRaEmissionsOverFactoryService;
import cn.cecep.talroad.vo.analysis.SRaEmissionsOverFactoryVo;
import cn.cecep.talroad.vo.query.analysis.SRaEmissionsOverFactoryQuery;
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("/emissionsOverFactory")
public class SRaEmissionsOverFactoryController extends BasesController {
    @Autowired
    private ISRaEmissionsOverFactoryService sRaEmissionsOverFactoryService;

    /**
     * 查询企业排放量超标分析列表
     */
    @ApiOperation(value = "查询企业排放量超标分析")
    @GetMapping("/list")
    public AjaxResults<IPage<SRaEmissionsOverFactoryVo>> list(SRaEmissionsOverFactoryQuery query) {
        Page<SRaEmissionsOverFactoryVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        sRaEmissionsOverFactoryService.selectEmissionsOverFactory(page, query);
        return AjaxResults.success(page);
    }


    @ApiOperation(value = "统计范围下拉选")
    @GetMapping("/statScope/list")
    public AjaxResults<List<String>> list() {
        List<String> list = sRaEmissionsOverFactoryService.getStatScopeList();
        return AjaxResults.success(list);
    }


    /**
     * 导出企业排放量超标分析列表
     */
    @ApiOperation(value = "导出企业排放量超标分析")
    @Log(title = "企业排放量超标分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody SRaEmissionsOverFactoryQuery query) {
        Page<SRaEmissionsOverFactoryVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<SRaEmissionsOverFactoryVo> list = sRaEmissionsOverFactoryService.selectEmissionsOverFactory(page, query);
        ExcelUtil<SRaEmissionsOverFactoryVo> util = new ExcelUtil<>(SRaEmissionsOverFactoryVo.class);
        util.exportExcel(response, list, "企业排放量超标分析数据");
    }

    /**
     * 获取企业排放量超标分析详细信息
     */
    @ApiOperation(value = "获取企业排放量超标分析详细信息")
    @PostMapping(value = "/{id}")
    public AjaxResults<SRaEmissionsOverFactory> getInfo(@PathVariable("id") Integer id) {
        return AjaxResults.success(sRaEmissionsOverFactoryService.getById(id));
    }

}
