GplotSystemCheckManager.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:GplotSystemCheckManager
  3. * 作者:xulisong
  4. * 创建时间: 2019/2/28 11:43:24
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.DB;
  13. using SAGA.DotNetUtils;
  14. using SAGA.DotNetUtils.Data;
  15. using SAGA.DotNetUtils.Extend;
  16. using SAGA.DotNetUtils.Utilities;
  17. using SAGA.MBI.Common;
  18. using SAGA.MBI.Tools;
  19. using SAGA.MBIAssistData;
  20. using SAGA.MBIAssistData.Model;
  21. using SAGA.RevitUtils.Extends;
  22. using SAGA.RevitUtils.ExtensibleStorage;
  23. using SAGA.RevitUtils.MEP;
  24. namespace SAGA.GplotRelationComputerManage.SystemChecks
  25. {
  26. public class GplotSystemCheckManager
  27. {
  28. #region 检查数据相关方法
  29. public static void CheckSystem(List<Document> documents, List<string> gplotTypeSystems)
  30. {
  31. if (gplotTypeSystems == null || !gplotTypeSystems.Any())
  32. return;
  33. if (documents == null || !documents.Any())
  34. return;
  35. GplotSystemCheckContext context = new GplotSystemCheckContext();
  36. context.Relations.AddRange(gplotTypeSystems);
  37. foreach (var document in documents)
  38. {
  39. var floorItem = new FloorCheckItem(document);
  40. floorItem.Parse(context);
  41. }
  42. #region 向数据库提交信息
  43. foreach (var reportItem in context.ReportItems)
  44. {
  45. SingleFactory<SystemCheckReportBll>.Instance.CreateReport(
  46. ModelConverterUtil.ReportFormReportItem(reportItem), reportItem.ResultItems.Select(ri => ModelConverterUtil.ResultFormResultItem(ri)).ToList());
  47. }
  48. #endregion
  49. }
  50. public static SystemCheckReportItem GetCacheCheckSystemResult(Document document, string gplotType)
  51. {
  52. /*
  53. * 判断数据库中是否存在;存在直接查询数据库返回;不存在的话进行检测,再返回
  54. */
  55. string floorId = document.PathName.GetFileName();
  56. if (string.IsNullOrWhiteSpace(floorId) || string.IsNullOrWhiteSpace(gplotType))
  57. {
  58. throw new Exception("图类型不能为null");
  59. }
  60. var exist = SingleFactory<SystemCheckReportBll>.Instance.ExistReport(floorId, gplotType);
  61. if (exist)
  62. {
  63. return GetReportItem(floorId, gplotType);
  64. }
  65. return CreateCheckSystemResult(document, gplotType);
  66. }
  67. public static SystemCheckReportItem CreateCheckSystemResult(Document document, string gplotType)
  68. {
  69. string floorId = document.PathName.GetFileName();
  70. if (string.IsNullOrWhiteSpace(floorId) || string.IsNullOrWhiteSpace(gplotType))
  71. {
  72. throw new Exception("图类型不能为null");
  73. }
  74. CheckSystem(new List<Document>() { document }, new List<string>() { gplotType });
  75. return GetReportItem(floorId, gplotType);
  76. }
  77. private static SystemCheckReportItem GetReportItem(string floorId, string gplotType)
  78. {
  79. var report = SingleFactory<SystemCheckReportBll>.Instance.GetCurrentReport(floorId, gplotType);
  80. if (report != null)
  81. {
  82. var item = ModelConverterUtil.ReportItemFormReport(report);
  83. var results = SingleFactory<SystemCheckResultBll>.Instance.FindResults(report.Id);
  84. results.ForEach(r =>
  85. {
  86. var converterItem = ModelConverterUtil.ResultItemFormResult(r);
  87. if (converterItem.IsMisinformation)
  88. {
  89. converterItem.ErrorCode = "004";
  90. }
  91. item.ResultItems.Add(converterItem);
  92. });
  93. return item;
  94. }
  95. return null;
  96. }
  97. #endregion
  98. #region 标记数据相关方法
  99. public static List<EquipmentCheckResultItem> GetEquipmentItems(Document document, string gplotType)
  100. {
  101. RelationTypeShell shell = new RelationTypeShell(RelationTypeManager.GetRelationTypeItem(gplotType));
  102. var familyInstances = document.FilterElements<FamilyInstance>().Where(fi => MBIInfoUtil.IsEquipment(fi))
  103. .ToList();
  104. HashSet<string> categorySet = new HashSet<string>();
  105. #region 过滤包含的category
  106. foreach (var familyInstance in familyInstances)
  107. {
  108. var pipes = familyInstance.GetFirstElements<MEPCurve>();
  109. if (pipes.Any(p => shell.IsMatchSystem(p.GetSystemTypeName())))
  110. {
  111. var currentCategory = MBIInfoUtil.GetEquipmentCategory(familyInstance);
  112. if (string.IsNullOrWhiteSpace(currentCategory))
  113. continue;
  114. categorySet.Add(currentCategory);
  115. }
  116. }
  117. #endregion
  118. List<EquipmentCheckResultItem> equipmentItems = new List<EquipmentCheckResultItem>();
  119. foreach (var category in categorySet)
  120. {
  121. EquipmentCheckResultItem item = new EquipmentCheckResultItem();
  122. item.GplotType = gplotType;
  123. item.Category = category;
  124. item.Name = CommonTool.GetEquipFamily(category)?.Name??category;
  125. item.IsSource = IsSourceEquipment(document,category,gplotType);
  126. equipmentItems.Add(item);
  127. }
  128. return equipmentItems;
  129. }
  130. private static string CreateEquipmentFlagKey(string category, string gplotType)
  131. {
  132. return string.Format("{0}-{1}", gplotType, category);
  133. }
  134. /// <summary>
  135. /// 创建设备标记
  136. /// </summary>
  137. /// <param name="document"></param>
  138. /// <param name="items"></param>
  139. public static void CreateEquipmentFlag(Document document,List<EquipmentCheckResultItem> items)
  140. {
  141. if (items == null || !items.Any())
  142. return;
  143. var sourceFlagDic = document.ProjectInformation.GetElementData<string, bool>(StorageEnum.EquipmentSource);
  144. if (sourceFlagDic == null)
  145. {
  146. sourceFlagDic = new Dictionary<string, bool>();
  147. }
  148. foreach (var equipmentCheckResultItem in items)
  149. {
  150. var useKey = CreateEquipmentFlagKey(equipmentCheckResultItem.Category, equipmentCheckResultItem.GplotType);
  151. sourceFlagDic[useKey] = equipmentCheckResultItem.IsSource;
  152. }
  153. //系统中只存储 true的值,减少存储空间
  154. sourceFlagDic = sourceFlagDic.Where(c => c.Value).ToDictionary(c=>c.Key,c=>c.Value);
  155. document.ProjectInformation.SetElementData<string, bool>(StorageEnum.EquipmentSource, sourceFlagDic);
  156. }
  157. public static bool IsSourceEquipment(Document doc,string category,
  158. string gplotType)
  159. {
  160. var sourceFlagDic = doc.ProjectInformation.GetElementData<string, bool>(StorageEnum.EquipmentSource);
  161. bool result = false;
  162. if (sourceFlagDic != null)
  163. {
  164. var useKey = CreateEquipmentFlagKey(category, gplotType);
  165. sourceFlagDic.TryGetValue(useKey, out result);
  166. }
  167. return result;
  168. }
  169. /// <summary>
  170. /// 判断设备是否是源
  171. /// </summary>
  172. /// <param name="familyInstance"></param>
  173. /// <param name="gplotType"></param>
  174. /// <returns></returns>
  175. public static bool IsSourceEquipment(FamilyInstance familyInstance,
  176. string gplotType)
  177. {
  178. return IsSourceEquipment(familyInstance.Document,familyInstance.GetFamily().Name,gplotType);
  179. }
  180. /// <summary>
  181. /// 获取指定图类型的【源】类别
  182. /// </summary>
  183. /// <param name="document"></param>
  184. /// <param name="gplotType"></param>
  185. /// <returns></returns>
  186. public static List<string> GetSourceCategories(Document document, string gplotType)
  187. {
  188. List<string> categories = new List<string>();
  189. var sourceFlagDic = document.ProjectInformation.GetElementData<string, bool>(StorageEnum.EquipmentSource);
  190. foreach (var keyValue in sourceFlagDic)
  191. {
  192. if (keyValue.Value)
  193. {
  194. keyValue.Key.StartsWith(gplotType);
  195. var arry = keyValue.Key.Split('-');
  196. if (arry.Length > 1)
  197. {
  198. categories.Add(arry[1].Trim());
  199. }
  200. }
  201. }
  202. return categories;
  203. }
  204. #endregion
  205. }
  206. }