Пример #1
0
        protected bool IsReachCondition(EGPSCurrentInfo current, ETraceAlertSetting alertSetting)
        {
            VLatLonRange aVLatLonRange = VLatLonRange.Get(current.Latitude, current.Longitude, alertSetting.Range);

            return ((aVLatLonRange.Latitude1 < alertSetting.TracePoint.Latitude && alertSetting.TracePoint.Latitude < aVLatLonRange.Latitude2) &&
                (aVLatLonRange.Longitude1 < alertSetting.TracePoint.Longitude && alertSetting.TracePoint.Longitude < aVLatLonRange.Longitude2));
            //return Static_TraceAlertSettingSearchService.IsInTraceRange(current.Latitude, current.Longitude, alertSetting.TracePoint.RecordID, alertSetting.Range);
        }
Пример #2
0
        protected bool IsReachCondition(EGPSCurrentInfo current, ETimingAlertSetting alertSetting)
        {
            DateTime now = current.ReportTime;
            DateTime before = now.AddMinutes(-1);
            DateTime after = now.AddMinutes(1);
            DateTime tailTime = DateTime.Parse(alertSetting.Time.ToString());

            return (tailTime.TimeOfDay >= before.TimeOfDay && tailTime.TimeOfDay <= after.TimeOfDay);
        }
Пример #3
0
 // //是否超出设防范围
 public bool CheckIsOutRange(EGPSCurrentInfo current, EFortifyAlertsetting setting) 
 {
     //获取设防区域
     var range = VLatLonRange.Get((decimal)setting.Latitude, (decimal)setting.Longitude, setting.RadiusLimit);
     //判断是否超出这个区域
     if ((range.Latitude1 < current.Latitude && current.Latitude < range.Latitude2) && (range.Longitude1 < current.Longitude && current.Longitude < range.Longitude2))
     {
         //在这个范围里面
         return false;
     }
     else 
     {
         //不在这个范围
         return true;
     }
 }
Пример #4
0
        public override void Handle(EGPSCurrentInfo current, AlarmHandleContext context)
        {
            // 获取Fortify的配置数据,没有配置则不进行任何处理
            var setting = AlarmSettingsService.Singleton.GetFortifyAlertSetting(current.VehicleCode.Value);
            if (setting == null)
            {
                this.RemoveRunningState(context.RunningState, EnumSMSInfoType.Fortify);
                AlarmLastStatusService.Singleton.RemoveLastFortifyWarning(current);
                return;
            }
            try
            {
                // 取上一条报警状态
                var lastCachingStatus = AlarmLastStatusService.Singleton.GetLastFortifyWarning(current);
                if (lastCachingStatus == null)
                {
                    lastCachingStatus = new LastFortifyAlertStatus();
                }
               
                if (!lastCachingStatus.IsOutRange)
                {
                    //如果上一次没有离开设防区域 那么检查这次是否离开了设防区域
                    var isOutRange = CheckIsOutRange(current, setting);
                    if (isOutRange)
                    {
                        
                        //如果离开了设防区域
                        //触发报警
                        Alert(context, current, setting, true);
                        //设置状态为超出设防范围 目的是用于下一次不再触发报警
                        lastCachingStatus.IsOutRange = true;
                        lastCachingStatus.LastAlertTime = current.ReportTime;
                    }
                }
                
                //保存目前状态
                AlarmLastStatusService.Singleton.SaveLastFortifyWarning(current, lastCachingStatus);

            }
            catch (Exception ex)
            {
                Logger.Error(ex, "VehicleCode", current.VehicleCode, "GPSCode", current.GPSCode);
            }

        }
Пример #5
0
        private void Alert(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, ETimingAlertSetting alertSetting, LastTimingAlertStatus lastCachingStatus)
        {
            if (alertSetting.EnableSMS || alertSetting.Enable)
            {
                // 生成报警实例,并将报警存入数据库,最新的报警状态放入缓存中
                ETimingAlertReport alertReport = this.CreateAlertReport(context, current, state, alertSetting);
                GPSServiceFacade.AlertService.Add<ETimingAlertReport>(alertReport);

                lastCachingStatus.LastAlertTime = current.ReportTime;
                AlarmLastStatusService.Singleton.SaveLastTimingAlertStatus(current.VehicleCode.Value, lastCachingStatus);

                if (alertSetting.EnableSMS && this.IsInMobileReceiveTime(alertReport))
                {
                    this.SendSMS(context, alertReport);
                }

                if (alertSetting.Enable && this.IsInUserReceiveTime(alertReport))
                {
                    this.SendWebSiteSMS(context, alertReport);
                }
            }
        }
Пример #6
0
        protected void Alert(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, EOverSpeedAlertSetting setting, LastOverSpeedAlertStatus lastCachingStatus)
        {
            if (setting.EnableSMS || setting.Enable)
            {
                // 生成报警实例,并将报警存入数据库,放入缓存中
                EOverSpeedAlertReport alertReport = this.CreateAlertReport(context, current, state, setting);
                GPSServiceFacade.AlertService.Add<EOverSpeedAlertReport>(alertReport);

                lastCachingStatus.AlertState = state;
                AlarmLastStatusService.Singleton.SaveLastOverSpeedAlertStatus(current.VehicleCode.Value, lastCachingStatus);

                if (setting.EnableSMS && this.IsInMobileReceiveTime(alertReport))
                {
                    this.SendSMS(context, alertReport);
                }

                if (setting.Enable && this.IsInUserReceiveTime(alertReport))
                {
                    this.SendWebSiteSMS(context, alertReport);
                }
            }
        }
