package cn.cecep.talroad.controller.effective;

import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.domain.effective.ERmStationHour;
import cn.cecep.talroad.service.effective.ERmStationExceedService;
import cn.cecep.talroad.service.effective.ERmStationHourService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.PcFactoryVo;
import cn.cecep.talroad.vo.effective.ERmStationInfo;
import cn.cecep.talroad.vo.effective.SEnvGasMonValueVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
//import org.junit.jupiter.api.Disabled;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
* (e_rm_station_exceed)表控制层
*
* @author lxh
*/
@Api(tags = "站点预警数据")
@RestController
@RequestMapping("/stationExceed")
public class ERmStationExceedController {
    /**
    * 服务对象
    */
    @Autowired
    private ERmStationExceedService exceedService;
    @Autowired
    private ERmStationHourService hourService;


    @GetMapping("/selectList")
    @ApiOperation("查询站点预警列表")
    public AjaxResults<IPage<ERmStationInfo>> selectListAll(ERmStationInfo entity) {
         return    AjaxResults.success(exceedService.selectListInfo(entity));
    }

    @GetMapping("/selectInfo")
    @ApiOperation("查询站点信息--弃用，使用接口 POST station/detail/air/{id}")
//    @Disabled("使用cn.cecep.talroad.controller.TCodStationController.airStationDetail")
    public AjaxResults<ERmStationHour> selectInfo(@RequestParam(name = "stationCode") String stationCode) {
        QueryWrapper<ERmStationHour>  ew = new QueryWrapper<>();
        ew.eq(ERmStationHour.COL_STATION_CODE, stationCode);
        ew.orderByDesc(ERmStationHour.COL_DATA_TIME);
        ew.last("limit 1");
        return    AjaxResults.success(hourService.getBaseMapper().selectOne(ew));
    }
    @GetMapping("/changingTrends")
    @ApiOperation("站点某一污染源变化趋势")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationIds", value = "站点编码集合"),
            @ApiImplicitParam(name = "contaminant", value = "污染物"),
            @ApiImplicitParam(name = "start", value = "开始时间,yyyy-MM-dd HH"),
            @ApiImplicitParam(name = "end", value = "结束时间,yyyy-MM-dd HH")
    })
    public AjaxResults<EChartsVO> changingTrends(@RequestParam(name = "stationIds") List<String> stationIds,
                                                 @RequestParam(name = "contaminant")String contaminant,
                                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "start")Date start,
                                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "end") Date end) {
        return    AjaxResults.success(exceedService.changingTrends(stationIds, contaminant, start, end));
    }
    @GetMapping("/entChangingTrends")
    @ApiOperation("企业某一污染源变化趋势")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entIds", value = "企业id集合"),
            @ApiImplicitParam(name = "contaminant", value = "污染物,当前只支持：SO2：传递so2_emission，NO2：传递no2_emission，pm2.5和pm10传递smoke_dust_emission"),
            @ApiImplicitParam(name = "start", value = "开始时间,yyyy-MM-dd HH"),
            @ApiImplicitParam(name = "end", value = "结束时间,yyyy-MM-dd HH")
    })
    public AjaxResults<EChartsVO> entChangingTrends(@RequestParam(name = "entIds") List<String> entIds,
                                                 @RequestParam(name = "contaminant")String contaminant,
                                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "start")Date start,
                                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "end") Date end) {
        return    AjaxResults.success(exceedService.entChangingTrends(entIds, contaminant, start, end));
    }
    @GetMapping("/entMap")
    @ApiOperation("企业地图--》查询有经纬度且有大气污染物数据的企业")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "pageNum", value = "页码"), @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    public AjaxResults<List<PcFactoryVo.MapPointVo>> selectGasAndHaveDate(
            @RequestParam(name = "pageNum",defaultValue = "1",required = false ) Integer pageNum,
            @RequestParam(name = "pageSize",defaultValue = Integer.MAX_VALUE+"" ,required = false) Integer pageSize){
        return AjaxResults.success(exceedService.selectGasAndHaveData(pageNum,pageSize));
    }
    @GetMapping("/entPollutionMap")
    @ApiOperation("企业排放量数据信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "entId", value = "企业id"),
            @ApiImplicitParam(name = "start", value = "开始时间,yyyy-MM-dd HH"),
            @ApiImplicitParam(name = "end", value = "结束时间,yyyy-MM-dd HH")
    })
    public AjaxResults<EChartsVO> selectEntPollution(String entId,
                                                    @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "start")Date start,
                                                     @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "end") Date end){
        return AjaxResults.success(exceedService.selectEntPollution(entId, start, end));
    }
    @GetMapping("/entPollutionSum")
    @ApiOperation("企业排放量汇总")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entId", value = "企业id"),
            @ApiImplicitParam(name = "start", value = "开始时间,yyyy-MM-dd HH"),
            @ApiImplicitParam(name = "end", value = "结束时间,yyyy-MM-dd HH")
    })
    public AjaxResults<List<SEnvGasMonValueVo>> summaryOfCorporateEmissions(String entId,
                                                                            @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "start")Date start,
                                                                            @DateTimeFormat(pattern = "yyyy-MM-dd HH") @RequestParam(name = "end") Date end){
        return AjaxResults.success(exceedService.summaryOfCorporateEmissions(entId, start, end));
    }
    @GetMapping("/selectStationList")
    @ApiOperation("查询站点列表")
    public AjaxResults<IPage<ERmStationInfo>> selectStationList(ERmStationInfo entity) {
        return    AjaxResults.success(exceedService.selectStationList(entity));
    }
}
