Ver Fonte

增加接口处理内容

djs há 3 semanas atrás
pai
commit
a3c045bd27

+ 1 - 1
MeterVision/Patch/AddPatchDlg.xaml

@@ -27,7 +27,7 @@
                           Margin="0,5,0,0" Padding="2"/>
 
                 <!--暂时不需要-->
-                <CheckBox x:Name="chkJudgeLastnumFlag" Content="值相等条件包含最后一位数字" Visibility="Hidden"
+                <CheckBox x:Name="chkJudgeLastnumFlag" Content="值相等条件包含最后一位数字" Visibility="Visible"
                           IsChecked="True" FontSize="14px" Foreground="#000000"  Margin="0,20,0,0" />
             </StackPanel>
         </Border>

+ 3 - 3
MeterVision/Patch/AddPatchDlg.xaml.cs

@@ -158,12 +158,12 @@ namespace MeterVision.Patch
                         var standDetail = standDetails[i];
 
                         //水表类型大于0,说明这条模板数据配置过
-                        if(standDetail.MeterType > 0)
-                        {
+                        //if(standDetail.MeterType > 0)
+                        //{
                             //有有效配置
                             validStandDetail = new TStandDetail();
                             ObjectHelper.CopyMatchingFields(standDetail, validStandDetail);
-                        }
+                        //}
                         
                         if(validStandDetail == null)
                         {

+ 16 - 4
MeterVision/Patch/UCPatchGrid.xaml

@@ -188,7 +188,8 @@
                                     <!--<TextBlock Text="{Binding FinalValue}" Foreground="{Binding FinalValueColor}" FontSize="14px" Margin="0 0 0 0" VerticalAlignment="Center" Padding="2" />-->
                                     <TextBlock Text="识别值:" Foreground="{Binding EqualFlagColor}" FontSize="13px" Padding="5 0 0 0" VerticalAlignment="Center"/>
                                     <!--<TextBlock Text="{Binding FinalValueName2}" Foreground="{Binding EqualFlagColor}" FontSize="14px" Margin="0 0 0 0" VerticalAlignment="Center" Padding="2" />-->
-                                    <TextBlock Text="{Binding FinalValue2}" Foreground="{Binding EqualFlagColor}" FontSize="14px" Margin="0 0 0 0" VerticalAlignment="Center" Padding="2" />
+                                    <!--<TextBlock Text="{Binding FinalValue2}" Foreground="{Binding EqualFlagColor}" FontSize="14px" Margin="0 0 0 0" VerticalAlignment="Center" Padding="2" />-->
+                                    <TextBlock Text="{Binding FinalValueName2}" Foreground="{Binding EqualFlagColor}" FontSize="14px" Margin="0 0 0 0" VerticalAlignment="Center" Padding="2" />
                                 </StackPanel>
 
                                 <StackPanel Orientation="Horizontal" Margin="0 5 0 0" VerticalAlignment="Center">
@@ -216,7 +217,7 @@
 
 
 
-                <DataGridTemplateColumn Header="识别结果" Width="140">
+                <DataGridTemplateColumn Header="识别结果" Width="150">
                     <DataGridTemplateColumn.CellTemplate>
                         <DataTemplate>
                             <StackPanel Visibility="{Binding ResultVisiable}" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5 0 0 0">
@@ -232,11 +233,22 @@
                                     <!-- TextBlock: 显示文本 -->
                                     <TextBlock Text="{Binding ResultType}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="13px" Foreground="White" />
                                 </Grid>
-                                
+
+                                <StackPanel Orientation="Horizontal" Visibility="Visible" Margin="0 0 0 5">
+                                    <TextBlock Text="类型:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0" />
+                                    <TextBlock Text="{Binding MeterTypeName}" FontSize="13px" Foreground="#000000" />
+                                </StackPanel>
+
                                 <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0 0 0 5">
                                     <TextBlock Text="结果:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0"/>
                                     <!--<TextBlock Text="{Binding FinalValueName}" FontSize="14px" Foreground="#000000" />-->
-                                    <TextBlock Text="{Binding FinalValue2}" FontSize="14px" Foreground="#000000" />
+                                    <TextBlock Text="{Binding FinalValueName2}" FontSize="14px" Foreground="#000000" />
+                                </StackPanel>
+
+                                <StackPanel Orientation="Horizontal" Visibility="Visible">
+                                    <TextBlock Text="精度:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0" />
+                                    <TextBlock FontSize="13px" HorizontalAlignment="Left"  Margin="0 0 0 0"
+                                           Text="{Binding LastUnitName2,Mode=OneWay}" Foreground="#000000"/>
                                 </StackPanel>
 
                                 <!--20250725 暂时不需要-->

+ 13 - 2
MeterVision/Patch/UCPatchGrid.xaml.cs

@@ -375,13 +375,24 @@ namespace MeterVision.Patch
 
                 if (string.IsNullOrWhiteSpace(standValueModel.StandValue))
                 {
-                    equalFlag = 3;
+                    equalFlag = 2;
+                }
+                else if(detailItem.MeterType == int.MaxValue || 
+                    detailItem.LastUnit == int.MaxValue || 
+                    detailItem.FinalValue == long.MaxValue)
+                {
+                    equalFlag = 2;
+                }
+                else if(detailItem.MeterType == 0 || detailItem.MeterType == 88 || detailItem.MeterType == 90)
+                {
+                    equalFlag = 2;
                 }
                 else
                 {
                     if (double.TryParse(standValueModel.StandValue, out double dStandValue))
                     {
-                        equalFlag = detailItem.GetEqualFlag(dStandValue, detailItem.FinalValue);
+                        equalFlag = detailItem.GetEqualFlag_http(dStandValue, detailItem.FinalValue);
+                            //detailItem.GetEqualFlag(dStandValue, detailItem.FinalValue);
                     }
                 }
                 

+ 1 - 1
MeterVision/Patch/UCPatchMain.xaml

@@ -186,7 +186,7 @@
                                                        TextAlignment="Left" FontSize="13px" Foreground="#666666" VerticalAlignment="Center"/>
 
                                             <!--20250725,暂时不需要-->
-                                            <CheckBox IsChecked="{Binding JudgeLastnumFlagName,Mode=OneWay}"  Visibility="Collapsed"
+                                            <CheckBox IsChecked="{Binding JudgeLastnumFlagName,Mode=OneWay}"  Visibility="Visible"
                                                       IsEnabled="False" FontSize="14px" Content="判值相等包含尾数" Foreground="#000000" VerticalAlignment="Center" Margin="0 2 0 2" />
 
                                             <StackPanel Orientation="Vertical">

+ 2 - 2
MeterVision/Properties/AssemblyInfo.cs

@@ -51,5 +51,5 @@ using System.Windows;
 // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
 // 方法是按如下所示使用“*”: :
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.0.2")]
+[assembly: AssemblyFileVersion("1.0.0.2")]

+ 11 - 1
MeterVision/RemoteApi/RecogApi.cs

@@ -47,11 +47,21 @@ namespace MeterVision.RemoteApi
     //ApiResponse中的数据对象
     public class RecognData
     {
+        //没有识别出水表类别:0
+        //数字+指针水表:1
+        //全数字水表:2
+        //全指针水表:3
+        //压力表类型: 5
+        //水表没有摆正的图片:88
+        //只要有一个数字的概率低于50%:90
+
+        public int? meter_type { get; set; }        //水表类型
         public string image { get; set; }      // base64 编码图像
         public string logs { get; set; }       // base64 编码日志
-        public double reading { get; set; }    // 数值
+        public double? reading { get; set; }    // 数值
                                                // 可扩展字段,如:
                                                // public string timestamp { get; set; }
+        public double? reading_unit { get; set; }   //读数单位
     }
 
     //调用结果对象

+ 16 - 4
MeterVision/Single/UCSingleGrid.xaml

@@ -163,18 +163,30 @@
                                     <!-- TextBlock: 显示文本 -->
                                     <TextBlock Text="{Binding ResultType}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="13px" Foreground="White" />
                                 </Grid>
+
+                                <StackPanel Orientation="Horizontal" Visibility="Visible" Margin="0 0 0 5">
+                                    <TextBlock Text="类型:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0" />
+                                    <TextBlock Text="{Binding MeterTypeName}" FontSize="13px" Foreground="#000000" />
+                                </StackPanel>
+                                
                                 <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0 0 0 5">
                                     <TextBlock Text="结果:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0"/>
-                                    <TextBlock Text="{Binding FinalValue2}" FontSize="14px" Foreground="#000000" />
+                                    <!--<TextBlock Text="{Binding FinalValue2}" FontSize="14px" Foreground="#000000" />-->
+                                    <TextBlock Text="{Binding FinalValueName2}" FontSize="14px" Foreground="#000000" />
                                 </StackPanel>
+
                                 <StackPanel Orientation="Horizontal" Margin="0 0 0 5" Visibility="Collapsed">
                                     <TextBlock Text="原始:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0" />
                                     <TextBlock Text="{Binding RawValue}" FontSize="14px" Foreground="#000000" />
                                 </StackPanel>
-                                <StackPanel Orientation="Horizontal" Visibility="Collapsed">
-                                    <TextBlock Text="类型:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0" />
-                                    <TextBlock Text="{Binding ResultMeter}" FontSize="14px" Foreground="#000000" />
+
+
+                                <StackPanel Orientation="Horizontal" Visibility="Visible">
+                                    <TextBlock Text="精度:" FontSize="13px" Foreground="#666666" Padding="5 0 0 0" />
+                                    <TextBlock FontSize="13px" HorizontalAlignment="Left"  Margin="0 0 0 0"
+                                           Text="{Binding LastUnitName2,Mode=OneWay}" Foreground="#000000"/>
                                 </StackPanel>
+
                             </StackPanel>
                         </DataTemplate>
                     </DataGridTemplateColumn.CellTemplate>

+ 8 - 2
MeterVision/db/DBPatch.cs

@@ -309,7 +309,10 @@ namespace MeterVision.db
                     equal_flag = @EqualFlag,
                     ai_ver = @AiVer,
                     debug_info = @DebugInfo,
-                    log_path = @LogPath
+                    log_path = @LogPath,
+                    memo = @Memo,
+                    meter_type = @MeterType,
+                    last_unit = @LastUnit
                 WHERE patch_detail_id = @PatchDetailId;";
 
             // 创建 SQL 参数
@@ -328,7 +331,10 @@ namespace MeterVision.db
                 new SQLiteParameter("@EqualFlag", detail.EqualFlag),
                 new SQLiteParameter("@AiVer", detail.AiVer),
                 new SQLiteParameter("@DebugInfo", detail.DebugInfo),
-                new SQLiteParameter("@LogPath", detail.LogPath)
+                new SQLiteParameter("@LogPath", detail.LogPath),
+                new SQLiteParameter("@Memo",detail.Memo),
+                new SQLiteParameter("@MeterType",detail.MeterType),
+                new SQLiteParameter("@LastUnit",detail.LastUnit)
             };
             // 执行更新操作并返回受影响的行数
             return SQLiteHelper.ExecuteNonQuery(sql, parameters) > 0;

