DutyFMInfoCheck.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* ==============================================================================
  2. * 功能描述:岗位和资产信息点一致性检查
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/10/23 15:08:55
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using Autodesk.Revit.DB;
  12. using Autodesk.Revit.DB.Mechanical;
  13. using Newtonsoft.Json.Linq;
  14. using NPOI.SS.UserModel;
  15. using SAGA.DotNetUtils.Extend;
  16. using SAGA.DotNetUtils.Others;
  17. using SAGA.MBI.DataArrange;
  18. using SAGA.MBI.JsonConvert;
  19. using SAGA.MBI.Model;
  20. using SAGA.MBI.RequestData;
  21. using SAGA.MBI.Tools;
  22. using SAGA.MBI.ToolsData.CheckBase;
  23. using SAGA.MBI.ToolsData.ModeCheck;
  24. using SAGA.RevitUtils.Extends;
  25. namespace SAGA.MBI.ToolsData.DataCheck
  26. {
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. class DutyFMInfoCheck : DataCheckBase
  31. {
  32. public DutyFMInfoCheck()
  33. {
  34. Name = "资产与设备信息不一致";
  35. }
  36. [DataCheckProcessAspect]
  37. public override bool Check()
  38. {
  39. IsRight = GetCheckResult();
  40. return IsRight;
  41. }
  42. public override void Correct()
  43. {
  44. throw new NotImplementedException();
  45. }
  46. #region CheckMethod
  47. /// <summary>
  48. /// 缓存建筑下的所有岗位信息
  49. /// </summary>
  50. /// <returns></returns>
  51. private List<MRevitEquipBase> CacheBuildingDutys()
  52. {
  53. return CommonConvert.CacheEqEc(this.Context.BuildingId);
  54. }
  55. /// <summary>
  56. /// 缓存 建筑下的所有资产
  57. /// </summary>
  58. /// <returns></returns>
  59. private List<MEquipFM> CacheBuildingFMs()
  60. {
  61. return MatchFMConvert.GetAllEquipFmFromScanBuilding(this.Context.BuildingId); ;
  62. }
  63. /// <summary>
  64. /// 对比信息点是否一致
  65. /// </summary>
  66. /// <returns></returns>
  67. private bool GetCheckResult()
  68. {
  69. bool result = true;
  70. string buildingId = this.Context.BuildingId;
  71. if (buildingId.IsNullOrEmptyExt())
  72. {
  73. result = false;
  74. return result;
  75. }
  76. var dutys = CacheBuildingDutys();
  77. var fms = CacheBuildingFMs();
  78. foreach (var duty in dutys) {
  79. while (true)
  80. {
  81. string fmid = duty.FMID;
  82. if (fmid.IsNullOrEmptyExt()) break;
  83. var fm = fms.FirstOrDefault(t => t.Id == fmid);
  84. if (fm == null) break;
  85. var rs = GetCheckResult(duty,fm);
  86. if (rs == null) break;
  87. Results.Add(rs);
  88. break;
  89. }
  90. }
  91. return result;
  92. }
  93. //忽略的信息点
  94. private List<string> m_IgnoreList=new List<string>(){ "EquipID" ,"EquipName"};
  95. private DutyFMInfoCheckResult GetCheckResult(MRevitEquipBase duty, MEquipFM fm)
  96. {
  97. DutyFMInfoCheckResult result = null;
  98. try
  99. {
  100. var dutyJObject = duty.CloundJObject;
  101. var fmJson = fm.FMJson;
  102. var fmJObject = JObject.Parse(fmJson);
  103. PropertyDefineTb pdtb = PEPCodeConvert.GetPropertyDefineTb(duty.EquipClassCode);
  104. StringBuilder sb = new StringBuilder();
  105. foreach (KeyValuePair<string, JToken> pair in dutyJObject)
  106. {
  107. string key = pair.Key;
  108. //不检查的信息点
  109. if(m_IgnoreList.Contains(key))continue;
  110. string dutyValue = pair.Value.ToString();
  111. string fmValue = fmJObject.GetValueEx(key);
  112. if (dutyValue.IsNotNullEmptyExt() && fmValue.IsNotNullEmptyExt() && !dutyValue.Equals(fmValue))
  113. {
  114. var define = pdtb.PropertyDefineItems.FirstOrDefault(t => t.CodeName == key);
  115. sb.Append($"{define?.Name??key}、");
  116. }
  117. }
  118. result = new DutyFMInfoCheckResult();
  119. result.FloorName = DalProjectTree.GetFloorNameByFloorId(duty.FloorId);
  120. result.DutyId = duty.Id;
  121. result.DutyName = duty.ToString();
  122. result.BIMID = duty.BimID.GetBIMID().ToString();
  123. result.FMId = fm.Id;
  124. result.FMName = fm.ToString();
  125. result.IsRight = sb.Length == 0;
  126. result.RMessage = result.IsRight ? "" : $"值不一致的信息点有:{sb}";
  127. }
  128. catch (Exception e)
  129. {
  130. return result;
  131. }
  132. return result;
  133. }
  134. #endregion
  135. //[DataCheckProcessAspect]
  136. public override void Export()
  137. {
  138. // Check();
  139. try
  140. {
  141. IWorkbook book = DCRExport.GetWorkbook();
  142. //ISheet sheet = book.CreateSheet(Name);
  143. ISheet sheet = book.GetSheet(Name);
  144. #region 添加数据
  145. int index = 3;
  146. //添加 共检查XXX条数据,未通过检查的如下 提示
  147. IRow rowTip = sheet.CreateRow(index - 1);
  148. rowTip.AddCell(0, $"总检查{Results.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
  149. //IRow row4 = sheet.CreateRow(index);
  150. //row4.HeightInPoints = 15;
  151. //row4.AddCell(0, "楼层本地名称", DataCheckNPOIStyle.Title);
  152. //row4.AddCell(1, "文件名", DataCheckNPOIStyle.Title);
  153. //row4.AddCell(2, "文件地址", DataCheckNPOIStyle.Title);
  154. //row4.AddCell(3, "族名称", DataCheckNPOIStyle.Title);
  155. //row4.AddCell(4, "类型", DataCheckNPOIStyle.Title);
  156. //row4.AddCell(5, "ID", DataCheckNPOIStyle.Title);
  157. //row4.AddCell(6, "通过", DataCheckNPOIStyle.Title);
  158. //row4.AddCell(7, "备注(失败原因)", DataCheckNPOIStyle.Title);
  159. foreach (DutyFMInfoCheckResult result in Results)
  160. {
  161. //数量过多,只显示有问题的
  162. if (result.IsRight) continue;
  163. index++;
  164. IRow rowN = sheet.CreateRow(index);
  165. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  166. int i = 0;
  167. rowN.AddCell(i++, result.FloorName, style);
  168. rowN.AddCell(i++, result.FMId, style);
  169. rowN.AddCell(i++, result.FMName, style);
  170. rowN.AddCell(i++, result.DutyId, style);
  171. rowN.AddCell(i++, result.DutyName, style);
  172. rowN.AddCell(i++, result.BIMID, style);
  173. string rowN4 = result.IsRight ? "通过" : "不通过";
  174. rowN.AddCell(i++, rowN4, style);
  175. rowN.AddCell(i++, result.RMessage, style);
  176. }
  177. #endregion
  178. }
  179. catch (Exception e)
  180. {
  181. MessageShowBase.Show(e);
  182. }
  183. }
  184. }
  185. }