|
|
|
@ -26,6 +26,7 @@ using TouchSocket.Core;
|
|
|
|
|
using System.Windows.Interop;
|
|
|
|
|
using static Dm.net.buffer.ByteArrayBuffer;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
{
|
|
|
|
@ -49,6 +50,8 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
private SysData sysData = SysData.Instance;
|
|
|
|
|
//暂存库存容器分发配发机构数据
|
|
|
|
|
private Institution Institution;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 参数定义
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -275,6 +278,10 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
|
|
|
|
// 初始化定时器
|
|
|
|
|
_batchTimer.Elapsed += OnBatchTimerElapsed;
|
|
|
|
|
_batchTimer.AutoReset = true;
|
|
|
|
|
_batchTimer.Start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeleteLogsLogic();
|
|
|
|
@ -284,12 +291,7 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
service.AddTouchSocketAsync(appConfig.RFIDAddress);
|
|
|
|
|
WorkModelParam = Convert.ToInt32(appConfig.workModel);
|
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000 * 10);
|
|
|
|
|
throw new Exception("test");
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -587,6 +589,17 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
sqliteHelper.DeleteRFIDList();
|
|
|
|
|
GetRfidList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region test
|
|
|
|
|
//Task.Run(() =>
|
|
|
|
|
//{
|
|
|
|
|
// for (int i = 0; i < 1000; i++)
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// RefreshLabelInfoDataGrid($"B{i}");
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -597,13 +610,21 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
No = 0;
|
|
|
|
|
labelItems.Clear();
|
|
|
|
|
LabelCountParam = 0;
|
|
|
|
|
_rfidQueue.Clear();
|
|
|
|
|
_dataGridQueue.Clear();
|
|
|
|
|
_labelResultSet.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<RfidInfo> rfidInfos = sqliteHelper.GetRFIDList();
|
|
|
|
|
if(rfidInfos != null&& rfidInfos.Count > 0)
|
|
|
|
|
// 根据 Result 字段去重
|
|
|
|
|
rfidInfos = rfidInfos.GroupBy(r => r.Result)
|
|
|
|
|
.Select(g => g.First())
|
|
|
|
|
.ToList();
|
|
|
|
|
if (rfidInfos != null&& rfidInfos.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in rfidInfos)
|
|
|
|
|
{
|
|
|
|
|
_labelResultSet.Add(item.Result);
|
|
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)(() =>
|
|
|
|
|
{
|
|
|
|
|
int no = labelItems.Count;
|
|
|
|
@ -623,10 +644,10 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载标签信息DataGrid
|
|
|
|
|
/// TCP接收到RFID信息---卡死,暂不使用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="labelInfos"></param>
|
|
|
|
|
private void RefreshLabelInfoDataGrid(string code)
|
|
|
|
|
private void RefreshLabelInfoDataGrid1(string code)
|
|
|
|
|
{
|
|
|
|
|
RfidInfo rfidInfo = new RfidInfo();
|
|
|
|
|
rfidInfo.Dbdh = _transferOrderInfo.dbdh;
|
|
|
|
@ -654,19 +675,120 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
|
|
|
|
|
LabelCountParam += 1;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 优化卡死
|
|
|
|
|
|
|
|
|
|
// 使用线程安全的队列存储待处理的数据
|
|
|
|
|
private readonly ConcurrentQueue<RfidInfo> _rfidQueue = new ConcurrentQueue<RfidInfo>();
|
|
|
|
|
private readonly ConcurrentQueue<DataGridEnt> _dataGridQueue = new ConcurrentQueue<DataGridEnt>();
|
|
|
|
|
// 使用 HashSet 提高查找效率
|
|
|
|
|
private readonly HashSet<string> _labelResultSet = new HashSet<string>();
|
|
|
|
|
|
|
|
|
|
// 批量处理数据
|
|
|
|
|
private readonly System.Timers.Timer _batchTimer = new System.Timers.Timer(2000);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// TCP接收到RFID信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="code"></param>
|
|
|
|
|
private void RefreshLabelInfoDataGrid(string code)
|
|
|
|
|
{
|
|
|
|
|
// 检查是否已存在
|
|
|
|
|
if (_labelResultSet.Contains(code))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加到 HashSet
|
|
|
|
|
_labelResultSet.Add(code);
|
|
|
|
|
// 打印消息------改,批量刷新
|
|
|
|
|
PrintMessageToListBox(code);
|
|
|
|
|
|
|
|
|
|
// 创建 RFID 信息并加入队列
|
|
|
|
|
var rfidInfo = new RfidInfo
|
|
|
|
|
{
|
|
|
|
|
Dbdh = _transferOrderInfo.dbdh,
|
|
|
|
|
Result = code,
|
|
|
|
|
RecordTime = DateTime.Now.ToString()
|
|
|
|
|
};
|
|
|
|
|
_rfidQueue.Enqueue(rfidInfo);
|
|
|
|
|
|
|
|
|
|
// 创建界面数据并加入队列
|
|
|
|
|
LabelCountParam += 1;
|
|
|
|
|
int no = labelCountParam;
|
|
|
|
|
var dataGridEnt = new DataGridEnt
|
|
|
|
|
{
|
|
|
|
|
no = no,
|
|
|
|
|
dbdh = _transferOrderInfo.dbdh,
|
|
|
|
|
result = code,
|
|
|
|
|
recordtime = DateTime.Now
|
|
|
|
|
};
|
|
|
|
|
_dataGridQueue.Enqueue(dataGridEnt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBatchTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 批量插入数据库
|
|
|
|
|
BatchInsertRfidData();
|
|
|
|
|
|
|
|
|
|
// 批量刷新界面
|
|
|
|
|
BatchRefreshUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BatchInsertRfidData()
|
|
|
|
|
{
|
|
|
|
|
// 从队列中批量取出数据
|
|
|
|
|
var batch = new List<RfidInfo>();
|
|
|
|
|
while (_rfidQueue.TryDequeue(out var rfidInfo))
|
|
|
|
|
{
|
|
|
|
|
if (workModelParam == 101)
|
|
|
|
|
batch.Add(rfidInfo);
|
|
|
|
|
if (batch.Count >= 300) // 每批最多 100 条
|
|
|
|
|
{
|
|
|
|
|
var info = BatchOpenQuery.Instance;
|
|
|
|
|
info.rqtm = code;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 批量插入数据库
|
|
|
|
|
if (batch.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
sqliteHelper.InsertRFIDList(batch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_business.upload(101, jsonChange.ModeToJson(info), "新容器入库");
|
|
|
|
|
private void BatchRefreshUI()
|
|
|
|
|
{
|
|
|
|
|
// 从队列中批量取出数据
|
|
|
|
|
var batch = new List<DataGridEnt>();
|
|
|
|
|
while (_dataGridQueue.TryDequeue(out var dataGridEnt))
|
|
|
|
|
{
|
|
|
|
|
batch.Add(dataGridEnt);
|
|
|
|
|
if (batch.Count >= 100)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量更新界面
|
|
|
|
|
if (batch.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in batch)
|
|
|
|
|
{
|
|
|
|
|
labelItems.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
LabelInfoDataGrid = new ObservableCollection<DataGridEnt>(labelItems);
|
|
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// listBox绑定日志
|
|
|
|
|
/// </summary>
|
|
|
|
|