+ 12 - 5
MeterVision/db/DBSingle.cs

@@ -48,12 +48,12 @@ namespace MeterVision.db
                 INSERT INTO t_single_detail (
                     single_detail_id, create_time, src_image, run_flag, run_time,
                     dst_image, meter_type, digit_count, pointer_count, last_unit,
-                    result_type, raw_value, final_value, ai_ver, debug_info, log_path
+                    result_type, raw_value, final_value, ai_ver, debug_info, log_path, memo
                 )
                 VALUES (
                     @SingleDetailId, @CreateTime, @SrcImage, @RunFlag, @RunTime,
                     @DstImage, @MeterType, @DigitCount, @PointerCount, @LastUnit,
-                    @ResultType, @RawValue, @FinalValue, @AiVer, @DebugInfo, @LogPath
+                    @ResultType, @RawValue, @FinalValue, @AiVer, @DebugInfo, @LogPath, @Memo
                 );
             ";
 
@@ -75,7 +75,8 @@ namespace MeterVision.db
                 new SQLiteParameter("@FinalValue", detail.FinalValue),
                 new SQLiteParameter("@AiVer", detail.AiVer),
                 new SQLiteParameter("@DebugInfo", detail.DebugInfo),
-                new SQLiteParameter("@LogPath", detail.LogPath)
+                new SQLiteParameter("@LogPath", detail.LogPath),
+                new SQLiteParameter("@Memo",detail.Memo)
             };
 
             // 执行插入操作并返回受影响的行数
