123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /* ==============================================================================
- * 功能描述:二维码中的岗位和资产信息点一致性检查
- * 创 建 者: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 QRCodeContextCheck : DataCheckBase
- {
- public QRCodeContextCheck()
- {
- 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<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 fms = CacheBuildingFMs();
- var qrcodes = QRCodeConvert.QueryQRCodeList(fms.Select(t=>t.Id).ToList());
- foreach (var fm in fms) {
- while (true)
- {
- string dutyId = fm.EquipmentId;
- if (dutyId.IsNullOrEmptyExt()) break;
- var qrcode = qrcodes.FirstOrDefault(t=>t.FmId==fm.Id);
- if (qrcode == null) break;
- var rs = GetCheckResult(fm,qrcode);
- if (rs == null) break;
- Results.Add(rs);
- break;
- }
- }
- return Results.All(t => t.IsRight);
- }
- private QRCodeContextCheckResult GetCheckResult(MEquipFM fm,MQRCode qrcode)
- {
- QRCodeContextCheckResult result = null;
- try
- {
- string dutyId = fm?.EquipmentId;
- if (dutyId == null) return result;
- if (qrcode == null) return result;
- result = new QRCodeContextCheckResult();
- result.QRKey = qrcode.QRKey;
- result.FMId = qrcode.FmId;
- result.DutyId = dutyId;
- result.ReferDutyId = qrcode.ObjectId;
- result.IsRight = result.DutyId == result.ReferDutyId;
- result.RMessage = result.IsRight ? "" : $"物理世界中资产与设备关系与资产二维码内容不一致,请更新";
- }
- 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 (QRCodeContextCheckResult 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.QRKey, style);
- rowN.AddCell(i++, result.FMId, style);
- rowN.AddCell(i++, result.DutyId, style);
- rowN.AddCell(i++, result.ReferDutyId, style);
- string rowN4 = result.IsRight ? "通过" : "不通过";
- rowN.AddCell(i++, rowN4, style);
- rowN.AddCell(i++, result.RMessage, style);
- }
- #endregion
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- }
- }
- }
|