Пример #7
0
        private static readonly int Static_AlarnIntervalTime = 600; //unit:s

        public override void Handle(EGPSCurrentInfo current, AlarmHandleContext context)
        {
            // 获取Trace的配置数据,没有配置则不进行任何处理
            var setting = AlarmSettingsService.Singleton.GetTraceAlertSetting(current.VehicleCode.Value);
            if (setting == null || setting.Count == 0)
            {
                this.RemoveRunningState(context.RunningState, EnumSMSInfoType.Mark);
                return;
            }

            foreach (ETraceAlertSetting alertSetting in setting)
            {
                try
                {
                    if (!this.IsReachCondition(current, alertSetting))
                    {
                        this.ModifyRunningState(context.RunningState, EnumAlertState.Resume, EnumSMSInfoType.Mark);
                        continue;
                    }

                    // 取上一条Trace Point报警状态,如果找不到直接跳出(实际上不可能找不到的,因为至少会返回一个空内容的实例,除非数据库访问错误)
                    var lastCachingPointStatus = AlarmLastStatusService.Singleton.GetLastTracePointAlertStatus(current, alertSetting);
                    if (lastCachingPointStatus == null)
                        continue;

                    // 保证不重复提示
                    if (!this.IsReachConditionAlertAgain(current, alertSetting, lastCachingPointStatus))
                        continue;

                    // 生成Trace报警
                    this.Alert(context, current, EnumAlertState.Alerting, alertSetting, lastCachingPointStatus);
                    this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.Mark);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "VehicleCode", current.VehicleCode, "GPSCode", current.GPSCode);
                }
            }
        }
Пример #8
0
        private static readonly int Static_ResendInterval = 60; //unit:m

        public override void Handle(EGPSCurrentInfo current, AlarmHandleContext context)
        {
            // 获取Timing的配置数据,没有配置则不进行任何处理
            var setting = AlarmSettingsService.Singleton.GetTimingAlertSetting(current.VehicleCode.Value);
            if (setting == null || setting.Count == 0)
            {
                this.RemoveRunningState(context.RunningState, EnumSMSInfoType.Time);
                return;
            }

            foreach (ETimingAlertSetting alertSetting in setting)
            {
                try
                {
                    if (!this.IsReachCondition(current, alertSetting))
                    {
                        this.ModifyRunningState(context.RunningState, EnumAlertState.Resume, EnumSMSInfoType.Time);
                        continue;
                    }

                    // 取上一条Timing报警状态。如果找不到直接跳出(实际上不可能找不到的,因为至少会返回一个空内容的实例,除非数据库访问错误)
                    var lastCachingStatus = AlarmLastStatusService.Singleton.GetLastTimingAlertStatus(current, alertSetting);
                    if (lastCachingStatus == null)
                        continue;

                    // 保证不重复提示
                    if (lastCachingStatus.LastAlertTime.HasValue && (current.ReportTime - lastCachingStatus.LastAlertTime.Value).TotalMinutes < Static_ResendInterval)
                        continue;

                    // 生成Timing报警
                    this.Alert(context, current, EnumAlertState.Alerting, alertSetting, lastCachingStatus);
                    this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.Time);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "VehicleCode", current.VehicleCode, "GPSCode", current.GPSCode);
                }
            }
        }
Пример #9
0
        protected bool IsReachConditionAlertAgain(EGPSCurrentInfo current, ETraceAlertSetting seting, LastTracePointAlertStatus lastCachingPointStatus)
        {
            // 从来没有报警,则需要报警
            if (lastCachingPointStatus.LastAlertTime == null)
                return true;

            TimeSpan differenceTime = current.ReportTime - lastCachingPointStatus.LastAlertTime.Value;
            if (differenceTime.TotalSeconds <= Static_AlarnIntervalTime)
                return false;

            // 取上一条Trace报警状态,如果找不到直接跳出(实际上不可能找不到的,因为至少会返回一个空内容的实例,除非数据库访问错误)
            var lastCachingStatus = AlarmLastStatusService.Singleton.GetLastTraceAlertStatus(current, seting);
            if (lastCachingStatus == null || !lastCachingStatus.LastAlertExists)
                return true;

            // 若最后一个报警的标注点不是当前需要报警的标注点,则报警。
            if (lastCachingStatus.LastAlertTracePointId != seting.TracePointID.ToString().ToLower())
                return true;

            // 如果是同一个标注点内报警,且当前车辆的ACC为开,则符合再次报警条件。
            return (current.ACCState == 1);
        }
Пример #10
0
        private void Alert(AlarmHandleContext context, EGPSCurrentInfo current,EFortifyAlertsetting setting, bool isAlert)
        {
            DateTime dt1 = DateTime.Now;
            EFortifyAlertReport alertReport = this.CreateAlertReport(context, current, setting);
            GPSServiceFacade.Report.Fortify.Add<EFortifyAlertReport>(alertReport);
            Logger.Info(string.Format("Static_FortifyAlertReportService.Add<EFortifyAlertReport>(alertReport)共花销{0}毫秒", (DateTime.Now - dt1).TotalMilliseconds));

            if (isAlert)
            {
                

                if (setting.EnableSMS || setting.Enable)
                {
                    if (setting.EnableSMS && this.IsInMobileReceiveTime(alertReport))
                    {
                        this.SendSMS(context, alertReport);
                    }
                    if (setting.Enable && this.IsInUserReceiveTime(alertReport))
                    {
                        this.SendWebSiteSMS(context, alertReport);
                    }

                    try
                    {
                        //撤销设防
                        IAlertSettingService s = new AlertSettingService();
                        s.Delete<EFortifyAlertsetting>(setting.RecordID);
                    }
                    catch
                    {


                    }

                }

            }
        }
