Program.cs
2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using HHECS.DAQHandle;
using HHECS.DAQHandle.Common.Utils;
using HHECS.DAQHandle.EquipmentHandle;
using System.Configuration;
using System.Diagnostics;
var warehouseCode = ConfigurationManager.AppSettings["WarehouseCode"];
if (string.IsNullOrWhiteSpace(warehouseCode))
{
SystemLog.PrintWarn("仓库编号未配置!");
return;
}
var equipmentTypes = ConfigurationManager.AppSettings["EquipmentType"].Split(',')
.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => Convert.ToInt32(x)).ToList();
if (equipmentTypes == null || equipmentTypes.Count == 0)
{
SystemLog.PrintWarn("设备类型未配置!");
return;
}
var context = DbContextFactory.CreateDbContext();
while (true)
{
try
{
var equipmentInfos = context.Equipment.Where(x => equipmentTypes.Contains(x.EquipmentTypeId)).Include(x => x.EquipmentType).ToList(x => new
{
EquipmentTypeCode = x.EquipmentType.Code,
EquipmentCode = x.Code
});
var allEquipmentDataRecords = context.EquipmentDataRecord.Where(x => equipmentInfos.Select(x => x.EquipmentCode).Contains(x.EquipmentCode) && !x.IsHandle).ToList();
var tasks = new List<Task>();
foreach (var item in equipmentInfos.GroupBy(x => x.EquipmentTypeCode))
{
tasks.Add(Task.Run(() =>
{
Stopwatch stopwatch = Stopwatch.StartNew();
IAnalysis? handle = item.Key switch
{
"A1" => new SingleSRMAnalysis(),
"B1" => new DoubleSRMAnalysis(),
"C1" => new AGVAnalysis(),
"D1" => new RobotAnalysis(),
_ => null
};
//未知类型,则跳过
if (handle is null)
{
SystemLog.PrintWarn($"未实现设备类型[{item.Key}]对应的处理方法");
return;
}
var equipmentSNs = item.Select(x => x.EquipmentCode).ToList();
var equipmentDataRecords = allEquipmentDataRecords.Where(x => equipmentInfos.Select(x => x.EquipmentCode).Contains(x.EquipmentCode)).ToList();
handle.Execute(equipmentDataRecords);
stopwatch.Stop();
SystemLog.PrintInfo($"设备类型[{item.Key}]解析完成,数量{equipmentDataRecords.Count},耗时{stopwatch.ElapsedMilliseconds}ms");
}));
}
Task.WaitAll(tasks.ToArray());
await Task.Delay(100);
Console.WriteLine($"————————————————————————————————————————————————————————");
}
catch (Exception ex)
{
SystemLog.PrintError($"程序异常:{ex.Message}");
}
}