package com.yuchen.saas.park.service.controller.meifeng;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.device.PmgBatSmartEquipment;
import com.yuchen.saas.park.api.vo.park.*;
import com.yuchen.saas.park.api.vo.park.alarm.AlarmBasicInformationVO;
import com.yuchen.saas.park.api.vo.park.alarm.AlarmDetailsVO;
import com.yuchen.saas.park.api.vo.park.alarm.AlarmInformationVO;
import com.yuchen.saas.park.api.vo.park.alarm.AlarmListVO;
import com.yuchen.saas.park.service.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
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 javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 颜艺波
 * @date 2021/9/3 16:41
 * @Description 美峰大屏接口
 */
@RestController
@RequestMapping("/screen00")
@Api(value = "美峰大屏接口00", tags = "美峰大屏接口00")
public class ScreenController00 {


    @Autowired
    private PmgBatSmartEquipmentService pmgBatSmartEquipmentService;

    @Autowired
    private ParkDeviceDataService parkDeviceDataService;

    @Autowired
    private IWarningInfoService iWarningInfoService;

    @Resource
    private IPeopleCountService iPeopleCountService;

    /**
     * 视频事件
     */
    @Autowired
    private PmgLogVideoEventsCountService pmgLogVideoEventsCountService;

    /**
     * 告警详情
     */
    @GetMapping("/alarm/details")
    @ApiOperationSupport(order = 15)
    @ApiOperation(value = "59. 首页-告警详情", notes = "首页-告警详情")
    public R<AlarmDetailsVO> alarmDetails(Long parkId, Long buildingId, Long floorId) {
        AlarmDetailsVO alarmDetailsVO =
                iWarningInfoService.getAlarmDetails(parkId, buildingId, floorId);

        return R.data(alarmDetailsVO);
    }

    /**
     * 告警基本信息
     */
    @GetMapping("/alarm/basicInformation")
    @ApiOperationSupport(order = 16)
    @ApiOperation(value = "61. 首页-告警基本信息", notes = "告警基本信息")
    public R<AlarmBasicInformationVO> basicInformation(Long parkId, Long buildingId, Long floorId) {
        AlarmBasicInformationVO alarmBasicInformationVO = iWarningInfoService.
                getBasicInformation(parkId, buildingId, floorId);
        return R.data(alarmBasicInformationVO);
    }

    /**
     * 能耗设备数
     */
    @GetMapping("/energyConsumption/deviceCount")
    @ApiOperationSupport(order = 25)
    @ApiOperation(value = "62. 能耗设备数", notes = "能耗设备数")
    public R<DeviceOnLineCount> energyDeviceCount(Long parkId, Long buildingId, Long floorId) {

        DeviceOnLineCount DeviceOnLineCount = pmgBatSmartEquipmentService.getDeviceCountByCategoryCode(parkId,
                buildingId, floorId, "4");
        return R.data(DeviceOnLineCount);
    }

    /**
     * 能耗设备列表
     */
    @GetMapping("/energyConsumption/deviceList")
    @ApiOperationSupport(order = 26)
    @ApiOperation(value = "63. 能耗设备列表", notes = "能耗设备列表")
    public R<List<GetEnvironmentAssistVO>> energyDeviceList(Long parkId, Long buildingId, Long floorId) {

        List<GetEnvironmentAssistVO> map = pmgBatSmartEquipmentService
                .getEquipmentCountInfo(parkId, null, null,
                        "4");;
        return R.data(map);
    }

    /**
     * 能耗设备分布
     */
    @GetMapping("/energyConsumption/deviceDistribution")
    @ApiOperationSupport(order = 27)
    @ApiOperation(value = "64. 能耗设备分布", notes = "能耗设备分布")
    public R<List<GetEnvironmentInfo>> energyDeviceDistribution(Long parkId, Long buildingId, Long floorId) {

        return R.data(pmgBatSmartEquipmentService.getDeviceDistributionByCategoryCode(parkId, buildingId, floorId,
                "4"));
    }

    /**
     * 能耗告警列表
     */
    @GetMapping("/energyConsumption/alarmList")
    @ApiOperationSupport(order = 28)
    @ApiOperation(value = "65. 能耗告警列表", notes = "能耗告警列表")
    public R<List<AlarmListVO>> energyAlarmList(Long parkId, Long buildingId, Long floorId) {

        return R.data(iWarningInfoService.getAlarmListByCategoryCode(parkId, buildingId, floorId, "4"));
    }

