package com.shzg.project.worn.controller;

import com.shzg.framework.web.controller.BaseController;
import com.shzg.framework.web.domain.AjaxResult;
import com.shzg.framework.web.page.TableDataInfo;
import com.shzg.project.system.domain.SysDept;
import com.shzg.project.system.service.ISysDeptService;
import com.shzg.project.worn.service.IMqttSensorEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home")
public class SysHomeController extends BaseController
{
    @Autowired
    private ISysDeptService deptService;

    @Autowired
    private IMqttSensorEventService eventService;

    /**
     * 首页统计
     */
    @GetMapping("/stat")
    public AjaxResult stat()
    {
        Map<String, Object> data = deptService.getHomeStat();
        return AjaxResult.success(data);
    }

    /**
     * 设备统计（总数 / 在线 / 离线）
     */
    @GetMapping("/device/stat")
    public AjaxResult deviceStat()
    {
        Map<String, Object> data = deptService.getDeviceStat();
        return AjaxResult.success(data);
    }

    /**
     * 告警统计（今日告警 / 未处理告警）
     */
    @GetMapping("/alarm/stat")
    public AjaxResult alarmStat()
    {
        Map<String, Object> data = eventService.getAlarmStat();
        return AjaxResult.success(data);
    }

    /**
     * 告警趋势（近7天）
     */
    @GetMapping("/alarm/trend")
    public AjaxResult alarmTrend()
    {
        return AjaxResult.success(eventService.getAlarmTrend());
    }

    /**
     * 告警类型占比
     */
    @GetMapping("/alarm/type")
    public AjaxResult alarmType()
    {
        return AjaxResult.success(eventService.getAlarmTypeStat());
    }

    /**
     * 仓库运行状态（全部仓库）
     */
    @GetMapping("/warehouse/list")
    public AjaxResult warehouseList()
    {
        List<Map<String, Object>> list = deptService.selectWarehouseList();
        return AjaxResult.success(list);
    }

}