package com.mvc.controller.sthjb;

import com.mvc.model.ResultGeekerModel;
import com.mvc.service.sthjb.SthjbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = "生态环境部相关接口")
@RequestMapping("/SthjbController")
@Controller
public class SthjbController {
    @Resource
    private SthjbService sthjbService;

    @ApiOperation("获取用水用途")
    @RequestMapping(value = "/findWaterMeteringLogicModel", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel findWaterMeteringLogicModel(String unitCode, String startTime, String endTime) {
        ResultGeekerModel resultModel;
        try {
            var res = sthjbService.findWaterMeteringLogicModel(unitCode, startTime, endTime);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            //初期数据不完整,给前端较人性化的错误信息
            //resultModel = new ResultGeekerModel(e.getMessage());
            resultModel = new ResultGeekerModel("基础数据不完整,尝试切换时间范围");
        }
        return resultModel;
    }

    @ApiOperation("计算次级用水计量率")
    @RequestMapping(value = "/calcSubWaterMeteringRatio", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel calcSubWaterMeteringRatio(String unitCode, String startTime, String endTime) {
        ResultGeekerModel resultModel;
        try {
            var res = sthjbService.calcSubWaterMeteringRatio(unitCode, startTime, endTime);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            //resultModel = new ResultGeekerModel(e.getMessage());
            //初期数据不完整,给前端较人性化的错误信息
            resultModel = new ResultGeekerModel("基础数据不完整,尝试切换时间范围");
        }
        return resultModel;
    }

    @ApiOperation("计算用水效率数据")
    @RequestMapping(value = "/calcWatereFficiency", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel calcWatereFficiency(String unitCode) {
        ResultGeekerModel resultModel;
        try {
            var res = sthjbService.calcWatereFficiency(unitCode);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            //初期数据不完整,给前端较人性化的错误信息
            resultModel = new ResultGeekerModel("基础数据不完整,尝试切换时间范围");
        }
        return resultModel;
    }

    @ApiOperation("计算中央空调冷却补水率")
    @RequestMapping(value = "/calcCoolingTowerMakeup", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel calcCoolingTowerMakeup(String unitCode, String startTime, String endTime) {
        ResultGeekerModel resultModel;
        try {
            var res = sthjbService.calcCoolingTowerMakeup(unitCode, startTime, endTime);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            //resultModel = new ResultGeekerModel(e.getMessage());
            //初期数据不完整,给前端较人性化的错误信息
            resultModel = new ResultGeekerModel("基础数据不完整,尝试切换时间范围");
        }
        return resultModel;
    }

    @ApiOperation("根据单位代码和天数获取最近用水量")
    @RequestMapping(value = "/getRecentUsageData", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel getRecentUsageData(String unitCode, int days) {
        ResultGeekerModel resultModel;
        try {
            var res = sthjbService.getRecentUsageData(unitCode, days);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }


    @ApiOperation("根据单位代码和年月获取用量")
    @RequestMapping(value = "/getUsageDataByStationCodeAndYMonth", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel getUsageDataByStationCodeAndYMonth(String stationCode, int year, int month) {
        ResultGeekerModel resultModel;
        try {
            var res = sthjbService.getUsageDataByStationCodeAndYMonth(stationCode, year,month);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("根据单位代码和年获取用量")
    @RequestMapping(value = "/getAnnualUsageDataByStationCodeAndYear", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel getAnnualUsageDataByStationCodeAndYear(String stationCode, int year) {
        ResultGeekerModel resultModel;
        try {
            var res = sthjbService.getAnnualUsageDataByStationCodeAndYear(stationCode, year);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }
}
