Exemplo n.º 1
0
        /// <summary>
        /// 解析经纬度,需要用到第三方服务
        /// </summary>
        /// <param name="lat"></param>
        /// <param name="lon"></param>
        /// <returns></returns>
        protected virtual string GetPlaceName(AlarmHandleContext context, decimal lat, decimal lon)
        {
            // 直接从上下文中获取,以避免重复获取
            if (!string.IsNullOrEmpty(context.LatitudeLongitudePlaceName))
                return context.LatitudeLongitudePlaceName;

            string position = GetPlaceName(lat, lon);

            context.LatitudeLongitudePlaceName = position;
            return position;
        }
Exemplo n.º 2
0
 private void Alert(EOfflineTimeoutAlertSetting setting)
 {
     if (setting.EnableSMS || setting.Enable)
     {
         if (setting.EnableSMS && this.IsInReceiveTime(_alertReport.MobileReceiveBeginTime, _alertReport.MobileReceiveEndTime))
         {
             SendSMS(_alertReport);
         }
         if (setting.Enable && this.IsInReceiveTime(_alertReport.UserReceiveBeginTime, _alertReport.UserReceiveEndTime))
         {
             AlarmHandleContext context = new AlarmHandleContext();
             this.SendWebSiteSMS(context, _alertReport);
         }
     }
 }
Exemplo n.º 3
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);
            }

        }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取车牌号码
        /// </summary>
        /// <param name="vehicleCode"></param>
        /// <param name="tenantCode"></param>
        /// <returns></returns>
        protected virtual string GetLicensePlate(AlarmHandleContext context, Guid vehicleCode, string tenantCode)
        {
            // 直接从上下文中获取,以避免重复获取
            if (!string.IsNullOrEmpty(context.VehicleLicenceNumber))
                return context.VehicleLicenceNumber;

            try
            {                

                // 如果找不到车,则从表move_vehicle这个表里查找车牌号
                DateTime dt1 = DateTime.Now;
                context.VehicleLicenceNumber = DatabaseUtility.SelectLicenceNumberFromMovo(vehicleCode.ToString());
             
                Logger.Info(string.Format("DatabaseUtility.SelectLicenceNumberFromMovo(vehicleCode.ToString())共花销{0}毫秒", (DateTime.Now - dt1).TotalMilliseconds));
                return context.VehicleLicenceNumber;
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "vehicleCode", vehicleCode, "tenantCode", tenantCode);
            }
            return string.Empty;
        }
Exemplo n.º 8
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);
                }
            }
        }
Exemplo n.º 9
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
                    {


                    }

                }

            }
        }
Exemplo n.º 10
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);
                }
            }
        }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
 protected virtual void SendSMS(AlarmHandleContext context, EBaseAlertReport report)
 {
     this.SendSMS(report.GetReceiveMobiles(), report.DownSendOrderCode, report.GetSMSParamters(),
         report.TenantCode, ConsumeType.SMSAlert, report.GetReceiveUsers());
 }
Exemplo n.º 13
0
 public abstract void Handle(EGPSCurrentInfo current, AlarmHandleContext context);
Exemplo n.º 14
0
        private EStopCarAlertReport CreateAlertReport(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, EStopCarAlertSetting alertSetting, DateTime lastStopCarTime, Guid newReportId)
        {
            EStopCarAlertReport newReport = new EStopCarAlertReport();

            newReport.RecordID = newReportId;
            newReport.EnumAlarmGrade = EnumAlarmGrade.Prompt;
            newReport.EnumSMSInfoType = EnumSMSInfoType.StopCarOverTime;
            newReport.ACCState = current.ACCState;
            newReport.Speed = current.Speed;
            newReport.StarkMileage = current.StarkMileage;
            newReport.ACCState = current.ACCState;
            newReport.Speed = current.Speed;
            newReport.VStarkMileage = current.StarkMileage;
            newReport.GPSCode = current.GPSCode;
            newReport.GPSReportTime = lastStopCarTime;
            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.VehicleStop;
            newReport.StopAlertTimeSpan = (int)((current.ReportTime - lastStopCarTime).TotalMinutes);

            return newReport;
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 17
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);
            }
        }
Exemplo n.º 18
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;
        }
