package com.zcxk.charge.web.controller;

import com.zcxk.charge.api.dto.generalview.WaterSupplyChart;
import com.zcxk.charge.api.dto.homepage.WaterQualityRate;
import com.zcxk.charge.api.dto.homepage.WaterQualityRateForScene;
import com.zcxk.charge.api.vo.CompanyCountVo;
import com.zcxk.charge.api.vo.MonthRevenueVo;
import com.zcxk.charge.web.service.HomePageReportService;
import com.zcxk.charge.web.service.RevenueService;
import com.zcxk.core.common.pojo.AjaxMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description
 * @author  wangli
 * @data 2021/2/24 9:09
 */
@RestController
@RequestMapping("/homePageReport")
@Api(tags = "主页大屏报表")
public class HomePageReportController extends BaseController{

    @Autowired
    private HomePageReportService homePageReportService;

    @Autowired
    private RevenueService revenueService;

    @RequestMapping(value = "getDeviceWaterIntake",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——取水图表(近6月)")
    public AjaxMessage getDeviceWaterIntake(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
        return AjaxMessage.success(homePageReportService.deviceWaterReportForSixMonth(companyOrgId, WATER_SOURCE.getMessage(),4));
    }

    @RequestMapping(value = "getDeviceWaterMaking",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——制水图表(近6月)")
    public AjaxMessage getDeviceWaterMaking(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
        return AjaxMessage.success(homePageReportService.deviceWaterReportForSixMonth(companyOrgId, WATER_WORKS.getMessage(),3));
    }

    @RequestMapping(value = "getCompanyResouces",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——公司资源统计")
    public AjaxMessage getCompanyResouces(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
        CompanyCountVo result = homePageReportService.countSceneByType(companyOrgId);
        List<MonthRevenueVo> monthRevenue = revenueService.selectMonthRevenue(companyOrgId,1);
        if (!CollectionUtils.isEmpty(monthRevenue)) {
            result.setWaterMeter(monthRevenue.get(0).getUserMeterCount());
        }
        return AjaxMessage.success(result);
    }

    @RequestMapping(value = "getDeviceWaterAmount",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——生产经营（制水售水）统计")
    public AjaxMessage getDeviceWaterAmount(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false)  Integer companyOrgId){
        return AjaxMessage.success(homePageReportService.deviceWaterAmount(companyOrgId));
    }

    @RequestMapping(value = "getWaterQualification",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水质安全")
    public AjaxMessage<WaterQualityRate> getWaterQualification(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
        return AjaxMessage.success(homePageReportService.getWaterQualification(companyOrgId));
    }

    @RequestMapping(value = "getWaterIntakeFifteenDays",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水库取水15天")
    public AjaxMessage getWaterIntakeFifteenDays(@ApiParam(value = "水库id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.monitorDataFifteenDays(sceneId,WATER_SOURCE.getMessage(),4));
    }
    @RequestMapping(value = "getWaterLevelFifteenDays",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水库水位15天")
    public AjaxMessage getWaterLevelFifteenDays(
            @ApiParam(value = "水库id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.monitorDataFifteenDays(sceneId,WATER_SOURCE.getMessage(),12));
    }

    @RequestMapping(value = "getWaterMakingFifteenDays",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水厂制水15天")
    public AjaxMessage getWaterMakingFifteenDays(
            @ApiParam(value = "水厂id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.monitorDataFifteenDays(sceneId,WATER_WORKS.getMessage(),3));
    }

    @RequestMapping(value = "getWaterMakingFifteenDaysForPumpingStation",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——泵站制水15天")
    public AjaxMessage getWaterMakingFifteenDaysForPumpingStation(
            @ApiParam(value = "泵站id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.monitorDataFifteenDays(sceneId,PUMPING_STATION.getMessage(),3));
    }

    @RequestMapping(value = "getWaterQualityRateForWaterSource",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水库水质")
    public AjaxMessage<WaterQualityRateForScene> waterQualityRateForWaterSource(
            @ApiParam(value = "水库id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.waterQualityRateForWaterSource(sceneId));
    }

    @RequestMapping(value = "waterQualityRateForWaterFactory",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水厂水质")
    public AjaxMessage<WaterQualityRateForScene> waterQualityRateForWaterFactory(@ApiParam(value = "水厂id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.waterQualityRateForWaterFactory(sceneId));
    }

    @RequestMapping(value = "waterQualityRateForPumpingStation",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——泵站水质")
    public AjaxMessage<WaterQualityRateForScene> waterQualityRateForPumpingStation(
            @ApiParam(value = "泵站id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.waterQualityRateForPumpingStation(sceneId));
    }

    @RequestMapping(value = "waterEnergyConsumptionForWaterFactory",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水厂能耗")
    public AjaxMessage<List<WaterSupplyChart>> waterEnergyConsumptionForWaterFactory(
            @ApiParam(value = "水厂id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.waterEnergyConsumption(sceneId,WATER_SOURCE.getMessage()));
    }

    @RequestMapping(value = "waterEnergyConsumptionForPumpingStation",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——泵站能耗")
    public AjaxMessage<List<WaterSupplyChart>> waterEnergyConsumptionForPumpingStation(
            @ApiParam(value = "泵站id",required = true) @RequestParam Integer sceneId){
        return AjaxMessage.success(homePageReportService.waterEnergyConsumption(sceneId,PUMPING_STATION.getMessage()));
    }

}
