// 更新警员位置 // 返回警员位置变化状态,并同时返回警员位置变化异常状态结果 private bool UpgradeOfficerLocation(UpLoadDataPackage data, TagBindModel bdm, out UpgradeOfficerLocationResult result) { var handler = new OfficerLocationHandle(Repository); var lc = handler.First(t => t.OfficerId == bdm.Officer.Id); result = new UpgradeOfficerLocationResult { PreLocation = lc, IsLocationException = false }; var isEmpty = (null == lc); // 首次进入基站 if (isEmpty && !data.IsOut) { lc = new OfficerLocation { OfficerId = bdm.Officer.Id, EquipId = bdm.Equipment.Id, SiteId = data.SiteId, Status = (short)LocationStatus.In, UpTime = data.TTime }; handler.Add(lc); return(true); } // 进入基站,并且位置发生变化 if (!isEmpty && !data.IsOut && data.SiteId != lc.SiteId) { // 警员位置异常范围最小值 var tmin = lc.UpTime - OfficerLocationExceptionTimeRange; // 警员位置异常范围最大 值 var tmax = lc.UpTime + OfficerLocationExceptionTimeRange; // 进一步判断是否发生在异常时间内,并标识是否发生异常 result.IsLocationException = (tmin <= data.TTime && tmax >= data.TTime); if (result.IsLocationException) { // 位置异常,中断执行后续处理,并触发位置异常处理 return(false); } // 位置没有发生异常,继续执行后续处理 lc.SiteId = data.SiteId; lc.EquipId = bdm.Equipment.Id; lc.Status = (short)LocationStatus.In; lc.UpTime = data.TTime; handler.Modify(lc); return(true); } // 离开基站 if (!isEmpty && data.IsOut && lc.SiteId == data.SiteId) { lc.EquipId = bdm.Equipment.Id; lc.Status = (short)LocationStatus.Out; lc.UpTime = data.TTime; handler.Modify(lc); } return(false); }
// 警员位置异常处理 // 当同一个警员的不同装备在异常时间范围内出现在不同的位置时,触发当前异常 private void ExecuteOfficerLocationException(UpLoadDataPackage data, TagBindModel bdm, OfficerLocation location) { var expt = new EquipmentAllopatryExcept { CTime = DateTime.Now.ToUnixTime(), DTime = 0L, OfficerId = bdm.Officer.Id, Status = (short)OfficerLocaionExceptStatus.Doing }; var epHandler = new EquipmentAllopatryExceptHandle(Repository); epHandler.Add(expt); var aepc = new AllopatryEquipmentPosition { AeId = expt.Id, EquipId = bdm.Equipment.Id, SiteId = data.SiteId, UpTime = data.TTime }; var aepp = new AllopatryEquipmentPosition { AeId = expt.Id, EquipId = location.EquipId, SiteId = location.SiteId, UpTime = location.UpTime }; var apHandler = new AllopatryEquipmentPositionHandle(Repository); apHandler.Add(aepc); apHandler.Add(aepp); }