    /**
     * 能耗设备搜索
     */
    @GetMapping("/energyConsumption/search")
    @ApiOperationSupport(order = 29)
    @ApiOperation(value = "66. 能耗设备搜索", notes = "能耗设备搜索")
    public R<IPage<PmgEquipmentPropertyVO>> energySearch(PmgBatSmartEquipment equipment, Query query) {

        equipment.setCategoryCode("4");
        return R.data(pmgBatSmartEquipmentService.searchDevice(equipment, query));
    }

    /**
     * 安防设备数
     */
    @GetMapping("/security/deviceCount")
    @ApiOperationSupport(order = 33)
    @ApiOperation(value = "79. 安防设备数", notes = "安防设备数")
    public R<DeviceOnLineCount> securityDeviceCount(Long parkId, Long buildingId, Long floorId) {

        DeviceOnLineCount DeviceOnLineCount = pmgBatSmartEquipmentService.getDeviceCountByCategoryCode(parkId,
                buildingId, floorId, "5");
        return R.data(DeviceOnLineCount);
    }

    /**
     * 安防异常行为趋势
     */
    @GetMapping("/security/abnormalBehavior")
    @ApiOperationSupport(order = 30)
    @ApiOperation(value = "80. 安防异常行为趋势", notes = "安防异常行为趋势")
    public R<Map<String, Object>> securityAbnormalBehavior(Long parkId, Long buildingId, Long floorId) {

        Map<String, Object> map = new HashMap<>();
        List<GetEnvironmentInfo> listToday = pmgLogVideoEventsCountService.getHourSecurityAbnormalToday(parkId, buildingId, floorId);
        List<GetEnvironmentInfo> listMonth = pmgLogVideoEventsCountService.getDaySecurityAbnormalMonth(parkId, buildingId, floorId);
        map.put("abnormalBehaviorToday", listToday);
        map.put("abnormalBehaviorMonth", listMonth);
        return R.data(map);
    }

    /**
     * 安防异常行为分布
     */
    @GetMapping("/security/abnormalDistribution")
    @ApiOperationSupport(order = 31)
    @ApiOperation(value = "81. 安防异常行为分布", notes = "安防异常行为分布")
    public R<Map<String, List<GetEnvironmentInfo>>> securityAbnormalDistribution(Long parkId, Long buildingId, Long floorId) {

        Map<String, List<GetEnvironmentInfo>> map = pmgLogVideoEventsCountService.getSecurityAbnormalDistribution(parkId,
                buildingId, floorId);
        return R.data(map);
    }

    /**
     * 安防设备分布
     */
    @GetMapping("/security/deviceDistribution")
    @ApiOperationSupport(order = 35)
    @ApiOperation(value = "82. 安防设备分布", notes = "安防设备分布")
    public R<List<GetEnvironmentInfo>> securityDeviceDistribution(Long parkId, Long buildingId, Long floorId) {

        return R.data(pmgBatSmartEquipmentService.getDeviceDistributionByCategoryCode(parkId, buildingId, floorId,
                "6"));
    }

    /**
     * 安防告警列表
     */
    @GetMapping("/security/alarmList")
    @ApiOperationSupport(order = 36)
    @ApiOperation(value = "83. 安防告警列表", notes = "安防告警列表")
    public R<List<AlarmListVO>> securityAlarmList(Long parkId, Long buildingId, Long floorId) {

        return R.data(iWarningInfoService.getAlarmListByCategoryCode(parkId, buildingId, floorId, "6"));
    }

    /**
     * 安防设备列表
     */
    @GetMapping("/security/deviceList")
    @ApiOperationSupport(order = 34)
    @ApiOperation(value = "84. 安防设备列表", notes = "安防设备列表")
    public R<List<GetEnvironmentAssistVO>> securityDeviceList(Long parkId, Long buildingId, Long floorId) {

        List<GetEnvironmentAssistVO> map = pmgBatSmartEquipmentService
                .getEquipmentCountInfo(parkId, buildingId, floorId,
                        "6");
        return R.data(map);
    }

    /**
     * 安防异常行为列表
     */
    @GetMapping("/security/abnormalList")
    @ApiOperationSupport(order = 32)
    @ApiOperation(value = "85. 安防异常行为列表", notes = "安防异常行为列表")
    public R<List<AbnormalListVO>> securityAbnormalList(Long parkId, Long buildingId, Long floorId) {

        List<AbnormalListVO> list = pmgLogVideoEventsCountService.getAbnormalList("6", parkId, buildingId, floorId);
        return R.data(list);
    }

