Dictionary <string, int> codeToRelationIndex; //定位卡-设置顺序(位置排序)

        private void UpdateDynamicAreaInfo(List <Position> posList)
        {
            string costTime = "";
            //增加标志位,是否需要启用这个功能
            DateTime recordTime = DateTime.Now;

            if (bll == null)
            {
                bll = GetLocationBll();
            }
            if (codeToAreaDic == null)
            {
                codeToAreaDic = bll.LocationCardToArea.ToDictionary();
            }
            if (codeToRelationIndex == null)
            {
                codeToRelationIndex = bll.LocationCardToArea.GetCardToRelationIndex();
            }
            if (codeToAreaDic == null || codeToAreaDic.Count == 0)
            {
                return;
            }
            DynamicMonitorAreaUpdate areaUpdateInfo = new DynamicMonitorAreaUpdate();
            Dictionary <int, Area>   areaDic        = TagRelationBuffer.Instance().GetAreaDictionary();

            if (areaDic == null)
            {
                return;
            }
            //1.判断位置点是否属于动态电子围栏,缓存电子围栏下位置
            foreach (var item in posList)
            {
                if (codeToAreaDic.ContainsKey(item.Code))
                {
                    int areaId = codeToAreaDic[item.Code];
                    if (areaDic.ContainsKey(areaId))
                    {
                        Area areaT = areaDic[areaId];
                        areaUpdateInfo.SaveTempInfo(areaT, item);
                    }
                }
            }
            costTime  += string.Format("GetDicSaveInfo {0} ms\n", (DateTime.Now - recordTime).TotalMilliseconds.ToString());
            recordTime = DateTime.Now;
            //2.计算并更新区域位置和角度信息
            List <Area> newAreas = areaUpdateInfo.AreaInfoUpdate(codeToRelationIndex);

            costTime  += string.Format("AreaInfoUpdate {0} ms\n", (DateTime.Now - recordTime).TotalMilliseconds.ToString());
            recordTime = DateTime.Now;
            //3.保存至数据库,并发送给客户端
            if (newAreas != null)
            {
                bll.Areas.EditRange(newAreas);
                List <Location.TModel.Location.AreaAndDev.PhysicalTopology> updateData = newAreas.ToWcfModelList();
                MonitorRangeHub.SendMonitorRangeInfos(updateData);
            }
            costTime += string.Format("SendMonitorRangeInfos {0} ms\n", (DateTime.Now - recordTime).TotalMilliseconds.ToString());
            Log.Info(costTime);
        }
Ejemplo n.º 2
0
        public bool EditMonitorRange(PhysicalTopology pt)
        {
            try
            {
                Area area = db.Areas.Find((i) => i.Id == pt.Id);
                if (area != null && pt.InitBound != null)
                {
                    RemoveDynamicAreaInfo(area, pt);
                    area.Name          = pt.Name;//2019_07_18_cww:添加名称,区域名称可以修改的
                    area.IsDynamicArea = pt.IsDynamicArea;
                    area.ModelName     = pt.ModelName;
                    var transform = pt.Transfrom;

                    //var parent = db.Areas.Find(area.ParentId);//父区域
                    //var parentBound = db.Bounds.Find(parent.InitBoundId);//父区域的范围
                    //if (parent.Type == AreaTypes.楼层 && pt.IsRelative)//加上偏移量
                    //{
                    //    transform.X += parentBound.MinX;
                    //    transform.Z += parentBound.MinY;
                    //}

                    pt.InitBound.SetInitBound(pt.Transfrom);
                    area.SetTransform(pt.Transfrom.ToDbModel());
                    db.Areas.Edit(area);

                    var InitBoundT = pt.InitBound.ToDbModel();
                    var InitBound  = db.Bounds.Find(p => p.Id == InitBoundT.Id);
                    InitBound.SetInitBound(InitBoundT);
                    db.Bounds.Edit(InitBound);//修改

                    List <DbModel.Location.AreaAndDev.Point> lst = db.Points.FindAll(p => p.BoundId == InitBound.Id);
                    foreach (var item in InitBoundT.Points)
                    {
                        DbModel.Location.AreaAndDev.Point pi = lst.Find(p => p.Index == item.Index);
                        pi.SetPoint(item.X, item.Y, item.Z);
                    }

                    db.Points.EditRange(lst);

                    TagRelationBuffer.Instance().PuUpdateData();
                    BLL.Buffers.AuthorizationBuffer.Instance(db).PubUpdateData();
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Log.Error(tag, "EditMonitorRange", ex.ToString());
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public PhysicalTopology AddMonitorRange(PhysicalTopology pt)
        {
            try
            {
                if (pt == null)
                {
                    return(null);
                }
                var transform = pt.Transfrom;

                //var parent = db.Areas.Find(pt.ParentId);//父区域
                //var parentBound = db.Bounds.Find(parent.InitBoundId);//父区域的范围
                //if (parent.Type == AreaTypes.楼层 && pt.IsRelative)//加上偏移量
                //{
                //    transform.X += parentBound.MinX;
                //    transform.Z += parentBound.MinY;
                //}

                //return db.Areas.Add(pt.ToDbModel());
                var areaNew = pt.ToDbModel();
                pt.InitBound = NewBound(pt);
                var newTransform = transform.ToDbModel();
                areaNew.SetTransform(newTransform);
                var newBound = pt.InitBound.ToDbModel();
                db.Bounds.Add(newBound);
                areaNew.SetBound(newBound);
                var points = areaNew.InitBound.Points;
                //db.Points.AddRange(points);

                var addR = db.Areas.Add(areaNew);

                if (addR)
                {
                    TagRelationBuffer.Instance().PuUpdateData();
                    BLL.Buffers.AuthorizationBuffer.Instance(db).PubUpdateData();

                    var result = areaNew.ToTModel();

                    //if (parent.Type == AreaTypes.楼层 && pt.IsRelative)//减去偏移量
                    //{
                    //    result.Transfrom.X -= parentBound.MinX;
                    //    result.Transfrom.Z -= parentBound.MinY;
                    //}
                    return(result);
                }
                return(null);
            }
            catch (Exception e)
            {
                Log.Error(tag, "AddMonitorRange", e.ToString());
                return(null);
            }
        }
Ejemplo n.º 4
0
        public bool DeleteMonitorRange(PhysicalTopology pt)
        {
            try
            {
                if (pt == null)
                {
                    return(false);
                }
                int  AreaId = pt.Id;
                Area aa     = db.Areas.Find(p => p.Id == AreaId);
                if (aa != null)
                {
                    db.Areas.Remove(aa);
                }

                if (pt.InitBound != null)
                {
                    int BoundId = pt.InitBound.Id;

                    db.Bounds.DeleteById(BoundId);

                    List <DbModel.Location.AreaAndDev.Point> lst = db.Points.FindAll(p => p.BoundId == BoundId);
                    if (lst != null)
                    {
                        db.Points.RemoveList(lst);
                    }
                }

                TagRelationBuffer.Instance().PuUpdateData();
                BLL.Buffers.AuthorizationBuffer.Instance(db).PubUpdateData();
            }
            catch (Exception ex)
            {
                Log.Error(tag, "DeleteMonitorRange", ex.ToString());
                return(false);
            }

            return(true);
        }