package com.zcloud.controller.positioning;

import com.alibaba.fastjson.JSON;
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.service.positAlarm.PositAlarmService;
import com.zcloud.util.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.*;

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

    @Value("${zf.biCount.url}")
    private String prePath;

    @Resource
    private PositAlarmService positAlarmService;

    /*
     * 告警类型占比情况
     * 告警记录总数
     * */
    @RequestMapping(value = "/statisticsAreCollectedBasedOnTheAlarmTypeV2")
    @ResponseBody
    public ReturnMap statisticsAreCollectedBasedOnTheAlarmTypeV2() throws Exception {
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            String url = prePath + "/alarmV2/count/statisticsAreCollectedBasedOnTheAlarmType?CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID();
            // 集团版加租户id
            if ("1".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                url += "&tenantId=" + PLSGroupUtil.getTenantId(Jurisdiction.getCORPINFO_ID());
            }
            JSONObject body = PLSUtil.GetGeneralCount(url, Jurisdiction.getCORPINFO_ID());
            return ReturnMap.ok().put("data", body);
        }
        PageData pageData = new PageData();
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("滞留报警", "0");
        objectObjectHashMap.put("串岗报警", "0");
        objectObjectHashMap.put("超员报警", "0");
        objectObjectHashMap.put("缺员报警", "0");
        objectObjectHashMap.put("静止报警", "0");
        objectObjectHashMap.put("一键报警", "0");
        objectObjectHashMap.put("越界报警", "0");
        objectObjectHashMap.put("聚集报警", "0");
        pageData.put("varList", new ArrayList<>(objectObjectHashMap.entrySet()));
        return ReturnMap.ok().put("data", pageData);
    }
