Пример #1
0
        /// <summary>
        /// 通过设备性质查找测点
        /// </summary>
        /// <param name="alarmRequest"></param>
        /// <returns></returns>
        public BasicResponse <List <Jc_DefInfo> > QueryPointByDevpropertIDCache(QueryPointByDevpropertRequest alarmRequest)
        {
            var response = new BasicResponse <List <Jc_DefInfo> >();
            PointDefineCacheGetByConditonRequest pointDefineCacheRequest = new PointDefineCacheGetByConditonRequest();

            pointDefineCacheRequest.Predicate = a => a.DevPropertyID == alarmRequest.DevPropertId;
            var result = pointDefineCacheService.GetPointDefineCache(pointDefineCacheRequest);

            response.Data = result.Data;
            return(response);
        }
        public BasicResponse <List <Jc_DefInfo> > GetPointDefineCache(PointDefineCacheGetByConditonRequest request)
        {
            //modified by  20170719
            //默认测点查询从只读缓存查询,只有特殊实时性要求高的才从写缓存查询
            var response = new BasicResponse <List <Jc_DefInfo> >();

            if (request.IsQueryFromWriteCache)
            {
                response.Data = PointWriteCache.GetInstance.Query(request.Predicate);
            }
            else
            {
                response.Data = PointReadonlyCache.GetInstance.Query(request.Predicate);
            }
            return(response);
        }
        public BasicResponse <List <Jc_DefInfo> > GetAllMasterPointsById(SysEmergencyLinkageGetRequest request)
        {
            List <Jc_DefInfo> masterpoints = new List <Jc_DefInfo>();

            EmergencyLinkageConfigCacheGetByKeyRequest getrequest = new EmergencyLinkageConfigCacheGetByKeyRequest();

            getrequest.Id = request.Id;
            SysEmergencyLinkageInfo item = _sysEmergencyLinkageCacheService.GetSysEmergencyLinkageCacheByKey(getrequest).Data;

            PointDefineCacheGetByConditonRequest pointgetrequest = new PointDefineCacheGetByConditonRequest();

            if (item != null && !string.IsNullOrEmpty(item.MasterAreaAssId) && item.MasterAreaAssId != "0")
            {
                item.MasterAreas.ForEach(area =>
                {
                    pointgetrequest.Predicate = p => p.Areaid == area.AreaId;
                    var areapoints            = _pointDefineCacheService.GetPointDefineCache(pointgetrequest).Data;
                    masterpoints.AddRange(areapoints);
                });
            }
            else if (item != null && !string.IsNullOrEmpty(item.MasterDevTypeAssId) && item.MasterDevTypeAssId != "0")
            {
                item.MasterDevTypes.ForEach(devtype =>
                {
                    pointgetrequest.Predicate = p => p.Devid == devtype.DevId;
                    var areapoints            = _pointDefineCacheService.GetPointDefineCache(pointgetrequest).Data;
                    masterpoints.AddRange(areapoints);
                });
            }
            else if (item != null && !string.IsNullOrEmpty(item.MasterPointAssId) && item.MasterPointAssId != "0")
            {
                item.MasterPoint.ForEach(point =>
                {
                    pointgetrequest.Predicate = p => p.PointID == point.PointId;
                    var pointdefine           = _pointDefineCacheService.GetPointDefineCache(pointgetrequest).Data.FirstOrDefault();
                    masterpoints.Add(pointdefine);
                });
            }

            var response = new BasicResponse <List <Jc_DefInfo> >();

            response.Data = masterpoints;

            return(response);
        }
 public BasicResponse <List <Jc_DefInfo> > GetPointDefineCache(PointDefineCacheGetByConditonRequest pointDefineCacheRequest)
 {
     throw new NotImplementedException();
 }
