package com.zcloud.modules.map.controller;


import com.zcloud.modules.map.service.UserPositionService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/map/UserPosition")
public class UserPositionController {
    @Autowired
    private UserPositionService usersService;

    /**
     * 获取人员定位
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/getCurrentLocationOnline")
    @ResponseBody
    public Object getCurrentLocationOnline() throws Exception{
        return usersService.getCurrentLocation();
    }

    @RequestMapping(value="/getCarCurrentLocationOnline")
    @ResponseBody
    public Object getCarCurrentLocationOnline() throws Exception{
        return usersService.getCarCurrentLocation();
    }

    /**
     * 查询人员在线及统计数据
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getCurrentPersonnelData")
    public Object getCurrentPersonnelData(@RequestBody Map<String, Object> params) throws Exception{
        if(StringUtils.isNotEmpty(params.get("route").toString())){
            return usersService.getCurrentPersonnelData(params.get("route").toString());
        }else {
            Map<String, Object> map = new HashMap<>();
            map.put("result","error");
            map.put("msg","缺少必填参数route");
            return map;
        }
    }

    /**
     * 查询车辆在线及统计数据
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getCurrentCarData")
    public Object getCurrentCarData(@RequestBody Map<String, Object> params) throws Exception{
        if(StringUtils.isNotEmpty(params.get("route").toString())){
            return usersService.getCurrentCarData(params.get("route").toString());
        }else {
            Map<String, Object> map = new HashMap<>();
            map.put("result","error");
            map.put("msg","缺少必填参数route");
            return map;
        }
    }

    /**
     * 获取人员定位统计列表
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/personPositioningStatistics")
    public Object getPersonPositioningStatistics(@RequestBody Map<String, Object> params) throws Exception{
        if(StringUtils.isNotEmpty(params.get("route").toString())){
            return usersService.getPersonPositioningStatistics(params.get("route").toString());
        }else {
            Map<String, Object> map = new HashMap<>();
            map.put("result","error");
            map.put("msg","缺少必填参数route");
            return map;
        }
    }

    /**
     * 获取车辆定位统计列表
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/carPositioningStatistics")
    public Object carPositioningStatistics(@RequestBody Map<String, Object> params) throws Exception{
        if(StringUtils.isNotEmpty(params.get("route").toString())){
            return usersService.getCarPositioningStatistics(params.get("route").toString());
        }else {
            Map<String, Object> map = new HashMap<>();
            map.put("result","error");
            map.put("msg","缺少必填参数route");
            return map;
        }
    }

    @RequestMapping(value="/getCurrentLocationOnlineCount")
    @ResponseBody
    public Object getCurrentLocationOnlineCount() throws Exception{
        return usersService.getCurrentLocationCount();
    }
}
