唐召明
authored
|
1
|
using HHECS.DAQHandle.Common.Enums;
|
唐召明
authored
|
2
|
using HHECS.DAQHandle.Common.Utils;
|
唐召明
authored
|
3
|
using HHECS.DAQHandle.DataAccess;
|
唐召明
authored
|
4
|
using HHECS.DAQHandle.EquipmentHandle;
|
唐召明
authored
|
5
|
using HHECS.EquipmentModel;
|
唐召明
authored
|
6
7
8
|
using System.Configuration;
using System.Diagnostics;
|
唐召明
authored
|
9
|
internal class Program
|
唐召明
authored
|
10
|
{
|
唐召明
authored
|
11
|
/// <summary>
|
唐召明
authored
|
12
|
/// 单次处理的数据量
|
唐召明
authored
|
13
14
|
/// </summary>
private const int _limit = 100;
|
唐召明
authored
|
15
|
|
唐召明
authored
|
16
|
private static void Main(string[] args)
|
唐召明
authored
|
17
|
{
|
唐召明
authored
|
18
|
try
|
李璐瑶
authored
|
19
|
{
|
李璐瑶
authored
|
20
21
|
Console.Title = "IOT数据处理端";
|
唐召明
authored
|
22
23
|
var warehouseCode = ConfigurationManager.AppSettings["WarehouseCode"];
if (string.IsNullOrWhiteSpace(warehouseCode))
|
李璐瑶
authored
|
24
|
{
|
唐召明
authored
|
25
26
|
SystemLog.PrintWarn("仓库编号未配置!");
return;
|
李璐瑶
authored
|
27
|
}
|
唐召明
authored
|
28
29
30
|
var equipmentTypeCodes = ConfigurationManager.AppSettings["EquipmentType"].Split(',').ToList();
if (equipmentTypeCodes == null || equipmentTypeCodes.Count == 0)
|
李璐瑶
authored
|
31
|
{
|
唐召明
authored
|
32
33
|
SystemLog.PrintWarn("设备类型未配置!");
return;
|
李璐瑶
authored
|
34
35
|
}
|
唐召明
authored
|
36
37
|
using var context = new DataContext();
var equipmentTypes = context.EquipmentType.Where(x => equipmentTypeCodes.Contains(x.Code)).IncludeMany(x => x.EquipmentTypePropTemplates).ToList();
|
唐召明
authored
|
38
39
40
41
42
43
44
|
Startup(equipmentTypes);
}
catch (Exception ex)
{
SystemLog.PrintWarn($"程序启动出现异常:{ex.Message}");
}
}
|
李璐瑶
authored
|
45
|
|
唐召明
authored
|
46
|
private static void Startup(IEnumerable<EquipmentType> equipmentTypes)
|
唐召明
authored
|
47
48
|
{
while (true)
|
唐召明
authored
|
49
|
{
|
唐召明
authored
|
50
|
try
|
唐召明
authored
|
51
|
{
|
唐召明
authored
|
52
53
|
var tasks = new List<Task>();
foreach (var item in equipmentTypes)
|
唐召明
authored
|
54
|
{
|
唐召明
authored
|
55
56
57
58
59
60
|
tasks.Add(Task.Run(() =>
{
Stopwatch stopwatch = Stopwatch.StartNew();
_ = Enum.TryParse<EquipmentTypeConst>(item.Code, out var equipmentTypeCode);
IAnalysis handle = equipmentTypeCode switch
{
|
唐召明
authored
|
61
62
63
64
65
66
|
EquipmentTypeConst.SingleForkSRM => new SingleForkSRMAnalysis(item),
EquipmentTypeConst.DoubleForkSRM => new DoubleForkSRMAnalysis(item),
EquipmentTypeConst.SingleForkSSRM => new SingleForkSSRMAnalysis(item),
EquipmentTypeConst.SingleForkSSRMV132 => new SingleForkSSRMV132Analysis(item),
EquipmentTypeConst.WeldRobot => new WeldRobotAnalysis(item),
EquipmentTypeConst.AGV => new AGVAnalysis(item),
|
唐召明
authored
|
67
68
69
70
71
72
73
74
|
_ => null
};
//未知类型,则跳过
if (handle is null)
{
SystemLog.PrintWarn($"未实现设备类型[{item.Code}]对应的处理方法");
return;
}
|
唐召明
authored
|
75
|
using var context = new DataContext();
|
唐召明
authored
|
76
77
|
var equipmentCodes = context.Equipment.Where(x => x.EquipmentTypeId == item.Id).ToList(x => x.Code);
var equipmentDataRecords = context.EquipmentDataRecord.Where(x => equipmentCodes.Contains(x.EquipmentCode) && !x.IsHandle).OrderBy(x => x.Timestamp).Take(_limit).ToList();
|
李璐瑶
authored
|
78
79
80
81
82
|
//if (equipmentDataRecords.Count == 0)
//{
// SystemLog.PrintInfo($"设备类型[{item.Code}]队列数据为空,跳过解析");
// return;
//}
|
唐召明
authored
|
83
|
|
唐召明
authored
|
84
|
var result = handle.Execute(equipmentDataRecords);
|
唐召明
authored
|
85
|
stopwatch.Stop();
|
李璐瑶
authored
|
86
|
if (!result.Success)
|
唐召明
authored
|
87
88
89
90
|
{
SystemLog.PrintError($"设备类型[{item.Code}]解析失败,{result.Msg},数量{equipmentDataRecords.Count},耗时{stopwatch.ElapsedMilliseconds}ms");
return;
}
|
唐召明
authored
|
91
92
|
SystemLog.PrintInfo($"设备类型[{item.Code}]解析完成,数量{equipmentDataRecords.Count},耗时{stopwatch.ElapsedMilliseconds}ms");
}));
|
唐召明
authored
|
93
|
}
|
唐召明
authored
|
94
95
96
97
98
99
100
|
Task.WaitAll(tasks.ToArray());
Console.WriteLine($"————————————————————————————————————————————————————————");
}
catch (Exception ex)
{
SystemLog.PrintError($"程序异常:{ex.Message}");
}
|
唐召明
authored
|
101
102
|
}
}
|
唐召明
authored
|
103
|
}
|