@@ -138,7 +139,10 @@ namespace MeterVision.db
                     result_meter = @ResultMeter,
                     ai_ver = @AiVer,
                     debug_info = @DebugInfo,
-                    log_path = @LogPath
+                    log_path = @LogPath,
+                    memo = @Memo,
+                    meter_type = @MeterType,
+                    last_unit = @LastUnit
                 WHERE single_detail_id = @SingleDetailId;";
 
             // 创建 SQL 参数
@@ -156,7 +160,10 @@ namespace MeterVision.db
                 new SQLiteParameter("@ResultMeter", detail.ResultMeter),
                 new SQLiteParameter("@AiVer", detail.AiVer),
                 new SQLiteParameter("@DebugInfo", detail.DebugInfo),
-                new SQLiteParameter("@LogPath", detail.LogPath)
+                new SQLiteParameter("@LogPath", detail.LogPath),
+                new SQLiteParameter("@Memo",detail.Memo),
+                new SQLiteParameter("@MeterType",detail.MeterType),
+                new SQLiteParameter("@LastUnit",detail.LastUnit)
             };
 
             // 执行更新操作并返回受影响的行数

+ 261 - 57
MeterVision/db/TPatchDetail.cs

@@ -154,49 +154,132 @@ namespace MeterVision.db
             ResultType = 1;
 
             //存储图像