    /**
     * 安防设备搜索
     */
    @GetMapping("/security/search")
    @ApiOperationSupport(order = 37)
    @ApiOperation(value = "86. 安防设备搜索", notes = "安防设备搜索")
    public R<IPage<PmgEquipmentPropertyVO>> securitySearch(PmgBatSmartEquipment equipment,Query query) {

        equipment.setCategoryCode("6");
        return R.data(pmgBatSmartEquipmentService.searchDevice(equipment, query));
    }

    /**
     * 消防设备数
     */
    @GetMapping("/fire/deviceCount")
    @ApiOperationSupport(order = 38)
    @ApiOperation(value = "87. 消防设备数", notes = "消防设备数")
    public R<DeviceOnLineCount> fireDeviceCount(Long parkId, Long buildingId, Long floorId) {

        DeviceOnLineCount DeviceOnLineCount = pmgBatSmartEquipmentService.getDeviceCountByCategoryCode(parkId,
                buildingId, floorId, "2");
        return R.data(DeviceOnLineCount);
    }

    /**
     * 消防设备分类信息
     * @param parkId
     * @param buildingId
     * @param floorId
     * @return
     */
    @GetMapping("/fire/groupCount")
    @ApiOperationSupport(order = 39)
    @ApiOperation(value = "88. 消防设备分类信息")
    public R<Map<String, List<GetEnvironmentInfo>>> fireGroupCount(String parkId, String buildingId, String floorId) {

        Map<String, List<GetEnvironmentInfo>> map = new HashMap<>();
        List<GetEnvironmentInfo> list = pmgBatSmartEquipmentService.getEnvironmentGroupCount(Long.parseLong(parkId),
                Func.isNotEmpty(buildingId) ? Long.parseLong(buildingId) : null,
                Func.isNotEmpty(floorId) ? Long.parseLong(floorId) : null, "2");
        map.put("groupList", list);
        return R.data(map);
    }

    /**
     * 消防火警统计信息
     */
    @GetMapping("/fire/fireStatInfo")
    @ApiOperationSupport(order = 43)
    @ApiOperation(value = "89. 消防火警统计信息", notes = "消防火警统计信息")
    public R<FireStatInfoVO> fireStatInfo(Long parkId, Long buildingId, Long floorId) {

        FireStatInfoVO fireStatInfoVO = iWarningInfoService.getFireStatInfo(parkId, buildingId, floorId);
        return R.data(fireStatInfoVO);
    }

    /**
     * 消防设备分布
     */
    @GetMapping("/fire/deviceDistribution")
    @ApiOperationSupport(order = 41)
    @ApiOperation(value = "90. 消防设备分布", notes = "消防设备分布")
    public R<List<GetEnvironmentInfo>> fireDeviceDistribution(Long parkId, Long buildingId, Long floorId) {

        return R.data(pmgBatSmartEquipmentService.getDeviceDistributionByCategoryCode(parkId, buildingId, floorId,
                "2"));
    }

    /**
     * 消防告警列表
     */
    @GetMapping("/fire/alarmList")
    @ApiOperationSupport(order = 42)
    @ApiOperation(value = "91. 消防告警列表", notes = "消防告警列表")
    public R<List<AlarmListVO>> fireAlarmList(Long parkId, Long buildingId, Long floorId) {

        return R.data(iWarningInfoService.getAlarmListByCategoryCode(parkId, buildingId, floorId, "2"));
    }

    /**
     * 消防设备列表
     */
    @GetMapping("/fire/deviceList")
    @ApiOperationSupport(order = 40)
    @ApiOperation(value = "92. 消防设备列表", notes = "消防设备列表")
    public R<List<GetEnvironmentAssistVO>> fireDeviceList(Long parkId, Long buildingId, Long floorId) {

        List<GetEnvironmentAssistVO> map = pmgBatSmartEquipmentService
                .getEquipmentCountInfo(parkId, buildingId, floorId,
                        "2");

        return R.data(map);
    }

    /**
     * 消防火警列表
     */
    @GetMapping("/fire/fireList")
    @ApiOperationSupport(order = 44)
    @ApiOperation(value = "93. 消防火警列表", notes = "消防火警列表")
    public R<List<FireListVO>> fireList(Long parkId, Long buildingId, Long floorId) {

        List<FireListVO> list = iWarningInfoService.getFireList(parkId, buildingId, floorId);
        return R.data(list);
    }

    /**
     * 消防设备搜索
     */
    @GetMapping("/fire/search")
    @ApiOperationSupport(order = 45)
    @ApiOperation(value = "94. 消防设备搜索", notes = "消防设备搜索")
    public R<IPage<PmgEquipmentPropertyVO>> fireSearch(PmgBatSmartEquipment equipment,Query query) {

        equipment.setCategoryCode("2");
        return R.data(pmgBatSmartEquipmentService.searchDevice(equipment, query));
    }