Пример #11
0
        protected void Alert(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, EStopCarAlertSetting setting, LastStopCarAlertStatus lastCachingStatus)
        {
            if (setting.EnableSMS || setting.Enable)
            {
                // 生成报警实例,并将报警存入数据库,放入缓存中
                EStopCarAlertReport alertReport = this.CreateAlertReport(context, current, state, setting, lastCachingStatus.LastStopCarTime.Value, Guid.NewGuid());
                GPSServiceFacade.AlertService.Add<EStopCarAlertReport>(alertReport);

                lastCachingStatus.LastAlertRecordId = alertReport.RecordID.ToString();
                lastCachingStatus.LastAlertStartTime = alertReport.GPSReportTime;
                lastCachingStatus.LastAlertEndTime = alertReport.StopEndTime;
                AlarmLastStatusService.Singleton.SaveLastStopCarAlertStatus(current.VehicleCode.Value, lastCachingStatus);

                if (setting.EnableSMS && this.IsInMobileReceiveTime(alertReport))
                {
                    this.SendSMS(context, alertReport);
                }

                if (setting.Enable && this.IsInUserReceiveTime(alertReport))
                {
                    this.SendWebSiteSMS(context, alertReport);
                }
            }
        }
Пример #12
0
        private EGPSCurrentInfo ConvertEntity(GPSDataEntity gpsData)
        {
            EGPSCurrentInfo result = new EGPSCurrentInfo();

            result.VehicleCode = gpsData.VehicleCode;
            result.StarkMileage = gpsData.StarkMileage;
            result.Speed = gpsData.Speed;
            result.ReportTime = gpsData.ReportTime;
            result.PowerState = gpsData.PowerState;
            result.PlunderState = gpsData.PlunderState;
            result.PhotoPath = gpsData.PhotoPath;
            result.OilState = gpsData.OilState;
            result.OilBearing = gpsData.OilBearing;
            result.Mileage = gpsData.Mileage;
            result.Longitude = gpsData.Longitude;
            result.Latitude = gpsData.Latitude;
            result.GPSCode = gpsData.GPSCode;

            result.DoorStatus = gpsData.DoorStatus;
            result.Direction = gpsData.Direction;
            result.AntennaState = gpsData.AntennaState;
            result.ACCState = gpsData.ACCState;
            result.Detector1 = gpsData.Detector1;
            result.Detector2 = gpsData.Detector2;

            result.Detector3 = gpsData.Detector3;
            result.Detector4 = gpsData.Detector4;

            return result;
        }
Пример #13
0
        protected ETraceAlertReport CreateAlertReport(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, ETraceAlertSetting alertSetting)
        {
            ETraceAlertReport newReport = new ETraceAlertReport();

            newReport.EnumAlarmGrade = EnumAlarmGrade.Prompt;
            newReport.EnumSMSInfoType = EnumSMSInfoType.Mark;
            newReport.ACCState = current.ACCState;
            newReport.Speed = current.Speed;
            newReport.VStarkMileage = current.StarkMileage;
            newReport.GPSCode = current.GPSCode;
            newReport.ACCState = current.ACCState;
            newReport.Speed = current.Speed;
            newReport.GPSReportTime = current.ReportTime;
            newReport.Latitude = current.Latitude;
            newReport.Longitude = current.Longitude;
            newReport.MobileReceiveBeginTime = alertSetting.MobileReceiveBeginTime;
            newReport.MobileReceiveEndTime = alertSetting.MobileReceiveEndTime;
            newReport.ReceiveMobileList = alertSetting.ReceiveMobileList;
            newReport.ReceiveUserList = alertSetting.ReceiveUserList;
            newReport.TenantCode = alertSetting.TenantCode;
            newReport.UserReceiveBeginTime = alertSetting.UserReceiveBeginTime;
            newReport.UserReceiveEndTime = alertSetting.UserReceiveEndTime;
            newReport.VehicleCode = alertSetting.VehicleCode;
            newReport.VehiclePosition = this.GetPlaceName(context, current.Latitude, current.Longitude);
            newReport.LicensePlate = this.GetLicensePlate(context, current.VehicleCode.Value, alertSetting.TenantCode);
            newReport.EnumAlertState = state;
            newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.AddressTracking;
            newReport.TracePoint = alertSetting.TracePoint;

            return newReport;
        }
Пример #14
0
        private bool IsInRange(EGPSCurrentInfo current, EAreaAlertSetting areaSet)
        {
            Polygon polygon = new Polygon(areaSet.Area.Points);
            double x = Convert.ToDouble(current.Latitude);
            double y = Convert.ToDouble(current.Longitude);
            Point point = new Point(x, y);

            return Polygon.PointInPolygon(point, polygon);
        }