-            string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
-            dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
-            if (!Directory.Exists(dstImagPath))
+            if (apiResult.recognResult.data.image != null)
             {
-                Directory.CreateDirectory(dstImagPath);
+                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");
+                //SaveBigJpg(api, dstImagPath);
+                //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
+                bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
+                DstImage = blSaveImage ? dstImagPath : string.Empty;
+            }
+            else
+            {
+                DstImage = "";
             }
-            dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
-            //SaveBigJpg(api, dstImagPath);
-            //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
-            bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
 
-            DstImage = blSaveImage ? dstImagPath : string.Empty;
 
             //存储日志
-            string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
-            aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
-            if (!Directory.Exists(aiLogPath))
+            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
             {
-                Directory.CreateDirectory(aiLogPath);
+                LogPath = "";
             }
-            aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
-            bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
 
-            LogPath = blSaveLog ? aiLogPath : string.Empty;
+            if (apiResult.recognResult.data != null)
+            {
+                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;
+                }
 
-            FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
+                if (string.IsNullOrWhiteSpace(StandValue))
+                {
+                    //EqualFlag = 2;
+                    EqualFlag = 2; //无标准值可供比较(理论上不会出现这种情况)
+                }
+                else if (MeterType == int.MaxValue || LastUnit == double.MaxValue || FinalValue == long.MaxValue)
+                {
+                    EqualFlag = 2;
+                }
+                else
+                {
+                    if (MeterType == 0 || MeterType == 88 || MeterType == 90)
+                    {
+                        EqualFlag = 2;
+                    }
+                    else
+                    {
+                        if (double.TryParse(StandValue, out double dStandValue))
+                        {
+                            //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
+                            //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
+                            EqualFlag = GetEqualFlag_http(dStandValue, FinalValue);
+                        }
+                    }
+                }
+                //else
+                //{
+                //    if (double.TryParse(StandValue, out double dStandValue))
+                //    {
+                //        //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
+                //        //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
+                //        EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
+
+                //    }//if
+                //}
+            }
+            else
+            {
+                FinalValue = long.MaxValue;
+                LastUnit = double.MaxValue;
+                MeterType = int.MaxValue;
+                EqualFlag = 2;
+            }
 
-            if (string.IsNullOrWhiteSpace(StandValue))
+
+
+
+            //等于0说明调用成功,但是AI服务未识别成功
+            if (apiResult.recognResult.result == 0)
             {
-                //EqualFlag = 2;
-                EqualFlag = 3; //无标准值可供比较(理论上不会出现这种情况)
+                Memo = apiResult.recognResult.message;
             }
             else
             {
-                if (double.TryParse(StandValue, out double dStandValue))
-                {
-                    //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
-                    //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
-                    EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
-
-                }//if
+                Memo = "";
             }
+
         }
 
 
@@ -244,48 +327,119 @@ namespace MeterVision.db
             ResultType = 1;
 
             //存储图像
-            string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
-            dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
-            if (!Directory.Exists(dstImagPath))
+            if (apiResult.recognResult.data.image != null)
             {
-                Directory.CreateDirectory(dstImagPath);
+                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");
+                //SaveBigJpg(api, dstImagPath);
+                //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
+                bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
+                DstImage = blSaveImage ? dstImagPath : string.Empty;
+            }
+            else
+            {
+                DstImage = "";
             }
-            dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
-            //SaveBigJpg(api, dstImagPath);
-            //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
-            bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
 
-            DstImage = blSaveImage ? dstImagPath : string.Empty;
 
             //存储日志
-            string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
-            aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
-            if (!Directory.Exists(aiLogPath))
+            if (!string.IsNullOrEmpty(apiResult.recognResult.data.logs))
             {
-                Directory.CreateDirectory(aiLogPath);
+                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 = "";
             }
-            aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
-            bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
 
-            LogPath = blSaveLog ? aiLogPath : string.Empty;
+            if (apiResult.recognResult.data.reading != null)
+            {
+                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;
+                }
 
-            FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
 
