TSingleDetail.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using MeterVision.Config;
  2. using MeterVision.model;
  3. using MeterVision.RemoteApi;
  4. using MeterVision.Util;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace MeterVision.db
  12. {
  13. public class TSingleDetail
  14. {
  15. public string SingleDetailId { get; set; }
  16. public string CreateTime { get; set; }
  17. public string SrcImage { get; set; } // SRC_IMAGE
  18. public int RunFlag { get; set; } // RUN_FLAG
  19. public string RunTime { get; set; } // RUN_TIME
  20. public string DstImage { get; set; } // DST_IMAGE
  21. public int MeterType { get; set; } // METER_TYPE
  22. public int DigitCount { get; set; } // DIGIT_COUNT
  23. public int PointerCount { get; set; } // POINTER_COUNT
  24. public double LastUnit { get; set; } // LAST_UNIT
  25. public int NumInUpper { get; set; }
  26. public int ResultType { get; set; } // RESULT_TYPE
  27. public long RawValue { get; set; } // STAND_VALUE
  28. public long FinalValue { get; set; } // RESULT_VALUE
  29. public long CompleteValue { get; set; }
  30. public int ResultMeter { get; set; }
  31. public string AiVer { get; set; } // AI_VER
  32. public string DebugInfo { get; set; } // DEBUG_INFO
  33. public string LogPath { get; set; } // LOG_PATH
  34. public string Memo { get; set; }
  35. public double BrightVal { get; set; }
  36. public int FlowRate { get; set; }
  37. public string MeterRegion { get; set; }
  38. public string FeatureRegion { get; set; }
  39. public double LastValue { get; set; }
  40. public string LastTime { get; set; }
  41. public string DeviceSn { get; set; }
  42. public string SampleTime { get; set; }
  43. public TSingleDetail()
  44. {
  45. SingleDetailId = string.Empty;
  46. CreateTime = string.Empty;
  47. SrcImage = string.Empty;
  48. RunFlag = 0;
  49. RunTime = string.Empty;
  50. DstImage = string.Empty;
  51. MeterType = 0;
  52. DigitCount = 0;
  53. PointerCount = 0;
  54. LastUnit = 0;
  55. ResultType = 0;
  56. RawValue = -1;
  57. FinalValue = -1;
  58. AiVer = string.Empty;
  59. DebugInfo = string.Empty;
  60. LogPath = string.Empty;
  61. Memo = string.Empty;
  62. BrightVal = 1.20;
  63. MeterRegion = string.Empty;
  64. FeatureRegion = string.Empty;
  65. LastValue = 0;
  66. LastTime = string.Empty;
  67. ResultMeter = 0;
  68. DeviceSn = "";
  69. SampleTime = "";
  70. CompleteValue = -1;
  71. }
  72. public TSingleDetail(SingleDetailItem singleDetail,ResultModel resultModel)
  73. {
  74. //SingleDetailId = singleDetail.SingleDetailId;
  75. //CreateTime = singleDetail.CreateTime;
  76. //SrcImage = singleDetail.SrcImage;
  77. ObjectHelper.CopyMatchingFields(singleDetail, this);
  78. RunFlag = 1;
  79. RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss();
  80. DstImage = resultModel.DstImage;
  81. ResultMeter = resultModel.ResultMeter;
  82. ResultType = resultModel.ResultType;
  83. RawValue = (long)resultModel.RawValue;
  84. FinalValue = (long)resultModel.FinalValue;
  85. CompleteValue = (long)resultModel.CompleteValue;
  86. AiVer = resultModel.AiVer;
  87. LogPath = resultModel.LogPath;
  88. // 使用 LINQ 进行转换和条件判断,并过滤掉空字符串
  89. //var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString())
  90. // .Where(s => !string.IsNullOrEmpty(s));
  91. // 使用 string.Join 将结果连接成逗号分割的字符串
  92. //DebugInfo = string.Join(",", formattedBytes);
  93. //DebugInfo = string.Join(",", resultModel.DebugInfoBytes.Select(b => b.ToString())); // 默认是十进制
  94. // 使用 LINQ 进行转换和条件判断
  95. //var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString());
  96. //DebugInfo = string.Join(",", formattedBytes);
  97. DebugInfo = ThisApp.GetDebugInfos(resultModel.DebugInfoBytes);
  98. }
  99. public TSingleDetail(SingleDetailItem singleDetail,CallApiResult apiResult)
  100. {
  101. ObjectHelper.CopyMatchingFields(singleDetail, this);
  102. RunFlag = 1;
  103. RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss();
  104. //存储图像
  105. if (apiResult.recognResult.data.image != null)
  106. {
  107. string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
  108. dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
  109. if (!Directory.Exists(dstImagPath))
  110. {
  111. Directory.CreateDirectory(dstImagPath);
  112. }
  113. dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
  114. bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
  115. DstImage = blSaveImage ? dstImagPath : string.Empty;
  116. }
  117. else
  118. {
  119. DstImage = "";
  120. }
  121. //存储日志
  122. if (!string.IsNullOrEmpty(apiResult.recognResult.data.logs))
  123. {
  124. string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
  125. aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
  126. if (!Directory.Exists(aiLogPath))
  127. {
  128. Directory.CreateDirectory(aiLogPath);
  129. }
  130. aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
  131. bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
  132. LogPath = blSaveLog ? aiLogPath : string.Empty;
  133. }
  134. else
  135. {
  136. LogPath = "";
  137. }
  138. //做一个兼容
  139. //借用RawValue来保存*10000后的数据
  140. //RawValue = (long)(apiResult.recognResult.data.reading * 10000);
  141. //FinalValue = (long)apiResult.recognResult.data.reading;
  142. if(apiResult.recognResult.data.reading == null)
  143. {
  144. FinalValue = long.MaxValue;
  145. }
  146. else
  147. {
  148. FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
  149. }
  150. //先借用配置的字段存放识别的数据
  151. //空的时候保存最大值
  152. if(apiResult.recognResult.data.meter_type == null)
  153. {
  154. MeterType = int.MaxValue;
  155. }
  156. else
  157. {
  158. MeterType = (int)apiResult.recognResult.data.meter_type;
  159. }
  160. if(apiResult.recognResult.data.reading_unit == null)
  161. {
  162. LastUnit = double.MaxValue;
  163. }
  164. else
  165. {
  166. LastUnit = (double)apiResult.recognResult.data.reading_unit;
  167. }
  168. //等于0说明调用成功,当时服务并未AI识别成功
  169. if(apiResult.recognResult.result == 0)
  170. {
  171. Memo = apiResult.recognResult.message;
  172. }
  173. else
  174. {
  175. Memo = "";
  176. }
  177. }
  178. /////////////////////////////////////////////////////////
  179. }
  180. }