Пример #15
0
        private void Handle(EGPSCurrentInfo current)
        {
            // 获取当前车辆相关的“运行状态”,初始化一个处理上下文实例
            AlarmHandleContext context = new AlarmHandleContext();
            context.RunningState = GPSServiceFacade.Vehicle.RunningState.Get(current.VehicleCode.Value);
            context.ExistRunningState = context.RunningState != null;
            context.LatitudeLongitudePlaceName = string.Empty;
 
            context.VehicleLicenceNumber = string.Empty;
           

            // 如果不存在则初始化一个“运行状态”实例
            if (!context.ExistRunningState)
            {
                context.RunningState = new EVehicleRunningState()
                {
                    VehicleCode = current.VehicleCode.Value,
                    State = (int)EnumRunningState.Running,
                    AlarmType = null,
                    Remark = string.Empty
                };
            }

            // 如下代码在下一版中应取消,以减少不必要的日志(数据量太大)
            Logger.Trace(string.Format("Handling: \r\n vehicleCode:{0}  gpscode:{1}  reporttime:{2}  acc:{3}  speed:{4} plastate:{5} starkmileage:{6} DoorStatus:{7} Lat:{8} Lon:{9} PowerState:{10} Detector1:{11} Detector2:{12} Detector3:{13} Detector4:{14} CoolerStatus:{15} OilBearin:{16}",
                current.VehicleCode.Value, current.GPSCode, current.ReportTime, current.ACCState, current.Speed,
                current.PlunderState, current.StarkMileage, current.DoorStatus, current.Latitude, current.Longitude,
                current.PowerState, current.Detector1, current.Detector2, current.Detector3, current.Detector4,
                current.CoolerStatus, current.OilBearing));

            // 处理报警
            foreach (IAlertHandler handler in Static_AlarmHandles)
            {
                DateTime dt1 = DateTime.Now;
                handler.Handle(current, context);

                double diff = (DateTime.Now - dt1).TotalMilliseconds / (double)1000;
                if ((int)diff > 0)
                {
                    Logger.Info(string.Format("vehicleCode:{0}, gpscode:{1}, 处理报警{2}共开销{3:N2}秒!", current.VehicleCode.Value, current.GPSCode, handler.GetType().ToString(), diff));
                }
            }

            // 更新当前车辆的报警状态
            if (context.RunningState.State == (int)EnumRunningState.Running)
            {
                if (context.ExistRunningState)
                {
                    GPSServiceFacade.Vehicle.RunningState.Delete(context.RunningState);
                }
            }
            else
            {
                if (context.ExistRunningState)
                {
                    GPSServiceFacade.Vehicle.RunningState.Update(context.RunningState);
                }
                else
                {
                    GPSServiceFacade.Vehicle.RunningState.Add(context.RunningState);
                }
            }
        }
Пример #16
0
        public override void Handle(EGPSCurrentInfo current, AlarmHandleContext context)
        {
            // 获取Area的配置数据,没有配置则不进行任何处理
            var settings = AlarmSettingsService.Singleton.GetAreaAlertSetting(current.VehicleCode.Value);
            if (settings == null || settings.Count == 0)
            {
                this.RemoveRunningState(context.RunningState, EnumSMSInfoType.Area);
                return;
            }

            foreach (EAreaAlertSetting areaSet in settings)
            {
                try
                {
                    // Polygon must have 3 point at least!
                    string[] arrPoints = areaSet.Area.Points.TrimEnd(new char[] { ';' }).Split(new char[] { ';' });
                    if (arrPoints.Length < 3)
                    {
                        Logger.Warn("Polygon must have 3 point at least!", "Area ID", areaSet.AreaID, "Area Name", areaSet.AreaName);
                        continue;
                    }

                    bool isSetIn = areaSet.EnableGoInAreaAlert;
                    bool isSetOut = areaSet.EnableGoOutAreaAlert;

                    bool isInRangeNow = this.IsInRange(current, areaSet);
                    bool isInRangeBefore = this.IsInRangeBefore(current, areaSet, isInRangeNow);

                    // 如果设置了进区域报警,并且之前没有在区域内,并且现在在区域内,那就表示第一次进入区域,所以要报警
                    if (!isInRangeBefore && isInRangeNow)
                    {
                        this.Alert(context, current, EnumAreaAlert.InArea, areaSet, isSetIn);
                        this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.Area);

                        // 更新第一次进区域的时间
                        VTempAreaWarning tempAreaWarning = AlarmLastStatusService.Singleton.GetLastAreaWarning(current, areaSet);
                        if (tempAreaWarning != null)
                        {
                            tempAreaWarning.FirstInAreaTime = current.ReportTime;
                            AlarmLastStatusService.Singleton.SaveLastAreaWarning(current, areaSet, tempAreaWarning);
                        }
                    }

                    // 如果设置了出区域报警,并且之前在区域内,并且现在在区域外,那就表示是从区域内跑到区域外了,所以要报警
                    if (isInRangeBefore && !isInRangeNow)
                    {
                        this.Alert(context, current, EnumAreaAlert.OutArea, areaSet, isSetOut);
                        this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.Area);

                        AlarmLastStatusService.Singleton.RemoveLastAreaWarning(current, areaSet);
                    }

                    // 如果设置了延时出区域报警
                    if (areaSet.EnableDelayGoOutAreaAlert)
                    {
                        bool isInRangeBeforeAndDelayStayNow = this.IsInRangeBeforeAndDelayStayNow(current, areaSet, isInRangeNow);
                        //并且之前在区域内且停留时间大于最大停留时间、而且现在还在区域内
                        if (isInRangeBeforeAndDelayStayNow && isInRangeNow)
                        {
                            this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.Area);
                            this.Alert(context, current, EnumAreaAlert.DelayStay, areaSet, true);
                        }
                    }

                    if (!isInRangeBefore && !isInRangeNow)
                    {
                        this.ModifyRunningState(context.RunningState, EnumAlertState.Resume, EnumSMSInfoType.Area);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "VehicleCode", current.VehicleCode, "GPSCode", current.GPSCode);
                }
            }
        }
