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.SRaOverRateGas;
import cn.cecep.talroad.service.analysis.ISRaOverRateGasService;
import cn.cecep.talroad.vo.analysis.SRaOverRateGasVo;
import cn.cecep.talroad.vo.query.analysis.SRaOverRateGasQuery;
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;


@Api(tags = "超标率分析-气污染要素")
@RestController
@RequestMapping("/over/gas")
public class SRaOverRateGasController extends BasesController {
    @Autowired
    private ISRaOverRateGasService sRaOverRateGasService;

    @ApiOperation(value = "查询超标率分析-气污染要素")
    @GetMapping("/list")
    public AjaxResults<IPage<SRaOverRateGasVo>> list(SRaOverRateGasQuery query) {
        Page<SRaOverRateGasVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        sRaOverRateGasService.selectOverRateGasPage(page, query);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "导出超标率分析-气污染要素")
    @Log(title = "超标率分析-气污染要素", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody SRaOverRateGasQuery query) {
        Page<SRaOverRateGasVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        sRaOverRateGasService.selectOverRateGasPage(page, query);
        ExcelUtil<SRaOverRateGasVo> util = new ExcelUtil<>(SRaOverRateGasVo.class);
        util.exportExcel(response, page.getRecords(), "超标率分析-气污染要素数据");
    }

    @ApiOperation(value = "获取超标率分析-气污染要素详细信息")
    @PostMapping(value = "/{id}")
    public AjaxResults<SRaOverRateGas> getInfo(@PathVariable("id") Integer id) {
        return AjaxResults.success(sRaOverRateGasService.getById(id));
    }
}