    /**
     * 今日告警信息
     */
    @GetMapping("/alarm/alarmInformationToday")
    @ApiOperationSupport(order = 17)
    @ApiOperation(value = "95. 今日告警信息", notes = "今日告警信息")
    public R<AlarmInformationVO> alarmInformationToday(Long parkId, Long buildingId, Long floorId) {
        AlarmInformationVO alarmInformationVO = iWarningInfoService.
                getAlarmInformationToday(parkId, buildingId, floorId);
        return R.data(alarmInformationVO);
    }

    /**
     * 本月告警信息
     */
    @GetMapping("/alarm/alarmInformationMonth")
    @ApiOperationSupport(order = 18)
    @ApiOperation(value = "96. 本月告警信息", notes = "本月告警信息")
    public R<AlarmInformationVO> alarmInformationMonth(Long parkId, Long buildingId, Long floorId) {

        AlarmInformationVO alarmInformationTodayVO = iWarningInfoService.
                getAlarmInformationMonth(parkId, buildingId, floorId);
        return R.data(alarmInformationTodayVO);
    }

    /**
     * 今日告警状态分布
     */
    @GetMapping("/alarm/alarmStatusDistributionToday")
    @ApiOperationSupport(order = 19)
    @ApiOperation(value = "97. 今日告警状态分布", notes = "今日告警状态分布")
    public R<List<GetEnvironmentInfo>> alarmStatusDistributionToday(Long parkId, Long buildingId, Long floorId) {

        return R.data(iWarningInfoService.
                getAlarmStatusDistributionToday(parkId, buildingId, floorId));
    }

    /**
     * 本月告警状态分布
     */
    @GetMapping("/alarm/alarmStatusDistributionMonth")
    @ApiOperationSupport(order = 20)
    @ApiOperation(value = "98. 本月告警状态分布", notes = "本月告警状态分布")
    public R<List<GetEnvironmentInfo>> alarmStatusDistributionMonth(Long parkId, Long buildingId, Long floorId) {
        return R.data(iWarningInfoService.
                getAlarmStatusDistributionMonth(parkId, buildingId, floorId));
    }

    /**
     * 今日告警设备类型分布
     */
    @GetMapping("/alarm/alarmDeviceTypeDistributionToday")
    @ApiOperationSupport(order = 21)
    @ApiOperation(value = "99. 今日告警设备类型分布", notes = "今日告警设备类型分布")
    public R<List<GetEnvironmentInfo>> alarmDeviceTypeDistributionToday(Long parkId, Long buildingId, Long floorId) {

        return R.data(iWarningInfoService.
                getAlarmDeviceTypeDistributionToday(parkId, buildingId, floorId));
    }

    /**
     * 本月告警设备类型分布
     */
    @GetMapping("/alarm/alarmDeviceTypeDistributionMonth")
    @ApiOperationSupport(order = 22)
    @ApiOperation(value = "100. 本月告警设备类型分布", notes = "本月告警设备类型分布")
    public R<List<GetEnvironmentInfo>> alarmDeviceTypeDistributionMonth(Long parkId, Long buildingId, Long floorId) {

        return R.data(iWarningInfoService.
                getAlarmDeviceTypeDistributionToday(parkId, buildingId, floorId));
    }

    /**
     * 今日告警处理时长分布
     */
    @GetMapping("/alarm/alarmHandlingTimeDistributionToday")
    @ApiOperationSupport(order = 23)
    @ApiOperation(value = "101. 今日告警处理时长分布", notes = "今日告警处理时长分布")
    public R<List<GetEnvironmentInfo>> alarmHandlingTimeDistributionToday(Long parkId, Long buildingId, Long floorId) {
        return R.data(iWarningInfoService.
                getAlarmHandlingTimeDistributionToday(parkId, buildingId, floorId));
    }
    /**
     * 本月告警处理时长分布
     */
    @GetMapping("/alarm/alarmHandlingTimeDistributionMonth")
    @ApiOperationSupport(order = 24)
    @ApiOperation(value = "102. 本月告警处理时长分布", notes = "本月告警处理时长分布")
    public R<List<GetEnvironmentInfo>> alarmHandlingTimeDistributionMonth(Long parkId, Long buildingId, Long floorId) {
        return R.data(iWarningInfoService.
                getAlarmHandlingTimeDistributionMonth(parkId, buildingId, floorId));
    }
}
