QRCodeContextCheck.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 QRCodeContextCheck : DataCheckBase
  31. {
  32. public QRCodeContextCheck()
  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<MEquipFM> CacheBuildingFMs()
  52. {
  53. return MatchFMConvert.GetAllEquipFmFromScanBuilding(this.Context.BuildingId); ;
  54. }
  55. /// <summary>
  56. /// 对比信息点是否一致
  57. /// </summary>
  58. /// <returns></returns>
  59. private bool GetCheckResult()
  60. {
  61. bool result = true;
  62. string buildingId = this.Context.BuildingId;
  63. if (buildingId.IsNullOrEmptyExt())
  64. {
  65. result = false;
  66. return result;
  67. }
  68. var fms = CacheBuildingFMs();
  69. var qrcodes = QRCodeConvert.QueryQRCodeList(fms.Select(t=>t.Id).ToList());
  70. foreach (var fm in fms) {
  71. while (true)
  72. {
  73. string dutyId = fm.EquipmentId;
  74. if (dutyId.IsNullOrEmptyExt()) break;
  75. var qrcode = qrcodes.FirstOrDefault(t=>t.FmId==fm.Id);
  76. if (qrcode == null) break;
  77. var rs = GetCheckResult(fm,qrcode);
  78. if (rs == null) break;
  79. Results.Add(rs);
  80. break;
  81. }
  82. }
  83. return Results.All(t => t.IsRight);
  84. }
  85. private QRCodeContextCheckResult GetCheckResult(MEquipFM fm,MQRCode qrcode)
  86. {
  87. QRCodeContextCheckResult result = null;
  88. try
  89. {
  90. string dutyId = fm?.EquipmentId;
  91. if (dutyId == null) return result;
  92. if (qrcode == null) return result;
  93. result = new QRCodeContextCheckResult();
  94. result.QRKey = qrcode.QRKey;
  95. result.FMId = qrcode.FmId;
  96. result.DutyId = dutyId;
  97. result.ReferDutyId = qrcode.ObjectId;
  98. result.IsRight = result.DutyId == result.ReferDutyId;
  99. result.RMessage = result.IsRight ? "" : $"物理世界中资产与设备关系与资产二维码内容不一致,请更新";
  100. }
  101. catch (Exception e)
  102. {
  103. return result;
  104. }
  105. return result;
  106. }
  107. #endregion
  108. //[DataCheckProcessAspect]
  109. public override void Export()
  110. {
  111. // Check();
  112. try
  113. {
  114. IWorkbook book = DCRExport.GetWorkbook();
  115. //ISheet sheet = book.CreateSheet(Name);
  116. ISheet sheet = book.GetSheet(Name);
  117. #region 添加数据
  118. int index = 3;
  119. //添加 共检查XXX条数据,未通过检查的如下 提示
  120. IRow rowTip = sheet.CreateRow(index - 1);
  121. rowTip.AddCell(0, $"总检查{Results.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
  122. //IRow row4 = sheet.CreateRow(index);
  123. //row4.HeightInPoints = 15;
  124. //row4.AddCell(0, "楼层本地名称", DataCheckNPOIStyle.Title);
  125. //row4.AddCell(1, "文件名", DataCheckNPOIStyle.Title);
  126. //row4.AddCell(2, "文件地址", DataCheckNPOIStyle.Title);
  127. //row4.AddCell(3, "族名称", DataCheckNPOIStyle.Title);
  128. //row4.AddCell(4, "类型", DataCheckNPOIStyle.Title);
  129. //row4.AddCell(5, "ID", DataCheckNPOIStyle.Title);
  130. //row4.AddCell(6, "通过", DataCheckNPOIStyle.Title);
  131. //row4.AddCell(7, "备注(失败原因)", DataCheckNPOIStyle.Title);
  132. foreach (QRCodeContextCheckResult result in Results)
  133. {
  134. //数量过多,只显示有问题的
  135. if (result.IsRight) continue;
  136. index++;
  137. IRow rowN = sheet.CreateRow(index);
  138. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  139. int i = 0;
  140. rowN.AddCell(i++, result.QRKey, style);
  141. rowN.AddCell(i++, result.FMId, style);
  142. rowN.AddCell(i++, result.DutyId, style);
  143. rowN.AddCell(i++, result.ReferDutyId, style);
  144. string rowN4 = result.IsRight ? "通过" : "不通过";
  145. rowN.AddCell(i++, rowN4, style);
  146. rowN.AddCell(i++, result.RMessage, style);
  147. }
  148. #endregion
  149. }
  150. catch (Exception e)
  151. {
  152. MessageShowBase.Show(e);
  153. }
  154. }
  155. }
  156. }