package com.mvc.controller.weixin;


import com.mvc.model.*;
import com.mvc.model.weixin.TotalDeviceInfo;
import com.mvc.model.weixin.YslModel;
import com.mvc.othermodel.WxTjModel;
import com.mvc.service.weixin.WxTongjiService;
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.List;
import java.util.Map;

@Api(tags = "小程序统计调用接口")
@RequestMapping("/WxTongjiAction")
@Controller
public class WxTongjiAction {

    @Autowired
    private WxTongjiService wxTongjiService;



    @ApiOperation("页面登录查找设备总数、设备在线、设备故障数")
    @RequestMapping(value = "/findTotalInfo/{unitCode}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findTotalInfo(@PathVariable("unitCode") String unitCode) {
        ResultModel resultModel;
        try {
            TotalDeviceInfo res = wxTongjiService.findTotalInfo(unitCode,null);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }


    @ApiOperation("根据单位代码获取全部可查看的用水户-包括统计信息")
    @RequestMapping(value = "/findTAffiliatedunitsByUnitCode/{unitCode}/{deviceType}/{page}/{rows}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findTAffiliatedunitsByUnitCode(@PathVariable("unitCode") String unitCode,@PathVariable("deviceType") String deviceType,
                                                              @PathVariable("page") int page,@PathVariable("rows") int rows) {
        ResultModel resultModel;
        try {
            ResPageModel res = wxTongjiService.findTAffiliatedunitsByUnitCode(unitCode,deviceType,page,rows);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }

    @ApiOperation("根据用4级水户站代码获取下属的所有站点-含最新读数")
    @RequestMapping(value = "/findStationAccsByUnitCode/{userId}/{unitCode}/{deviceType}/{page}/{rows}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findStationAccsByUnitCode(@PathVariable("userId") String userId,@PathVariable("unitCode") String unitCode, @PathVariable("deviceType") String deviceType,
                                                         @PathVariable("page") Integer page, @PathVariable("rows") Integer rows) {
        ResultModel resultModel;
        try {
            Map<String, Object> res = wxTongjiService.findStationAccsByUnitCode(userId,unitCode, deviceType,"", page, rows);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }


    @ApiOperation("根据4级用水户站代码获取下属的所有站点-含最新设备状态信息")
    @RequestMapping(value = "/findDeviceStatusByUnitCode/{unitCode}/{deviceType}/{page}/{rows}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findDeviceStatusByUnitCode(@PathVariable("unitCode") String unitCode, @PathVariable("deviceType") String deviceType,
                                                         @PathVariable("page") Integer page, @PathVariable("rows") Integer rows) {
        ResultModel resultModel;
        try {
            ResPageModel res = wxTongjiService.findDevicestatusByUnitCode(unitCode, deviceType, page, rows);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }


    @ApiOperation("根据站点代码获取时、日、月、年用水量")
    @RequestMapping(value = "/findYslByStationCode/{stationCode}/{kssj}/{jssj}/{type}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findYslByStationCode(@PathVariable("stationCode") String stationCode, @PathVariable("kssj") String kssj,
                                                          @PathVariable("jssj") String jssj, @PathVariable("type") String type) {
        ResultModel resultModel;
        try {
            List<YslModel> resList = wxTongjiService.findYslByStationCode(stationCode, kssj, jssj, type);
            resultModel=new ResultModel(resList);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }




    @ApiOperation("根据4级用水户代码获取日、月、年用水量")
    @RequestMapping(value = "/findYslByUnitCode/{unitCode}/{kssj}/{jssj}/{type}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findYslByUnitCode(@PathVariable("unitCode") String unitCode, @PathVariable("kssj") String kssj,
                                                    @PathVariable("jssj") String jssj, @PathVariable("type") String type) {
        ResultModel resultModel;
        try {
            List<YslModel> resList = wxTongjiService.findYslByUnitCode(unitCode, kssj, jssj, type);
            resultModel=new ResultModel(resList);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }



    @ApiOperation("根据userid查询重点关注的水表")
    @RequestMapping(value = "/findAttentionStationsByUserid/{userId}/{page}/{rows}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findAttentionStationsByUserid(@PathVariable("userId") String userId, @PathVariable("page") int page,
                                         @PathVariable("rows") int rows) {
        ResultModel resultModel;
        try {
            ResPageModel resPageModel = wxTongjiService.findAttentionStationsByUserid(userId, page, rows);
            resultModel=new ResultModel(resPageModel);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }


    @ApiOperation("关注站点调用接口")
    @RequestMapping(value = "/payAttentionByStationcode/{userId}/{stationCode}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel payAttentionByStationcode(@PathVariable("userId") String userId,@PathVariable("stationCode") String stationCode) {
        ResultModel resultModel;
        try {
            int res = wxTongjiService.payAttentionByStationcode(userId,stationCode);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }

    @ApiOperation("取消关注调用接口")
    @RequestMapping(value = "/cancelAttentionByStationcode/{userId}/{stationCode}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel cancelAttentionByStationcode(@PathVariable("userId") String userId,@PathVariable("stationCode") String stationCode) {
        ResultModel resultModel;
        try {
            int res = wxTongjiService.cancelAttentionByStationcode(userId,stationCode);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }


    @ApiOperation("根据单位代码获取有预警信息的用水户")
    @RequestMapping(value = "/findYujingTAffiliatedunitsByUnitCode/{unitCode}/{deviceType}/{page}/{rows}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findYujingTAffiliatedunitsByUnitCode(@PathVariable("unitCode") String unitCode,@PathVariable("deviceType") String deviceType,
                                                      @PathVariable("page") int page,@PathVariable("rows") int rows) {
        ResultModel resultModel;
        try {
            ResPageModel res = wxTongjiService.findYujingTAffiliatedunitsByUnitCode(unitCode,deviceType,page,rows);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }


    @ApiOperation("根据4级用水户站代码获取下属的所有预警站点-含设备状态信息")
    @RequestMapping(value = "/findDYujingeviceStatusByUnitCode/{unitCode}/{deviceType}/{page}/{rows}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findDYujingeviceStatusByUnitCode(@PathVariable("unitCode") String unitCode, @PathVariable("deviceType") String deviceType,
                                                  @PathVariable("page") Integer page, @PathVariable("rows") Integer rows) {
        ResultModel resultModel;
        try {
            ResPageModel res = wxTongjiService.findDYujingeviceStatusByUnitCode(unitCode, deviceType, page, rows);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }

    @ApiOperation("根据统计数据查看明细")
    @RequestMapping(value = "/findDetailInfoByNum", method = RequestMethod.POST)
    @ResponseBody
    public ResultModel findDetailInfoByNum(@RequestBody WxTjModel model) {

        ResultModel resultModel;
        try {
            ResPageModel res = wxTongjiService.findDetailInfoByNum(model);
            resultModel=new ResultModel(res);
            return resultModel;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
            return resultModel;
        }
    }

}
