Browse Source

xls:信息导出改善

xulisong 6 năm trước cách đây
mục cha
commit
39b3b739b2

+ 12 - 1
MBI/Menu/MBITool.xml

@@ -222,7 +222,18 @@
       <MenuTab>MBITool_W</MenuTab>
       <Modules>MBITool</Modules>
     </Button>
-
+<Button ButtonStyles="Large">
+      <ButtonName>SAGA.GplotManage.SearchShaftCommand</ButtonName>
+      <ButtonText>导出竖井关系</ButtonText>
+      <ImageName>10、空间管理</ImageName>
+      <DllName>..\OutputDll\SAGA.GplotManage.exe</DllName>
+      <ClassName>SAGA.GplotManage.SearchShaftCommand</ClassName>
+      <ToolTip>导出竖井关系</ToolTip>
+      <LongDescription>导出竖井关系</LongDescription>
+      <ToolTipImage></ToolTipImage>
+      <MenuTab>MBITool_W</MenuTab>
+      <Modules>MBITool</Modules>
+    </Button>
 </Panel>
 </Menus>
 <!--名称里面换行-->

+ 253 - 1
MBI/SAGA.GplotManage/GplotCommand.cs

@@ -1,15 +1,22 @@
 
 using System.Collections.Generic;
 using System.IO;
+using System.Linq;
 using Autodesk.Revit.Attributes;
 using Autodesk.Revit.DB;
 using Autodesk.Revit.UI;
 using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using SAGA.DotNetUtils.Data;
 using SAGA.GplotDrawData;
 using SAGA.GplotDrawData.View;
 using SAGA.GplotManage.RelationManager;
 using SAGA.GplotRelationComputerManage;
+using SAGA.MBI.RequestData;
 using SAGA.Models;
+using SAGA.RevitUtils;
 using SAGA.RevitUtils.Extends;
 
 namespace SAGA.GplotManage
@@ -195,5 +202,250 @@ namespace SAGA.GplotManage
             return true;
         }
     }
