change - 添加历史图像在线预览、合格率统计

master
wenjy 5 months ago
parent 944990ea8e
commit ccd3d6ba30

@ -4,6 +4,7 @@ using SlnMesnac.Repository.service.LogImpl;
using SlnMesnac.Repository.service.ScanLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
@ -65,7 +66,10 @@ namespace SlnMesnac.Business
{
exp = exp.And(x => x.LogLevel == logLevel);
}
result = logService.Query(exp);
var list = logService.Query(exp);
result = list.OrderByDescending(x => x.CreateTime).ToList();
}
}
}

@ -5,6 +5,7 @@ using SlnMesnac.TouchSocket;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
@ -135,7 +136,34 @@ namespace SlnMesnac.Business
{
exp = exp.And(x => x.Rfid == rfidStr);
}
result = scanLogService.Query(exp);
var list = scanLogService.Query(exp);
result = list.OrderByDescending(x => x.CreateTime).ToList();
}
/// <summary>
/// 扫描合格率计算
/// </summary>
public double TagScanPassRate()
{
Expression<Func<ScanLogModel, bool>> exp = s1 => true;
exp = exp.And(x => x.CreateTime >= DateTime.Now.Date && x.CreateTime <= DateTime.Now.AddDays(1).Date);
var tagScanList = scanLogService.Query(exp);
if (tagScanList.Count > 0)
{
var isOkList = tagScanList.Where(x => x.IsOk == "Ok").ToList();
double passRate = ((double)isOkList.Count / (double)tagScanList.Count)*100;
double result = Math.Round(passRate, 2);
return result;
}
return 0;
}
}

@ -40,6 +40,10 @@ namespace SlnMesnac.Model.domain
[SugarColumn(ColumnName = "url")]
public string Url { get; set; }
//[ExcelColumnName("ͼÏñÃû³Æ"), ExcelColumnWidth(50)]
//[SugarColumn(ColumnName = "image_name")]
//public string ImageName { get; set; }
[ExcelColumnName("½á¹û״̬"), ExcelColumnWidth(50)]
[SugarColumn(ColumnName = "is_ok")]

@ -219,7 +219,7 @@ namespace SlnMesnac.TouchSocket
Ocr = scanLog.ocr,
Url = scanLog.url,
IsOk = scanLog.isOk,
Result = scanLog.result,
Result = scanLog.result
};
ScanLogSocketAction?.Invoke(model);
@ -361,8 +361,7 @@ namespace SlnMesnac.TouchSocket
{
try
{
if(string.IsNullOrEmpty(sourceImagePath))
if (string.IsNullOrEmpty(sourceImagePath))
{
throw new ArgumentNullException("全景图像路径为空");
}
@ -381,24 +380,49 @@ namespace SlnMesnac.TouchSocket
if (!Directory.Exists(destinationFolder))
{
Directory.CreateDirectory(destinationFolder);
// 创建 ok、ng、mul 文件夹
string okFolder = Path.Combine(destinationFolder, "ok");
string ngFolder = Path.Combine(destinationFolder, "ng");
string mulFolder = Path.Combine(destinationFolder, "mul");
Directory.CreateDirectory(okFolder);
Directory.CreateDirectory(ngFolder);
Directory.CreateDirectory(mulFolder);
}
string sourceFileName = Path.GetFileName(sourceImagePath);
string extension = Path.GetExtension(sourceImagePath);
string newFileName = now.ToString("yyyyMMddHHmmss") + "-" + fileName + extension;
string newFileName = now.ToString("HHmmssfff") + "-" + fileName + extension;
destinationImagePath = Path.Combine(destinationFolder, newFileName);
string subFolder = DetermineSubFolder(fileName);
destinationImagePath = Path.Combine(destinationFolder, subFolder, newFileName);
File.Copy(sourceImagePath, destinationImagePath, true);
File.Delete(sourceImagePath);
//File.Delete(sourceImagePath);
}
catch (Exception ex)
{
throw new InvalidOperationException($"将全景图像复制到指定路径处理异常:{ex.Message}");
}
}
private string DetermineSubFolder(string fileName)
{
if (fileName.Contains("ead"))
{
return "ng";
}
else if (fileName.Contains("多条码"))
{
return "mul";
}
else
{
return "ok";
}
}
}
}

