Ejemplo n.º 1
0
        /// <summary>
        /// 跨天处理
        /// </summary>
        private void CrossDay(DateTime nowTime, DateTime tomorrowTime)
        {
            try
            {
                //DateTime nowTime = time;
                //nowTime = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59);

                //DateTime tomorrowTime = nowTime.AddDays(1);
                //tomorrowTime = new DateTime(tomorrowTime.Year, tomorrowTime.Month, tomorrowTime.Day, 0, 0, 0);

                List <Jc_DefInfo> pointDefineItems;
                List <Jc_DevInfo> pointDevItems;
                Jc_DevInfo        pointDevItem;
                IDriver           driverObj = null;

                pointDefineItems = CacheDataHelper.GetAllSystemPointDefineItems();
                pointDefineItems = pointDefineItems.Where(a => a.DevPropertyID == (int)DeviceProperty.Substation).ToList();
                pointDevItems    = CacheDataHelper.GetAllDevItems();

                foreach (Jc_DefInfo station in pointDefineItems)
                {
                    pointDevItem = pointDevItems.FirstOrDefault(a => a.Devid == station.Devid);
                    if (pointDevItem != null)
                    {
                        if (GlobleStaticVariable.driverHandle.DriverItems.ContainsKey(pointDevItem.Sysid))
                        {
                            driverObj = GlobleStaticVariable.driverHandle.DriverItems[pointDevItem.Sysid].DLLObj;
                            DriverTransferInterface.Drv_CrossDayPro(driverObj, station.Fzh, nowTime, tomorrowTime);
                        }
                    }
                }
                //人员定位报警表跨天处理  20171206
                KJ237CacheHelper.Drv_CrossDayPro(nowTime, tomorrowTime);
            }
            catch (Exception ex)
            {
                LogHelper.Error("CrossDay Error:" + ex.Message);
            }
        }
        private void DataProc()
        {
            List <Jc_DefInfo>             pointDefineItems         = null;
            SettingInfo                   settingInfo              = null;
            string                        settingTime              = ""; //上次加载倍率报警配置时间
            List <JC_MultiplesettingInfo> multiplesettingInfotems  = null;
            JC_MultiplesettingInfo        multiplesettingInfotem   = null;
            List <RatioAlarmConditions>   ratioAlarmConditionItems = null;
            RatioAlarmConditions          ratioAlarmConditionItem  = null;
            double                        sszValue   = 0;
            double                        basicValue = 0;
            int              alarmType         = 0;
            JC_MbInfo        ratioAlarm        = null;
            DateTime         getBasicValueDate = DateTime.Now.AddDays(-1); //上次获取周平均值的时间
            List <JC_MbInfo> alarm_AddItems    = new List <JC_MbInfo>();
            List <JC_MbInfo> alarm_DelItems    = new List <JC_MbInfo>();
            List <JC_MbInfo> alarm_UpdateItems = new List <JC_MbInfo>();

            DateTime lastProcData = DateTime.Now; //最后一次处理数据的日期
            DateTime nowTime      = DateTime.Now; //本次处理时间

            for (; ;)
            {
                try
                {
                    nowTime = DateTime.Now;
                    if (isStop)
                    {
                        break;
                    }
                    //获取定义信息
                    pointDefineItems = CacheDataHelper.GetKJPointDefineItems();

                    //判断是否重载倍率报警定义
                    settingInfo = CacheDataHelper.GetSettingByKeyStr("MultipleSettingUpdateTime");
                    if (settingInfo != null)
                    {
                        if (settingTime != settingInfo.StrValue)
                        {
                            //重新加载倍率报警定义信息
                            multiplesettingInfotems = GetAllMultiplesettingInfo();
                            settingTime             = settingInfo.StrValue;
                        }
                    }
                    else
                    {
                        Thread.Sleep(timeSpan * 1000);
                        continue;
                    }

                    //筛选模拟量
                    pointDefineItems = pointDefineItems.Where(a => (a.DevPropertyID == (int)DeviceProperty.Analog) &&
                                                              (multiplesettingInfotems.FirstOrDefault(b => b.Devid == a.Devid) != null)).ToList();

                    if (pointDefineItems.Count == 0)
                    {
                        Thread.Sleep(timeSpan * 1000); continue;
                    }


                    //重载周平均值
                    if (getBasicValueDate.Date != nowTime.Date)
                    {
                        ReloadBasicValues(pointDefineItems);
                        getBasicValueDate = nowTime;
                    }

                    if (pointDefineItems == null)
                    {
                        Thread.Sleep(timeSpan * 1000); continue;
                    }
                    if (pointDefineItems.Count == 0)
                    {
                        Thread.Sleep(timeSpan * 1000); continue;
                    }



                    alarm_AddItems    = new List <JC_MbInfo>();
                    alarm_DelItems    = new List <JC_MbInfo>();
                    alarm_UpdateItems = new List <JC_MbInfo>();

                    if (lastProcData.Date != nowTime.Date)
                    {
                        //结束报警重新生成
                        CrossDay(pointDefineItems, multiplesettingInfotems, new DateTime(lastProcData.Year, lastProcData.Month, lastProcData.Day, 23, 59, 59), new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 0, 0, 0));
                        lastProcData = nowTime;
                    }

                    foreach (Jc_DefInfo def in pointDefineItems)
                    {
                        if (isStop)
                        {
                            break;
                        }
                        if (double.TryParse(def.Ssz, out sszValue))
                        {
                            multiplesettingInfotem = multiplesettingInfotems.FirstOrDefault(a => a.Devid == def.Devid);
                            if (multiplesettingInfotem == null)
                            {
                                continue;
                            }                                                                                  //未定义该设备类型的倍率报警
                            ratioAlarmConditionItems = GetRatioAlarmConditionsFromStr(multiplesettingInfotem); //解析倍率报警配置
                            if (ratioAlarmConditionItems == null)
                            {
                                continue;
                            }                                       //提取倍率报警定义出错,不继续计算
                            basicValue = GetBasicValueByDef(def);   //获取周平均值
                            if (basicValue == 0)
                            {
                                continue;
                            }                                   //没有基础值,不计算
                            //计算报警等级
                            alarmType = JudgeAlarmType(sszValue, ratioAlarmConditionItems, basicValue);
                            if (alarmType != 0)
                            {
                                ratioAlarmConditionItem = ratioAlarmConditionItems[alarmType - 1];  //获取当前报警的倍率信息配置
                            }
                            ratioAlarm = GetAlarmInfo(def.Point);
                            #region ----报警处理----

                            if (ratioAlarm == null)
                            {
                                if (alarmType > 0)
                                {
                                    //之前没有报警 现在有报警(新增报警)
                                    ratioAlarm         = new JC_MbInfo();
                                    ratioAlarm.Id      = IdHelper.CreateLongId().ToString();
                                    ratioAlarm.Point   = def.Point;
                                    ratioAlarm.PointID = def.PointID;
                                    ratioAlarm.Fzh     = def.Fzh.ToString();
                                    ratioAlarm.Kh      = def.Kh.ToString();
                                    ratioAlarm.Dzh     = def.Dzh.ToString();
                                    ratioAlarm.Devid   = def.Devid;
                                    ratioAlarm.Wzid    = def.Wzid;
                                    ratioAlarm.Type    = alarmType.ToString();
                                    ratioAlarm.Bstj    = "[" + ratioAlarmConditionItem.minValue + "," + ratioAlarmConditionItem.maxValue + "," + ratioAlarmConditionItem.ratioValue + "]";
                                    ratioAlarm.Bsz     = ratioAlarmConditionItem.ratioValue;
                                    ratioAlarm.Stime   = nowTime;
                                    ratioAlarm.Ssz     = Convert.ToDouble(def.Ssz);
                                    ratioAlarm.Pjz     = basicValue;
                                    ratioAlarm.Zdz     = sszValue;
                                    ratioAlarm.Zdzs    = nowTime;

                                    alarm_AddItems.Add(ratioAlarm);
                                }
                            }
                            else
                            {
                                if (alarmType == 0)
                                {
                                    //之前有报警 现在没有报警(结束报警)
                                    ratioAlarm.Etime = nowTime;
                                    alarm_DelItems.Add(ratioAlarm);
                                }
                                else
                                {
                                    if (alarmType.ToString() != ratioAlarm.Type)
                                    {
                                        //之前有报警 报警切换(结束旧报警,生成新报警)
                                        ratioAlarm.Etime = nowTime;
                                        alarm_DelItems.Add(ratioAlarm);

                                        //生成新报警
                                        ratioAlarm         = new JC_MbInfo();
                                        ratioAlarm.Id      = IdHelper.CreateLongId().ToString();
                                        ratioAlarm.Point   = def.Point;
                                        ratioAlarm.PointID = def.PointID;
                                        ratioAlarm.Fzh     = def.Fzh.ToString();
                                        ratioAlarm.Kh      = def.Kh.ToString();
                                        ratioAlarm.Dzh     = def.Dzh.ToString();
                                        ratioAlarm.Devid   = def.Devid;
                                        ratioAlarm.Wzid    = def.Wzid;
                                        ratioAlarm.Type    = alarmType.ToString();
                                        ratioAlarm.Bstj    = "[" + ratioAlarmConditionItem.minValue + "," + ratioAlarmConditionItem.maxValue + "," + ratioAlarmConditionItem.ratioValue + "]";
                                        ratioAlarm.Bsz     = ratioAlarmConditionItem.ratioValue;
                                        ratioAlarm.Stime   = nowTime;
                                        ratioAlarm.Ssz     = Convert.ToDouble(def.Ssz);
                                        ratioAlarm.Pjz     = basicValue;
                                        ratioAlarm.Zdz     = sszValue;
                                        ratioAlarm.Zdzs    = nowTime;

                                        alarm_AddItems.Add(ratioAlarm);
                                    }
                                    else
                                    {
                                        //报警状态持续,更新报警期间最大值
                                        if (sszValue > ratioAlarm.Zdz)
                                        {
                                            ratioAlarm.Zdz  = sszValue;
                                            ratioAlarm.Zdzs = nowTime;
                                            //更新报警
                                            alarm_UpdateItems.Add(ratioAlarm);
                                        }
                                    }
                                }
                            }

                            #endregion
                        }
                    }
                    if (alarm_DelItems.Count > 0)
                    {
                        EndAlarmItems(alarm_DelItems);
                    }
                    if (alarm_AddItems.Count > 0)
                    {
                        StartAlarms(alarm_AddItems);
                    }
                    if (alarm_UpdateItems.Count > 0)
                    {
                        UpdateAlarm(alarm_UpdateItems);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error("RatioAlarmProcHandle DataProc Error" + ex.Message);
                }
                Thread.Sleep(timeSpan * 1000);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 跨天和五分钟处理方法
        /// </summary>
        private void CrossDayAndFiveMinite()
        {
            DateTime          fiveMiniteProcMinite = DateTime.Now;
            DateTime          nowTime = DateTime.Now;
            List <Jc_DefInfo> pointDefineItems;
            List <Jc_DevInfo> pointDevItems;
            Jc_DevInfo        pointDevItem;
            IDriver           driverObj = null;
            int totalcount = 0;

            bool doFiveMinData = false; //是否要处理五分钟数据  2017.9.15 by

            for (; ;)
            {
                try
                {
                    doFiveMinData = false;

                    if (isStop)
                    {
                        LogHelper.Info("停止数据处理模块【跨天和五分钟处理方法处理完成】!");
                        break;
                    }

                    if (DateTime.Now.Day != nowTime.Day)
                    {
                        //2017.12.18 by 异常处理跨天(手动修改电脑时间)
                        CrossDay(new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59),
                                 new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0));
                    }

                    nowTime = DateTime.Now;

                    //if (nowTime.Hour == 0 && nowTime.Minute == 0)
                    //{
                    //    doFiveMinData = false;  //刚跨天00:00:00 满足写记录条件,但不应该写记录
                    //}
                    //else  if (nowTime.Hour == 23 && nowTime.Minute == 59 && nowTime.Second > 40 && nowTime.Minute != fiveMiniteProcMinite.Minute) //2017.9.15 by
                    //{
                    //    doFiveMinData = true;
                    //}
                    //else
                    if ((nowTime.Minute % 5 == 0) && (nowTime.Minute != fiveMiniteProcMinite.Minute))
                    {
                        doFiveMinData = true;
                    }

                    //if ((nowTime.Minute % 5 == 0) && (nowTime.Minute != fiveMiniteProcMinite.Minute))
                    if (doFiveMinData)
                    {
                        fiveMiniteProcMinite = nowTime;
                        #region ----五分钟数据处理----
                        pointDefineItems = CacheDataHelper.GetKJPointDefineItems();
                        pointDefineItems = pointDefineItems.Where(a => a.DevPropertyID == (int)DeviceProperty.Substation).ToList();
                        pointDevItems    = CacheDataHelper.GetAllDevItems();

                        foreach (Jc_DefInfo station in pointDefineItems)
                        {
                            pointDevItem = pointDevItems.FirstOrDefault(a => a.Devid == station.Devid);
                            if (pointDevItem != null)
                            {
                                if (GlobleStaticVariable.driverHandle.DriverItems.ContainsKey(pointDevItem.Sysid))
                                {
                                    driverObj = GlobleStaticVariable.driverHandle.DriverItems[pointDevItem.Sysid].DLLObj;
                                    DriverTransferInterface.Drv_FiveMinPro(driverObj, station.Fzh, nowTime);
                                }
                            }
                        }

                        #endregion
                    }
                    if (nowTime.Hour == 23 && nowTime.Minute == 59 && nowTime.Second > 50)
                    {
                        isCrossDay = true;
                        #region ----跨天处理----
                        //判断数据处理线程数据是否处理完成,处理完成才继续进行跨天处理  20170703
                        while (DataProcHandle.Instance.GetArriveDataCount() > 0)
                        {
                            Thread.Sleep(200);
                        }
                        //处理时已跨天  输出日志  20170703
                        if (DateTime.Now.Day != nowTime.Day)
                        {
                            Basic.Framework.Logging.LogHelper.Error("处理跨天数据时,时间已到第二天!");
                        }

                        //DateTime nowTime = time;
                        //nowTime = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59);

                        //DateTime tomorrowTime = nowTime.AddDays(1);
                        //tomorrowTime = new DateTime(tomorrowTime.Year, tomorrowTime.Month, tomorrowTime.Day, 0, 0, 0);
                        CrossDay(new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59),
                                 new DateTime(nowTime.AddDays(1).Year, nowTime.AddDays(1).Month, nowTime.AddDays(1).Day, 0, 0, 0)); //2017.12.18 by  增加手动修改电脑日期处理时增加

                        while (true)
                        {
                            Thread.Sleep(200);
                            if (DateTime.Now.Hour != 23)
                            {
                                CreatDayTable(DateTime.Now);
                                break;
                            }
                        }

                        #endregion
                        isCrossDay = false;
                        nowTime    = DateTime.Now; //正常跨天处理完成,将时间赋值到第二天
                    }
                    totalcount++;
                    if (totalcount >= 20)//每4秒记算一次馈电信息
                    {
                        totalcount = 0;
                        CheckAlarmFeeding();
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error("CrossDayAndFiveMinite Error:" + ex.Message);
                }
                Thread.Sleep(200);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 判断需要向交换机下发的命令,  修改支持命令同时发送  20171207
        /// </summary>
        /// <param name="mac"></param>
        /// <param name="macItems"></param>
        /// <returns></returns>
        public static List <MasProtocol> GetMacSendData(string mac, List <Jc_MacInfo> macItems)
        {
            List <MasProtocol> masProtocolList = new List <MasProtocol>();

            try
            {
                Jc_MacInfo macInfo = macItems.FirstOrDefault(a => a.MAC == mac);
                if (macInfo != null)
                {
                    if ((macInfo.NCommandbz & 0x02) == 0x02)
                    {
                        #region ----下发模拟报警----

                        ResetDeviceCommandRequest resetDeviceCommandRequest = new ResetDeviceCommandRequest();
                        resetDeviceCommandRequest.DeviceCode     = mac;
                        resetDeviceCommandRequest.LastAcceptFlag = (byte)macInfo.testAlarmFlag;
                        resetDeviceCommandRequest.Mac            = mac;

                        MasProtocol masProtocol = null;
                        masProtocol          = new MasProtocol(SystemType.Security, DirectionType.Down, ProtocolType.ResetNetWorkDeviceRequest);
                        masProtocol.Protocol = resetDeviceCommandRequest;
                        masProtocolList.Add(masProtocol);

                        Dictionary <string, object> updateItems = new Dictionary <string, object>();
                        updateItems.Add("sendAlarmCount", macInfo.sendAlarmCount--);
                        if (macInfo.sendAlarmCount <= 0)
                        {
                            updateItems.Add("NCommandbz", (macInfo.NCommandbz & 0xFD));
                        }

                        CacheDataHelper.UpdateNetworkModeuleCacheByPropertys(macInfo.MAC, updateItems);
                        LogHelper.Info(macInfo.MAC + "下发模拟报警,待下发" + macInfo.sendAlarmCount + "次");

                        #endregion
                    }

                    if (((macInfo.NCommandbz & 0x01) == 0x01) || macInfo.SendBatteryControlCount > 0)
                    {
                        #region ----获取智能电源箱数据----
                        if ((DateTime.Now - macInfo.SendDtime).TotalSeconds <= 15)
                        {
                            if (macInfo.Type == 0 && macInfo.Bz4 == "1")//Bz4 = 1表示带智能电源箱
                            {
                                QueryBatteryRealDataRequest queryBatteryRealDataRequest = GetQueryBatteryRealDataRequest(macInfo);

                                MasProtocol masProtocol = null;
                                masProtocol          = new MasProtocol(SystemType.Security, DirectionType.Down, ProtocolType.QueryBatteryRealDataRequest);
                                masProtocol.Protocol = queryBatteryRealDataRequest;
                                masProtocolList.Add(masProtocol);
                            }
                        }
                        #endregion
                    }

                    #region ----人员定位呼叫命令(屏蔽  20180307) ----
                    //R_CallInfo tempCallInfo;
                    //string[] startAndEnd;
                    //int tempInt = 0;
                    //string tempStr;
                    //List<R_CallInfo> callItems = KJ237CacheHelper.GetCallItems().Where(a => a.CallType != 2).OrderBy(a => a.CallTime).ToList();
                    //if (callItems.Count > 0)//下发紧急呼叫及一般呼叫  20171206
                    //{
                    //    //先查找人员的全员呼叫命令并下发(呼叫所有设备与呼叫所有人员为同一命令)(优先级最高)
                    //    List<R_CallInfo> sendCallList = callItems.FindAll(a => a.CallType == 1 && (a.CallPersonDefType == 0 || a.CallPersonDefType == 3));
                    //    if (sendCallList.Count > 0)//全员呼叫下发
                    //    {
                    //        if (sendCallList[0].SendCount > 0)//判断是否还需要下发  20171213
                    //        {
                    //            CallPersonRequest request = new CallPersonRequest();
                    //            request.HJ_Type = 0;
                    //            request.HJ_State = 2;
                    //            request.DeviceCode = mac;
                    //            request.HJ_KH = new ushort[12];

                    //            MasProtocol masProtocol = null;
                    //            masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //            masProtocol.Protocol = request;


                    //            masProtocolList.Add(masProtocol);
                    //        }
                    //    }
                    //    else
                    //    {
                    //        #region//紧急呼叫井下设备
                    //        List<R_CallInfo> sendCallListByPoint = callItems.FindAll(a => a.CallType == 1 && (a.CallPersonDefType == 4));
                    //        if (sendCallListByPoint.Count > 0)
                    //        {
                    //            if (sendCallListByPoint[0].SendCount > 0)//判断是否还需要下发  20171213
                    //            {
                    //                CallPersonRequest request = new CallPersonRequest();
                    //                request.HJ_Type = 4;
                    //                request.HJ_State = 2;
                    //                request.DeviceCode = mac;
                    //                List<ushort> callContent = new List<ushort>();
                    //                foreach (R_CallInfo call in sendCallListByPoint)
                    //                {
                    //                    string[] callList = call.PointList.Split(',');
                    //                    foreach (string tempCall in callList)
                    //                    {
                    //                        callContent.Add(Convert.ToUInt16(((Convert.ToInt64(tempCall.Substring(0, 3)) << 8)) + Convert.ToInt64(tempCall.Substring(4, 2))));
                    //                        if (callContent.Count == 12)
                    //                        {
                    //                            request.HJ_KH = callContent.ToArray();
                    //                            MasProtocol masProtocol = null;
                    //                            masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                            masProtocol.Protocol = request;
                    //                            masProtocolList.Add(masProtocol);

                    //                            callContent = new List<ushort>();
                    //                        }
                    //                    }
                    //                }
                    //                if (callContent.Count > 0)
                    //                {
                    //                    request.HJ_KH = new ushort[12];
                    //                    for (int i = 0; i < callContent.Count; i++)
                    //                    {
                    //                        request.HJ_KH[i] = callContent[i];
                    //                    }
                    //                    MasProtocol masProtocol = null;
                    //                    masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                    masProtocol.Protocol = request;
                    //                    masProtocolList.Add(masProtocol);
                    //                }
                    //            }
                    //        }
                    //        #endregion
                    //        #region//紧急呼叫指定人员及指定卡号段下发,卡号段也按指定人员下发
                    //        List<R_CallInfo> sendCallListByPerson = callItems.FindAll(a => a.CallType == 1 && (a.CallPersonDefType == 1 || a.CallPersonDefType == 2));
                    //        if (sendCallListByPerson.Count > 0)
                    //        {
                    //            if (sendCallListByPerson[0].SendCount > 0)//判断是否还需要下发  20171213
                    //            {
                    //                CallPersonRequest request = new CallPersonRequest();
                    //                request.HJ_Type = 2;
                    //                request.HJ_State = 2;
                    //                request.DeviceCode = mac;
                    //                List<ushort> callContent = new List<ushort>();
                    //                foreach (R_CallInfo call in sendCallListByPerson)
                    //                {
                    //                    if (call.BhContent.Contains("-"))
                    //                    {//指定卡号段呼叫
                    //                        ushort sBh = ushort.Parse(call.BhContent.Split('-')[0]);
                    //                        ushort eBh = ushort.Parse(call.BhContent.Split('-')[1]);
                    //                        for (ushort i = sBh; i <= eBh; i++)
                    //                        {
                    //                            callContent.Add(i);
                    //                            if (callContent.Count == 12)
                    //                            {
                    //                                request.HJ_KH = callContent.ToArray();
                    //                                MasProtocol masProtocol = null;
                    //                                masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                                masProtocol.Protocol = request;
                    //                                masProtocolList.Add(masProtocol);

                    //                                callContent = new List<ushort>();
                    //                            }
                    //                        }
                    //                    }
                    //                    else//指定卡号呼叫
                    //                    {
                    //                        string[] callList = call.BhContent.Split(',');
                    //                        foreach (string tempCall in callList)
                    //                        {
                    //                            callContent.Add(ushort.Parse(tempCall));
                    //                            if (callContent.Count == 12)
                    //                            {
                    //                                request.HJ_KH = callContent.ToArray();
                    //                                MasProtocol masProtocol = null;
                    //                                masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                                masProtocol.Protocol = request;
                    //                                masProtocolList.Add(masProtocol);

                    //                                callContent = new List<ushort>();
                    //                            }
                    //                        }
                    //                    }
                    //                }
                    //                if (callContent.Count > 0)
                    //                {
                    //                    request.HJ_KH = new ushort[12];
                    //                    for (int i = 0; i < callContent.Count; i++)
                    //                    {
                    //                        request.HJ_KH[i] = callContent[i];
                    //                    }
                    //                    MasProtocol masProtocol = null;
                    //                    masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                    masProtocol.Protocol = request;
                    //                    masProtocolList.Add(masProtocol);
                    //                }
                    //            }
                    //        }
                    //        #endregion

                    //        if (sendCallListByPerson.Count == 0 && sendCallListByPoint.Count == 0)
                    //        {//如果不存在紧急呼叫,则判断一般呼叫并下发
                    //            List<R_CallInfo> sendGeneralCallListAll = callItems.FindAll(a => a.CallType == 0 && (a.CallPersonDefType == 0 || a.CallPersonDefType == 3));
                    //            if (sendGeneralCallListAll.Count > 0)//全员呼叫下发
                    //            {
                    //                if (sendGeneralCallListAll[0].SendCount > 0)//判断是否还需要下发  20171213
                    //                {
                    //                    CallPersonRequest request = new CallPersonRequest();
                    //                    request.HJ_Type = 0;
                    //                    request.HJ_State = 1;
                    //                    request.DeviceCode = mac;
                    //                    request.HJ_KH = new ushort[12];

                    //                    MasProtocol masProtocol = null;
                    //                    masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                    masProtocol.Protocol = request;


                    //                    masProtocolList.Add(masProtocol);
                    //                }
                    //            }
                    //            #region//一般呼叫井下设备
                    //            List<R_CallInfo> sendGeneralCallListByPoint = callItems.FindAll(a => a.CallType == 0 && (a.CallPersonDefType == 4));
                    //            if (sendGeneralCallListByPoint.Count > 0)
                    //            {
                    //                if (sendGeneralCallListByPoint[0].SendCount > 0)//判断是否还需要下发  20171213
                    //                {
                    //                    CallPersonRequest request = new CallPersonRequest();
                    //                    request.HJ_Type = 4;
                    //                    request.HJ_State = 1;
                    //                    request.DeviceCode = mac;
                    //                    List<ushort> callContent = new List<ushort>();
                    //                    foreach (R_CallInfo call in sendGeneralCallListByPoint)
                    //                    {
                    //                        string[] callList = call.PointList.Split(',');
                    //                        foreach (string tempCall in callList)
                    //                        {
                    //                            callContent.Add(Convert.ToUInt16(((Convert.ToInt64(tempCall.Substring(0, 3)) << 8)) + Convert.ToInt64(tempCall.Substring(4, 2))));
                    //                            if (callContent.Count == 12)
                    //                            {
                    //                                request.HJ_KH = callContent.ToArray();
                    //                                MasProtocol masProtocol = null;
                    //                                masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                                masProtocol.Protocol = request;
                    //                                masProtocolList.Add(masProtocol);

                    //                                callContent = new List<ushort>();
                    //                            }
                    //                        }
                    //                    }
                    //                    if (callContent.Count > 0)
                    //                    {
                    //                        request.HJ_KH = new ushort[12];
                    //                        for (int i = 0; i < callContent.Count; i++)
                    //                        {
                    //                            request.HJ_KH[i] = callContent[i];
                    //                        }
                    //                        MasProtocol masProtocol = null;
                    //                        masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                        masProtocol.Protocol = request;
                    //                        masProtocolList.Add(masProtocol);
                    //                    }
                    //                }
                    //            }
                    //            #endregion
                    //            #region//一般呼叫指定人员及指定卡号段下发,卡号段也按指定人员下发
                    //            List<R_CallInfo> sendGeneralCallListByPerson = callItems.FindAll(a => a.CallType == 0 && (a.CallPersonDefType == 1 || a.CallPersonDefType == 2));
                    //            if (sendGeneralCallListByPerson.Count > 0)
                    //            {
                    //                if (sendGeneralCallListByPerson[0].SendCount > 0)//判断是否还需要下发  20171213
                    //                {
                    //                    CallPersonRequest request = new CallPersonRequest();
                    //                    request.HJ_Type = 2;
                    //                    request.HJ_State = 1;
                    //                    request.DeviceCode = mac;
                    //                    List<ushort> callContent = new List<ushort>();
                    //                    foreach (R_CallInfo call in sendGeneralCallListByPerson)
                    //                    {
                    //                        if (call.BhContent.Contains("-"))
                    //                        {//指定卡号段呼叫
                    //                            ushort sBh = ushort.Parse(call.BhContent.Split('-')[0]);
                    //                            ushort eBh = ushort.Parse(call.BhContent.Split('-')[1]);
                    //                            for (ushort i = sBh; i <= eBh; i++)
                    //                            {
                    //                                callContent.Add(i);
                    //                                if (callContent.Count == 12)
                    //                                {
                    //                                    request.HJ_KH = callContent.ToArray();
                    //                                    MasProtocol masProtocol = null;
                    //                                    masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                                    masProtocol.Protocol = request;
                    //                                    masProtocolList.Add(masProtocol);

                    //                                    callContent = new List<ushort>();
                    //                                }
                    //                            }
                    //                        }
                    //                        else//指定卡号呼叫
                    //                        {
                    //                            string[] callList = call.BhContent.Split(',');
                    //                            foreach (string tempCall in callList)
                    //                            {
                    //                                callContent.Add(ushort.Parse(tempCall));
                    //                                if (callContent.Count == 12)
                    //                                {
                    //                                    request.HJ_KH = callContent.ToArray();
                    //                                    MasProtocol masProtocol = null;
                    //                                    masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                                    masProtocol.Protocol = request;
                    //                                    masProtocolList.Add(masProtocol);

                    //                                    callContent = new List<ushort>();
                    //                                }
                    //                            }
                    //                        }
                    //                    }
                    //                    if (callContent.Count > 0)
                    //                    {
                    //                        request.HJ_KH = new ushort[12];
                    //                        for (int i = 0; i < callContent.Count; i++)
                    //                        {
                    //                            request.HJ_KH[i] = callContent[i];
                    //                        }
                    //                        MasProtocol masProtocol = null;
                    //                        masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //                        masProtocol.Protocol = request;
                    //                        masProtocolList.Add(masProtocol);
                    //                    }
                    //                }
                    //            }
                    //            #endregion
                    //        }
                    //    }

                    //}
                    //else//如果不存在紧急呼叫和一般呼叫命令则下发解除呼叫命令  20171206
                    //{
                    //    callItems = KJ237CacheHelper.GetCallItems().Where(a => a.CallType == 2).OrderBy(a => a.CallTime).ToList();
                    //    if (callItems.Count > 0)
                    //    {
                    //        CallPersonRequest request = new CallPersonRequest();
                    //        request.HJ_Type = 0;
                    //        request.HJ_State = 0;
                    //        request.DeviceCode = mac;
                    //        request.HJ_KH = new ushort[12];

                    //        MasProtocol masProtocol = null;
                    //        masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest);
                    //        masProtocol.Protocol = request;

                    //        masProtocolList.Add(masProtocol);
                    //    }
                    //}
                    #endregion
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取向交换机下发的命令失败,原因:" + ex);
            }

            return(masProtocolList);
        }