DataCheckRule.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* ==============================================================================
  2. * 功能描述:数据检查规范
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/11/7 15:40:23
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text.RegularExpressions;
  11. using SAGA.DotNetUtils;
  12. using SAGA.DotNetUtils.NPOI;
  13. using ServiceRevitLib.Common;
  14. namespace ServiceRevitLib.Utils
  15. {
  16. /// <summary>
  17. /// DataCheckRule
  18. /// </summary>
  19. class DataCheckRule
  20. {
  21. public static string MCRPath = Path.Combine(AppBaseInfo.DllRunPath, @"DataCheckResource\模型检查结果输出格式-模版.xlsx");
  22. /// <summary>
  23. /// 获取设备编码检查Cateogry 列表
  24. /// </summary>
  25. /// <returns></returns>
  26. public static List<DCR_CodeCheckCategory> GetCodeCheckCategories()
  27. {
  28. var list = NPOIHelper
  29. .ConvertExcelSheetToModel<DCR_CodeCheckCategory>(MCRPath);
  30. return list;
  31. }
  32. /// <summary>
  33. /// 获取预定义的连接件类
  34. /// </summary>
  35. /// <returns></returns>
  36. public static List<DCR_Connector> GetPreDefineConnectors()
  37. {
  38. var list = NPOIHelper
  39. .ConvertExcelSheetToModel<DCR_Connector>(MCRPath);
  40. return list;
  41. }
  42. /// <summary>
  43. /// 获取可识别的管道系统名称
  44. /// </summary>
  45. /// <returns></returns>
  46. public static List<DCR_MEPSystem> GetMepSystems()
  47. {
  48. var list = NPOIHelper
  49. .ConvertExcelSheetToModel<DCR_MEPSystem>(MCRPath);
  50. return list;
  51. }
  52. /// <summary>
  53. /// 获取设备关联的系统类型
  54. /// </summary>
  55. /// <returns></returns>
  56. public static List<DCR_EquipReferSystem> GetEquipReferSystems()
  57. {
  58. var list = NPOIHelper
  59. .ConvertExcelSheetToModel<DCR_SystemReferEquip>(MCRPath);
  60. List<Tuple<string, string>> tuples = new List<Tuple<string, string>>();
  61. //将集合转化为:系统名称-设备名称
  62. list.ForEach(t => t.Equips.ForEach(tt => tuples.Add(new Tuple<string, string>(t.SystemName, tt))));
  63. //将集合转化为:设备名称-多个系统名称
  64. var newList = tuples.GroupBy(t => t.Item2).Select(tt => new DCR_EquipReferSystem()
  65. { EquipName = tt.Key, Systems = tt.Select(t => t.Item1).ToList() }).ToList();
  66. return newList;
  67. }
  68. }
  69. /// <summary>
  70. /// 参考-可识别的系统名称
  71. /// </summary>
  72. [SheetInfo(SheetName = "参考-可识别的系统名称", RowStartIndex = 0)]
  73. public class DCR_MEPSystem
  74. {
  75. [CellIndex(0)]
  76. public string Name { get; set; }
  77. }
  78. /// <summary>
  79. /// 参考-revit分类
  80. /// </summary>
  81. [SheetInfo(SheetName = "参考-revit分类", RowStartIndex = 0)]
  82. public class DCR_CodeCheckCategory
  83. {
  84. [CellIndex(0)]
  85. public string Name { get; set; }
  86. }
  87. /// <summary>
  88. /// 设备类是否有连接件
  89. /// </summary>
  90. [SheetInfo(SheetName = "参考-连接件对照表", RowStartIndex = 1)]
  91. public class DCR_Connector
  92. {
  93. [CellIndex(4)]
  94. public string Name { get; set; }
  95. [CellIndex(5)]
  96. public string Code { get; set; }
  97. [CellIndex(6)]
  98. public string PName { get; set; }
  99. [CellIndex(7)]
  100. public string PCode { get; set; }
  101. [CellIndex(8)]
  102. public string HvacConnector { get; set; }
  103. [CellIndex(9)]
  104. public string PipeConnector { get; set; }
  105. }
  106. /// <summary>
  107. /// 参考-管网与相关设备
  108. /// </summary>
  109. [SheetInfo(SheetName = "参考-管网及相关设备", RowStartIndex = 3)]
  110. public class DCR_SystemReferEquip
  111. {
  112. [CellIndex(3)]
  113. public string SystemName { get; set; }
  114. [CellIndex(4)]
  115. public string ReferEquipName { get; set; }
  116. private List<string> m_Equips;
  117. public List<string> Equips
  118. {
  119. get
  120. {
  121. if (m_Equips == null)
  122. m_Equips = ConverToList(ReferEquipName);
  123. return m_Equips;
  124. }
  125. }
  126. public List<string> ConverToList(string str)
  127. {
  128. var list = new List<string>();
  129. if (str.IsNotNullEmpty())
  130. {
  131. Regex regex = new Regex(@"^[A-Z]{4}");
  132. list = str.Split(new[] { ',', ',' })
  133. .Where(t => Regex.IsMatch(t, $"{RegexConstPattern.IsEquip}"))
  134. .Select(tt => regex.Match(tt).Value).ToList();
  135. }
  136. return list;
  137. }
  138. }
  139. /// <summary>
  140. /// 设备关联的系统
  141. /// </summary>
  142. public class DCR_EquipReferSystem
  143. {
  144. /// <summary>
  145. /// 设备名称
  146. /// </summary>
  147. public string EquipName { get; set; }
  148. /// <summary>
  149. /// 系统名称
  150. /// </summary>
  151. public List<string> Systems { get; set; }
  152. }
  153. }