//
    // http://localhost:10001/alarm/count/previewDataStatisticsOfPersonnelLocationAlarms?type=3&time=

    /**
     * @Description: 告警区域统计
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/aggregationAlarmAreaStatisticsV2")
    @ResponseBody
    public ReturnMap aggregationAlarmAreaStatisticsV2() throws Exception {
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            String url = prePath + "/alarmV2/count/alarmAreaStatistics?CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID();
            // 集团版加租户id
            if ("1".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                url += "&tenantId=" + PLSGroupUtil.getTenantId(Jurisdiction.getCORPINFO_ID());
            }
            JSONObject body = PLSUtil.GetGeneralCount(url, Jurisdiction.getCORPINFO_ID());
            return ReturnMap.ok().put("data", body);
        }
        return ReturnMap.ok().put("data", new ArrayList<>());
    }

    /**
     * @Description: 待处理告警数
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/alarmDataYearV2")
    @ResponseBody
    public ReturnMap alarmDataYearV2() throws Exception {
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            String url = prePath + "/alarmV2/count/pendingAlarmsNumber?CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID();
            // 集团版加租户id
            if ("1".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                url += "&tenantId=" + PLSGroupUtil.getTenantId(Jurisdiction.getCORPINFO_ID());
            }
            JSONObject body = PLSUtil.GetGeneralCount(url, Jurisdiction.getCORPINFO_ID());
            return ReturnMap.ok().put("data", body);
        }
        PageData pageData = new PageData();
        pageData.put("pendingAlarm", 0);
        return ReturnMap.ok().put("data", pageData);
    }

    /**
     * @Description: 本年度告警，处理总数
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/alarmDataYear")
    @ResponseBody
    public ReturnMap alarmDataYear() throws Exception {
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                try {
                    JSONObject body = PLSUtil.GetGeneralCount(prePath + "/alarm/count/alarmDataYear?CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID(), Jurisdiction.getCORPINFO_ID());
                    return ReturnMap.ok().put("data", body);
                } catch (Exception e) {
                    HashMap<Object, Object> objectObjectHashMap1 = new HashMap<>();
                    HashMap<String, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put("alarm_count", 0);
                    objectObjectHashMap.put("dispose_count", 0);
                    objectObjectHashMap1.put("data", objectObjectHashMap);

                    return ReturnMap.ok().put("data", objectObjectHashMap1);
                }
            } else {
                try {
                    Calendar cal = Calendar.getInstance();  // 获取当前时间的Calendar实例
                    int year = cal.get(Calendar.YEAR);
                    JSONObject body = PLSGroupUtil.GetGeneralCount("/deploy/alarm/count/previewDataStatisticsOfPersonnelLocationAlarms?type=&time=" + year, Jurisdiction.getCORPINFO_ID());
                    HashMap<Object, Object> map = (HashMap<Object, Object>) body.get("data");
                    int alarm_count = 0, dispose_count = 0;
                    List<Integer> processingTotal = (List<Integer>) map.get("处理数");
                    for (Integer integer : processingTotal) {
                        dispose_count += integer;
                    }
                    List<Integer> alarmTotal = (List<Integer>) map.get("告警总数");
                    for (Integer integer : alarmTotal) {
                        alarm_count += integer;
                    }
                    HashMap<Object, Object> objectObjectHashMap1 = new HashMap<>();
                    HashMap<String, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put("alarm_count", alarm_count);
                    objectObjectHashMap.put("dispose_count", dispose_count);
                    objectObjectHashMap1.put("data", objectObjectHashMap);
                    return ReturnMap.ok().put("data", objectObjectHashMap1);
                } catch (Exception e) {
                    HashMap<Object, Object> objectObjectHashMap1 = new HashMap<>();
                    HashMap<String, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put("alarm_count", 0);
                    objectObjectHashMap.put("dispose_count", 0);
                    objectObjectHashMap1.put("data", objectObjectHashMap);

                    return ReturnMap.ok().put("data", objectObjectHashMap1);
                }
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }

    /**
     * @Description: 人员定位告警预览数据统计
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/previewDataStatisticsOfPersonnelLocationAlarms")
    @ResponseBody
    public ReturnMap previewDataStatisticsOfPersonnelLocationAlarms() throws Exception {

        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            PageData pageData = this.getPageData();
            String url = prePath + "/alarmV2/count/previewLocationAlarms?type=" + pageData.getString("type") + "&CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID() + "&time=" + pageData.getOrDefault("time", "");
            // 集团版加租户id
            if ("1".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                url += "&tenantId=" + PLSGroupUtil.getTenantId(Jurisdiction.getCORPINFO_ID());
            }
            JSONObject body = PLSUtil.GetGeneralCount(url, Jurisdiction.getCORPINFO_ID());
            return ReturnMap.ok().put("data", body);
        } else {
            HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
            HashMap<Object, Object> o2 = new HashMap<>();
            ArrayList<String> alarmType = new ArrayList<>();
            ArrayList<Integer> processingTotal = new ArrayList<>();
            ArrayList<Integer> alarmTotal = new ArrayList<>();
            alarmType.add("滞留报警");
            alarmType.add("串岗报警");
            alarmType.add("超员报警");
            alarmType.add("静止报警");
            alarmType.add("一键报警");
            alarmType.add("越界报警");
            alarmType.add("聚集报警");

            processingTotal.add(0);
            processingTotal.add(0);
            processingTotal.add(0);
            processingTotal.add(0);
            processingTotal.add(0);
            processingTotal.add(0);
            processingTotal.add(0);

            alarmTotal.add(0);
            alarmTotal.add(0);
            alarmTotal.add(0);
            alarmTotal.add(0);
            alarmTotal.add(0);
            alarmTotal.add(0);
            alarmTotal.add(0);
            o2.put("alarmType", alarmType);
            o2.put("processingTotal", processingTotal);
            o2.put("alarmTotal", alarmTotal);
            objectObjectHashMap.put("list", o2);
            return ReturnMap.ok().put("data", objectObjectHashMap);
        }
//        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
//            PageData pageData = this.getPageData();
//
//            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
//                // 1:每日告警,2:每周告警,3:每月告警
//                try {
//                    JSONObject body = PLSUtil.GetGeneralCount(prePath + "/alarm/count/previewDataStatisticsOfPersonnelLocationAlarms?type=" + pageData.getString("type") + "&CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID() + "&time="+ pageData.getOrDefault("time",""), Jurisdiction.getCORPINFO_ID());
//                    return ReturnMap.ok().put("data", body);
//                } catch (Exception e) {
//                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
//                    HashMap<Object, Object> o2 = new HashMap<>();
//                    ArrayList<String> alarmType = new ArrayList<>();
//                    ArrayList<Integer> processingTotal = new ArrayList<>();
//                    ArrayList<Integer> alarmTotal = new ArrayList<>();
//                    alarmType.add("滞留报警");
//                    alarmType.add("串岗报警");
//                    alarmType.add("超员报警");
//                    alarmType.add("静止报警");
//                    alarmType.add("一键报警");
//                    alarmType.add("越界报警");
//                    alarmType.add("聚集报警");
//
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    o2.put("alarmType", alarmType);
//                    o2.put("processingTotal", processingTotal);
//                    o2.put("alarmTotal", alarmTotal);
//                    objectObjectHashMap.put("list", o2);
//                    return ReturnMap.ok().put("data", objectObjectHashMap);
//                }
//            } else {
//                // 新的人员定位
//                PageData pageData = this.getPageData();
//                // 1:每日告警,2:每周告警,3:每月告警
//                try {
//                    JSONObject body = PLSGroupUtil.GetGeneralCount("/deploy/alarm/count/previewDataStatisticsOfPersonnelLocationAlarms?type=" + pageData.getString("type") + "&time=", Jurisdiction.getCORPINFO_ID());
//                    HashMap<Object, Object> map = (HashMap<Object, Object>) body.get("data");
//                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
//                    HashMap<Object, Object> o2 = new HashMap<>();
//                    o2.put("processingTotal", map.get("处理数"));
//                    o2.put("alarmType", map.get("告警类型"));
//                    o2.put("alarmTotal", map.get("告警总数"));
//                    objectObjectHashMap.put("list", o2);
//                    return ReturnMap.ok().put("data", objectObjectHashMap);
//                } catch (Exception e) {
//                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
//                    HashMap<Object, Object> o2 = new HashMap<>();
//                    ArrayList<String> alarmType = new ArrayList<>();
//                    ArrayList<Integer> processingTotal = new ArrayList<>();
//                    ArrayList<Integer> alarmTotal = new ArrayList<>();
//                    alarmType.add("滞留报警");
//                    alarmType.add("串岗报警");
//                    alarmType.add("超员报警");
//                    alarmType.add("静止报警");
//                    alarmType.add("一键报警");
//                    alarmType.add("越界报警");
//                    alarmType.add("聚集报警");
//
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//                    processingTotal.add(0);
//
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    alarmTotal.add(0);
//                    o2.put("alarmType", alarmType);
//                    o2.put("processingTotal", processingTotal);
//                    o2.put("alarmTotal", alarmTotal);
//                    objectObjectHashMap.put("list", o2);
//                    return ReturnMap.ok().put("data", objectObjectHashMap);
//                }
//            }
//        }
//        return ReturnMap.error("人员定位系统升级中");
    }


    /**
     * @Description: 聚集告警区域统计
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/aggregationAlarmAreaStatistics")
    @ResponseBody
    public ReturnMap aggregationAlarmAreaStatistics() throws Exception {
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                try {
                    JSONObject body = PLSUtil.GetGeneralCount(prePath + "/alarm/count/aggregationAlarmAreaStatistics2?CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID(), Jurisdiction.getCORPINFO_ID());
                    return ReturnMap.ok().put("data", body);
                } catch (Exception e) {
                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put("list", Collections.emptyList());
                    return ReturnMap.ok().put("data", objectObjectHashMap).put("infoError", e.getMessage());
                }
            } else {
                // 新的人员定位
                try {
                    JSONObject body = PLSGroupUtil.GetGeneralCount("/deploy/alarm/count/aggregationAlarmAreaStatistics", Jurisdiction.getCORPINFO_ID());
                    List<HashMap<Object, Object>> hashMapList = (List<HashMap<Object, Object>>) body.get("data");
                    List<String> stringList = new ArrayList<>();
                    for (HashMap<Object, Object> map : hashMapList) {
                        stringList.add((String) map.get("name"));
                    }
                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put("seriesData", hashMapList);
                    objectObjectHashMap.put("legendData", stringList);
                    return ReturnMap.ok().put("data", objectObjectHashMap);
                } catch (Exception e) {
                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put("list", Collections.emptyList());
                    return ReturnMap.ok().put("data", objectObjectHashMap).put("infoError", e.getMessage());
                }
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }

    /**
     * @Description: 按照告警类型 数据统计
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/statisticsAreCollectedBasedOnTheAlarmType")
    @ResponseBody
    public ReturnMap statisticsAreCollectedBasedOnTheAlarmType() throws Exception {
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                try {
                    JSONObject body = PLSUtil.GetGeneralCount(prePath + "/alarm/count/statisticsAreCollectedBasedOnTheAlarmType?CORPINFO_ID=" + Jurisdiction.getCORPINFO_ID(), Jurisdiction.getCORPINFO_ID());
                    LinkedHashMap<String, Object> originalMap = body.getObject("list", LinkedHashMap.class);
                    ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
                    for (Map.Entry<String, Object> entry : originalMap.entrySet()) {
                        String key = entry.getKey();
                        Object value = entry.getValue();
                        if (key.length() == 1) {
                            continue;
                        }
                        // 如果 value 是键中某个值，则替换为 0
                        if (originalMap.containsValue(value)) {
                            value = originalMap.get(value);
                        }

                        // 构建新的 HashMap
                        HashMap<String, Object> map = new HashMap<>();
                        map.put("name", key);
                        map.put("value", value);

                        // 添加到结果列表
                        resultList.add(map);
                    }
//                    dataList.get("")
                    return ReturnMap.ok().put("data", body).put("resultList", resultList);
                } catch (Exception e) {
                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put(0, 0);
                    objectObjectHashMap.put(1, 0);
                    objectObjectHashMap.put(2, 0);
                    objectObjectHashMap.put(3, 0);
                    objectObjectHashMap.put(4, 0);
                    objectObjectHashMap.put(5, 0);
                    objectObjectHashMap.put(6, 0);
                    objectObjectHashMap.put(7, 0);
                    objectObjectHashMap.put(8, 0);
                    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                    stringObjectHashMap.put("list", objectObjectHashMap);
                    return ReturnMap.ok().put("data", stringObjectHashMap).put("resultList", new ArrayList<HashMap<String, Object>>());
                }
            } else {
                // 新的
                try {
                    JSONObject body = PLSGroupUtil.GetGeneralCount("/deploy/alarm/count/statisticsAreCollectedBasedOnTheAlarmType", Jurisdiction.getCORPINFO_ID());
                    List<HashMap<String, Object>> lists = (List<HashMap<String, Object>>) body.get("data");
                    Map<String, Object> merged = new HashMap<>();
                    ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
                    lists.forEach(item -> {
                        for (Map.Entry<String, Object> entry : item.entrySet()) {
                            HashMap<String, Object> map = new HashMap<>();
                            map.put("name", entry.getKey());
                            map.put("value", entry.getValue());
                            resultList.add(map);
                        }
                        merged.putAll(item);
                    });
                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put(1, null != merged.get("滞留报警") ? merged.get("滞留报警") : 0);
                    objectObjectHashMap.put(2, null != merged.get("串岗报警") ? merged.get("串岗报警") : 0);
                    objectObjectHashMap.put(3, null != merged.get("超员报警") ? merged.get("超员报警") : 0);
                    objectObjectHashMap.put(4, null != merged.get("缺员报警") ? merged.get("缺员报警") : 0);
                    objectObjectHashMap.put(5, null != merged.get("静止报警") ? merged.get("静止报警") : 0);
                    objectObjectHashMap.put(6, null != merged.get("一键报警") ? merged.get("一键报警") : 0);
                    objectObjectHashMap.put(7, null != merged.get("越界报警") ? merged.get("越界报警") : 0);
                    objectObjectHashMap.put(8, null != merged.get("聚集报警") ? merged.get("聚集报警") : 0);
                    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                    stringObjectHashMap.put("list", objectObjectHashMap);
                    return ReturnMap.ok().put("data", stringObjectHashMap).put("resultList", resultList);
                } catch (Exception e) {
                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put(0, 0);
                    objectObjectHashMap.put(1, 0);
                    objectObjectHashMap.put(2, 0);
                    objectObjectHashMap.put(3, 0);
                    objectObjectHashMap.put(4, 0);
                    objectObjectHashMap.put(5, 0);
                    objectObjectHashMap.put(6, 0);
                    objectObjectHashMap.put(7, 0);
                    objectObjectHashMap.put(8, 0);
                    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                    stringObjectHashMap.put("list", objectObjectHashMap);
                    return ReturnMap.ok().put("data", stringObjectHashMap).put("resultList", new ArrayList<HashMap<String, Object>>());
                }
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                pageData.put("str", pageData.getOrDefault("pageData", ""));
                pageData.put("eleType", pageData.getOrDefault("eleType", ""));
                pageData.put("status", pageData.getOrDefault("status", ""));
                JSONObject body = PLSUtil.GeneralList("/region/alarm/list", pageData);
//                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;
            } else {
                pageData.put("str", pageData.getOrDefault("pageData", ""));
                pageData.put("eleType", pageData.getOrDefault("eleType", ""));
                pageData.put("status", pageData.getOrDefault("status", ""));
                JSONObject body = PLSGroupUtil.GeneralList("/deploy/alarm/list", pageData);
//                JSONObject body = PLSGroupUtil.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;
            }
        }
        return ReturnMap.ok().put("page", page);
    }


    /**
     * @Description: 告警数据 来自人员定位系统
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/getAlArmDataListLocal")
    @ResponseBody
    public Object getAlArmDataListLocal(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("CORP_ID", Jurisdiction.getCORPINFO_ID());
        page.setPd(pd);
        List<PageData> list = positAlarmService.findPositAlarmListByCorpId(page);
        list.forEach(item -> {
            item.put("alarm_time", String.valueOf(item.getString("alarm_time")).contains(".")? String.valueOf(item.getString("alarm_time")).substring(0,String.valueOf(item.getString("alarm_time")).indexOf(".")): String.valueOf(item.getString("alarm_time")));
            item.put("dispose_time", String.valueOf(item.getString("dispose_time")).contains(".")? String.valueOf(item.getString("dispose_time")).substring(0,String.valueOf(item.getString("dispose_time")).indexOf(".")): String.valueOf(item.getString("dispose_time")));
        });
        map.put("varList", list);
        map.put("code", 0);
        map.put("msg", "success");
        map.put("result",errInfo);
        map.put("page",page);
        return map;
    }

    /**·
     * @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();
        String ids = pageData.getString("ids");
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                if (Tools.isEmpty(ids)) {
                    PageData editPosi = new PageData();
                    editPosi.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                    editPosi.put("NAME", Jurisdiction.getName());
                    List<PageData> list = positAlarmService.findPositAlarmList(editPosi);
                    List<String> idsList = new ArrayList<>();
                    list.forEach(item -> idsList.add(item.getString("id")));
                    editPosi.put("ArrayDATA_IDS", idsList);
                    // 是空的那么就是进行一键处理
                    JSONObject body = PLSUtil.GeneralPost("/region/alarm/alarmHandlingAll", pageData, Jurisdiction.getCORPINFO_ID());
                    if (body != null) {
                        returnMap.putAll(body);
                    }
                    positAlarmService.editDisposePerson(editPosi);
                    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);
                }
                // 修改处理人  为当前登录人
                PageData editPosi = new PageData();
                editPosi.put("ArrayDATA_IDS", pageData.getString("ids").split(","));
                editPosi.put("NAME", Jurisdiction.getName());
                editPosi.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                positAlarmService.editDisposePerson(editPosi);
                return returnMap;
            } else {
                PageData editPosi = new PageData();
                editPosi.put("ArrayDATA_IDS", pageData.getString("ids").split(","));
                editPosi.put("NAME", Jurisdiction.getName());
                editPosi.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                if (Tools.isEmpty(ids)) {
                    JSONObject body = PLSGroupUtil.GeneralPost("/deploy/alarm/alarmHandlingAll", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                    if (body != null) {
                        returnMap.putAll(body);
                    }
                    List<PageData> list = positAlarmService.findPositAlarmList(editPosi);
                    List<String> idsList = new ArrayList<>();
                    list.forEach(item -> idsList.add(item.getString("id")));
                    editPosi.put("ArrayDATA_IDS", idsList);
                } else {
                    JSONObject body = PLSGroupUtil.GeneralPost("/deploy/alarm/alarmHandling", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                    if (body != null) {
                        returnMap.putAll(body);
                    }
                }
                positAlarmService.editDisposePerson(editPosi);
                return returnMap;
            }
        }
        return ReturnMap.ok();
    }


    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                PageData editPosi = new PageData();
                editPosi.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                editPosi.put("NAME", Jurisdiction.getName());
                List<PageData> list = positAlarmService.findPositAlarmList(editPosi);
                List<String> idsList = new ArrayList<>();
                list.forEach(item -> idsList.add(item.getString("id")));
                editPosi.put("ArrayDATA_IDS", idsList);
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSUtil.GeneralPost("/region/alarm/alarmHandlingAll", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }

                positAlarmService.editDisposePerson(editPosi);

                return returnMap;
            } else {
                PageData editPosi = new PageData();
                editPosi.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                editPosi.put("NAME", Jurisdiction.getName());
                List<PageData> list = positAlarmService.findPositAlarmList(editPosi);
                List<String> idsList = new ArrayList<>();
                list.forEach(item -> idsList.add(item.getString("id")));
                editPosi.put("ArrayDATA_IDS", idsList);
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSGroupUtil.GeneralPost("/deploy/alarm/alarmHandlingAll", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                positAlarmService.editDisposePerson(editPosi);
                return returnMap;
            }
        }
        return ReturnMap.ok();
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralPut("/region/region", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GeneralPut("/deploy/region", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralDelete("/region/region/", pageData.getString("DATA_IDS"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
            } else {
                JSONObject body = PLSGroupUtil.GeneralDel("/deploy/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) {
            if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
                if (!"0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                    LinkedHashMap resData = (LinkedHashMap) body.get("data");
                    resData.put("regName", resData.get("mc"));
                    resData.put("layId", resData.get("layerId"));
                    body.put("data", resData);
                }
                returnMap.putAll(body);
            }
            return returnMap;
        }
        return ReturnMap.error("人员定位系统升级中");
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralPost("/region/region", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(pageData));
                jsonObject.put("layerId", jsonObject.getString("layId"));
                jsonObject.put("mc", jsonObject.getString("regName"));
                JSONObject body = PLSGroupUtil.GeneralPost("/deploy/region", jsonObject, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.ok();
    }

    /**
     * @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);
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSUtil.GeneralPost("/region/region/redrawTheArea", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSGroupUtil.GeneralPost("/deploy/region/redrawTheArea", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.ok();
    }

    /**
     * @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 {
        ReturnMap returnMap = new ReturnMap();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GetGeneral("/region/region/selectRegionTreeVo", Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GetGeneral("/deploy/region/selectRegionTreeVo?type=0", Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.ok();
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralPut("/region/region", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
            } else {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("id", pageData.getString("id"));
                jsonObject.put("mc", pageData.getString("regName"));
                jsonObject.put("layerId", pageData.getString("layId"));
                jsonObject.put("status", 0);
                JSONObject body = PLSGroupUtil.GeneralPut("/deploy/region", jsonObject, 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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                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;
            } else {
                pageData.put("eleName", pageData.getString("str"));
                PageData vaurl = new PageData();
                vaurl.put("eleName", pageData.getString("str"));
                vaurl.put("currentPage", pageData.getString("currentPage"));
                vaurl.put("showCount", pageData.getString("showCount"));
                JSONObject body;
                if ("0".equals(pageData.getString("isGatheringAlarm"))) {
//                    围栏告警配置
                    // /deploy/fence/list
                    body = PLSGroupUtil.GeneralList("/deploy/fence/list", vaurl);
                } else {
//                   聚集告警配置
                    body = PLSGroupUtil.GeneralList("/deploy/gatherFence/list", vaurl);
                }
                if (body != null) {
                    returnMap.putAll(body);
                    page.setTotalResult(body.getIntValue("total"));
                    returnMap.put("page", page);
                }
                return returnMap;
            }
        }
        return ReturnMap.ok();
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralGetById("/region/electronicFence/", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GeneralGetById("/deploy/fence/", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位服务升级中");
    }

    @RequestMapping(value = "/electronicFenceJjGoEdit")
    @ResponseBody
    public ReturnMap electronicFenceJjGoEdit() throws Exception {
        PageData pageData = this.getPageData();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralGetById("/region/electronicFence/", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body;
                if ("0".equals(pageData.getString("isGatheringAlarm"))) {
                    // 围栏告警配置
                    body = PLSGroupUtil.GeneralGetById("/deploy/fence/", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
                } else {
                    // 聚集告警配置
                    body = PLSGroupUtil.GeneralGetById("/deploy/gatherFence/", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
                }
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位服务升级中");
    }

    /**
     * @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);
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSUtil.GeneralPut("/region/electronicFence/", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body;
                if ("0".equals(pageData.getString("isGatheringAlarm"))) {
//                    围栏告警配置
                    // /deploy/fence/list
                    body = PLSGroupUtil.GeneralPut("/deploy/fence", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());

                } else {
//                   聚集告警配置
                    body = PLSGroupUtil.GeneralPut("/deploy/gatherFence", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                }

//                JSONObject body = PLSGroupUtil.GeneralPut("/deploy/fence", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.ok();

    }

    /**
     * @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);
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSUtil.GeneralPost("/region/electronicFence/", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSGroupUtil.GeneralPost("/deploy/gatherFence", JSONObject.parseObject(JSON.toJSONString(pageData)), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.ok();

    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralPut("/region/electronicFence/", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSUtil.GeneralPut("/deploy/fence", pageData, Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位服务升级中");
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralDelete("/region/electronicFence/", pageData.getString("DATA_IDS"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GeneralDel("/deploy/fence/" + pageData.getString("DATA_IDS"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位服务升级中");
    }


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

    @RequestMapping(value = "/getAlarmRecordList")
    @ResponseBody
    public ReturnMap getAlarmRecordList(Page page) throws Exception {
        PageData pageData = this.getPageData();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();

            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                // /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;
            } else {
                JSONObject body = PLSGroupUtil.GeneralList("/deploy/gatherAlarms/regAlarmGatherList", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                    page.setTotalResult(body.getIntValue("total"));
                    returnMap.put("page", page);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("定位服务升级中");

    }

    /* 聚集概览 */

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/aggregateAlarmTrends", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GeneralList("/deploy/gatherAlarms/aggregateAlarmTrends", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        // /old/gatherAlarms/aggregateAlarmTrends?type=2&time=2023-12-18
        return ReturnMap.error("定位服务升级中");
    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/aggregateDataStatisticsByGroup", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                ReturnMap returnMap = new ReturnMap();
                JSONObject body = PLSGroupUtil.GeneralList("/deploy/gatherAlarms/aggregateDataStatisticsByGroup", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位服务升级中");

    }

    /**
     * @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();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralList("/old/gatherAlarms/aggregateDataStatistics", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GeneralList("/deploy/gatherAlarms/aggregateDataStatistics", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }


    //串岗告警参数
    //允许进入人员
    @RequestMapping(value = "/getPsnInfo")
    @ResponseBody
    public ReturnMap getPsnInfo() throws Exception {
        PageData pageData = this.getPageData();
        pageData.put("pageNum", 1);
        pageData.put("pageSize", 9999);
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralList("/deploy/psnmgt/getPsnInfo", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GeneralList("/deploy/personnel/list", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位服务升级中");

    }

    // 允许进入部门
    ///deploy/dept/list
    @RequestMapping(value = "/getDeptList")
    @ResponseBody
    public ReturnMap getDeptList() throws Exception {
        PageData pageData = this.getPageData();
        pageData.put("pageNum", 1);
        pageData.put("pageSize", 9999);
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {

                JSONObject body = PLSUtil.GeneralList("/deploy/dept/list", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSUtil.GeneralList("/system/dept/list", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }

    @RequestMapping(value = "/alarmRecordgoEdit")
    @ResponseBody
    public ReturnMap alarmRecordgoEdit(Page page) throws Exception {
        PageData pageData = this.getPageData();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            ReturnMap returnMap = new ReturnMap();

            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                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;
            } else {
                JSONObject body = PLSGroupUtil.GeneralList("/old/gatherAlarms/regAlarmGatherInfoList", pageData);
                if (body != null) {
                    returnMap.putAll(body);
                    page.setTotalResult(body.getIntValue("total"));
                    returnMap.put("page", page);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }

    @RequestMapping(value = "/getAlarmGatherPsnInfo")
    @ResponseBody
    public ReturnMap getAlarmGatherPsnInfo() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        if ("0".equals(Jurisdiction.getPERSONNEL_POSITION())) {
            if ("0".equals(Jurisdiction.getPERSONNEL_TYPE())) {
                JSONObject body = PLSUtil.GeneralGetById("/old/gatherAlarms/getAlarmGatherPsnInfo?id=", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            } else {
                JSONObject body = PLSGroupUtil.GeneralGetById("/deploy/gatherAlarms/getAlarmGatherPsnInfo?id=", pageData.getString("id"), Jurisdiction.getCORPINFO_ID());
                if (body != null) {
                    returnMap.putAll(body);
                }
                return returnMap;
            }
        }
        return ReturnMap.error("人员定位系统升级中");
    }
}

