package com.gyee.runeconomy.controller.monitor;/*
@author   谢生杰
@date   2023/3/28-8:43
*/

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.dto.AjaxResult;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.dto.result.JsonResult;
import com.gyee.runeconomy.dto.result.ResultCode;
import com.gyee.runeconomy.model.auto.ProEconAlarmType;
import com.gyee.runeconomy.model.vo.PoliceVo;
import com.gyee.runeconomy.service.auto.IProEconAlarmTypeService;
import com.gyee.runeconomy.service.monitor.AlarmService;
import com.gyee.runeconomy.service.monitor.MatrixService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/matrix")
@Api(value = "矩阵", tags = "矩阵")
public class MatrixController {
    @Resource
    private MatrixService matrixService;

    @Resource
    private IProEconAlarmTypeService proEconAlarmTypeService;

    @Resource
    private AlarmService alarmService;
    /**
     * 基础矩阵
     *
     * @return
     */
    @GetMapping("/basic")
    @ResponseBody
    @ApiOperation(value = "基础矩阵", notes = "基础矩阵")
    public R basic(@RequestParam(value = "type", required = true) String type,
                   @RequestParam(value = "company", required = true) String company) throws Exception {

        Map<String, Object> resultMap = matrixService.basic(company, type);
        if (StringUtils.isNotNull(resultMap)) {
            return R.data(ResultMsg.ok(resultMap));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    /**
     * 明细矩阵
     *
     * @return
     */
    @GetMapping("/detailed")
    @ResponseBody
    @ApiOperation(value = "明细矩阵", notes = "明细矩阵")
    public JSONObject detailed(@RequestParam(value = "type", required = true) String type,
                      @RequestParam(value = "company", required = true) String company) throws Exception {

        Map<String, Object> resultMap = matrixService.matrixMX(company, type);
        if (StringUtils.isNotNull(resultMap)) {
            return JsonResult.successData(ResultCode.SUCCESS, resultMap);
        } else {
            return JsonResult.error();
        }
    }

    /**
     * 明细矩阵弹窗-报警分类
     *
     * @return
     */
    @GetMapping("/alarmtype")
    @ResponseBody
    @ApiOperation(value = "报警分类", notes = "报警分类")
    public JSONObject alarmtype(@RequestParam(value = "wtid", required = true) String wtid) throws Exception {
        Map<String, Object> resultMap = alarmService.flAlarm(wtid);

        if (StringUtils.isNotNull(resultMap)) {
            return JsonResult.successData(ResultCode.SUCCESS, resultMap);
        } else {
            return JsonResult.error();
        }
    }


    /**
     *  明细矩阵弹窗-报警信息
     *
     * @return
     */
    @GetMapping("/alarm")
    @ResponseBody
    @ApiOperation(value = "报警信息", notes = "报警信息")
    public JSONObject alarm(@RequestParam(value = "type", required = true) String type,
                      @RequestParam(value = "wtid", required = true) String wtid) throws Exception {

        List<PoliceVo.AlarmDetails> resultMap = alarmService.Alarm(type,wtid);
        if (StringUtils.isNotNull(resultMap)) {
            return JsonResult.successData(ResultCode.SUCCESS, resultMap);
        } else {
            return JsonResult.error();
        }
    }

    /**
     * 单场矩阵
     *
     * @return
     */
    @GetMapping("/single")
    @ResponseBody
    @ApiOperation(value = "单场矩阵", notes = "单场矩阵")
    public R single(@RequestParam(value = "wpid", required = true) String wpid) throws Exception {

        Map<String, Object> resultMap = matrixService.single(wpid);
        if (StringUtils.isNotNull(resultMap)) {
            return R.data(ResultMsg.ok(resultMap));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    /**
     * 基础矩阵
     *
     * @return
     */
    @GetMapping("/sbxx")
    @ResponseBody
    @ApiOperation(value = "矩阵设备信息", notes = "矩阵设备信息")
    public AjaxResult basic(@RequestParam(value = "wtid", required = true) String wtid) throws Exception {

        Map<String, String> resultList = new HashMap<>();
        if (com.gyee.runeconomy.util.StringUtils.notEmp(wtid)) {
            resultList = matrixService.equipment(wtid);
        }

        if (null != resultList) {
            return AjaxResult.successData(200, resultList);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

}