-            if (string.IsNullOrWhiteSpace(StandValue))
-            {
-                //EqualFlag = 2;
-                EqualFlag = 3; //无标准值可供比较(理论上不会出现这种情况)
+
+                if (string.IsNullOrWhiteSpace(StandValue))
+                {
+                    //EqualFlag = 2;
+                    EqualFlag = 2; //无标准值可供比较(理论上不会出现这种情况)
+                }
+                else if (MeterType == int.MaxValue || LastUnit == double.MaxValue || FinalValue == long.MaxValue)
+                {
+                    EqualFlag = 2;
+                }
+                else
+                {
+                    if (MeterType == 0 || MeterType == 88 || MeterType == 90)
+                    {
+                        EqualFlag = 2;
+                    }
+                    else
+                    {
+                        if (double.TryParse(StandValue, out double dStandValue))
+                        {
+                            //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
+                            //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
+                            //EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
+                            EqualFlag = GetEqualFlag_http(dStandValue, FinalValue);
+                        }//if
+                    }
+                }
             }
             else
             {
-                if (double.TryParse(StandValue, out double dStandValue))
-                {
-                    //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
-                    //EqualFlag = GetEqualFlag(dStandValue, FinalValue);
-                    EqualFlag = (long)(dStandValue * 10000) == FinalValue ? 1 : 0;
+                FinalValue = long.MaxValue;
+                LastUnit = double.MaxValue;
+                MeterType = int.MaxValue;
+                EqualFlag = 2;
+            }
 
-                }//if
+            //等于0说明调用成功,但是服务并未AI识别成功
+            if(apiResult.recognResult.result == 0)
+            {
+                Memo = apiResult.recognResult.message;
+            }
+            else
+            {
+                Memo = "";
             }
         }
 
@@ -422,7 +576,6 @@ namespace MeterVision.db
             }
         }
 
-
         public int GetEqualFlag(double standValue, long finalValue)
         {
             bool isEqual = false;
@@ -433,9 +586,14 @@ namespace MeterVision.db
                 {
                     //数字+指针(只比较数字部分)
                     //获取真正数据部分的值
-                    int standValue1 = (int)(standValue / LastUnit);
+                    //int standValue1 = (int)(standValue / LastUnit);
+                    //int standValue1 = (int)((long)(standValue * 10000) / (long)(LastUnit * 10000));
+                     int standValue1 = (int)Math.Round(standValue / LastUnit);
+
                     //(int)Math.Ceiling(standValue / LastUnit);
-                    int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                    //int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                    int finalValue1 = (int)Math.Round(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+
                     //isEqual = (standValue1 == finalValue1);
 
                     //判断如果按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
@@ -466,6 +624,52 @@ namespace MeterVision.db
             return 2;
         }
 
+        public int GetEqualFlag_http(double standValue, long finalValue)
+        {
+            bool isEqual = false;
+
+            //if (MeterType == 1 || MeterType == 3)
+            //{
+                //数字+指针(只比较数字部分)
+                //获取真正数据部分的值
+                //int standValue1 = (int)(standValue / LastUnit);
+                //int standValue1 = (int)((long)(standValue * 10000) / (long)(LastUnit * 10000));
+                int standValue1 = (int)Math.Round(standValue / LastUnit);
+
+                //(int)Math.Ceiling(standValue / LastUnit);
+                //int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                int finalValue1 = (int)Math.Round(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+
+                //isEqual = (standValue1 == finalValue1);
+
+                //判断如果按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
+
+                isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
+                if (isEqual == false && JudgeLastnumFlag == 0)
+                {
+                    int standValue1_lastnum = standValue1 % 10;
+                    int finalValue1_lastnum = finalValue1 % 10;
+                    //上面的值,也就规划为数字的整数
+                    int standValue2 = standValue1 - standValue1_lastnum;
+                    int finalValue2 = finalValue1 - finalValue1_lastnum;
+                    isEqual = standValue2 == finalValue2;
+                }
+                return isEqual ? 1 : 0;
+            //}
+            //else if (MeterType == 2)
+            //{
+            //    int standValue1 = (int)standValue;
+            //    int finalValue1 = (int)(finalValue / FaConstant.CUBE_VALUE);
+
+            //    isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
+            //    return isEqual ? 1 : 0;
+            //}
+            //return 2;
+        }
+
+
 
         //恢复运行时的默认值
         public void ResetRunValue()

+ 70 - 18
MeterVision/db/TSingleDetail.cs

@@ -122,39 +122,91 @@ namespace MeterVision.db
             RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss();
 
             //存储图像
-            string dstImagPath = CfginiItem.GetConfigItem().DstImgPath;
-            dstImagPath = Path.Combine(dstImagPath, ThisApp.GetNowTime_yyyyMMdd());
-            if (!Directory.Exists(dstImagPath))
+
+            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
             {
-                Directory.CreateDirectory(dstImagPath);
+                DstImage = "";
             }
-            dstImagPath = Path.Combine(dstImagPath, Guid.NewGuid().ToString() + ".jpg");
-            //SaveBigJpg(api, dstImagPath);
-            //bool blSave = RecogApi.SaveDstJpg(apiResult.recognResult.data.image, dstImagPath);
-            bool blSaveImage = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.image, dstImagPath);
 
