package com.zcxk.controller;

import com.zcxk.dto.MonthRevenueDto;
import com.zcxk.dto.generalView.DeviceWaterSupply;
import com.zcxk.dto.generalView.WaterSupplyChart;
import com.zcxk.dto.homePage.CompanyCount;
import com.zcxk.dto.homePage.CompanyProduce;
import com.zcxk.dto.homePage.WaterQualityRate;
import com.zcxk.dto.homePage.WaterQualityRateForScene;
import com.zcxk.model.AjaxMessage;
import com.zcxk.model.ResultStatus;
import com.zcxk.service.HomePageReportService;
import com.zcxk.service.RevenueService;
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.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
 * @auto wangli
 * @data 2021/2/24 9:09
 */
@RestController
@RequestMapping("/homePageReport")
@Api(tags = "主页大屏报表")
public class HomePageReportController {

    @Autowired
    private HomePageReportService homePageReportService;
    @Autowired
    private RevenueService revenueService;

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

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


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

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

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

    @RequestMapping(value = "getWaterIntakeFifteenDays",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水库取水15天")
    public AjaxMessage<List<DeviceWaterSupply>> getWaterIntakeFifteenDays(
            @ApiParam(value = "水库id",required = true) @RequestParam Integer sceneId){
        return new AjaxMessage<>(ResultStatus.OK,homePageReportService.monitorDataFifteenDays(sceneId,"水源",4));
    }
    @RequestMapping(value = "getWaterLevelFifteenDays",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——水库水位15天")
    public AjaxMessage<List<DeviceWaterSupply>> getWaterLevelFifteenDays(
            @ApiParam(value = "水库id",required = true) @RequestParam Integer sceneId){
        return new AjaxMessage<>(ResultStatus.OK,homePageReportService.monitorDataFifteenDays(sceneId,"水源",12));
    }

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

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

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

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

    @RequestMapping(value = "waterQualityRateForPumpingStation",method = RequestMethod.GET)
    @ApiOperation(value = "综合展示——泵站水质")
    public AjaxMessage<WaterQualityRateForScene> waterQualityRateForPumpingStation(
            @ApiParam(value = "泵站id",required = true) @RequestParam Integer sceneId){
        return new AjaxMessage<>(ResultStatus.OK,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 new AjaxMessage<>(ResultStatus.OK,homePageReportService.waterEnergyConsumption(sceneId,"水厂"));
    }

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

}