-  
+
+    /// <summary>
+    /// 竖井查找
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class SearchShaftCommand : ExternalCommand
+    {
+        public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            //按计算结果计算 2019年4月10日10:17:23
+
+            /*1、加载所有空间信息
+             *2、加载关系数据,确定关系信息;
+             *3、找到相关关系,和给定基准空间不同的关系
+             */
+            string relationType = "ElementSpNeighborhood";
+            string graphId = RelationRequest.GetCurrentGraphId(relationType);
+            List<string> baseSpaceIds = new List<string>();
+            Dictionary<string, List<SpaceInfo>> dicGroup = new Dictionary<string, List<SpaceInfo>>();
+            foreach (var baseSpaceId in baseSpaceIds)
+            {
+                List<RoomItem> singleItems = new List<RoomItem>();
+           
+                var roomItem = GetRoomItem(baseSpaceId);
+                if (roomItem == null)
+                {
+                    continue;
+                }
+                singleItems.Add(roomItem);
+                //找到楼层下的,空间对
+                for (int i = 0; i < singleItems.Count; i++)
+                {
+                    var currentItem = singleItems[i];
+                    var currentFloorId = currentItem.FloorId;
+                    var relationsItems = QueryRelations(currentItem.Id, graphId);
+                    foreach (var relationsItem in relationsItems)
+                    {
+                        if (singleItems.Any(room => room.Id == relationsItem))
+                        {
+                            continue;
+                        }
+                        var tempRoomItem = GetRoomItem(relationsItem);
+                        if (tempRoomItem == null)
+                        {
+                            continue;
+                        }
+                        if (tempRoomItem.FloorId != currentFloorId)
+                        {
+                            singleItems.Add(tempRoomItem);
+                        }
+                    }
+                }
+
+
+                dicGroup[baseSpaceId] = singleItems.Select(r =>
+                {
+                    var tempRoom = SpaceInfo.Parse(r);
+                    tempRoom.FloorName = GetFloorItem(r.FloorId)?.LocalName ?? string.Empty;
+                    return tempRoom;
+                }).ToList();
+            }
+
+            ExportExcel(@"C:\Users\sagacloud\Desktop\亚心电梯井BIMID统计.xlsx", dicGroup);
+            MessageShow.Infomation("导出成功");
+            return Result.Succeeded;
+        }
+        /// <summary>
+        /// 缓存空间对象
+        /// </summary>
+        private Dictionary<string, RoomItem> m_Rooms = null;
+        /// <summary>
+        /// 获取根据指定bimId,获取空间信息
+        /// </summary>
+        /// <param name="siId"></param>
+        /// <returns></returns>
+        public RoomItem GetRoomItem(string siId)
+        {
+            if (m_Rooms == null)
+            {
+                m_Rooms = new Dictionary<string, RoomItem>();
+                var str = new string[] { MBIBuiltInCategory.Si };//元空间为Si
+                List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
+                foreach (var data in datas)
+                {
+                    var roomItem = MBIItemFactory.Create<RoomItem>(data);
+                    m_Rooms[roomItem.Id] = roomItem;
+                }
+            }
+
+            m_Rooms.TryGetValue(siId, out RoomItem resultItem);
+            return resultItem;
+        }
+
+        /// <summary>
+        /// 缓存空间对象
+        /// </summary>
+        private Dictionary<string, FloorItem> m_Floors = null;
+        /// <summary>
+        /// 获取根据指定bimId,获取空间信息
+        /// </summary>
+        /// <param name="floorId"></param>
+        /// <returns></returns>
+        public FloorItem GetFloorItem(string floorId)
+        {
+            if (m_Floors == null)
+            {
+                m_Floors = new Dictionary<string, FloorItem>();
+                var str = new string[] { MBIBuiltInCategory.Fl };//元空间为Si
+                List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
+                foreach (var data in datas)
+                {
+                    var floorItem = MBIItemFactory.Create<FloorItem>(data);
+                    m_Floors[floorItem.Id] = floorItem;
+                }
+            }
+
+            m_Floors.TryGetValue(floorId, out FloorItem resultItem);
+            return resultItem;
+        }
+
+        private Dictionary<string, SimpleGraph<string, string>> m_DicGraph =
+            new Dictionary<string, SimpleGraph<string, string>>();
+        public List<string> QueryRelations(string itemId, string graphId)
+        {
+            string useKey = graphId;
+            if(!m_DicGraph.TryGetValue(useKey,out SimpleGraph<string, string>  graph))
+            {
+                var tuples = RelationRequest.QueryRelations(graphId, null);
+                var tempGraph = new SimpleGraph<string, string>();
+                foreach (var tuple in tuples)
+                {
+                    tempGraph.AddVertex(new SimpleVertex<string>() {Id = tuple.Item1});
+                    tempGraph.AddVertex(new SimpleVertex<string>() { Id = tuple.Item2 });
+                    tempGraph.AddEdge(new SimpleEdge<string>(tuple.Item1, tuple.Item2));
+                }
+
+                m_DicGraph[useKey] = tempGraph;
+                graph = tempGraph;
+            }
+
+            var vertexes=graph.GetOutVertexes(itemId)??new List<SimpleVertex<string>>();
+            return vertexes.Select(v => v.Id).ToList();
+        }
+        public class SpaceInfo
+        {
+            /// <summary>
+            /// 元空间Id
+            /// </summary>
+            public string Id { get; set; }
+            /// <summary>
+            /// BimId
+            /// </summary>
+            public string BimId { get; set; }
+            /// <summary>
+            /// 楼层Id
+            /// </summary>
+            public string FloorId { get; set; }
+            /// <summary>
+            /// 楼层名称
+            /// </summary>
+            public string FloorName { get; set; }
+            /// <summary>
+            /// 本地名称
+            /// </summary>
+            public string Name { get; set; }
+
+            public static SpaceInfo Parse(RoomItem roomItem)
+            {
+                SpaceInfo info = new SpaceInfo();
+                info.Id = roomItem.Id;
+                info.FloorId = roomItem.FloorId;
+                info.Name = roomItem.GetDisplay();
+                info.BimId = roomItem.RevitId.ToString();
+                return info;
+            }
+        }
+
+        public void ExportExcel(string path, Dictionary<string, List<SpaceInfo>> dicSpaces)
+        {
+            IWorkbook book = new XSSFWorkbook(path);
+            ISheet sheet = book.GetSheet("Sheet1");
+            Dictionary<string, int> dicCoulmnIndexs = new Dictionary<string, int>();
+            Dictionary<string, int> dicRowIndexs = new Dictionary<string, int>();
+            for (int i = 0; i < 45; i++)
+            {
+                var tempValue = sheet.GetRow(6).GetCell(i).StringCellValue;
+                if (tempValue != null&& tempValue.Contains("Si"))
+                {
+                    dicCoulmnIndexs[tempValue] = i;
+                }
+            }
+            for (int i = 0; i < 30; i++)
+            {
+                var tempValue = sheet.GetRow(i).GetCell(1).StringCellValue;
+                if (tempValue != null && tempValue.Contains("F"))
+                {
+                    dicRowIndexs[tempValue] = i;
+                }
+            }
+            foreach (var dicSpace in dicSpaces)
+            {
+                var key = dicSpace.Key;
+                if (!dicCoulmnIndexs.TryGetValue(key, out int tempColumnIndex))
+                {
+                    continue;
+                }
+                var columnIndex = tempColumnIndex;
+                foreach (var spaceInfo in dicSpace.Value)
+                {
+                    if (!dicRowIndexs.TryGetValue(key, out int temprRowIndex))
+                    {
+                        continue;
+                    }
+                    var rowIndex = temprRowIndex;
+                    var cell = sheet.GetRow(rowIndex).GetCell(columnIndex);
+                    if (cell != null)
+                    {
+                        string oldValue = cell.StringCellValue??string.Empty;
+                        cell.SetCellValue(oldValue + "\r" + spaceInfo.Id);
+                    }
+                    
+                }
+            }
+            #region 写入excel
+
+            book.Close();
+            //MemoryStream ms = new MemoryStream();
+            //book.Write(ms);
+            //book = null;
+            //using (System.IO.FileStream fs = new System.IO.FileStream(path, FileMode.Open, FileAccess.Write))
+            //{
+            //    byte[] data = ms.ToArray();
+            //    fs.Write(data, 0, data.Length);
+            //    fs.Flush();
+            //}
+            //ms.Close();
+            //ms.Dispose(); 
+
+            #endregion
+        }
+    }
 }