-            DstImage = blSaveImage ? dstImagPath : string.Empty;
 
-            //存储日志
-            string aiLogPath = CfginiItem.GetConfigItem().AiLogPath;
-            aiLogPath = Path.Combine(aiLogPath, ThisApp.GetNowTime_yyyyMMdd());
-            if (!Directory.Exists(aiLogPath))
+            //存储日志            
+            if (!string.IsNullOrEmpty(apiResult.recognResult.data.logs))
             {
-                Directory.CreateDirectory(aiLogPath);
+                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 = "";
             }
-            aiLogPath = Path.Combine(aiLogPath, Guid.NewGuid().ToString() + ".txt");
-            bool blSaveLog = RecogApi.SaveBase64ToFile(apiResult.recognResult.data.logs, aiLogPath);
 
-            LogPath = blSaveLog ? aiLogPath : string.Empty;
 
             //做一个兼容
             //借用RawValue来保存*10000后的数据
             //RawValue = (long)(apiResult.recognResult.data.reading * 10000);
 
             //FinalValue = (long)apiResult.recognResult.data.reading;
-            FinalValue = (long)(apiResult.recognResult.data.reading * 10000);
 
+            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 = "";
+            }            
+            
         }
 
         /////////////////////////////////////////////////////////

+ 103 - 22
MeterVision/model/PatchDetailItem.cs

@@ -255,11 +255,27 @@ namespace MeterVision.model
                     OnPropertyChanged(nameof(FinalValueName));
                     OnPropertyChanged(nameof(FinalValueName2));
                     OnPropertyChanged(nameof(FinalValue2));
+                    OnPropertyChanged(nameof(LastUnitName2));
                 }
             }
         }
 
-        public double FinalValue2 => (double)(FinalValue / (double)10000);
+        //public double FinalValue2 => (double)(FinalValue / (double)10000);
+
+        public string FinalValue2
+        {
+            get
+            {
+                if(FinalValue == long.MaxValue)
+                {
+                    return "";
+                }
+                else
+                {
+                    return ((double)(FinalValue / (double)10000)).ToString();
+                }
+            }
+        }
 
         public string FinalValueName
         {
@@ -278,33 +294,36 @@ namespace MeterVision.model
         {
             get
             {
-                if(MeterType == ResultMeter)
+                if(FinalValue == long.MaxValue)
                 {
-                    string valueStr = LastUnit.ToString(); //LastUnit.ToString("G17");
-                    int decimalIndex = valueStr.IndexOf('.');
-                    int decimalPlaces = 0;
-                    if (decimalIndex == -1)
+                    return "";
+                }
+                else                
+                {
+                    if (LastUnit != double.MaxValue)
                     {
-                        decimalPlaces = 0;
+                        string valueStr = LastUnit.ToString(); //LastUnit.ToString("G17");
+                        int decimalIndex = valueStr.IndexOf('.');
+                        int decimalPlaces = 0;
+                        if (decimalIndex == -1)
+                        {
+                            decimalPlaces = 0;
+                        }
+                        else
+                        {
+                            decimalPlaces = valueStr.Length - decimalIndex - 1;
+                        }
+
+                        int iValue = (int)(FinalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                        double dValue = iValue * LastUnit;
+
+                        return dValue.ToString($"F{decimalPlaces}");
                     }
                     else
                     {
-                        decimalPlaces = valueStr.Length - decimalIndex - 1;
+                        return ((double)FinalValue / FaConstant.CUBE_VALUE).ToString();
                     }
-                    //double dValue = (double)FinalValue / (FaConstant.CUBE_VALUE * LastUnit);
-                    //return dValue.ToString($"F{decimalPlaces}");
-                    //return dValue.ToString()
-                    int iValue = (int)(FinalValue / (FaConstant.CUBE_VALUE * LastUnit));
-                    double dValue = iValue * LastUnit;
-
-                    return dValue.ToString($"F{decimalPlaces}");
                 }
-                return "";
-                //if (FinalValue >= 0)
-                //{
-                //    return ((double)FinalValue / FaConstant.CUBE_VALUE).ToString();
-                //}
-                //return "";
             }
         }
 
@@ -542,6 +561,8 @@ namespace MeterVision.model
                     _lastUnit = value;
                     OnPropertyChanged(nameof(LastUnit));
                     OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
+                    OnPropertyChanged(nameof(FinalValueName2));
+                    OnPropertyChanged(nameof(LastUnitName2));
                 }
             }
         }
@@ -561,6 +582,19 @@ namespace MeterVision.model
             }
         }
 
