123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- /*-------------------------------------------------------------------------
- * 功能描述:GplotSystemCheckManager
- * 作者:xulisong
- * 创建时间: 2019/2/28 11:43:24
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Data;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Utilities;
- using SAGA.MBI.Common;
- using SAGA.MBI.Tools;
- using SAGA.MBIAssistData;
- using SAGA.MBIAssistData.Model;
- using SAGA.RevitUtils.Extends;
- using SAGA.RevitUtils.ExtensibleStorage;
- using SAGA.RevitUtils.MEP;
- namespace SAGA.GplotRelationComputerManage.SystemChecks
- {
- public class GplotSystemCheckManager
- {
- #region 检查数据相关方法
- public static void CheckSystem(List<Document> documents, List<string> gplotTypeSystems)
- {
- if (gplotTypeSystems == null || !gplotTypeSystems.Any())
- return;
- if (documents == null || !documents.Any())
- return;
- GplotSystemCheckContext context = new GplotSystemCheckContext();
- context.Relations.AddRange(gplotTypeSystems);
- foreach (var document in documents)
- {
- var floorItem = new FloorCheckItem(document);
- floorItem.Parse(context);
- }
- #region 向数据库提交信息
- foreach (var reportItem in context.ReportItems)
- {
- SingleFactory<SystemCheckReportBll>.Instance.CreateReport(
- ModelConverterUtil.ReportFormReportItem(reportItem), reportItem.ResultItems.Select(ri => ModelConverterUtil.ResultFormResultItem(ri)).ToList());
- }
- #endregion
- }
- public static SystemCheckReportItem GetCacheCheckSystemResult(Document document, string gplotType)
- {
- /*
- * 判断数据库中是否存在;存在直接查询数据库返回;不存在的话进行检测,再返回
- */
- string floorId = document.PathName.GetFileName();
- if (string.IsNullOrWhiteSpace(floorId) || string.IsNullOrWhiteSpace(gplotType))
- {
- throw new Exception("图类型不能为null");
- }
- var exist = SingleFactory<SystemCheckReportBll>.Instance.ExistReport(floorId, gplotType);
- if (exist)
- {
- return GetReportItem(floorId, gplotType);
- }
- return CreateCheckSystemResult(document, gplotType);
- }
- public static SystemCheckReportItem CreateCheckSystemResult(Document document, string gplotType)
- {
- string floorId = document.PathName.GetFileName();
- if (string.IsNullOrWhiteSpace(floorId) || string.IsNullOrWhiteSpace(gplotType))
- {
- throw new Exception("图类型不能为null");
- }
- CheckSystem(new List<Document>() { document }, new List<string>() { gplotType });
- return GetReportItem(floorId, gplotType);
- }
- private static SystemCheckReportItem GetReportItem(string floorId, string gplotType)
- {
- var report = SingleFactory<SystemCheckReportBll>.Instance.GetCurrentReport(floorId, gplotType);
- if (report != null)
- {
- var item = ModelConverterUtil.ReportItemFormReport(report);
- var results = SingleFactory<SystemCheckResultBll>.Instance.FindResults(report.Id);
- results.ForEach(r =>
- {
- var converterItem = ModelConverterUtil.ResultItemFormResult(r);
- if (converterItem.IsMisinformation)
- {
- converterItem.ErrorCode = "004";
- }
- item.ResultItems.Add(converterItem);
- });
- return item;
- }
- return null;
- }
- #endregion
- #region 标记数据相关方法
- public static List<EquipmentCheckResultItem> GetEquipmentItems(Document document, string gplotType)
- {
- RelationTypeShell shell = new RelationTypeShell(RelationTypeManager.GetRelationTypeItem(gplotType));
- var familyInstances = document.FilterElements<FamilyInstance>().Where(fi => MBIInfoUtil.IsEquipment(fi))
- .ToList();
- HashSet<string> categorySet = new HashSet<string>();
- #region 过滤包含的category
- foreach (var familyInstance in familyInstances)
- {
- var pipes = familyInstance.GetFirstElements<MEPCurve>();
- if (pipes.Any(p => shell.IsMatchSystem(p.GetSystemTypeName())))
- {
- var currentCategory = MBIInfoUtil.GetEquipmentCategory(familyInstance);
- if (string.IsNullOrWhiteSpace(currentCategory))
- continue;
- categorySet.Add(currentCategory);
- }
- }
- #endregion
- List<EquipmentCheckResultItem> equipmentItems = new List<EquipmentCheckResultItem>();
- foreach (var category in categorySet)
- {
- EquipmentCheckResultItem item = new EquipmentCheckResultItem();
- item.GplotType = gplotType;
- item.Category = category;
- item.Name = CommonTool.GetEquipFamily(category)?.Name??category;
- item.IsSource = IsSourceEquipment(document,category,gplotType);
- equipmentItems.Add(item);
- }
- return equipmentItems;
- }
- private static string CreateEquipmentFlagKey(string category, string gplotType)
- {
- return string.Format("{0}-{1}", gplotType, category);
- }
- /// <summary>
- /// 创建设备标记
- /// </summary>
- /// <param name="document"></param>
- /// <param name="items"></param>
- public static void CreateEquipmentFlag(Document document,List<EquipmentCheckResultItem> items)
- {
- if (items == null || !items.Any())
- return;
- var sourceFlagDic = document.ProjectInformation.GetElementData<string, bool>(StorageEnum.EquipmentSource);
- if (sourceFlagDic == null)
- {
- sourceFlagDic = new Dictionary<string, bool>();
- }
- foreach (var equipmentCheckResultItem in items)
- {
- var useKey = CreateEquipmentFlagKey(equipmentCheckResultItem.Category, equipmentCheckResultItem.GplotType);
- sourceFlagDic[useKey] = equipmentCheckResultItem.IsSource;
- }
- //系统中只存储 true的值,减少存储空间
- sourceFlagDic = sourceFlagDic.Where(c => c.Value).ToDictionary(c=>c.Key,c=>c.Value);
- document.ProjectInformation.SetElementData<string, bool>(StorageEnum.EquipmentSource, sourceFlagDic);
- }
- public static bool IsSourceEquipment(Document doc,string category,
- string gplotType)
- {
- var sourceFlagDic = doc.ProjectInformation.GetElementData<string, bool>(StorageEnum.EquipmentSource);
- bool result = false;
- if (sourceFlagDic != null)
- {
- var useKey = CreateEquipmentFlagKey(category, gplotType);
- sourceFlagDic.TryGetValue(useKey, out result);
- }
- return result;
- }
- /// <summary>
- /// 判断设备是否是源
- /// </summary>
- /// <param name="familyInstance"></param>
- /// <param name="gplotType"></param>
- /// <returns></returns>
- public static bool IsSourceEquipment(FamilyInstance familyInstance,
- string gplotType)
- {
- return IsSourceEquipment(familyInstance.Document,familyInstance.GetFamily().Name,gplotType);
- }
- /// <summary>
- /// 获取指定图类型的【源】类别
- /// </summary>
- /// <param name="document"></param>
- /// <param name="gplotType"></param>
- /// <returns></returns>
- public static List<string> GetSourceCategories(Document document, string gplotType)
- {
- List<string> categories = new List<string>();
- var sourceFlagDic = document.ProjectInformation.GetElementData<string, bool>(StorageEnum.EquipmentSource);
- foreach (var keyValue in sourceFlagDic)
- {
- if (keyValue.Value)
- {
- keyValue.Key.StartsWith(gplotType);
- var arry = keyValue.Key.Split('-');
- if (arry.Length > 1)
- {
- categories.Add(arry[1].Trim());
- }
- }
- }
- return categories;
- }
- #endregion
- }
- }
|