@ -37,7 +37,7 @@
<Border Grid.Row="1" BorderBrush="#EBF4FD" BorderThickness="2" CornerRadius="10" Background="#EBF4FD" Margin="10,10">
<DataGrid Grid.Row="0" ItemsSource="{Binding ScanItems}" Background="Transparent"
FontSize="18" ColumnHeaderHeight="35"
RowHeight="31" AutoGenerateColumns="False" RowHeaderWidth="0"
RowHeight="40" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0" CanUserAddRows="False" HorizontalAlignment="Center"
Foreground="#31446E" x:Name="dataGrid" Margin="0,10,0,0" >
@ -47,7 +47,17 @@
<DataGridTextColumn Binding="{Binding Rfid}" Header="RFID" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Code}" Header="ATR" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Ocr}" Header="OCR" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Url}" Header="图像路径" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Result}" Header="最终结果" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding IsOk}" Header="结果状态" Width="1*" IsReadOnly="True"/>
<DataGridTemplateColumn Header="操作" Width="1*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="查看图像" Command="{Binding DataContext.OpenImageFileCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding}" Style="{StaticResource BUTTON_AGREE}" FontSize="14" Width="80" Height="30" Background="#009999" BorderBrush="#FF36B5C1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Border>

@ -28,7 +28,7 @@
<ComboBoxItem>Info</ComboBoxItem>
<ComboBoxItem>Warn</ComboBoxItem>
<ComboBoxItem>Error</ComboBoxItem>
<ComboBoxItem>所有</ComboBoxItem>
<ComboBoxItem IsSelected="True">所有</ComboBoxItem>
</ComboBox>
<TextBlock Text="日志时间" FontSize="18" Foreground="#31446E" Margin="20,3,10,0"/>

@ -3,7 +3,9 @@ using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Win32;
using MiniExcelLibs;
using NVelocity.Util.Introspection;
using SlnMesnac.Business;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using System;
using System.Collections.Generic;
@ -40,10 +42,11 @@ namespace SlnMesnac.WPF.ViewModel
public partial class HistoryViewModel : ObservableObject
{
private TagScanBusiness tagScanBusiness;
private AppConfig _appConfig;
public HistoryViewModel()
{
tagScanBusiness = App.ServiceProvider.GetService<TagScanBusiness>();
_appConfig = App.ServiceProvider.GetService<AppConfig>();
}
public string _rfidCode;
@ -60,7 +63,7 @@ namespace SlnMesnac.WPF.ViewModel
set => SetProperty(ref _beginTime, value);
}
public DateTime _endTime = DateTime.Now;
public DateTime _endTime = DateTime.Now.AddDays(1);
public DateTime EndTime
{
get => _endTime;
@ -108,5 +111,45 @@ namespace SlnMesnac.WPF.ViewModel
MessageBox.Show($"扫描记录导出异常:{ex.Message}");
}
}
[RelayCommand]
private void OpenImageFile(ScanLogModel scanLog)
{
if (!string.IsNullOrEmpty(scanLog.Url))
{
Task.Run(() =>
{
lock (string.Empty)
{
ShowImageInPopup(scanLog.Url);
}
});
}
else
{
MessageBox.Show("无法打开全景图像,图像路径为空");
}
}
private void ShowImageInPopup(string ImagePath)
{
App.Current.Dispatcher.Invoke(() =>
{
var window = new Window
{
Title = "全景图像在线预览",
Content = new System.Windows.Controls.Image
{
Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(ImagePath))
},
Width = 800,
Height = 650,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
window.ShowDialog();
});
}
}
}

@ -51,7 +51,7 @@ namespace SlnMesnac.WPF.ViewModel
private void Init()
{
PassRate = 30;
PassRate = tagScanBusiness.TagScanPassRate();
// 初始化数据
RecogEfficiency = new SeriesCollection
@ -92,8 +92,8 @@ namespace SlnMesnac.WPF.ViewModel
/// <summary>
/// 合格率
/// </summary>
public int _passRate;
public int PassRate
public double _passRate;
public double PassRate
{
get => _passRate;
set => SetProperty(ref _passRate, value);
@ -162,11 +162,11 @@ namespace SlnMesnac.WPF.ViewModel
TagCode = info.Rfid;
ImagePath = info.Url;
string fileName = Path.GetFileName(info.Url);
info.Url = fileName;
ScanItems.Add(info);
TagAmount++;
PassRate = tagScanBusiness.TagScanPassRate();
});
};

@ -60,7 +60,7 @@ namespace SlnMesnac.WPF.ViewModel
set => SetProperty(ref _beginTime, value);
}
public DateTime _endTime = DateTime.Now;
public DateTime _endTime = DateTime.Now.AddDays(1);
public DateTime EndTime
{
get => _endTime;
@ -77,7 +77,8 @@ namespace SlnMesnac.WPF.ViewModel
[RelayCommand]
private void Query()
{
logInfoBusiness.QueryLogInfo(_logLevel.Content.ToString(), _beginTime, _endTime, out List<BaseLog> info);
string logLevel = _logLevel == null ? string.Empty : _logLevel.Content.ToString();
logInfoBusiness.QueryLogInfo(logLevel, _beginTime, _endTime, out List<BaseLog> info);
ScanItems = new ObservableCollection<BaseLog>(info);
}

Loading…
Cancel
Save