+        public string LastUnitName2
+        {
+            get
+            {
+                if (LastUnit == double.MaxValue)
+                {
+                    return "";
+                }
+                return LastUnit.ToString();
+            }
+        }
+
+
         public int _numInUpper;
         public int NumInUpper
         {
@@ -963,6 +997,8 @@ namespace MeterVision.model
         {
             switch (MeterType)
             {
+                case 0:
+                    return "未识别出";
                 case 1:
                     return "数字+指针";
                 case 2:
@@ -973,8 +1009,21 @@ namespace MeterVision.model
                     return "LED表";
                 case 5:
                     return "压力表";
+                case 88:
+                    return "无法摆正";
+                case 90:
+                    return "概率太低";
                 default:
-                    return "";
+                    if (MeterType == int.MaxValue)
+                    {
+                        return "";
+                    }
+                    else
+                    {
+                        return "未知值";
+                    }
+                    //return "";
+                    //return "非水表";
             }
         }
 
@@ -1220,6 +1269,38 @@ namespace MeterVision.model
             return 2;
         }
 
+        public int GetEqualFlag_http(double standValue, long finalValue)
+        {
+            bool isEqual = false;
+
+            //if (MeterType == 1 || MeterType == 3)
+            //{
+            //数字+指针(只比较数字部分)
+            //获取真正数据部分的值
+            //int standValue1 = (int)(standValue / LastUnit);
+            //int standValue1 = (int)((long)(standValue * 10000) / (long)(LastUnit * 10000));
+            int standValue1 = (int)Math.Round(standValue / LastUnit);
+
+            //(int)Math.Ceiling(standValue / LastUnit);
+            //int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+            int finalValue1 = (int)Math.Round(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+
+
+            //判断如果按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
+
+            isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
+            if (isEqual == false && JudgeLastnumFlag == 0)
+            {
+                int standValue1_lastnum = standValue1 % 10;
+                int finalValue1_lastnum = finalValue1 % 10;
+                //上面的值,也就规划为数字的整数
+                int standValue2 = standValue1 - standValue1_lastnum;
+                int finalValue2 = finalValue1 - finalValue1_lastnum;
+                isEqual = standValue2 == finalValue2;
+            }
+            return isEqual ? 1 : 0;
+        }
         /////////////////////////////
     }
 }

+ 89 - 3
MeterVision/model/SingleDetailItem.cs

@@ -1,4 +1,5 @@
 using MeterVision.db;
+using MeterVision.FreeAi;
 using MeterVision.Util;
 using System;
 using System.ComponentModel;
@@ -136,6 +137,8 @@ namespace MeterVision.model
                     OnPropertyChanged(nameof(FeatureRegionName));
                     OnPropertyChanged(nameof(MeterRegionName));
                     OnPropertyChanged(nameof(NumInUpper));
+                    OnPropertyChanged(nameof(LastUnitName2));
+                    OnPropertyChanged(nameof(FinalValueName2));
                 }
             }
         }
@@ -185,6 +188,8 @@ namespace MeterVision.model
                     _lastUnit = value;
                     OnPropertyChanged(nameof(LastUnit));
                     OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
+                    OnPropertyChanged(nameof(FinalValueName2));
+                    OnPropertyChanged(nameof(LastUnitName2));
                 }
             }
         }
@@ -204,6 +209,19 @@ namespace MeterVision.model
             }
         }
 
+        public string LastUnitName2
+        {
+            get
+            {
+                if(LastUnit == double.MaxValue)
+                {
+                    return "";
+                }
+                return LastUnit.ToString();
+            }
+        }
+
+
         public int _numInUpper;
         public int NumInUpper
         {
@@ -285,12 +303,66 @@ namespace MeterVision.model
                     //}
                     OnPropertyChanged(nameof(FinalValue));
                     OnPropertyChanged(nameof(FinalValue2));
+                    OnPropertyChanged(nameof(FinalValueName2));
+                    OnPropertyChanged(nameof(LastUnitName2));
+                }
+            }
+        }
+
+        //public double FinalValue2 => (double)(FinalValue / (double)10000);
+        public string FinalValue2
+        {
+            get
+            {
+                if(FinalValue == long.MaxValue)
+                {
+                    return "";
+                }
+                else
+                {
+                    return ((double)(FinalValue / (double)10000)).ToString();
                 }
             }
         }
 
