package com.zcloud.modules.map.controller;


import com.zcloud.common.utils.R;
import com.zcloud.modules.map.service.impl.UsersPositionServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

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

    /**
     * 获取人员定位
     * @return
     * @throws Exception
     */
    @PostMapping(value="/getCurrentLocationOnline")
    public R getCurrentLocationOnline() throws Exception{
        R r = usersService.findRedisAll();
        return r;
    }

    /**
     * 获取人员轨迹
     * @return
     * @throws Exception
     */
    @PostMapping(value="/getPersonnelTrack")
    public R getPersonnelTrack(@RequestBody Map<String, Object> params) throws Exception{
         if(StringUtils.isEmpty(params.get("startTime").toString())){
            return R.error("缺少必填参数startTime");
         }else if(StringUtils.isEmpty(params.get("endTime").toString())){
             return R.error("缺少必填参数endTime");
         }else if(StringUtils.isEmpty(params.get("terminalNo").toString())){
             return R.error("缺少必填参数terminalNo");
         }
        R r = usersService.getPersonnelTrack(params);
        return r;
    }

    /**
     * 获取电子围栏
     * @return
     * @throws Exception
     */
    @PostMapping(value="/getFenceList")
    public R getFenceList() throws Exception{
        R r = usersService.getFenceList();
        return r;
    }

    /**
     * 获取统计数据
     * @return
     * @throws Exception
     */
    @PostMapping(value="/getAlarmCount")
    public R getAlarmCount() throws Exception{
        R r = usersService.getAlarmCount();
        return r;
    }

    /**
     * 获取报警列表
     * @return
     * @throws Exception
     */
    @PostMapping(value="/getAlarmList")
    public R getAlarmList() throws Exception{
        R r = usersService.getAlarmList();
        return r;
    }
}
