123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /* ==============================================================================
- * 功能描述:ExportAllCategory
- * 创 建 者:Garrett
- * 创建日期:2018/10/11 8:58:18
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using Microsoft.Win32;
- using NPOI.SS.UserModel;
- using NPOI.XSSF.UserModel;
- using SAGA.DotNetUtils.Logger;
- using SAGA.DotNetUtils.Others;
- using SAGA.MBI.Calc;
- using SAGA.MBI.DataArrange;
- using SAGA.MBI.Model;
- using SAGA.MBI.Tools;
- using SAGA.MBI.WinView.Upload;
- using SAGA.RevitUtils.Extends;
- using CellType = Autodesk.Revit.DB.CellType;
- using SAGA.DotNetUtils;
- using SAGA.RevitUtils;
- using SAGA.MBI.JsonConvert;
- namespace SAGA.MBI.ToolsData
- {
- /// <summary>
- /// ExportAllCategory
- /// </summary>
- class CorrectLossDuty
- {
- /// <summary>
- /// 检查并处理所有楼层
- /// </summary>
- public static void OperateAll()
- {
- var floors = DalUploadFloor.GetHasFileFloors();
- foreach (UploadFloor floor in floors)
- {
- Operate(floor.MFloor);
- }
- }
- /// <summary>
- /// 只处理当前楼层
- /// </summary>
- public static void OperateCurFloor()
- {
- MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
- if (floor != null)
- Operate(floor);
- }
- /// <summary>
- /// 检查并处理
- /// </summary>
- /// <param name="floor"></param>
- /// <returns></returns>
- private static void Operate(MFloor floor)
- {
- var tuple = GetCheckResult(floor);
- //分组
- var beaddContext = tuple.Item1;
- var bedelContext = tuple.Item2;
- RebuildCloudData(bedelContext, beaddContext);
- ////参照扫楼数据库BIMID数据,更新岗位和资产关系
- //var equipments = DalCommon.DownLoadCouldData(floor).MEquipments;
- //var buildingId = DalProjectTree.GetBuildingIdByFloor(floor.Id);
- //var m_AllEquipFms = MatchFMConvert.GetAllEquipFmFromScanBuilding(buildingId);
- //foreach (MEquipFM fm in m_AllEquipFms)
- //{
- // string bimid = fm.BimID;
- // if (bimid.IsOnlyDutyNoModelBIMID()) continue;
- // var duty = equipments.FirstOrDefault(t => t.BimID == bimid);
- // if (duty == null) continue;
- // MatchFMConvert.CreateRelationFMWithId(duty, fm);
- //}
- }
- /// <summary>
- /// 获取需要增加或删除的内容
- /// Item1增加,Item2删除
- /// </summary>
- /// <param name="floor"></param>
- /// <returns></returns>
- public static Tuple<CalcContext, CalcContext>
- GetCheckResult(MFloor floor)
- {
- Log4Net.Debug("start");
- var oldContext = DalCommon.DownLoadFloorDataByBIMFloorInfo(floor);
- Log4Net.Debug("download");
- var newContext = ObjectCalc.Calc_Simple(floor);
- Log4Net.Debug("calc");
- //分组
- var beaddContext = DalModeFileManange.GetAddContext(oldContext, newContext, true);
- Log4Net.Debug("addcontext");
- var bedelContext = (DalModeFileManange.GetDelContext(oldContext, newContext, true));
- Log4Net.Debug("delcontext");
- RemoveNoBimIdDuty(bedelContext);
- return new Tuple<CalcContext, CalcContext>(beaddContext, bedelContext);
- }
- /// <summary>
- /// 重建物理世界有问题的数据
- /// </summary>
- /// <param name="delcontext"></param>
- /// <param name="addContext"></param>
- private static void RebuildCloudData(CalcContext delcontext, CalcContext addContext)
- {
- delcontext.SetState(DocumentChangedOperator.Delete);
- delcontext.Upload();
- addContext.SetState(DocumentChangedOperator.Add);
- addContext.Upload();
- //var tip =
- // $"{addContext.MEquipments} 个设备受到影响;{string.Join(addContext.MEquipments.Select(t => t.BimID).ToArray())}";
- //Log4Net.Debug(tip);
- }
- public static bool Upload(CalcContext context)
- {
- bool result = true;
- Log4Net.Debug("更新楼层数据开始");
- try
- {
- //修改设备
- DalEquip.BatchUpdate(context.MEquipments);
- //修改部件
- DalCommon.BatchUpdate(context.MEquipmentParts);
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- result = false;
- }
- Log4Net.Debug("更新楼层数据结束");
- return result;
- }
- /// <summary>
- /// 根据用户选择,进行删除,或者清除BimId的保留
- /// </summary>
- /// <returns></returns>
- public static bool Del(CalcContext context)
- {
- bool result = true;
- try
- {
- //修改空间
- context.MSpaces.ToList().ForEach(t => t.DelOrClearBIMIDSave());
- //修改设备
- context.MEquipments.ToList().ForEach(t => t.DelOrClearBIMIDSave());
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- result = false;
- }
- return result;
- }
- public static void RemoveNoBimIdDuty(CalcContext context)
- {
- var nobimdutyEquips = context.MEquipments.Where(t => t.BimID.IsOnlyDutyNoModelBIMID()).ToList();
- foreach (var equip in nobimdutyEquips)
- {
- context.MEquipments.Remove(equip);
- }
- var nobimdutyParts = context.MEquipmentParts.Where(t => t.BimID.IsOnlyDutyNoModelBIMID()).ToList();
- foreach (var equip in nobimdutyParts)
- {
- context.MEquipmentParts.Remove(equip);
- }
- var nobimdutyBeacons = context.MBeacons.Where(t => t.BimID.IsOnlyDutyNoModelBIMID()).ToList();
- foreach (var equip in nobimdutyBeacons)
- {
- context.MBeacons.Remove(equip);
- }
- }
- }
- }
|