-        public double FinalValue2 => (double)(FinalValue / (double)10000);
-        
+        public string FinalValueName2
+        {
+            get
+            {
+                if (FinalValue == long.MaxValue)
+                {
+                    return "";
+                }
+                else                
+                {
+                    if (LastUnit != double.MaxValue)
+                    {
+                        string valueStr = LastUnit.ToString(); //LastUnit.ToString("G17");
+                        int decimalIndex = valueStr.IndexOf('.');
+                        int decimalPlaces = 0;
+                        if (decimalIndex == -1)
+                        {
+                            decimalPlaces = 0;
+                        }
+                        else
+                        {
+                            decimalPlaces = valueStr.Length - decimalIndex - 1;
+                        }
+
+                        int iValue = (int)(FinalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                        double dValue = iValue * LastUnit;
+
+                        return dValue.ToString($"F{decimalPlaces}");
+                    }
+                    else
+                    {
+                        return ((double)FinalValue / FaConstant.CUBE_VALUE).ToString();
+                    }
+                }               
+            }
+        }
+
+
 
         private long _completeValue;
         public long CompleteValue
@@ -567,6 +639,8 @@ namespace MeterVision.model
         {
             switch (MeterType)
             {
+                case 0:
+                    return "未识别出";
                 case 1:
                     return "数字+指针";
                 case 2:
@@ -577,9 +651,21 @@ namespace MeterVision.model
                     return "LED表";
                 case 5:
                     return "压力表";
+                case 88:
+                    return "无法摆正";
+                case 90:
+                    return "概率太低";
                 default:
+                    if(MeterType == int.MaxValue)
+                    {
+                        return "";
+                    }
+                    else
+                    {
+                        return "未知值";
+                    }
                     //return "";
-                    return "非水表";
+                    //return "非水表";
             }
         }
 

+ 2 - 1
MeterVision/model/StandValueModel.cs

@@ -36,7 +36,8 @@ namespace MeterVision.model
             SrcImage = detailItem.SrcImage;
             DstImage = detailItem.DstImage;
             StandValue = detailItem.StandValue;
-            FinalValue = ((double)detailItem.FinalValue / FaConstant.CUBE_VALUE).ToString();
+            FinalValue = detailItem.FinalValueName2;
+                //((double)detailItem.FinalValue / FaConstant.CUBE_VALUE).ToString();
         }
         //------------------------------------------------
     }

+ 32 - 0
需求/压力表.txt

@@ -0,0 +1,32 @@
+PC端压力表
+
+1.新增"reading_unit":unit   读数精度
+2.压力表类型 5
+   没有识别出表盘类别:0
+   通过旋转没有找到水表图片:88
+   只要有一个数字的概率低于50%:90
+  "result"里返回类型增加两个, 88,90属于无效图片
+图片识别正确
+return {
+            "result": 1,
+            "data": {
+                "meter_type": meter_type,  # ✅ 新增字段
+	"reading_unit":unit # ✅ 新增字段(eg.  1  0.1  0.01  0.001)
+                "reading": round(reading, 3) if reading is not None else None,
+                "image": output_image_base64,
+                "logs": logs_str
+            },
+            "message": ""
+        }
+图片识别失败
+return {
+            "result": 0,
+            "data": {
+                "meter_type": none,  # ✅ 新增字段
+	"reading_unit":None # ✅ 新增字段(eg.  1  0.1  0.01  0.001)
+                "reading": round(reading, 3) if reading is not None else None,
+                "image": output_image_base64 if 'output_image_base64' in locals() else None,
+                "logs": logs_str
+            },
+            "message": f"❌ 图像处理失败:{str(e)}"
+        }

+ 41 - 0
需求/水表(1).txt

@@ -0,0 +1,41 @@
+pc端水表:
+1."meter_type"返回值加了三个水表类别和三个其他参数:
+没有识别出水表类别:0
+数字+指针水表:1
+全数字水表:2
+全指针水表:3
+水表没有摆正的图片:88
+只要有一个数字的概率低于50%:90
+
+"meter_type"返回值是是88,90都属于无效图片
+如:
+成功识别图片:
+ return {
+            "result": 1,
+            "data": {
+                "meter_type": meter_type,  # ✅ 新增字段
+	"reading_unit":unit,  # ✅ 新增字段
+                "reading": meter_reading,
+                "out_put_image": save_path,
+                "logs": logs,
+                "metadata": {}
+            },
+            "message": "读取成功"
+        }
+识别图片失败:
+return {
+            "result": 0,
+            "data": {
+                "meter_type": None,# ✅ 新增字段
+	"reading_unit":None,  # ✅ 新增字段
+                "reading": None,
+                "out_put_image": None,
+                "logs": [],
+                "metadata": {}
+            },
+            "message": f"❌ 图像处理失败:{str(e)}"
+        }
+
+
+2.reading_unit会返回尾数单位,x1(尾数单位是1),x01(尾数单位是0.1),x001(尾数单位是0.01),x0001(尾数单位是0.001),x00001(尾数单位是0.0001)
+