package com.gci.boot.modules.monitor.controller;

import com.gci.boot.annotation.permission.DataPermission;
import com.gci.boot.common.log.annotation.AddSysLog;
import com.gci.boot.common.vo.Result;
import com.gci.boot.modules.gis.vo.GisRedisVehicleVo;
import com.gci.boot.modules.monitor.service.IMonitorService;
import com.gci.boot.modules.monitor.vo.AlarmCountVO;
import com.gci.boot.modules.monitor.vo.OverallMonitorVO;
import com.gci.boot.modules.monitor.vo.RunningbusVO;
import com.gci.boot.modules.monitor.vo.VehicleTreeVO;
import com.gci.boot.modules.video.vo.VideoDeviceVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags="全局监控")
@Slf4j
@RestController
@RequestMapping("/monitor")
public class MonitorController {

    @Autowired
    private IMonitorService monitorService;

    /**
     * 全部列表查询
     * @param statusType
     * @return
     */
    @AddSysLog(value = "全局监控-全部列表查询")
    @DataPermission(item="tgr.projectId", sqlIds = {"com.gci.boot.modules.gis.mapper.TbGisRunningbusMapper.queryOverallVehicle"})
    @GetMapping(value = "/list")
    public Result<?> queryList(String statusType, String plateNumber, String projectId, String vehicleType) {
        List<OverallMonitorVO> list = monitorService.getOverallVehicle(statusType,plateNumber,projectId,vehicleType);
        return Result.ok(list);
    }

    /**
     * 获取项目车辆树形数据
     * @param plateNumber
     * @return
     */
    @AddSysLog(value = "全局监控-获取项目车辆树形数据")
    @DataPermission(item="a.projectId", sqlIds = {"com.gci.boot.modules.gis.mapper.TbGisRunningbusMapper.queryProjrctVehicle"})
    @GetMapping(value = "/getVehicleTree")
    public Result<?> getVehicleTree(String plateNumber) {
        //获取所有车辆对应项目，为空的归到其它。 --》项目名称->车牌
        List<VehicleTreeVO> list = monitorService.getVehicleTree(plateNumber);
        return Result.ok(list);
    }

    /**
     * 获取车辆详情
     * @param plateNumber
     * @return
     */
    @AddSysLog(value = "全局监控-获取车辆详情")
    @GetMapping(value = "/getVehicleInfo")
    public Result<?> getVehicleInfo(String plateNumber) {
        OverallMonitorVO vo = monitorService.getVehicleInfo(plateNumber);
        return Result.ok(vo);
    }

    /**
     * 获取车辆数量
     * @return
     */
    @AddSysLog(value = "全局监控-获取车辆数量")
    @DataPermission(item="tb_gis_runningbus.projectId", sqlIds = {"com.gci.boot.modules.gis.mapper.TbGisRunningbusMapper.selectList"})
    @GetMapping(value = "/getVehicleCount")
    public Result<?> getVehicleCount() {
        List<AlarmCountVO> list = monitorService.getVehicleCount();
        return Result.ok(list);
    }

    /**
     * 根据车牌获取车辆视频通道信息
     * @return
     */
    @AddSysLog(value = "全局监控-根据车牌获取车辆视频通道信息")
    @GetMapping(value = "/getVehicleVideoChannel")
    public Result<?> getVehicleVideoChannel(String plateNumber) {
        try{
            VideoDeviceVO vo = monitorService.getVehicleVideoChannel(plateNumber);
            return Result.ok(vo);
        }catch (Exception e){
            return Result.error(101,e.getMessage());
        }
    }

    /**
     * 实时监控--获取车辆详情
     * @return
     */
    @AddSysLog(value = "实时监控-获取车辆详情")
    @GetMapping(value = "/getRunningbusInfo")
    public Result<?> getRunningbusInfo(String plateNumber) {
        RunningbusVO vo = monitorService.getRunningbusInfo(plateNumber);
        return Result.ok(vo);
    }

    /**
     * 实时监控--实时获取车辆关联围栏
     * @return
     */
    @AddSysLog(value = "实时监控-实时获取车辆关联围栏")
    @GetMapping(value = "/getVehicleFenceInfo")
    public Result<?> getVehicleFenceInfo(String plateNumber) {
        List<GisRedisVehicleVo> list = monitorService.getVehicleFenceInfo(plateNumber);
        return Result.ok(list);
    }
}
