示例#1
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);
                }
            }
        }
 public void SaveLastStopCarAlertStatus(Guid vehicleCode, LastStopCarAlertStatus status)
 {
     string key = CONST_KEY_LAST_STOPCAR_STATUS + vehicleCode.ToString();
     if (status == null)
     {
         status = new LastStopCarAlertStatus();
     }
     this.CachedService.Add(key, status, DateTime.Now.AddDays(1));
 }
        public LastStopCarAlertStatus GetLastStopCarAlertStatus(EGPSCurrentInfo current)
        {
            if (!current.VehicleCode.HasValue) return null;

            string key = CONST_KEY_LAST_STOPCAR_STATUS + current.VehicleCode.Value.ToString();
            var result = this.CachedService.Get(key) as LastStopCarAlertStatus;
            if (result == null)
            {
                // 找不到则从数据库查找最后一条报表记录
                DateTime dt1 = DateTime.Now;
                var lastReport = GPSServiceFacade.Report.StopCar.GetRecentReport(current.VehicleCode.Value);
                Logger.Info("从数据库查找最后一条StopCar报表记录", "开销时间(毫秒)", (DateTime.Now - dt1).TotalMilliseconds, "Vehicle Code", current.VehicleCode.Value);

                result = new LastStopCarAlertStatus();
                if (lastReport != null)
                {
                    result.LastAlertRecordId = lastReport.RecordID.ToString();
                    result.LastAlertStartTime = lastReport.GPSReportTime;
                    result.LastAlertEndTime = lastReport.StopEndTime;
                    result.LastStopCarTime = null;
                }
                lastReport = null;

                this.SaveLastStopCarAlertStatus(current.VehicleCode.Value, result);
            }

            return result;
        }