Пример #5
0
        private static void HandleThreadFun()
        {
            while (_isRun)
            {
                try
                {
                    #region 计算交换机电源箱信息
                    NetworkModuleCacheGetByConditonRequest networkModuleCacheRequest = new NetworkModuleCacheGetByConditonRequest();
                    networkModuleCacheRequest.Predicate = a => a.Bz4 == "1";
                    List <Jc_MacInfo> macList = networkModuleService.GetNetworkModuleCache(networkModuleCacheRequest).Data;//所有挂接了智能电源箱的设备
                    foreach (Jc_MacInfo mac in macList)
                    {
                        if (mac.State == (short)DeviceDataState.EquipmentDC)//交换机进入直流状态,表示电源箱已处于放电状态
                        {
                            List <PointElectricityInfo> pointElectricityInfo = pointElectricityInfoList.FindAll(a => a.PointId == mac.MAC);
                            if (pointElectricityInfo.Count < 1) //表示第一次放电,则记录放电的开始时间
                            {
                                sendD(16, mac.MAC);             //下发获取电源箱数据命令
                                Thread.Sleep(10000);

                                PointElectricityInfo tempPointElectricityInfo = new PointElectricityInfo();
                                tempPointElectricityInfo.StartTime = DateTime.Now;
                                tempPointElectricityInfo.EndTime   = DateTime.Parse("1900-01-01 00:00:00");
                                if (mac.BatteryItems != null)
                                {
                                    foreach (BatteryItem battery in mac.BatteryItems)
                                    {
                                        tempPointElectricityInfo.Channel          = battery.Channel;
                                        tempPointElectricityInfo.PowerConsumption = battery.PowerPackVOL;
                                        if (pointElectricityInfoList.FindAll(a => a.Channel == battery.Channel && a.PointId == mac.MAC).Count < 1)
                                        {
                                            pointElectricityInfoList.Add(tempPointElectricityInfo);
                                        }
                                    }
                                }
                            }
                            else//表示之前已经添加了第一次放电的时间,判断放电是否达到了5分钟
                            {
                                if (pointElectricityInfo[0].EndTime != DateTime.Parse("1900-01-01 00:00:00"))
                                {
                                    continue;//如果之前已经计算过,则不用重复计算
                                }
                                TimeSpan ts = DateTime.Now - pointElectricityInfo[0].StartTime;
                                if (ts.TotalMinutes >= 5) //到5分钟时,计算当前5分钟消耗的电量,并存储
                                {
                                    sendD(16, mac.MAC);   //下发获取电源箱数据命令
                                    Thread.Sleep(10000);

                                    Dictionary <string, object>    updateItems = new Dictionary <string, object>();
                                    List <BatteryPowerConsumption> batteryPowerConsumptions = new List <BatteryPowerConsumption>();
                                    for (int i = 0; i < mac.BatteryItems.Count; i++)
                                    {
                                        int powerConsumption = pointElectricityInfo[i].PowerConsumption - mac.BatteryItems[i].PowerPackVOL;//得到当前5分钟的电量衰减量
                                        //将5分钟电量衰减参数更新到实时缓存
                                        BatteryPowerConsumption batteryPowerConsumption = new BatteryPowerConsumption();
                                        batteryPowerConsumption.Channel          = pointElectricityInfo[i].Channel;
                                        batteryPowerConsumption.PowerConsumption = powerConsumption;
                                        batteryPowerConsumptions.Add(batteryPowerConsumption);
                                    }
                                    updateItems.Add("BatteryPowerConsumptions", batteryPowerConsumptions);
                                    UpdateNetWorkInfoByProperties(mac.MAC, updateItems);

                                    //更新临时缓存的结束时间,后续不用再重复计算
                                    foreach (PointElectricityInfo temp in pointElectricityInfo)
                                    {
                                        temp.EndTime = DateTime.Now;
                                    }
                                }
                            }
                        }
                        else//交换机状态改变,重新计算
                        {
                            //清除临时缓存,并重新计算
                            foreach (PointElectricityInfo temp in pointElectricityInfoList)
                            {
                                if (temp.PointId == mac.MAC)
                                {
                                    pointElectricityInfoList.Remove(temp);
                                }
                            }
                        }
                    }
                    #endregion

                    #region 计算分站电源箱信息
                    PointDefineCacheGetByConditonRequest pointDefineCacheRequest = new PointDefineCacheGetByConditonRequest();
                    pointDefineCacheRequest.Predicate = a => a.DevPropertyID == 0 && (a.Bz3 & 0x8) == 0x8;
                    List <Jc_DefInfo> stationList = PointDefineCacheService.GetPointDefineCache(pointDefineCacheRequest).Data;
                    foreach (Jc_DefInfo station in stationList)
                    {
                        if (station.DataState == (short)DeviceDataState.EquipmentDC)//分站进入直流状态,表示电源箱已处于放电状态
                        {
                            List <PointElectricityInfo> pointElectricityInfo = pointElectricityInfoList.FindAll(a => a.PointId == station.PointID);
                            if (pointElectricityInfo.Count < 1)   //表示第一次放电,则记录放电的开始时间
                            {
                                sendD(0, station.Fzh.ToString()); //下发获取电源箱命令
                                Thread.Sleep(10000);

                                PointElectricityInfo tempPointElectricityInfo = new PointElectricityInfo();
                                tempPointElectricityInfo.PointId   = station.PointID;
                                tempPointElectricityInfo.StartTime = DateTime.Now;
                                tempPointElectricityInfo.EndTime   = DateTime.Parse("1900-01-01 00:00:00");
                                if (station.BatteryItems != null)
                                {
                                    foreach (BatteryItem battery in station.BatteryItems)
                                    {
                                        tempPointElectricityInfo.Channel          = battery.Channel;
                                        tempPointElectricityInfo.PowerConsumption = battery.PowerPackVOL;
                                        if (pointElectricityInfoList.FindAll(a => a.Channel == battery.Channel && a.PointId == station.PointID).Count < 1)
                                        {
                                            pointElectricityInfoList.Add(tempPointElectricityInfo);
                                        }
                                    }
                                }
                                else
                                {
                                    sendD(0, station.Fzh.ToString());
                                }
                            }
                            else//表示之前已经添加了第一次放电的时间,判断放电是否达到了5分钟
                            {
                                if (pointElectricityInfo[0].EndTime != DateTime.Parse("1900-01-01 00:00:00"))
                                {
                                    continue;//如果之前已经计算过,则不用重复计算
                                }
                                TimeSpan ts = DateTime.Now - pointElectricityInfo[0].StartTime;
                                if (ts.TotalMinutes >= 5)             //到5分钟时,计算当前5分钟消耗的电量,并存储
                                {
                                    sendD(0, station.Fzh.ToString()); //下发获取电源箱命令
                                    Thread.Sleep(10000);

                                    Dictionary <string, object>    updateItems = new Dictionary <string, object>();
                                    List <BatteryPowerConsumption> batteryPowerConsumptions = new List <BatteryPowerConsumption>();
                                    for (int i = 0; i < station.BatteryItems.Count; i++)
                                    {
                                        int powerConsumption = pointElectricityInfo[i].PowerConsumption - station.BatteryItems[i].PowerPackVOL;//得到当前5分钟的电量衰减量
                                        //将5分钟电量衰减参数更新到实时缓存
                                        BatteryPowerConsumption batteryPowerConsumption = new BatteryPowerConsumption();
                                        batteryPowerConsumption.Channel          = pointElectricityInfo[i].Channel;
                                        batteryPowerConsumption.PowerConsumption = powerConsumption;
                                        batteryPowerConsumptions.Add(batteryPowerConsumption);
                                    }
                                    updateItems.Add("BatteryPowerConsumptions", batteryPowerConsumptions);
                                    UpdatePointDefineInfoByProperties(station.PointID, updateItems);

                                    //更新临时缓存的结束时间,后续不用再重复计算
                                    foreach (PointElectricityInfo temp in pointElectricityInfo)
                                    {
                                        temp.EndTime = DateTime.Now;
                                    }
                                }
                            }
                        }
                        else//分站状态改变,重新计算
                        {
                            //清除临时缓存,并重新计算
                            foreach (PointElectricityInfo temp in pointElectricityInfoList)
                            {
                                if (temp.PointId == station.PointID)
                                {
                                    pointElectricityInfoList.Remove(temp);
                                }
                            }
                        }
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }

                Thread.Sleep(5000);
            }
            _isRun = true;
            LogHelper.Info("【ElectricityStatistics】充放电电量统计线程结束成功。");
        }
        /// <summary>
        /// 重新加载分站控制信息
        /// </summary>
        /// <param name="reLoadRequest"></param>
        public void ReLoad(DriverManualCrossControlReLoadRequest reLoadRequest)
        {
            ManualCrossControlCacheGetAllRequest manualCrossControlGetAllRequest = new ManualCrossControlCacheGetAllRequest();
            PointDefineCacheGetByConditonRequest pointDefineStationRequest       = new PointDefineCacheGetByConditonRequest();
            //分站信息是否有更新
            List <string> StationControlChangeList = new List <string>();

            //获取所有分站
            pointDefineStationRequest.Predicate = point => point.DevPropertyID == (int)DeviceProperty.Substation;
            var stationsResponse = poingDefineCacheService.GetPointDefineCache(pointDefineStationRequest);
            List <Jc_DefInfo> stationPointInsos = new List <Jc_DefInfo>();

            if (stationsResponse != null && stationsResponse.IsSuccess && stationsResponse.Data != null)
            {
                stationPointInsos = stationsResponse.Data;
            }

            //获取所有手动交叉控制缓存
            var manualCrossControlResponse = manualCrossControlCacheService.GetAllManualCrossControlCache(manualCrossControlGetAllRequest);
            List <Jc_JcsdkzInfo> manualCrossControlInfos = new List <Jc_JcsdkzInfo>();

            if (manualCrossControlResponse != null && manualCrossControlResponse.IsSuccess && manualCrossControlResponse.Data.Any())
            {
                manualCrossControlInfos = manualCrossControlResponse.Data;
            }

            #region ----加载控制列表----
            uint oldControlInt = 0;
            uint newControlInt = 0;
            bool updateFlag    = false; //分站结构体是否需要更新
            List <Jc_DefInfo> updateStations = new List <Jc_DefInfo>();
            foreach (Jc_DefInfo station in stationPointInsos)
            {
                if (station.DeviceControlItems == null)
                {
                    station.DeviceControlItems = new List <ControlItem>();
                }

                updateFlag    = false;
                oldControlInt = GetControlInt(station.DeviceControlItems);
                station.DeviceControlItems.Clear();
                var stationDischargeControl = manualCrossControlInfos.FirstOrDefault(m => m.Type == (int)ControlType.ControlDisCharge && short.Parse(m.Bkpoint.Substring(0, 3)) == station.Fzh);
                #region ----------------放电命令判断----------------

                if (stationDischargeControl == null && station.BDisCharge == 2)
                {
                    //==null 表示不放电,若此时状态是放电,则更新放电状态
                    updateFlag         = true;
                    station.BDisCharge = 1;
                    station.realControlCount++;
                    station.ClsCommObj.NCommandbz |= 0x80; // todo  此处走0x0002
                }
                else if (stationDischargeControl != null && station.BDisCharge != 2)
                {
                    //不为null表示要放电,若此时状态是不放电,则更新放电状态
                    updateFlag         = true;
                    station.BDisCharge = 2;
                    station.realControlCount++;
                    station.ClsCommObj.NCommandbz |= 0x80;
                }

                #endregion
                #region ----------------三分封电闭锁强制解锁命令判断----------------

                var sationGasThreeUnlockControl = manualCrossControlInfos.FirstOrDefault(m => m.Type == (int)ControlType.GasThreeUnlockControl && short.Parse(m.Bkpoint.Substring(0, 3)) == station.Fzh);
                if (sationGasThreeUnlockControl == null && station.GasThreeUnlockContro == 1)
                {
                    //交叉控制表中已删除,但内存还是解锁状态
                    updateFlag = true;
                    station.GasThreeUnlockContro = 0;
                    station.realControlCount++;
                    station.ClsCommObj.NCommandbz |= 0x80;
                }
                else if (sationGasThreeUnlockControl != null && station.GasThreeUnlockContro == 0)
                {
                    //交叉控制表中已增加,但内存是不解锁状态
                    updateFlag = true;
                    station.GasThreeUnlockContro = 1;
                    station.realControlCount++;
                    station.ClsCommObj.NCommandbz |= 0x80;
                }

                #endregion
                #region ----------------手动交叉控制命令判断(Type < 50 表示需要直接加载到分站控制链表的控制命令)----------------
                var stationcontrolInfos = manualCrossControlInfos.Where(m => short.Parse(m.Bkpoint.Substring(0, 3)) == station.Fzh && m.Type <= 50 && m.Type != 12).ToList();//type=12 是大数据分析的传感器分级报警控制,在下面单独处理
                foreach (Jc_JcsdkzInfo jckzItem in stationcontrolInfos)
                {
                    int controlType = 1;
                    if (jckzItem.Type == (short)ControlType.RemoveLocalControl)
                    {
                        controlType = 2;//表示强制解控
                    }
                    //重新根据JC_JCKZ表重新生成控制列表
                    ControlItem controlItem = new ControlItem
                    {
                        Channel     = short.Parse(jckzItem.Bkpoint.Substring(4, 2)),
                        ControlType = controlType
                    };
                    station.DeviceControlItems.Add(controlItem);
                }
                newControlInt = GetControlInt(station.DeviceControlItems);
                if (oldControlInt != newControlInt)
                {
                    //本次控制字与之前控制字不一样,更新内存下发控制标记
                    updateFlag = true;
                    station.realControlCount++;
                    station.ClsCommObj.NCommandbz |= 0x80;
                }
                #endregion
                #region ----------------分级报警控制列表---------------------
                List <GradingAlarmItem> oldControls = station.GradingAlarmItems;
                List <GradingAlarmItem> newControls = GetGradeControls(station.Fzh, manualCrossControlInfos);
                if (CompareGradeControls(oldControls, newControls) == false)
                {
                    updateFlag = true;
                    station.GradingAlarmCount++;
                    station.GradingAlarmItems      = newControls;
                    station.GradingAlarmTime       = DateTime.Now;
                    station.ClsCommObj.NCommandbz |= 0x0010;
                }
                #endregion
                #region ----------------清除分站历史数据命令判断----------------

                var stationHisDataClearControl = manualCrossControlInfos.FirstOrDefault(m => m.Type == (int)ControlType.StationHisDataClear && short.Parse(m.Bkpoint.Substring(0, 3)) == station.Fzh);
                if (stationHisDataClearControl == null && station.StationHisDataClear == 1)
                {
                    //交叉控制表中已删除,但内存还是解锁状态
                    updateFlag = true;
                    station.StationHisDataClear = 0;
                    station.realControlCount++;
                    station.ClsCommObj.NCommandbz |= 0x80;
                }
                else if (stationHisDataClearControl != null && station.StationHisDataClear == 0)
                {
                    //交叉控制表中已增加,但内存是不解锁状态
                    updateFlag = true;
                    station.StationHisDataClear = 1;
                    station.realControlCount++;
                    station.ClsCommObj.NCommandbz |= 0x80;
                }

                #endregion

                if (updateFlag)
                {
                    updateStations.Add(station);
                }
            }
            if (updateStations.Count > 0)
            {
                //更新分站内存
                PointDefineCacheUpdateControlReqest updateControlRequest = new PointDefineCacheUpdateControlReqest();
                updateStations.ForEach(updateItem =>
                {
                    updateControlRequest.PointDefineInfo = updateItem;
                    poingDefineCacheService.UpdatePointDefineControl(updateControlRequest);
                });
            }
            #endregion
        }