Пример #17
0
        public EAreaAlertReport CreateAlertReport(AlarmHandleContext context, EGPSCurrentInfo current, EnumAreaAlert state, EAreaAlertSetting alertSetting)
        {
            EAreaAlertReport newReport = new EAreaAlertReport();

            newReport.EnumAlarmGrade = EnumAlarmGrade.Prompt;
            newReport.EnumSMSInfoType = EnumSMSInfoType.Area;
            newReport.ACCState = current.ACCState;
            newReport.Speed = current.Speed;
            newReport.VStarkMileage = current.StarkMileage;
            newReport.GPSCode = current.GPSCode;
            newReport.GPSReportTime = current.ReportTime;
            newReport.Latitude = current.Latitude;
            newReport.Longitude = current.Longitude;
            newReport.MobileReceiveBeginTime = alertSetting.MobileReceiveBeginTime;
            newReport.MobileReceiveEndTime = alertSetting.MobileReceiveEndTime;
            newReport.ReceiveMobileList = alertSetting.ReceiveMobileList;
            newReport.ReceiveUserList = alertSetting.ReceiveUserList;
            newReport.TenantCode = alertSetting.TenantCode;
            newReport.UserReceiveBeginTime = alertSetting.UserReceiveBeginTime;
            newReport.UserReceiveEndTime = alertSetting.UserReceiveEndTime;
            newReport.VehicleCode = alertSetting.VehicleCode;
            newReport.VehiclePosition = this.GetPlaceName(context, current.Latitude, current.Longitude);
            newReport.LicensePlate = this.GetLicensePlate(context, current.VehicleCode.Value, alertSetting.TenantCode);
            newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.IntoRegion;
            newReport.IsInArea = state != EnumAreaAlert.OutArea ? true : false;
            newReport.Area = alertSetting.Area;

            if (state == EnumAreaAlert.OutArea)
            {
                newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.OutRegion;
                EAreaAlertReport inReport = GPSServiceFacade.Report.Area.GetRectInAreaEntity(newReport.Area.RecordID, newReport.VehicleCode, newReport.GPSReportTime);
                if (inReport != null)
                {
                    newReport.InAreaID = inReport.RecordID;
                    newReport.StayTime = newReport.GPSReportTime - inReport.GPSReportTime;
                }
            }
            else if (state == EnumAreaAlert.DelayStay)
            {
                newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.DelayOutRegion;
                EAreaAlertReport inReport = GPSServiceFacade.Report.Area.GetRectInAreaEntity(newReport.Area.RecordID, newReport.VehicleCode, newReport.GPSReportTime);
                if (inReport != null)
                {
                    newReport.InAreaID = inReport.RecordID;
                    newReport.StayTime = newReport.GPSReportTime - inReport.GPSReportTime;
                }
                newReport.IsDelayStay = true;
                newReport.DelayDuration = alertSetting.DelayDuration;
            }

            return newReport;
        }
Пример #18
0
        // 之间在区域内而且停留时间超过设置中的最大停留时间。
        private bool IsInRangeBeforeAndDelayStayNow(EGPSCurrentInfo current, EAreaAlertSetting areaSet, bool isInRangeNow)
        {
            bool isReachCondition = false;

            VTempAreaWarning tempAreaWarning = AlarmLastStatusService.Singleton.GetLastAreaWarning(current, areaSet);
            if (tempAreaWarning != null)
            {
                if (tempAreaWarning.IsInArea == (int)EnumAreaAlert.InArea)
                {
                    // 如果当前停留时间大于区域延时设置最大停留时间
                    TimeSpan stayTime = current.ReportTime - tempAreaWarning.FirstInAreaTime;
                    if (stayTime.TotalMinutes > (double)areaSet.DelayDuration)
                    {
                        string logs = string.Format("stayTime:{0}秒,current reportTime:{1},firstInAreaTime:{2}", stayTime.TotalSeconds, current.ReportTime, tempAreaWarning.FirstInAreaTime);
                        Logger.Info(logs);
                        if (tempAreaWarning.LastWarnTime == null)//如果上一次报警时间为空,则表示第一次报警
                        {
                            isReachCondition = true;
                        }
                        //else//如果第二次报警时间和上一次报警时间相减速的间隔大于5分钟则符合条件。
                        //{
                        //    TimeSpan alarmTimespan = _gpsCurrentInfo.ReportTime - tempAreaWarning.LastWarnTime.Value;
                        //    if (alarmTimespan.TotalMinutes > DealyGoOutAlarmInterval)
                        //    {
                        //        isReachCondition = true;
                        //    }
                        //}
                    }
                }
            }

            if (isReachCondition)
            {
                tempAreaWarning.LastWarnTime = current.ReportTime;
                AlarmLastStatusService.Singleton.SaveLastAreaWarning(current, areaSet, tempAreaWarning);   //更新上一次报警时间
            }
            return isReachCondition;
        }
