change - 历史纪录查询、导出逻辑实现

master
wenjy 4 months ago
parent 708d6e8c45
commit eae79fb515

@ -1,8 +1,11 @@
using SlnMesnac.Model.domain; using SlnMesnac.Common;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.ScanLog;
using SlnMesnac.TouchSocket; using SlnMesnac.TouchSocket;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq.Expressions;
using System.Text; using System.Text;
#region << 版 本 注 释 >> #region << 版 本 注 释 >>
@ -32,6 +35,7 @@ namespace SlnMesnac.Business
public class TagScanBusiness public class TagScanBusiness
{ {
private ApiServer apiServer; private ApiServer apiServer;
private IScanLogService scanLogService;
public delegate void RefreshTagScanInfo(ScanLogModel scanLogModel); public delegate void RefreshTagScanInfo(ScanLogModel scanLogModel);
public event RefreshTagScanInfo? RefreshTagScanInfoEvent; public event RefreshTagScanInfo? RefreshTagScanInfoEvent;
@ -43,13 +47,17 @@ namespace SlnMesnac.Business
public event RefreshDeviceStatus? RefreshDeviceStatusEvent; public event RefreshDeviceStatus? RefreshDeviceStatusEvent;
public TagScanBusiness(ApiServer apiServer) public TagScanBusiness(ApiServer apiServer, IScanLogService scanLogService)
{ {
this.apiServer = apiServer; this.apiServer = apiServer;
this.scanLogService = scanLogService;
this.RefreshScanInfo(); this.RefreshScanInfo();
} }
/// <summary>
/// 扫描信息刷新
/// </summary>
private void RefreshScanInfo() private void RefreshScanInfo()
{ {
//扫描记录刷新 //扫描记录刷新
@ -99,6 +107,33 @@ namespace SlnMesnac.Business
}; };
} }
/// <summary>
/// 查询扫描记录
/// </summary>
/// <param name="rfidStr"></param>
/// <param name="beginTime"></param>
/// <param name="endTime"></param>
/// <param name="result"></param>
public void QuerySacnInfo(string rfidStr,DateTime beginTime,DateTime endTime,out List<ScanLogModel> result)
{
//var info = scanLogService.Query(x => x.CreateTime >= beginTime && x.CreateTime <= endTime);
Expression<Func<ScanLogModel, bool>> exp = s1 => true;
if(beginTime != null)
{
exp = exp.And(x => x.CreateTime >= beginTime);
}
if (endTime != null)
{
exp = exp.And(x => x.CreateTime <= endTime);
}
if (!string.IsNullOrEmpty(rfidStr))
{
exp = exp.And(x => x.Rfid == rfidStr);
}
result = scanLogService.Query(exp);
}
} }
} }

@ -6,6 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MiniExcel" Version="1.34.2" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.134" /> <PackageReference Include="SqlSugarCore" Version="5.1.4.134" />
</ItemGroup> </ItemGroup>

@ -1,5 +1,6 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using MiniExcelLibs.Attributes;
using SqlSugar; using SqlSugar;
namespace SlnMesnac.Model.domain namespace SlnMesnac.Model.domain
@ -11,18 +12,31 @@ namespace SlnMesnac.Model.domain
/// <summary> /// <summary>
/// ///
///</summary> ///</summary>
[ExcelColumnName("标识"), ExcelColumnWidth(15)]
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)] [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; } public int Id { get; set; }
[ExcelColumnName("扫描时间"), ExcelColumnWidth(30)]
[SugarColumn(ColumnName = "create_time")] [SugarColumn(ColumnName = "create_time")]
public DateTime CreateTime { get; set; } public DateTime CreateTime { get; set; }
[ExcelColumnName("数据类型"), ExcelColumnWidth(15)]
[SugarColumn(ColumnName = "data_type")] [SugarColumn(ColumnName = "data_type")]
public int DataType { get; set; } public int DataType { get; set; }
[ExcelColumnName("RFID条码"), ExcelColumnWidth(30)]
[SugarColumn(ColumnName = "rfid")] [SugarColumn(ColumnName = "rfid")]
public string Rfid { get; set; } public string Rfid { get; set; }
[ExcelColumnName("ATR识别"), ExcelColumnWidth(30)]
[SugarColumn(ColumnName = "code")] [SugarColumn(ColumnName = "code")]
public string Code { get; set; } public string Code { get; set; }
[ExcelColumnName("OCR识别"), ExcelColumnWidth(30)]
[SugarColumn(ColumnName = "ocr")] [SugarColumn(ColumnName = "ocr")]
public string Ocr { get; set; } public string Ocr { get; set; }
[ExcelColumnName("全景图像路径"), ExcelColumnWidth(50)]
[SugarColumn(ColumnName = "url")] [SugarColumn(ColumnName = "url")]
public string Url { get; set; } public string Url { get; set; }
} }

