123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- /* ==============================================================================
- * 功能描述:岗位和资产信息点一致性检查
- * 创 建 者:Garrett
- * 创建日期:2018/10/23 15:08:55
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Mechanical;
- using Newtonsoft.Json.Linq;
- using NPOI.SS.UserModel;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Others;
- using SAGA.MBI.DataArrange;
- using SAGA.MBI.JsonConvert;
- using SAGA.MBI.Model;
- using SAGA.MBI.RequestData;
- using SAGA.MBI.Tools;
- using SAGA.MBI.ToolsData.CheckBase;
- using SAGA.MBI.ToolsData.ModeCheck;
- using SAGA.RevitUtils.Extends;
- namespace SAGA.MBI.ToolsData.DataCheck
- {
- /// <summary>
- ///
- /// </summary>
- class DutyFMInfoCheck : DataCheckBase
- {
- public DutyFMInfoCheck()
- {
- Name = "资产与设备信息不一致";
- }
- [DataCheckProcessAspect]
- public override bool Check()
- {
- IsRight = GetCheckResult();
- return IsRight;
- }
- public override void Correct()
- {
- throw new NotImplementedException();
- }
- #region CheckMethod
- /// <summary>
- /// 缓存建筑下的所有岗位信息
- /// </summary>
- /// <returns></returns>
- private List<MRevitEquipBase> CacheBuildingDutys()
- {
- return CommonConvert.CacheEqEc(this.Context.BuildingId);
- }
- /// <summary>
- /// 缓存 建筑下的所有资产
- /// </summary>
- /// <returns></returns>
- private List<MEquipFM> CacheBuildingFMs()
- {
- return MatchFMConvert.GetAllEquipFmFromScanBuilding(this.Context.BuildingId); ;
- }
- /// <summary>
- /// 对比信息点是否一致
- /// </summary>
- /// <returns></returns>
- private bool GetCheckResult()
- {
- bool result = true;
- string buildingId = this.Context.BuildingId;
- if (buildingId.IsNullOrEmptyExt())
- {
- result = false;
- return result;
- }
- var dutys = CacheBuildingDutys();
- var fms = CacheBuildingFMs();
- foreach (var duty in dutys) {
- while (true)
- {
- string fmid = duty.FMID;
- if (fmid.IsNullOrEmptyExt()) break;
- var fm = fms.FirstOrDefault(t => t.Id == fmid);
- if (fm == null) break;
- var rs = GetCheckResult(duty,fm);
- if (rs == null) break;
- Results.Add(rs);
- break;
- }
- }
- return result;
- }
- //忽略的信息点
- private List<string> m_IgnoreList=new List<string>(){ "EquipID" ,"EquipName"};
- private DutyFMInfoCheckResult GetCheckResult(MRevitEquipBase duty, MEquipFM fm)
- {
- DutyFMInfoCheckResult result = null;
- try
- {
- var dutyJObject = duty.CloundJObject;
- var fmJson = fm.FMJson;
- var fmJObject = JObject.Parse(fmJson);
- PropertyDefineTb pdtb = PEPCodeConvert.GetPropertyDefineTb(duty.EquipClassCode);
- StringBuilder sb = new StringBuilder();
- foreach (KeyValuePair<string, JToken> pair in dutyJObject)
- {
- string key = pair.Key;
- //不检查的信息点
- if(m_IgnoreList.Contains(key))continue;
- string dutyValue = pair.Value.ToString();
- string fmValue = fmJObject.GetValueEx(key);
- if (dutyValue.IsNotNullEmptyExt() && fmValue.IsNotNullEmptyExt() && !dutyValue.Equals(fmValue))
- {
- var define = pdtb.PropertyDefineItems.FirstOrDefault(t => t.CodeName == key);
- sb.Append($"{define?.Name??key}、");
- }
- }
- result = new DutyFMInfoCheckResult();
- result.FloorName = DalProjectTree.GetFloorNameByFloorId(duty.FloorId);
- result.DutyId = duty.Id;
- result.DutyName = duty.ToString();
- result.BIMID = duty.BimID.GetBIMID().ToString();
- result.FMId = fm.Id;
- result.FMName = fm.ToString();
- result.IsRight = sb.Length == 0;
- result.RMessage = result.IsRight ? "" : $"值不一致的信息点有:{sb}";
- }
- catch (Exception e)
- {
- return result;
- }
- return result;
- }
- #endregion
- //[DataCheckProcessAspect]
- public override void Export()
- {
- // Check();
- try
- {
- IWorkbook book = DCRExport.GetWorkbook();
- //ISheet sheet = book.CreateSheet(Name);
- ISheet sheet = book.GetSheet(Name);
- #region 添加数据
- int index = 3;
- //添加 共检查XXX条数据,未通过检查的如下 提示
- IRow rowTip = sheet.CreateRow(index - 1);
- rowTip.AddCell(0, $"总检查{Results.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
- //IRow row4 = sheet.CreateRow(index);
- //row4.HeightInPoints = 15;
- //row4.AddCell(0, "楼层本地名称", DataCheckNPOIStyle.Title);
- //row4.AddCell(1, "文件名", DataCheckNPOIStyle.Title);
- //row4.AddCell(2, "文件地址", DataCheckNPOIStyle.Title);
- //row4.AddCell(3, "族名称", DataCheckNPOIStyle.Title);
- //row4.AddCell(4, "类型", DataCheckNPOIStyle.Title);
- //row4.AddCell(5, "ID", DataCheckNPOIStyle.Title);
- //row4.AddCell(6, "通过", DataCheckNPOIStyle.Title);
- //row4.AddCell(7, "备注(失败原因)", DataCheckNPOIStyle.Title);
- foreach (DutyFMInfoCheckResult result in Results)
- {
- //数量过多,只显示有问题的
- if (result.IsRight) continue;
- index++;
- IRow rowN = sheet.CreateRow(index);
- DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
- int i = 0;
- rowN.AddCell(i++, result.FloorName, style);
- rowN.AddCell(i++, result.FMId, style);
- rowN.AddCell(i++, result.FMName, style);
- rowN.AddCell(i++, result.DutyId, style);
- rowN.AddCell(i++, result.DutyName, style);
- rowN.AddCell(i++, result.BIMID, style);
- string rowN4 = result.IsRight ? "通过" : "不通过";
- rowN.AddCell(i++, rowN4, style);
- rowN.AddCell(i++, result.RMessage, style);
- }
- #endregion
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- }
- }
- }
|