+ 1 - 0
MBI/SAGA.GplotManage/SAGA.GplotManage.csproj

@@ -67,6 +67,7 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\Dlls\NPOI.OOXML.dll</HintPath>
     </Reference>
+    <Reference Include="NPOI.OpenXml4Net, Version=2.2.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1" />
     <Reference Include="RevitAPI, Version=16.0.0.0, Culture=neutral, processorArchitecture=AMD64">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\Dlls\R2017\RevitAPI.dll</HintPath>

+ 8 - 8
MBI/SAGA.MBI/Common/MessageManager.cs

@@ -22,14 +22,14 @@ namespace SAGA.MBI.Common
              * 本来想根据地址,映射变量动态生成。现在简化写成固定的
              */
             MessageMap map = new MessageMap();
-            map.Add(new MessageMapItem() {MessageCode = "godhand", MessageDescription = "上帝之后后台"});
-            map.Add(new MessageMapItem() { MessageCode = "ScanBuilding", MessageDescription = "扫楼后台" });
-            map.Add(new MessageMapItem() { MessageCode = "data-platform-3", MessageDescription = "数据平台" });
-            map.Add(new MessageMapItem() { MessageCode = "venders", MessageDescription = "厂商库" });
-            map.Add(new MessageMapItem() { MessageCode = "venders-dp", MessageDescription = "厂商库辅助" });
-            map.Add(new MessageMapItem() { MessageCode = "image-service", MessageDescription = "文件服务器" });
-            map.Add(new MessageMapItem() { MessageCode = ":8888/#/", MessageDescription = "前端页面" });
-            map.Add(new MessageMapItem() { MessageCode = ":8889/#/", MessageDescription = "前端页面" });
+            map.Add(new MessageMapItem() {MessageCode = "godhand", MessageDescription = "上帝之后后台",MatchType=CodeMatchType.Mistiness});
+            map.Add(new MessageMapItem() { MessageCode = "ScanBuilding", MessageDescription = "扫楼后台", MatchType = CodeMatchType.Mistiness });
+            map.Add(new MessageMapItem() { MessageCode = "data-platform-3", MessageDescription = "数据平台", MatchType = CodeMatchType.Mistiness });        
+            map.Add(new MessageMapItem() { MessageCode = "venders-dp", MessageDescription = "厂商库辅助", MatchType = CodeMatchType.Mistiness });
+            map.Add(new MessageMapItem() { MessageCode = "venders", MessageDescription = "厂商库", MatchType = CodeMatchType.Mistiness });
+            map.Add(new MessageMapItem() { MessageCode = "image-service", MessageDescription = "文件服务器", MatchType = CodeMatchType.Mistiness });
+            map.Add(new MessageMapItem() { MessageCode = ":8888/#/", MessageDescription = "前端页面", MatchType = CodeMatchType.Mistiness });
+            map.Add(new MessageMapItem() { MessageCode = ":8889/#/", MessageDescription = "前端页面", MatchType = CodeMatchType.Mistiness });
             map.Save();
         }
     }