@ -14,7 +14,7 @@
<Border Grid.Row="0" BorderBrush="#EBF4FD" BorderThickness="2" CornerRadius="10" Background="#EBF4FD" Margin="10,10"> <Border Grid.Row="0" BorderBrush="#EBF4FD" BorderThickness="2" CornerRadius="10" Background="#EBF4FD" Margin="10,10">
<StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal"> <StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
<TextBlock Text="RFID" FontSize="18" Foreground="#31446E" Margin="10,3"/> <TextBlock Text="RFID" FontSize="18" Foreground="#31446E" Margin="10,3"/>
<TextBox Text="{Binding TagCode}" FontSize="24" Grid.Row="1" Width="180" Height="30" VerticalContentAlignment="Center" HorizontalAlignment="Center" Padding="5"> <TextBox Text="{Binding RfidCode}" FontSize="24" Grid.Row="1" Width="180" Height="30" VerticalContentAlignment="Center" HorizontalAlignment="Center" Padding="5">
<TextBox.Template> <TextBox.Template>
<ControlTemplate TargetType="TextBox"> <ControlTemplate TargetType="TextBox">
<Border Background="White" BorderBrush="White" BorderThickness="1" CornerRadius="5"> <Border Background="White" BorderBrush="White" BorderThickness="1" CornerRadius="5">
@ -25,9 +25,9 @@
</TextBox> </TextBox>
<TextBlock Text="扫描时间" FontSize="18" Foreground="#31446E" Margin="20,3,10,0"/> <TextBlock Text="扫描时间" FontSize="18" Foreground="#31446E" Margin="20,3,10,0"/>
<DatePicker x:Name="BeginTimeDatePicker" Width="120" VerticalAlignment="Center" Margin="0,0,5,0"/> <DatePicker x:Name="BeginTimeDatePicker" SelectedDate="{Binding BeginTime}" Width="120" VerticalAlignment="Center" Margin="0,0,5,0"/>
<TextBlock Text="-" FontSize="18" Foreground="#31446E" Margin="10,3"/> <TextBlock Text="-" FontSize="18" Foreground="#31446E" Margin="10,3"/>
<DatePicker x:Name="EndTimeDatePicker" Width="120" VerticalAlignment="Center" Margin="0,0,5,0"/> <DatePicker x:Name="EndTimeDatePicker" SelectedDate="{Binding EndTime}" Width="120" VerticalAlignment="Center" Margin="0,0,5,0"/>
<Button Content="查 询" Command="{Binding QueryCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#5095F3" BorderBrush="#5095F3" Margin="10,0,10,0"/> <Button Content="查 询" Command="{Binding QueryCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#5095F3" BorderBrush="#5095F3" Margin="10,0,10,0"/>
<Button Content="导 出" Command="{Binding ExportCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="0,0,10,0"/> <Button Content="导 出" Command="{Binding ExportCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="0,0,10,0"/>
@ -47,7 +47,7 @@
<DataGridTextColumn Binding="{Binding Rfid}" Header="RFID" Width="2*" IsReadOnly="True"/> <DataGridTextColumn Binding="{Binding Rfid}" Header="RFID" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Code}" Header="ATR" 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 Ocr}" Header="OCR" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding url}" Header="图像路径" Width="2*" IsReadOnly="True"/> <DataGridTextColumn Binding="{Binding Url}" Header="图像路径" Width="2*" IsReadOnly="True"/>
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
</Border> </Border>

@ -1,4 +1,5 @@
using System; using SlnMesnac.WPF.ViewModel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -23,6 +24,7 @@ namespace SlnMesnac.WPF.Page.History
public HistoryControl() public HistoryControl()
{ {
InitializeComponent(); InitializeComponent();
this.DataContext = new HistoryViewModel();
} }
} }
} }

@ -0,0 +1,112 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Win32;
using MiniExcelLibs;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* T14-GEN3-7895
* SlnMesnac.WPF.ViewModel
* 363901e3-4a2d-433c-862a-6ea822f784fb
*
* WenJY
*
* 2024-09-20 10:23:24
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel
{
public partial class HistoryViewModel : ObservableObject
{
private TagScanBusiness tagScanBusiness;
public HistoryViewModel()
{
tagScanBusiness = App.ServiceProvider.GetService<TagScanBusiness>();
}
public string _rfidCode;
public string RfidCode
{
get => _rfidCode;
set => SetProperty(ref _rfidCode, value);
}
public DateTime _beginTime = DateTime.Now;
public DateTime BeginTime
{
get => _beginTime;
set => SetProperty(ref _beginTime, value);
}
public DateTime _endTime = DateTime.Now;
public DateTime EndTime
{
get => _endTime;
set => SetProperty(ref _endTime, value);
}
private ObservableCollection<ScanLogModel> _scanItems = new ObservableCollection<ScanLogModel>();
public ObservableCollection<ScanLogModel> ScanItems
{
get => _scanItems;
set => SetProperty(ref _scanItems, value);
}
[RelayCommand]
private void Query()
{
tagScanBusiness.QuerySacnInfo(_rfidCode, _beginTime, _endTime,out List<ScanLogModel> info);
ScanItems = new ObservableCollection<ScanLogModel>(info);
}
[RelayCommand]
private void Export()
{
try
{
var info = _scanItems;
// 创建 SaveFileDialog 对象
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*";
saveFileDialog.Title = "保存文件";
saveFileDialog.FileName = $"扫描记录{DateTime.Now.Date:yyyy-MM-dd}.xlsx";
if (saveFileDialog.ShowDialog() == true)
{
string filePath = saveFileDialog.FileName;
MiniExcel.SaveAs(filePath, info);
MessageBox.Show($"扫描记录导出成功:{filePath}");
}
}
catch (Exception ex)
{
MessageBox.Show($"扫描记录导出异常:{ex.Message}");
}
}
}
}
Loading…
Cancel
Save