CorrectLossDuty.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* ==============================================================================
  2. * 功能描述:ExportAllCategory
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/10/11 8:58:18
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Autodesk.Revit.DB;
  14. using Microsoft.Win32;
  15. using NPOI.SS.UserModel;
  16. using NPOI.XSSF.UserModel;
  17. using SAGA.DotNetUtils.Logger;
  18. using SAGA.DotNetUtils.Others;
  19. using SAGA.MBI.Calc;
  20. using SAGA.MBI.DataArrange;
  21. using SAGA.MBI.Model;
  22. using SAGA.MBI.Tools;
  23. using SAGA.MBI.WinView.Upload;
  24. using SAGA.RevitUtils.Extends;
  25. using CellType = Autodesk.Revit.DB.CellType;
  26. using SAGA.DotNetUtils;
  27. using SAGA.RevitUtils;
  28. using SAGA.MBI.JsonConvert;
  29. namespace SAGA.MBI.ToolsData
  30. {
  31. /// <summary>
  32. /// ExportAllCategory
  33. /// </summary>
  34. class CorrectLossDuty
  35. {
  36. /// <summary>
  37. /// 检查并处理所有楼层
  38. /// </summary>
  39. public static void OperateAll()
  40. {
  41. var floors = DalUploadFloor.GetHasFileFloors();
  42. foreach (UploadFloor floor in floors)
  43. {
  44. Operate(floor.MFloor);
  45. }
  46. }
  47. /// <summary>
  48. /// 只处理当前楼层
  49. /// </summary>
  50. public static void OperateCurFloor()
  51. {
  52. MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
  53. if (floor != null)
  54. Operate(floor);
  55. }
  56. /// <summary>
  57. /// 检查并处理
  58. /// </summary>
  59. /// <param name="floor"></param>
  60. /// <returns></returns>
  61. private static void Operate(MFloor floor)
  62. {
  63. var tuple = GetCheckResult(floor);
  64. //分组
  65. var beaddContext = tuple.Item1;
  66. var bedelContext = tuple.Item2;
  67. RebuildCloudData(bedelContext, beaddContext);
  68. ////参照扫楼数据库BIMID数据,更新岗位和资产关系
  69. //var equipments = DalCommon.DownLoadCouldData(floor).MEquipments;
  70. //var buildingId = DalProjectTree.GetBuildingIdByFloor(floor.Id);
  71. //var m_AllEquipFms = MatchFMConvert.GetAllEquipFmFromScanBuilding(buildingId);
  72. //foreach (MEquipFM fm in m_AllEquipFms)
  73. //{
  74. // string bimid = fm.BimID;
  75. // if (bimid.IsOnlyDutyNoModelBIMID()) continue;
  76. // var duty = equipments.FirstOrDefault(t => t.BimID == bimid);
  77. // if (duty == null) continue;
  78. // MatchFMConvert.CreateRelationFMWithId(duty, fm);
  79. //}
  80. }
  81. /// <summary>
  82. /// 获取需要增加或删除的内容
  83. /// Item1增加,Item2删除
  84. /// </summary>
  85. /// <param name="floor"></param>
  86. /// <returns></returns>
  87. public static Tuple<CalcContext, CalcContext>
  88. GetCheckResult(MFloor floor)
  89. {
  90. Log4Net.Debug("start");
  91. var oldContext = DalCommon.DownLoadFloorDataByBIMFloorInfo(floor);
  92. Log4Net.Debug("download");
  93. var newContext = ObjectCalc.Calc_Simple(floor);
  94. Log4Net.Debug("calc");
  95. //分组
  96. var beaddContext = DalModeFileManange.GetAddContext(oldContext, newContext, true);
  97. Log4Net.Debug("addcontext");
  98. var bedelContext = (DalModeFileManange.GetDelContext(oldContext, newContext, true));
  99. Log4Net.Debug("delcontext");
  100. RemoveNoBimIdDuty(bedelContext);
  101. return new Tuple<CalcContext, CalcContext>(beaddContext, bedelContext);
  102. }
  103. /// <summary>
  104. /// 重建物理世界有问题的数据
  105. /// </summary>
  106. /// <param name="delcontext"></param>
  107. /// <param name="addContext"></param>
  108. private static void RebuildCloudData(CalcContext delcontext, CalcContext addContext)
  109. {
  110. delcontext.SetState(DocumentChangedOperator.Delete);
  111. delcontext.Upload();
  112. addContext.SetState(DocumentChangedOperator.Add);
  113. addContext.Upload();
  114. //var tip =
  115. // $"{addContext.MEquipments} 个设备受到影响;{string.Join(addContext.MEquipments.Select(t => t.BimID).ToArray())}";
  116. //Log4Net.Debug(tip);
  117. }
  118. public static bool Upload(CalcContext context)
  119. {
  120. bool result = true;
  121. Log4Net.Debug("更新楼层数据开始");
  122. try
  123. {
  124. //修改设备
  125. DalEquip.BatchUpdate(context.MEquipments);
  126. //修改部件
  127. DalCommon.BatchUpdate(context.MEquipmentParts);
  128. }
  129. catch (Exception e)
  130. {
  131. MessageShow.Show(e);
  132. result = false;
  133. }
  134. Log4Net.Debug("更新楼层数据结束");
  135. return result;
  136. }
  137. /// <summary>
  138. /// 根据用户选择,进行删除,或者清除BimId的保留
  139. /// </summary>
  140. /// <returns></returns>
  141. public static bool Del(CalcContext context)
  142. {
  143. bool result = true;
  144. try
  145. {
  146. //修改空间
  147. context.MSpaces.ToList().ForEach(t => t.DelOrClearBIMIDSave());
  148. //修改设备
  149. context.MEquipments.ToList().ForEach(t => t.DelOrClearBIMIDSave());
  150. }
  151. catch (Exception e)
  152. {
  153. MessageShow.Show(e);
  154. result = false;
  155. }
  156. return result;
  157. }
  158. public static void RemoveNoBimIdDuty(CalcContext context)
  159. {
  160. var nobimdutyEquips = context.MEquipments.Where(t => t.BimID.IsOnlyDutyNoModelBIMID()).ToList();
  161. foreach (var equip in nobimdutyEquips)
  162. {
  163. context.MEquipments.Remove(equip);
  164. }
  165. var nobimdutyParts = context.MEquipmentParts.Where(t => t.BimID.IsOnlyDutyNoModelBIMID()).ToList();
  166. foreach (var equip in nobimdutyParts)
  167. {
  168. context.MEquipmentParts.Remove(equip);
  169. }
  170. var nobimdutyBeacons = context.MBeacons.Where(t => t.BimID.IsOnlyDutyNoModelBIMID()).ToList();
  171. foreach (var equip in nobimdutyBeacons)
  172. {
  173. context.MBeacons.Remove(equip);
  174. }
  175. }
  176. }
  177. }