+ 119 - 0
MBI/SAGA.MBI/RequestData/RelationRequest.cs

@@ -10,6 +10,7 @@ using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json.Linq;
 using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Extend;
 using SAGA.DotNetUtils.Http;
 using SAGA.DotNetUtils.Others;
 using SAGA.MBI.Common;
@@ -288,5 +289,123 @@ namespace SAGA.MBI.RequestData
             }
             return null;
         }
+
+        /// <summary>
+        ///查询与指定Id的关系
+        /// </summary>
+        /// <param name="itemId"></param>
+        /// <param name="graphId"></param>
+        /// <param name="relType"></param>
+        /// <returns></returns>
+        public static List<string> QueryRelations(string itemId, string graphId, string relType)
+        {
+            if (string.IsNullOrWhiteSpace(itemId))
+            {
+                throw new ArgumentNullException(nameof(itemId));
+            }
+            List<string> items = new List<string>();
+            try
+            {
+                string url = MBIConst.DataPlatformLocalHost + $"data-platform-3/relation/query?secret={MBIControl.ProjectCur.Password}&projectId={MBIControl.ProjectCur.Id}";
+
+                JObject fromObject = new JObject();
+                fromObject.Add("from_id", itemId);
+                fromObject.Add("graph_id", graphId);
+            
+                JObject toObject = new JObject();
+                toObject.Add("to_id", itemId);
+                toObject.Add("graph_id", graphId);
+
+                if (!string.IsNullOrWhiteSpace(relType))
+                {
+                    fromObject.Add("rel_type", relType);
+                    toObject.Add("rel_type", relType);
+                }
+
+                JArray array = new JArray();
+                array.Add(fromObject);
+                array.Add(toObject);
+                JObject queryObject = new JObject();
+                queryObject.Add("criterias", array);
+
+                string postData = queryObject.ToString();
+                RestClient client = new RestClient(url, HttpVerb.POST, postData);
+                string request = client.PostRequest();
+                if (request.IsRequestHasItem())
+                {
+                    JObject jObject = JObject.Parse(request);
+                    foreach (JObject jobj in jObject["Content"])
+                    {
+                        string toid = jobj.GetValueEx("to_id");
+                        if (toid != itemId)
+                        {
+                            items.Add(toid);
+                            continue;
+                        }
+                        string fromid = jobj.GetValueEx("from_id");
+                        if (fromid != itemId)
+                        {
+                            items.Add(fromid);
+                            continue;
+                        }
+                    }
+                }
+                return items;
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+            return items;
+        }
+
+        /// <summary>
+        /// 查询实例的所有关系
+        /// </summary>
+        /// <param name="graphId"></param>
+        /// <param name="relType"></param>
+        /// <returns></returns>
+        public static List<Tuple<string,string>> QueryRelations(string graphId, string relType)
+        {       
+            List<Tuple<string, string>> items =new List<Tuple<string, string>>();
+            try
+            {
+                string url = MBIConst.DataPlatformLocalHost + $"data-platform-3/relation/query?secret={MBIControl.ProjectCur.Password}&projectId={MBIControl.ProjectCur.Id}";
+
+                JObject fromObject = new JObject();
+                fromObject.Add("graph_id", graphId);
+                if (!string.IsNullOrWhiteSpace(relType))
+                {
+                    fromObject.Add("rel_type", relType);
+                }
+                JArray array = new JArray();
+                array.Add(fromObject);
+                JObject queryObject = new JObject();
+                queryObject.Add("criterias", array);
+
+                string postData = queryObject.ToString();
+                RestClient client = new RestClient(url, HttpVerb.POST, postData);
+                string request = client.PostRequest();
+                if (request.IsRequestHasItem())
+                {
+                    JObject jObject = JObject.Parse(request);
+                    foreach (JObject jobj in jObject["Content"])
+                    {
+                        string toid = jobj.GetValueEx("to_id");                   
+                        string fromid = jobj.GetValueEx("from_id");
+                        if (!string.IsNullOrWhiteSpace(toid) && !string.IsNullOrWhiteSpace(fromid))
+                        {
+                            items.Add(new Tuple<string, string>(toid, fromid));
+                        }
+                    }
+                }
+                return items;
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+            return items;
+        }
     }
 }