Пример #19
0
        private void Alert(AlarmHandleContext context, EGPSCurrentInfo current, EnumAreaAlert enumAreaAlert, EAreaAlertSetting areaSet, bool isAlert)
        {
            DateTime dt1 = DateTime.Now;
            EAreaAlertReport alertReport = this.CreateAlertReport(context, current, enumAreaAlert, areaSet);
            GPSServiceFacade.Report.Area.Add<EAreaAlertReport>(alertReport);
            Logger.Info(string.Format("Static_AreaAlertReportService.Add<EAreaAlertReport>(alertReport)共花销{0}毫秒", (DateTime.Now - dt1).TotalMilliseconds));

            if (isAlert)
            {
                if (areaSet.EnableSMS || areaSet.Enable)
                {
                    if (areaSet.EnableSMS && this.IsInMobileReceiveTime(alertReport))
                    {
                        this.SendSMS(context, alertReport);
                    }
                    if (areaSet.Enable && this.IsInUserReceiveTime(alertReport))
                    {
                        this.SendWebSiteSMS(context, alertReport);
                    }
                }
            }
        }
Пример #20
0
        private EOverSpeedAlertReport CreateAlertReport(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, EOverSpeedAlertSetting alertSetting)
        {
            EOverSpeedAlertReport newReport = new EOverSpeedAlertReport();

            newReport.EnumAlarmGrade = EnumAlarmGrade.Prompt;
            newReport.GPSReportTime = current.ReportTime;
            if (state == EnumAlertState.Resume)
            {
                newReport.EnumSMSInfoType = EnumSMSInfoType.NormalSpeed;
                newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.SpeedResume;
            }
            else
            {
                newReport.EnumSMSInfoType = EnumSMSInfoType.OverSpeed;
                newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.ExceedSpeed;
            }
            newReport.ACCState = current.ACCState;
            newReport.Speed = current.Speed;
            newReport.VStarkMileage = current.StarkMileage;
            newReport.GPSCode = current.GPSCode;
            newReport.Latitude = current.Latitude;
            newReport.Longitude = current.Longitude;
            newReport.MobileReceiveBeginTime = alertSetting.MobileReceiveBeginTime;
            newReport.MobileReceiveEndTime = alertSetting.MobileReceiveEndTime;
            newReport.ReceiveMobileList = alertSetting.ReceiveMobileList;
            newReport.ReceiveUserList = alertSetting.ReceiveUserList;
            newReport.TenantCode = alertSetting.TenantCode;
            newReport.UserReceiveBeginTime = alertSetting.UserReceiveBeginTime;
            newReport.UserReceiveEndTime = alertSetting.UserReceiveEndTime;
            newReport.VehicleCode = alertSetting.VehicleCode;
            newReport.VehiclePosition = this.GetPlaceName(context, current.Latitude, current.Longitude);
            newReport.LicensePlate = this.GetLicensePlate(context, current.VehicleCode.Value, alertSetting.TenantCode);
            newReport.EnumAlertState = state;
            newReport.SpeedLimit = alertSetting.SpeedLimit;
            newReport.VehicleSpeed = Convert.ToInt32(current.Speed);
            newReport.AlertState = (int)state;

            return newReport;
        }
Пример #21
0
        static readonly int Static_Min_PowerDown_Duration = 1;      //当超过指定分钟后,发送报警

        public override void Handle(EGPSCurrentInfo current, AlarmHandleContext context)
        {
            try
            {
                // 获取PowerDown的配置数据,没有配置则不进行任何处理
                EPowerDownAlertSetting setting = AlarmSettingsService.Singleton.GetPowerDownAlertSetting(current.VehicleCode.Value);
                if (setting == null)
                {
                    this.RemoveRunningState(context.RunningState, EnumSMSInfoType.BreakElectricity);
                    return;
                }

                // 取上一条断电报警状态,如果找不到直接跳出(实际上不可能找不到的,因为至少会返回一个空内容的实例,除非数据库访问错误)
                var lastCachingStatus = AlarmLastStatusService.Singleton.GetLastPowerDownAlertStatus(current);
                if (lastCachingStatus == null)
                    return;

                // 没有收到PowerDown报警指示
                if (current.PowerState != (int)EnumGPSPowerState.Break)
                {
                    // 如果上一条断电报警实例已存在,且未停止报警,则置该断电报警停止(即恢复不报警状态)
                    if (lastCachingStatus.LastAlertExists && lastCachingStatus.LastAlertEndTime == null)
                    {
                        // 修改数据库及缓存中的数据
                        DatabaseUtility.UpdatePowndownAlertReportStopEndTime(lastCachingStatus.LastAlertRecordId, current.ReportTime);

                        lastCachingStatus.LastAlertEndTime = current.ReportTime;
                        lastCachingStatus.LastPownDownTime = null;
                        AlarmLastStatusService.Singleton.SaveLastPowerDownAlertStatus(current.VehicleCode.Value, lastCachingStatus);

                        this.ModifyRunningState(context.RunningState, EnumAlertState.Resume, EnumSMSInfoType.BreakElectricity);
                        return;
                    }

                    // 如果此前记录了最后断电时间,则清除该断电时间
                    if (lastCachingStatus.LastPownDownTime.HasValue)
                    {
                        lastCachingStatus.LastPownDownTime = null;
                        AlarmLastStatusService.Singleton.SaveLastPowerDownAlertStatus(current.VehicleCode.Value, lastCachingStatus);
                        return;
                    }

                    return;
                }

                // 或收到的断电报警指示没有超过一定的持续时间,则直接跳过该报警信息
                if (lastCachingStatus.LastPownDownTime == null)
                {
                    lastCachingStatus.LastPownDownTime = current.ReportTime;
                    AlarmLastStatusService.Singleton.SaveLastPowerDownAlertStatus(current.VehicleCode.Value, lastCachingStatus);
                    return;
                }
                if ((current.ReportTime - lastCachingStatus.LastPownDownTime.Value).TotalMinutes < Static_Min_PowerDown_Duration)
                    return;

                // 已处在报警状态(还未停止),则不用重复处理
                if (lastCachingStatus.LastAlertExists && lastCachingStatus.LastAlertEndTime == null)
                    return;

                // 生成断电报警
                this.Alert(context, current, EnumAlertState.Alerting, setting, lastCachingStatus);
                this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.BreakElectricity);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "VehicleCode", current.VehicleCode, "GPSCode", current.GPSCode);
            }
        }
