public void SaveLastPowerDownAlertStatus(Guid vehicleCode, LastPowerDownAlertStatus status)
        {
            var key = CONST_KEY_LAST_POWERDOWN_STATUS + vehicleCode.ToString();
            if (status == null)
            {
                status = new LastPowerDownAlertStatus();
            }

            this.CachedService.Add(key, status, DateTime.Now.AddDays(1));
        }
示例#2
0
        protected void Alert(AlarmHandleContext context, EGPSCurrentInfo current, EnumAlertState state, EPowerDownAlertSetting setting, LastPowerDownAlertStatus lastCachingStatus)
        {
            if (setting.EnableSMS || setting.Enable)
            {
                // 生成报警实例,并将报警存入数据库,放入缓存中
                EPowerDownAlertReport alertReport = this.CreateAlertReport(context, current, state, setting, lastCachingStatus.LastPownDownTime.Value);
                GPSServiceFacade.AlertService.Add<EPowerDownAlertReport>(alertReport);

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

                // 发送手机短信
                if (setting.EnableSMS && this.IsInMobileReceiveTime(alertReport))
                {
                    this.SendSMS(context, alertReport);
                }

                // 发送Web站内信
                if (setting.Enable && this.IsInUserReceiveTime(alertReport))
                {
                    this.SendWebSiteSMS(context, alertReport);
                }
            }
        }
        public LastPowerDownAlertStatus GetLastPowerDownAlertStatus(EGPSCurrentInfo current)
        {
            if (!current.VehicleCode.HasValue) return null;

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

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

                this.SaveLastPowerDownAlertStatus(current.VehicleCode.Value, result);
            }
            return result;
        }