+ 2 - 0
MBI/SAGA.MBI/TestCommand.cs

@@ -493,4 +493,6 @@ namespace SAGA.MBI
         }
 
     }
+
+   
 }

+ 2 - 0
MBI/SAGA.Models/MBIItem/Builder/FloorItemBuilder.cs

@@ -18,6 +18,8 @@ namespace SAGA.Models
             item.Name = infos.GetValueEx(MBIBuiltInParameter.FloorName);
             item.LocalName = infos.GetValueEx(MBIBuiltInParameter.FloorLocalName);
             item.FloorMap = infos.GetValueEx(MBIBuiltInParameter.FloorMap);
+            item.FloorType = infos.GetValueEx(MBIBuiltInParameter.FloorType);
+            item.FloorSequenceID = infos.GetValueEx(MBIBuiltInParameter.FloorSequenceID);
             return item;
         }
     }

+ 5 - 0
MBI/SAGA.Models/MBIItem/Entity/FloorItem.cs

@@ -16,5 +16,10 @@ namespace SAGA.Models
         {
             get;set;
         }
+        /// <summary>
+        /// 楼层类型
+        /// </summary>
+        public string FloorType { get; set; }
+        public string FloorSequenceID { get; set; }
     }
 }

+ 4 - 0
MBI/SAGA.Models/MBIItem/MBIBuiltInCategory.cs

@@ -27,6 +27,10 @@ namespace SAGA.Models
         /// </summary>
         public static readonly string Si = "Si";
         /// <summary>
+        /// 楼层
+        /// </summary>
+        public static readonly string Fl = "Fl";
+        /// <summary>
         /// 低压开关柜
         /// </summary>
         public readonly static string TDLS = "TDLS";

+ 9 - 0
MBI/SAGA.Models/MBIItem/MBIBuiltInParameter.cs

@@ -155,6 +155,15 @@ namespace SAGA.Models
         /// 楼层底图信息点
         /// </summary>
         public readonly static string FloorMap = "FloorMap";
+        /// <summary>
+        /// 楼层顺序Id
+        /// </summary>
+        public readonly static string FloorSequenceID = "FloorSequenceID";
+        /// <summary>
+        /// 楼层类型
+        /// </summary>
+        public readonly static string FloorType = "FloorType";
+        
         #endregion
 
         #region 设备自定义