Пример #22
0
        public override void Handle(EGPSCurrentInfo current, AlarmHandleContext context)
        {
            try
            {
                // 获取OverSpeed的配置数据,没有配置则不进行任何处理
                EOverSpeedAlertSetting setting = AlarmSettingsService.Singleton.GetOverSpeedAlertSetting(current.VehicleCode.Value);
                if (setting == null)
                {
                    this.RemoveRunningState(context.RunningState, EnumSMSInfoType.OverSpeed);
                    return;
                }

                // 取上一条报警状态,如果找不到直接跳出(实际上不可能找不到的,因为至少会返回一个空内容的实例,除非数据库访问错误)
                var lastCachingStatus = AlarmLastStatusService.Singleton.GetLastOverSpeedAlertStatus(current);
                if (lastCachingStatus == null)
                    return;

                // 没有收到OverSpeed报警指示,则去除缓存中的最后OverSpeed时间
                if (current.Speed < setting.SpeedLimit)
                {
                    // 如果上一条OverSpeed报警实例已存在,且未停止报警,则置该OverSpeed报警停止(即恢复不报警状态)
                    if (lastCachingStatus.AlertState == (int)EnumAlertState.Alerting)
                    {
                        // 发送恢复OverSpeed报警的站内信和手机短信
                        lastCachingStatus.LastOverSpeedTime = null;
                        this.Alert(context, current, EnumAlertState.Resume, setting, lastCachingStatus);
                        this.ModifyRunningState(context.RunningState, EnumAlertState.Resume, EnumSMSInfoType.OverSpeed);
                        return;
                    }

                    // 如果此前记录了最后OverSpeed时间,则清除该OverSpeed时间
                    if (lastCachingStatus.LastOverSpeedTime.HasValue)
                    {
                        lastCachingStatus.AlertState = EnumAlertState.Resume;
                        lastCachingStatus.LastOverSpeedTime = null;
                        AlarmLastStatusService.Singleton.SaveLastOverSpeedAlertStatus(current.VehicleCode.Value, lastCachingStatus);
                        return;
                    }

                    return;
                }

                // 或收到的OverSpeed报警指示没有超过一定的持续时间,则直接跳过该报警信息
                if (lastCachingStatus.LastOverSpeedTime == null)
                {
                    lastCachingStatus.LastOverSpeedTime = current.ReportTime;
                    AlarmLastStatusService.Singleton.SaveLastOverSpeedAlertStatus(current.VehicleCode.Value, lastCachingStatus);
                    return;
                }
                if ((current.ReportTime - lastCachingStatus.LastOverSpeedTime.Value).TotalMinutes < setting.Duration)
                    return;

                // 已处在OverSpeed报警状态(还未停止),则不用重复处理
                if (lastCachingStatus.AlertState == (int)EnumAlertState.Alerting)
                    return;

                // 生成OverSpeed报警
                this.Alert(context, current, EnumAlertState.Alerting, setting, lastCachingStatus);
                this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.OverSpeed);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "VehicleCode", current.VehicleCode, "GPSCode", current.GPSCode);
            }
        }
Пример #23
0
        public void RemoveLastFortifyWarning(EGPSCurrentInfo current)
        {
            string key = CONST_KEY_LAST_FORTIFY_STATUS + current.VehicleCode.Value.ToString();

            this.CachedService.Remove(key);
        }
Пример #24
0
        private EnumRunningState GetRunningState(EGPSCurrentInfo gpsCurrentInfo)
        {
            EnumRunningState state = EnumRunningState.Running;

            if (gpsCurrentInfo.Speed == 0 || gpsCurrentInfo.ACCState == 0)
                state = EnumRunningState.Stop;
            if (gpsCurrentInfo.Speed == 0 && gpsCurrentInfo.ACCState == 1)
                state = EnumRunningState.StopAccOn;
            return state;
        }
Пример #25
0
 public abstract void Handle(EGPSCurrentInfo current, AlarmHandleContext context);
Пример #26
0
        private IList<EGPSCurrentInfo> GetCurrentInfo(IList<string> codeList)
        {
            IList<EGPSCurrentInfo> result = new List<EGPSCurrentInfo>();

            string sql = "select vehicleCode,Speed,AccState from gps_currentInfo ";
            sql+=string.Format("where vehicleCode in('{0}')",string.Join("','",codeList.ToArray()));
            string connectionString = ConnectionStringHelper.DefaultConnectionString;
            DataSet ds = MySqlHelper.ExecuteDataSet(connectionString, sql);
            if (null != ds && ds.Tables[0].Rows.Count>0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    EGPSCurrentInfo info = new EGPSCurrentInfo()
                    {
                        VehicleCode = new Guid(row["vehicleCode"].ToString()),
                        Speed = decimal.Parse(row["Speed"].ToString()),
                        ACCState = int.Parse(row["AccState"].ToString())
                    };
                    result.Add(info);
                }
            }
            return result;
        }
