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); }
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); } } }
public void SaveLastTracePointAlertStatus(EGPSCurrentInfo current, ETraceAlertSetting alertSetting, LastTracePointAlertStatus status) { string key = CONST_KEY_LAST_TRACEPOINT_STATUS + current.VehicleCode.Value.ToString() + "_" + alertSetting.TracePoint.RecordID; if (status == null) { status = new LastTracePointAlertStatus(); } this.CachedService.Add(key, status, DateTime.Now.AddDays(1)); }
public LastTracePointAlertStatus GetLastTracePointAlertStatus(EGPSCurrentInfo current, ETraceAlertSetting alertSetting) { if (!current.VehicleCode.HasValue) return null; string key = CONST_KEY_LAST_TRACEPOINT_STATUS + current.VehicleCode.Value.ToString() + "_" + alertSetting.TracePoint.RecordID; var result = this.CachedService.Get(key) as LastTracePointAlertStatus; if (result == null) { // 找不到则从数据库查找最后一条报表记录 DateTime dt1 = DateTime.Now; var lastReport = GPSServiceFacade.Report.Trace.GetRecentReport(alertSetting.TracePoint.RecordID, alertSetting.VehicleCode); Logger.Info("从数据库查找最后一条Trace Point报表记录", "开销时间(毫秒)", (DateTime.Now - dt1).TotalMilliseconds, "Vehicle Code", current.VehicleCode.Value, "TracePoint", alertSetting.TracePoint.RecordID); result = new LastTracePointAlertStatus(); if (lastReport != null) { result.LastAlertTime = lastReport.GPSReportTime; } lastReport = null; this.SaveLastTracePointAlertStatus(current, alertSetting, result); } return result; }