using MeterVision.Config; using MeterVision.model; using MeterVision.RemoteApi; using MeterVision.Util; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MeterVision.db { public class TSingleDetail { public string SingleDetailId { get; set; } public string CreateTime { get; set; } public string SrcImage { get; set; } // SRC_IMAGE public int RunFlag { get; set; } // RUN_FLAG public string RunTime { get; set; } // RUN_TIME public string DstImage { get; set; } // DST_IMAGE public int MeterType { get; set; } // METER_TYPE public int DigitCount { get; set; } // DIGIT_COUNT public int PointerCount { get; set; } // POINTER_COUNT public double LastUnit { get; set; } // LAST_UNIT public int NumInUpper { get; set; } public int ResultType { get; set; } // RESULT_TYPE public long RawValue { get; set; } // STAND_VALUE public long FinalValue { get; set; } // RESULT_VALUE public long CompleteValue { get; set; } public int ResultMeter { get; set; } public string AiVer { get; set; } // AI_VER public string DebugInfo { get; set; } // DEBUG_INFO public string LogPath { get; set; } // LOG_PATH public string Memo { get; set; } public double BrightVal { get; set; } public int FlowRate { get; set; } public string MeterRegion { get; set; } public string FeatureRegion { get; set; } public double LastValue { get; set; } public string LastTime { get; set; } public string DeviceSn { get; set; } public string SampleTime { get; set; } public TSingleDetail() { SingleDetailId = string.Empty; CreateTime = string.Empty; SrcImage = string.Empty; RunFlag = 0; RunTime = string.Empty; DstImage = string.Empty; MeterType = 0; DigitCount = 0; PointerCount = 0; LastUnit = 0; ResultType = 0; RawValue = -1; FinalValue = -1; AiVer = string.Empty; DebugInfo = string.Empty; LogPath = string.Empty; Memo = string.Empty; BrightVal = 1.20; MeterRegion = string.Empty; FeatureRegion = string.Empty; LastValue = 0; LastTime = string.Empty; ResultMeter = 0; DeviceSn = ""; SampleTime = ""; CompleteValue = -1; } public TSingleDetail(SingleDetailItem singleDetail,ResultModel resultModel) { //SingleDetailId = singleDetail.SingleDetailId; //CreateTime = singleDetail.CreateTime; //SrcImage = singleDetail.SrcImage; ObjectHelper.CopyMatchingFields(singleDetail, this); RunFlag = 1; RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss(); DstImage = resultModel.DstImage; ResultMeter = resultModel.ResultMeter; ResultType = resultModel.ResultType; RawValue = (long)resultModel.RawValue; FinalValue = (long)resultModel.FinalValue; CompleteValue = (long)resultModel.CompleteValue; AiVer = resultModel.AiVer; LogPath = resultModel.LogPath; // 使用 LINQ 进行转换和条件判断,并过滤掉空字符串 //var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString()) // .Where(s => !string.IsNullOrEmpty(s)); // 使用 string.Join 将结果连接成逗号分割的字符串 //DebugInfo = string.Join(",", formattedBytes); //DebugInfo = string.Join(",", resultModel.DebugInfoBytes.Select(b => b.ToString())); // 默认是十进制 // 使用 LINQ 进行转换和条件判断 //var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString()); //DebugInfo = string.Join(",", formattedBytes); DebugInfo = ThisApp.GetDebugInfos(resultModel.DebugInfoBytes); } public TSingleDetail(SingleDetailItem singleDetail,CallApiResult apiResult) { ObjectHelper.CopyMatchingFields(singleDetail, this); RunFlag = 1; RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss(); //存储图像 if (apiResult.recognResult.data.image != null) { string dstImagPath = CfginiItem.GetConfigItem().DstImgPath; dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd()); if (!Directory.Exists(dstImagPath)) { Directory.CreateDirectory(dstImagPath); } dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg"); bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath); DstImage = blSaveImage ? dstImagPath : string.Empty; } else { DstImage = ""; } //存储日志 if (!string.IsNullOrEmpty(apiResult.recognResult.data.logs)) { string aiLogPath = CfginiItem.GetConfigItem().AiLogPath; aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd()); if (!Directory.Exists(aiLogPath)) { Directory.CreateDirectory(aiLogPath); } aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt"); bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath); LogPath = blSaveLog ? aiLogPath : string.Empty; } else { LogPath = ""; } //做一个兼容 //借用RawValue来保存*10000后的数据 //RawValue = (long)(apiResult.recognResult.data.reading * 10000); //FinalValue = (long)apiResult.recognResult.data.reading; if(apiResult.recognResult.data.reading == null) { FinalValue = long.MaxValue; } else { FinalValue = (long)(apiResult.recognResult.data.reading * 10000); } //先借用配置的字段存放识别的数据 //空的时候保存最大值 if(apiResult.recognResult.data.meter_type == null) { MeterType = int.MaxValue; } else { MeterType = (int)apiResult.recognResult.data.meter_type; } if(apiResult.recognResult.data.reading_unit == null) { LastUnit = double.MaxValue; } else { LastUnit = (double)apiResult.recognResult.data.reading_unit; } //等于0说明调用成功,当时服务并未AI识别成功 if(apiResult.recognResult.result == 0) { Memo = apiResult.recognResult.message; } else { Memo = ""; } } ///////////////////////////////////////////////////////// } }