Пример #27
0
 public RealTimeInfoViewEntity(EGPSCurrentInfo eGPSCurrentInfo,EBaseVehicle vehicleInfo)
 {
     this.CurrentGPSInfo = eGPSCurrentInfo;
     this.VehicleInfo = vehicleInfo;
 }
Пример #28
0
        private bool IsInRangeBefore(EGPSCurrentInfo current, EAreaAlertSetting areaSet, bool isInRangeNow)
        {
            VTempAreaWarning tempAreaWarning = AlarmLastStatusService.Singleton.GetLastAreaWarning(current, areaSet);
            if (tempAreaWarning == null)
            {
                tempAreaWarning = new VTempAreaWarning();
                tempAreaWarning.AreaCode = areaSet.Area.RecordID;
                tempAreaWarning.GPSCode = current.GPSCode;
                tempAreaWarning.IsInArea = isInRangeNow ? 1 : 0;
                tempAreaWarning.ReportTime = current.ReportTime;
                tempAreaWarning.VehicleCode = current.VehicleCode.Value;

                AlarmLastStatusService.Singleton.SaveLastAreaWarning(current, areaSet, tempAreaWarning);
                return false;
            }

            bool isIn = (tempAreaWarning.IsInArea == (int)EnumAreaAlert.InArea);
            tempAreaWarning.IsInArea = isInRangeNow ? 1 : 0;
            tempAreaWarning.ReportTime = current.ReportTime;
            AlarmLastStatusService.Singleton.SaveLastAreaWarning(current, areaSet, tempAreaWarning);

            return isIn;
        }
Пример #29
0
        protected void Alert(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, ETraceAlertSetting alertSetting, LastTracePointAlertStatus lastCachingPointStatus)
        {
            if (alertSetting.EnableSMS || alertSetting.Enable)
            {
                // 生成报警实例,并将报警存入数据库,最新的报警状态放入缓存中
                ETraceAlertReport alertReport = this.CreateAlertReport(context, current, state, alertSetting);

                DateTime dt1 = DateTime.Now;
                GPSServiceFacade.AlertService.Add<ETraceAlertReport>(alertReport);
                Logger.Info(string.Format("Static_AlertReportService.Add<ETraceAlertReport>(alertReport)共花销{0}毫秒", (DateTime.Now - dt1).TotalMilliseconds));

                lastCachingPointStatus.LastAlertTime = current.ReportTime;
                AlarmLastStatusService.Singleton.SaveLastTracePointAlertStatus(current, alertSetting, lastCachingPointStatus);

                LastTraceAlertStatus lastCachingStatus = new LastTraceAlertStatus()
                {
                    LastAlertTracePointId = alertSetting.TracePointID.ToString().ToLower(),
                    LastAlertTime = current.ReportTime
                };
                AlarmLastStatusService.Singleton.SaveLastTraceAlertStatus(current.VehicleCode.Value, lastCachingStatus);

                if (alertSetting.EnableSMS && this.IsInMobileReceiveTime(alertReport))
                {
                    this.SendSMS(context, alertReport);
                }

                if (alertSetting.Enable && this.IsInUserReceiveTime(alertReport))
                {
                    this.SendWebSiteSMS(context, alertReport);
                }
            }
        }
Пример #30
0
        private EPowerDownAlertReport CreateAlertReport(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, EPowerDownAlertSetting alertSetting, DateTime lastPowerDownTime)
        {
            EPowerDownAlertReport newReport = new EPowerDownAlertReport();

            newReport.EnumAlarmGrade = EnumAlarmGrade.Alarm;
            newReport.ACCState = current.ACCState;
            newReport.Speed = current.Speed;
            newReport.VStarkMileage = current.StarkMileage;
            newReport.EnumSMSInfoType = EnumSMSInfoType.BreakElectricity;
            newReport.GPSCode = current.GPSCode;
            newReport.GPSReportTime = lastPowerDownTime;
            newReport.Latitude = current.Latitude;
            newReport.Longitude = current.Longitude;
            newReport.MobileReceiveBeginTime = alertSetting.MobileReceiveBeginTime;
            newReport.MobileReceiveEndTime = alertSetting.MobileReceiveEndTime;
            newReport.ReceiveMobileList = alertSetting.ReceiveMobileList;
            newReport.ReceiveUserList = alertSetting.ReceiveUserList;
            newReport.TenantCode = alertSetting.TenantCode;
            newReport.UserReceiveBeginTime = alertSetting.UserReceiveBeginTime;
            newReport.UserReceiveEndTime = alertSetting.UserReceiveEndTime;
            newReport.VehicleCode = alertSetting.VehicleCode;
            newReport.VehiclePosition = this.GetPlaceName(context, current.Latitude, current.Longitude);
            newReport.LicensePlate = this.GetLicensePlate(context, current.VehicleCode.Value, alertSetting.TenantCode);
            newReport.EnumAlertState = state;
            newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.BreakPower;

            return newReport;
        }