public BasicResponse DeleteFinishedBcall()
 {
     return(_bcallService.DeleteFinishedBcall());
 }
Exemple #2
0
        /// <summary>分析函数
        ///
        /// </summary>
        private static void Analyze()
        {
            var nowTime = DateTime.Now;
            //if (_ifFirstRun)
            //{
            //    _ifFirstRun = false;
            //}
            //else
            //{

            //结束已删除的应急联动
            var res4 = EmergencyLinkHistoryService.GetDeleteButNotEndLinkageIds();

            //var allDelLinkageConfig = allLinkageConfig.Where(a => a.Type == 1 && a.Activity != 1 && a.EmergencyLinkageState==1).ToList(); //所有非活动的普通应急联动
            foreach (var item in res4.Data)
            {
                EndLinkageHisAndCall(item, nowTime, false);
            }

            var triggerDataState = LinkageConstant.TriggerDataStateVlaue;
            var req18            = new AlarmCacheGetAllRequest();
            var allJcbCache      = AlarmCacheService.GetAllAlarmCache(req18).Data;
            var time1900         = new DateTime(1900, 1, 1);
            var sievingJcb       = allJcbCache.Where(a =>
                                                     (a.Point.Contains("A") || a.Point.Contains("D")) && triggerDataState.Contains(a.Type) &&
                                                     a.Etime == time1900).ToList(); //筛选后的未结束的jcb

            //判断jcb是否有重复数据
            var groupData = sievingJcb.GroupBy(a => new { a.Point, a.Type }).Select(a => new { Group = a.Key, Count = a.Count() });

            if (sievingJcb.Count != groupData.Count())
            {
                StringBuilder repeatStr = new StringBuilder();
                foreach (var item in groupData)
                {
                    if (item.Count > 1)
                    {
                        var repeat = sievingJcb.Where(a => a.Point == item.Group.Point && a.Type == item.Group.Type);
                        foreach (var item2 in repeat)
                        {
                            repeatStr.Append("\r\nPoint:" + item2.Point + " PointId:" + item2.PointID + " JcbId:" +
                                             item2.ID + " Stime:" + item2.Stime + " Etime:" + item2.Etime);
                        }
                    }
                }
                LogHelper.Error("Sys.Safety.Processing.Linkage.LinkageAnalyze:jc_b缓存存在重复数据。" + repeatStr);
            }

            var res = SysEmergencyLinkageService.GetAllSysEmergencyLinkageList();
            var allLinkageConfig         = res.Data;
            var allActivityLinkageConfig = allLinkageConfig.Where(a => a.Type == 1 && a.Activity == 1).ToList(); //所有活动的普通应急联动

            var req3     = new PointDefineCacheGetAllRequest();
            var res3     = PointDefineCacheService.GetAllPointDefineCache(req3);
            var allPoint = res3.Data; //所有测点

            foreach (var item in allActivityLinkageConfig)
            {
                //判断是否处于强制解除状态 todo  需要加锁
                if (item.IsForceEnd)
                {
                    var endTime = item.EndTime.AddSeconds(item.DelayTime);
                    if (nowTime <= endTime)
                    {
                        continue;
                    }
                    else
                    {
                        item.IsForceEnd = false;
                    }
                }

                //获取主控测点
                List <Jc_DefInfo> masterPoint = null; //主控测点
                if (item.MasterDevTypeAssId != "0")   //主控为设备类型
                {
                    var req2 = new LongIdRequest()
                    {
                        Id = Convert.ToInt64(item.MasterDevTypeAssId)
                    };
                    var res2     = SysEmergencyLinkageService.GetMasterEquTypeInfoByAssId(req2);
                    var allDev   = res2.Data;
                    var allDevId = new List <string>();
                    foreach (var item2 in allDev)
                    {
                        allDevId.Add(item2.Devid);
                    }

                    masterPoint = allPoint.Where(a => allDevId.Contains(a.Devid)).ToList();
                }
                if (item.MasterAreaAssId != "0")
                {
                    var req2 = new LongIdRequest()
                    {
                        Id = Convert.ToInt64(item.MasterAreaAssId)
                    };
                    var res2      = SysEmergencyLinkageService.GetMasterAreaInfoByAssId(req2);
                    var allArea   = res2.Data;
                    var allAreaId = new List <string>();
                    foreach (var item2 in allArea)
                    {
                        allAreaId.Add(item2.Areaid);
                    }

                    masterPoint = allPoint.Where(a => allAreaId.Contains(a.Areaid)).ToList();
                }
                if (item.MasterPointAssId != "0")
                {
                    var req2 = new LongIdRequest()
                    {
                        Id = Convert.ToInt64(item.MasterPointAssId)
                    };
                    var res2 = SysEmergencyLinkageService.GetMasterPointInfoByAssId(req2);
                    masterPoint = res2.Data;
                }

                if (masterPoint == null)
                {
                    continue;
                }

                var masterPointId = new List <string>(); //主控测点id
                foreach (var item2 in masterPoint)
                {
                    if (item2 == null)
                    {
                        continue;
                    }
                    masterPointId.Add(item2.PointID);
                }

                var duration = item.Duration;

                //获取触发主控状态
                var triDataState = new List <short>();
                foreach (var item2 in item.MasterTriDataStates)
                {
                    triDataState.Add(Convert.ToInt16(item2.DataStateId));
                }

                var satisfyJcb = sievingJcb.Where(a =>
                                                  (a.State == 21 || a.State == 20 || a.State == 5 || a.State == 24) && masterPointId.Contains(a.PointID) && triDataState.Contains(a.Type) &&
                                                  (nowTime - a.Stime).TotalSeconds >= duration)
                                 .OrderBy(a => a.PointID).ThenBy(a => a.Type).ToList(); //满足条件的jcb

                //去掉设备实时状态为标校、红外遥控的jcb数据
                for (int i = satisfyJcb.Count - 1; i >= 0; i--)
                {
                    var ifExist = allPoint.Any(a => a.PointID == satisfyJcb[i].PointID && (a.State == 5 || a.State == 24));
                    if (ifExist)
                    {
                        satisfyJcb.RemoveAt(i);
                    }
                }

                var req11 = new LongIdRequest()
                {
                    Id = Convert.ToInt64(item.Id)
                };
                var res11 = EmergencyLinkHistoryService.GetNotEndLastLinkageHistoryMasterPointByLinkageId(req11);
                var lastNotEndHisLinkagePointInfo =
                    res11.Data.OrderBy(a => a.PointId).ThenBy(a => a.DataState).ToList(); //当前联动上一次未结束的历史联动记录主控测点

                //判断触发的测点及其状态是否一样
                bool same = true;
                if (satisfyJcb.Count == lastNotEndHisLinkagePointInfo.Count)
                {
                    for (int i = 0; i < satisfyJcb.Count; i++)
                    {
                        if (satisfyJcb[i].PointID != lastNotEndHisLinkagePointInfo[i].PointId ||
                            satisfyJcb[i].Type != lastNotEndHisLinkagePointInfo[i].DataState)
                        {
                            same = false;
                            break;
                        }
                    }
                }
                else
                {
                    same = false;
                }

                if (satisfyJcb.Count != 0) //触发联动
                {
                    if (lastNotEndHisLinkagePointInfo.Count > 0)
                    {
                        if (!same) //主控不一样则先结束之前的联动
                        {
                            EndLinkageHisAndCall(item, nowTime, false);

                            AddLinkageHisAndCall(item, satisfyJcb, nowTime, true);
                        }
                    }
                    else
                    {
                        AddLinkageHisAndCall(item, satisfyJcb, nowTime, true);
                    }
                }
                else //解除联动
                {
                    EndLinkageHisAndCall(item, nowTime, true);
                }
                //}

                //删除2天前的已结束的bcall
                BcallService.DeleteFinishedBcall();
                //删除2天前的已结束的rcall
                RcallService.DeleteFinishedBcall();
            }
        }