package com.mvc.controller.ysfx;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.ysfx.SameTimeDataModel;
import com.mvc.service.ysfx.YsfxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "用水分析接口")
@RequestMapping("/YsfxAction")
@Controller
public class YsfxAction {

    @Autowired
    private YsfxService ysfxService;

    @ApiOperation("根据单位代码查询站点用水情况")
    @RequestMapping(value = "/findWaterConsumptionByUnitCode/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findWaterConsumptionByUnitCode(@PathVariable("unitCode") String unitCode){
        try {
            var res= ysfxService.findWaterConsumptionByUnitCode(unitCode);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("根据单位代码查询用水结构")
    @RequestMapping(value = "/findTypeWaterConsByUnitCode/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findTypeWaterConsByUnitCode(@PathVariable("unitCode") String unitCode){
        try {
            var res= ysfxService.findTypeWaterConsByUnitCode(unitCode);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("获取月度用水量统计")
    @RequestMapping(value = "/getMonthlyWaterCons/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getMonthlyWaterCons(@PathVariable("unitCode") String unitCode){
        try {
            var res = ysfxService.getMonthlyWaterCons(unitCode,20);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("获取用水标准")
    @RequestMapping(value = "/getWaterStandard/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getWaterStandard(@PathVariable("unitCode") String unitCode){
        try {
            var res = ysfxService.getWaterStandard(unitCode);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("获取漏溢、漏损数据")
    @RequestMapping(value = "/getLeakageData/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getLeakageData(@PathVariable("unitCode") String unitCode){
        try {
            var res = ysfxService.getLeakageData(unitCode);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("根据单位代码获取都有数据的时刻")
    @RequestMapping(value = "/getSameTimeData/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getSameTimeData(@PathVariable("unitCode") String unitCode){
        try {
            var res = ysfxService.getSameTimeData(unitCode);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }
/**--------------------------------POST方式开始---------------------------------------------------*/
    @ApiOperation("根据单位代码查询站点用水情况")
    @RequestMapping(value = "/findWaterConsumptionByUnitCode",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findWaterConsumptionByUnitCode(@RequestBody SameTimeDataModel model){
        try {
            var res= ysfxService.findWaterConsumptionByUnitCode(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("根据单位代码查询用水结构")
    @RequestMapping(value = "/findTypeWaterConsByUnitCode",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findTypeWaterConsByUnitCode(@RequestBody SameTimeDataModel model){
        try {
            var res= ysfxService.findTypeWaterConsByUnitCode(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("获取月度用水量统计")
    @RequestMapping(value = "/getMonthlyWaterCons",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getMonthlyWaterCons(@RequestBody SameTimeDataModel model){
        try {
            var res = ysfxService.getMonthlyWaterCons(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("获取用水标准")
    @RequestMapping(value = "/getWaterStandard",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getWaterStandard(@RequestBody SameTimeDataModel model){
        try {
            var res = ysfxService.getWaterStandard(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("获取漏溢、漏损数据")
    @RequestMapping(value = "/getLeakageData",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getLeakageData(@RequestBody SameTimeDataModel model){
        try {
            var res = ysfxService.getLeakageData(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

/**--------------------------------POST方式结束---------------------------------------------------*/
}