Exemplo n.º 19
0
        public override void Handle(EGPSCurrentInfo current, AlarmHandleContext context)
        {
            try
            {
                // 获取StopCar的配置数据,没有配置则不进行任何处理
                EStopCarAlertSetting setting = AlarmSettingsService.Singleton.GetStopCarAlertSetting(current.VehicleCode.Value);
                if (setting == null)
                {
                    this.RemoveRunningState(context.RunningState, EnumSMSInfoType.StopCarOverTime);
                    return;
                }

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

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

                        lastCachingStatus.LastAlertEndTime = current.ReportTime;
                        lastCachingStatus.LastStopCarTime = null;
                        AlarmLastStatusService.Singleton.SaveLastStopCarAlertStatus(current.VehicleCode.Value, lastCachingStatus);

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

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

                    return;
                }

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

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

                // 生成StopCar报警
                this.Alert(context, current, EnumAlertState.Alerting, setting, lastCachingStatus);
                this.ModifyRunningState(context.RunningState, EnumAlertState.Alerting, EnumSMSInfoType.StopCarOverTime);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "VehicleCode", current.VehicleCode, "GPSCode", current.GPSCode);
            }
        }
        private void Alert(EnumAlertState state, EFatigueDrivingAlertSetting setting)
        {
            if (state == EnumAlertState.Alerting)
            {
                if (setting.EnableSMS || setting.Enable)
                {
                    _alertReport = (EFatigueDrivingReport)CreateAlertReport(state, setting);
                    SaveAlertReport();
                    if (setting.EnableSMS && this.IsInReceiveTime(_alertReport.MobileReceiveBeginTime, _alertReport.MobileReceiveEndTime))
                    {
                        SendSMS(_alertReport);
                    }
                    if (setting.Enable && this.IsInReceiveTime(_alertReport.UserReceiveBeginTime, _alertReport.UserReceiveEndTime))
                    {
                        AlarmHandleContext context = new AlarmHandleContext();                        
                        this.SendWebSiteSMS(context, _alertReport);
                    }
                }

            }
            else
            {
                UpdateAlertReport();
            }
        }
Exemplo n.º 21
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);
                    }
                }
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 23
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;
        }
Exemplo n.º 24
0
        protected virtual void SendWebSiteSMS(AlarmHandleContext context, EBaseAlertReport report)
        {
            try
            {
                var arrUser = report.GetReceiveUsers();
                if (arrUser == null || arrUser.Length == 0)
                    return;

                string title = report.GetAlertTitle();
                string content = report.GetAlertMessage();
                if (report.EnumAlertState == EnumAlertState.Resume)
                {
                    title = report.GetResumeAlertTitle();
                    content = report.GetResumeAlertMessage();
                }

                DateTime dt1 = DateTime.Now;
                EWebSMSInfo webSMS = GPSServiceFacade.Alarm.WebSMS.Add(arrUser, title, content, report.VehicleCode, report.EnumSMSInfoType);
                Logger.Info(string.Format("Static_WebSMSManager.Add()共花销{0}毫秒", (DateTime.Now - dt1).TotalMilliseconds), "Users", string.Join(",", arrUser));

                if (report.EnumAlarmGrade == EnumAlarmGrade.Alarm)
                {
                    DateTime dt2 = DateTime.Now;
                    GPSServiceFacade.Alarm.AlarmInfo.Add(this.CreateAlarmEntity(context, report, webSMS));
                    Logger.Info(string.Format("Static_AlarmInfoManager.Add()共花销{0}毫秒", (DateTime.Now - dt2).TotalMilliseconds));
                }

                Logger.Info(string.Format("WebSiteSMS [{0}],{1},{2}", title, content, report.ReceiveUserList));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Exemplo n.º 25
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;
        }
Exemplo n.º 26
0
        protected EAlarmInfo CreateAlarmEntity(AlarmHandleContext context, EBaseAlertReport report, EWebSMSInfo webSMS)
        {
            EAlarmInfo eAlarmInfo = new EAlarmInfo();
            eAlarmInfo.ACCState = report.ACCState;
            eAlarmInfo.AlarmGrade = (int)report.EnumAlarmGrade;
          
            eAlarmInfo.GPSTime = report.GPSReportTime;
            eAlarmInfo.IsLock = false;
            eAlarmInfo.ProcessState = (int)EnumProcessState.UnProcess;
            eAlarmInfo.Position = this.GetPlaceName(context, report.Latitude, report.Longitude);
            eAlarmInfo.SMSInfoType = (int)report.EnumSMSInfoType;
            eAlarmInfo.Speed = report.Speed;
            eAlarmInfo.StarkMileage = report.VStarkMileage;
            eAlarmInfo.VehicleCode = report.VehicleCode;
            eAlarmInfo.WebSMSInfoID = webSMS.RecordID;

            return eAlarmInfo;
        }
Exemplo n.º 27
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);
                }
            }
        }
Exemplo n.º 28
0
        public EFortifyAlertReport CreateAlertReport(AlarmHandleContext context, EGPSCurrentInfo current, EFortifyAlertsetting alertSetting)
        {
            EFortifyAlertReport newReport = new EFortifyAlertReport();

            newReport.EnumAlarmGrade = EnumAlarmGrade.Alarm;
            newReport.EnumSMSInfoType = EnumSMSInfoType.Fortify;
            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.OutFortifyRegion.ToString();
            return newReport;
        }