public static DbModel.Location.Data.LocationCardPosition ToDbModel( this Location.TModel.Location.Data.TagPosition item1) { if (item1 == null) { return(null); } var item2 = new DbModel.Location.Data.LocationCardPosition(); item2.Id = item1.Tag; item2.X = item1.X; item2.Y = item1.Y; item2.Z = item1.Z; item2.DateTime = TimeConvert.ToDateTime(item1.Time); item2.DateTimeStamp = item1.Time; item2.Power = item1.Power; item2.Number = item1.Number; item2.Flag = item1.Flag; item2.Archors = item1.Archors; item2.AreaId = item1.AreaId; item2.AreaState = item1.AreaState; item2.PowerState = item1.PowerState; item2.MoveState = item1.MoveState; return(item2); }
public static Location.TModel.Location.Data.TagPosition ToTModel( this DbModel.Location.Data.LocationCardPosition item1) { if (item1 == null) { return(null); } var item2 = new Location.TModel.Location.Data.TagPosition(); item2.Tag = item1.Id; item2.X = item1.X; item2.Y = item1.Y; item2.Z = item1.Z; item2.Time = item1.DateTimeStamp; item2.DateTime = item1.DateTime;//在TagPosition添加DateTime item2.Power = item1.Power; item2.Number = item1.Number; item2.Flag = item1.Flag; if (!string.IsNullOrEmpty(item1.ArchorsText)) { item2.Archors = item1.ArchorsText.Split('@').ToList(); } else { item2.Archors = null; } item2.AreaId = item1.AreaId; //item2.AreaPath = item1.AreaPath; //item2.PersonId = item1.PersonId; item2.AreaState = item1.AreaState; item2.PowerState = item1.PowerState; item2.MoveState = item1.MoveState; return(item2); }
public List <NearbyDev> GetNearbyDev_Currency(int id, float fDis, int nFlag) { List <NearbyDev> lst = new List <NearbyDev>(); List <NearbyDev> lst2 = new List <NearbyDev>(); DbModel.Location.Data.LocationCardPosition lcp = db.LocationCardPositions.DbSet.Where(p => p.PersonId == id).FirstOrDefault(); if (lcp == null || lcp.AreaId == null) { return(lst); } int?AreadId = lcp.AreaId; float PosX = lcp.X; float PosY = lcp.Y; float PosZ = lcp.Z; float PosX2 = 0; float PosY2 = 0; float PosZ2 = 0; float sqrtDistance = 0; float Distance = 0; var query = from t1 in db.DevInfos.DbSet join t2 in db.DevTypes.DbSet on t1.Local_TypeCode equals t2.TypeCode join t3 in db.Areas.DbSet on t1.ParentId equals t3.Id where t1.ParentId == AreadId && (nFlag == 0 ? true : (t1.Local_TypeCode == 3000201 || t1.Local_TypeCode == 14 || t1.Local_TypeCode == 3000610 || t1.Local_TypeCode == 1000102)) select new NearbyDev { id = t1.Id, Name = t1.Name, TypeCode = t1.Local_TypeCode, TypeName = t2.TypeName, Area = t3.Name, X = t1.PosX, Y = t1.PosY, Z = t1.PosZ }; if (query != null) { lst2 = query.ToList(); } foreach (NearbyDev item in lst2) { PosX2 = item.X - PosX; PosY2 = item.Y - PosY; PosZ2 = item.Z - PosZ; sqrtDistance = PosX2 * PosX2 + PosY2 * PosY2 + PosZ2 * PosZ2; Distance = (float)System.Math.Sqrt(sqrtDistance); item.Distance = Distance; if (Distance <= fDis) { NearbyDev item2 = item.Clone(); if (item2 != null) { item2.X = PosX2; item2.Y = PosY2; item2.Z = PosZ2; lst.Add(item2); } } PosX2 = 0; PosY2 = 0; PosZ2 = 0; sqrtDistance = 0; Distance = 0; } lst.Sort(new DevDistanceCompare()); if (lst.Count == 0) { lst = null; } return(lst); }
public List <NearbyDev> GetNearbyDev_Currency(int id, float fDis, int nFlag) { List <NearbyDev> lst = new List <NearbyDev>(); List <NearbyDev> lst2 = new List <NearbyDev>(); DbModel.Location.Data.LocationCardPosition lcp = db.LocationCardPositions.DbSet.Where(p => p.PersonId == id).FirstOrDefault(); if (lcp == null || lcp.AreaId == null) { return(lst); } int?AreadId = lcp.AreaId; float PosX = lcp.X; float PosY = lcp.Y; float PosZ = lcp.Z; float PosX2 = 0; float PosY2 = 0; float PosZ2 = 0; float sqrtDistance = 0; float Distance = 0; //根据区域ID和标志位获取摄像头 GetCameraDevByAreaId(AreadId, nFlag, lst2); if (lst2.Count <= 0) { DbModel.Location.AreaAndDev.Area area = db.Areas.Find(p => p.Id == AreadId); GetCameraDevByAreaId(area.ParentId, nFlag, lst2); } //var query = from t1 in db.DevInfos.DbSet // join t2 in db.DevTypes.DbSet on t1.Local_TypeCode equals t2.TypeCode // join t3 in db.Areas.DbSet on t1.ParentId equals t3.Id // where t1.ParentId == AreadId && (nFlag == 0 ? true : (t1.Local_TypeCode == 3000201 || t1.Local_TypeCode == 14 || t1.Local_TypeCode == 3000610 || t1.Local_TypeCode == 1000102)) // select new NearbyDev { id = t1.Id, Name = t1.Name, TypeCode = t1.Local_TypeCode, TypeName = t2.TypeName, Area = t3.Name, X = t1.PosX, Y = t1.PosY, Z = t1.PosZ }; //if (query != null) //{ // lst2 = query.ToList(); //} var areas = db.Areas.ToDictionary(); var bounds = db.Bounds.ToDictionary(); foreach (var item in areas) { var area = item.Value; if (area.InitBoundId != null) { area.InitBound = bounds[(int)area.InitBoundId]; } } foreach (NearbyDev item in lst2) { float x = item.X; float y = item.Y; float z = item.Z; if (areas.ContainsKey(item.AreaId)) { var area = areas[item.AreaId];//所在区域 if (area.Type == AreaTypes.机房) { var floor = areas[(int)area.ParentId]; var building = areas[(int)floor.ParentId];// var minX = area.InitBound.GetZeroX() + floor.InitBound.GetZeroX() + building.InitBound.GetZeroX(); var minY = area.InitBound.GetZeroY() + floor.InitBound.GetZeroY() + building.InitBound.GetZeroY(); x += minX; z += minY; } else if (area.Type == AreaTypes.楼层) { var floor = area; var building = areas[(int)floor.ParentId];// var minX = floor.InitBound.GetZeroX() + building.InitBound.GetZeroX(); var minY = floor.InitBound.GetZeroY() + building.InitBound.GetZeroY(); x += minX; z += minY; } } PosX2 = x - PosX; PosY2 = y - PosY; PosZ2 = z - PosZ; sqrtDistance = PosX2 * PosX2 + PosY2 * PosY2 + PosZ2 * PosZ2; Distance = (float)System.Math.Sqrt(sqrtDistance); item.Distance = Distance; if (Distance <= fDis) { NearbyDev item2 = item.Clone(); if (item2 != null) { item2.X = PosX2; item2.Y = PosY2; item2.Z = PosZ2; lst.Add(item2); } } PosX2 = 0; PosY2 = 0; PosZ2 = 0; sqrtDistance = 0; Distance = 0; } lst.Sort(new DevDistanceCompare()); if (lst.Count == 0) { lst = null; } return(lst); }