package com.zcloud.controller.positioning;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.PLSUtil;
import com.zcloud.util.ReturnMap;
import com.zcloud.util.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * 说明：定位管理-告警管理
 * 作者：wangxuan
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/positAlarm")
public class PositAlarmController extends BaseController {

    /**
     * @Description: 告警数据 来自人员定位系统
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/getAlArmDataList")
    @ResponseBody
    public ReturnMap getAlArmDataList(Page page) throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.getAlArmDataList(
                Jurisdiction.getCORPINFO_ID(), page.getCurrentPage() + 1, page.getShowCount(), "", Integer.parseInt(pageData.getString("status")), Integer.parseInt(pageData.getString("eleType"))
        );
        if (body != null) {
            List<JSONObject> list = body.getJSONArray("rows").toJavaList(JSONObject.class);
            returnMap.put("varList", list);
            page.setTotalResult(body.getIntValue("total"));
            returnMap.put("page", page);
        }
        return returnMap;
    }

    /**
     * @Description: 处理告警
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/alarmHandling")
    @ResponseBody
    public ReturnMap alarmHandling() throws Exception {
        ReturnMap returnMap = new ReturnMap();

        PageData pageData = this.getPageData();
//        JSONArray list = JSONObject.parseArray();
        String ids = pageData.getString("ids");
        if (Tools.isEmpty(ids)) {
            // 是空的那么就是进行一键处理
            JSONObject body = PLSUtil.GeneralPost("/region/alarm/alarmHandlingAll", pageData, Jurisdiction.getCORPINFO_ID());
            if (body != null) {
                returnMap.putAll(body);
            }
            return returnMap;
        }
        pageData.put("ids", pageData.getString("ids").split(","));
        JSONObject body = PLSUtil.GeneralPost("/region/alarm/alarmHandling", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }


    /**
     * @Description: 一键处理
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/alarmHandlingAll")
    @ResponseBody
    public ReturnMap alarmHandlingAll() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPost("/region/alarm/alarmHandlingAll", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域列表
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/otherRegion/list")
    @ResponseBody
    public ReturnMap otherRegionList(Page page) throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.getRyRegionList(Jurisdiction.getCORPINFO_ID(), pageData.getString("str"), Integer.parseInt(pageData.getString("currentPage")), Integer.parseInt(pageData.getString("showCount")), Integer.parseInt(pageData.getString("type")));
        if (body != null) {
            returnMap.putAll(body);
            page.setTotalResult(body.getIntValue("total"));
            returnMap.put("page", page);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域禁、起用
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/otherRegion/editStatus")
    @ResponseBody
    public ReturnMap editStatus() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPut("/region/region", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域删除
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/otherRegion/regionDelete")
    @ResponseBody
    public ReturnMap regionDelete() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralDelete("/region/region/", pageData.getString("DATA_IDS"), Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域单个详情
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/otherRegion/regionGoEdit")
    @ResponseBody
    public ReturnMap regionGoEdit() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralGetById("/region/region/", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 确认选点 /region/region/redrawTheArea
     * @Author: dearLin
     * @Date: 2024/2/22/022 15:06
     * @Param:
     * @Return:
     */
    @RequestMapping(value = "/otherRegion/save")
    @ResponseBody
    public ReturnMap otherRegionSave() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray list = JSONObject.parseArray(pageData.getString("list"));
        pageData.put("list", list);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPost("/region/region", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 确认选点 /region/region/redrawTheArea
     * @Author: dearLin
     * @Date: 2024/2/22/022 15:06
     * @Param:
     * @Return:
     */
    @RequestMapping(value = "/otherRegion/redrawTheArea")
    @ResponseBody
    public ReturnMap redrawTheArea() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray list = JSONObject.parseArray(pageData.getString("list"));
        pageData.put("list", list);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPost("/region/region/redrawTheArea", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域所属图层
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/otherRegion/selectRegionTreeVo")
    @ResponseBody
    public ReturnMap selectRegionTreeVo() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GetGeneral("/region/region/selectRegionTreeVo", Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域修改
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/otherRegion/regionEdit")
    @ResponseBody
    public ReturnMap regionEdit() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray list = JSONObject.parseArray(pageData.getString("list"));
        pageData.put("list", list);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPut("/region/region", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域配置列表
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/electronicFence/list")
    @ResponseBody
    public ReturnMap electronicFenceList(Page page) throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralList("/region/electronicFence/list", pageData);
        if (body != null) {
            returnMap.putAll(body);
            page.setTotalResult(body.getIntValue("total"));
            returnMap.put("page", page);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域配置单个详情
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/electronicFenceGoEdit")
    @ResponseBody
    public ReturnMap electronicFenceGoEdit() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralGetById("/region/electronicFence/", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域配置修改
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/electronicFenceEdit")
    @ResponseBody
    public ReturnMap electronicFenceEdit() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray regGatherId = JSONObject.parseArray(pageData.getString("regGatherId"));
        JSONArray gatherRegions = JSONObject.parseArray(pageData.getString("gatherRegions"));
        JSONArray list = JSONObject.parseArray(pageData.getString("eleType"));
        JSONArray eleDept = JSONObject.parseArray(pageData.getString("eleDept"));
        JSONArray eleCrossed = JSONObject.parseArray(pageData.getString("eleCrossed"));
        JSONArray regId = JSONObject.parseArray(pageData.getString("regId"));
        JSONArray regions = JSONObject.parseArray(pageData.getString("regions"));
        JSONArray regId1 = JSONObject.parseArray(pageData.getString("regId1"));
        JSONArray doubles = JSONObject.parseArray(pageData.getString("doubles"));
        pageData.put("regGatherId", regGatherId);
        pageData.put("gatherRegions", gatherRegions);
        pageData.put("eleType", list);
        pageData.put("eleDept", eleDept);
        pageData.put("eleCrossed", eleCrossed);
        pageData.put("regions", regions);
        pageData.put("regId", regId);
        pageData.put("regId1", regId1);
        pageData.put("doubles", doubles);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPut("/region/electronicFence/", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域配置修改
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/electronicFenceSave")
    @ResponseBody
    public ReturnMap electronicFenceSave() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray list = JSONObject.parseArray(pageData.getString("eleType"));
        JSONArray eleDept = JSONObject.parseArray(pageData.getString("eleDept"));
        JSONArray eleCrossed = JSONObject.parseArray(pageData.getString("eleCrossed"));
        JSONArray regId = JSONObject.parseArray(pageData.getString("regId"));
        JSONArray regions = JSONObject.parseArray(pageData.getString("regions"));
        JSONArray regId1 = JSONObject.parseArray(pageData.getString("regId1"));
        JSONArray doubles = JSONObject.parseArray(pageData.getString("doubles"));
        JSONArray regGatherId = JSONObject.parseArray(pageData.getString("regGatherId"));
        pageData.put("eleType", list);
        pageData.put("eleDept", eleDept);
        pageData.put("eleCrossed", eleCrossed);
        pageData.put("regions", regions);
        pageData.put("regId", regId);
        pageData.put("regId1", regId1);
        pageData.put("doubles", doubles);
        pageData.put("regGatherId", regGatherId);

        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPost("/region/electronicFence/", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警区域配置停用启用
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/electronicFenceStatus")
    @ResponseBody
    public ReturnMap electronicFenceStatus() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPut("/region/electronicFence/", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 其他告警配置删除
     * @Author: dearLin
     * @Date: 2024/2/22/022 9:29
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/electronicFenceDelete")
    @ResponseBody
    public ReturnMap electronicFenceDelete() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralDelete("/region/electronicFence/", pageData.getString("DATA_IDS"), Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }


    /*
     * 聚集告警记录
     * */

    @RequestMapping(value = "/getAlarmRecordList")
    @ResponseBody
    public ReturnMap getAlarmRecordList(Page page) throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        // /old/gatherAlarms/regAlarmGatherList?pageNum=1&pageSize=10&status=1
        JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/regAlarmGatherList", pageData);
        if (body != null) {
            returnMap.putAll(body);
            page.setTotalResult(body.getIntValue("total"));
            returnMap.put("page", page);
        }
        return returnMap;
    }

    /* 聚集概览 */

    /**
     * @Description: 聚集告警趋势统计
     * @Author: dearLin
     * @Date: 2024/2/26/026 9:20
     * @Param: [com.zcloud.entity.Page] [page]
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/aggregateAlarmTrends")
    @ResponseBody
    public ReturnMap aggregateAlarmTrends() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        // /old/gatherAlarms/aggregateAlarmTrends?type=2&time=2023-12-18
        JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/aggregateAlarmTrends", pageData);
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 根据告警区域进行聚集数据统计
     * @Author: dearLin
     * @Date: 2024/2/26/026 9:20
     * @Param: [com.zcloud.entity.Page] [page]
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/aggregateDataStatisticsByGroup")
    @ResponseBody
    public ReturnMap aggregateDataStatisticsByGroup() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/aggregateDataStatisticsByGroup", pageData);
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 根据告警等级进行聚集数据统计
     * @Author: dearLin
     * @Date: 2024/2/26/026 9:20
     * @Param: [com.zcloud.entity.Page] [page]
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/aggregateDataStatistics")
    @ResponseBody
    public ReturnMap aggregateDataStatistics() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/aggregateDataStatistics", pageData);
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }


    //串岗告警参数
    //允许进入人员
    @RequestMapping(value = "/getPsnInfo")
    @ResponseBody
    public ReturnMap getPsnInfo() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralList("/deploy/psnmgt/getPsnInfo", pageData);
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    // 允许进入部门
    ///deploy/dept/list
    @RequestMapping(value = "/getDeptList")
    @ResponseBody
    public ReturnMap getDeptList() throws Exception {
        PageData pageData = this.getPageData();
        pageData.put("pageNum", 1);
        pageData.put("pageSize", 9999);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralList("/deploy/dept/list", pageData);
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    @RequestMapping(value = "/alarmRecordgoEdit")
    @ResponseBody
    public ReturnMap alarmRecordgoEdit(Page page) throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/regAlarmGatherInfoList", pageData);
        if (body != null) {
            returnMap.putAll(body);
            page.setTotalResult(body.getIntValue("total"));
            returnMap.put("page", page);
        }
        return returnMap;
    }

    @RequestMapping(value = "/getAlarmGatherPsnInfo")
    @ResponseBody
    public ReturnMap getAlarmGatherPsnInfo() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralGetById("/old/gatherAlarms/getAlarmGatherPsnInfo?id=", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }
}

