You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
4.5 KiB
C#
113 lines
4.5 KiB
C#
using Admin.Core.IService;
|
|
using Admin.Core.Model;
|
|
using log4net;
|
|
using StackExchange.Profiling.Internal;
|
|
|
|
/// <summary>
|
|
/// 测温数据采集
|
|
/// </summary>
|
|
namespace Aucma.Core.TemperatureTask
|
|
{
|
|
public class AucamTemperatureMeasurementService: IAucamTemperatureMeasurementService
|
|
{
|
|
public delegate Task RefreshBoxFoamDataDelegate();
|
|
public static event RefreshBoxFoamDataDelegate? RefreshBoxFoamDataDelegateEvent;
|
|
|
|
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(AucamTemperatureMeasurementService));
|
|
private readonly IBoxTemperatureMeasurementHistoryServices _boxTMHistoryServices;
|
|
private readonly ITemperatureHistoryServices _temperatureHistoryServices;
|
|
|
|
public AucamTemperatureMeasurementService(ITemperatureHistoryServices temperatureHistoryServices, IBoxTemperatureMeasurementHistoryServices boxTMHistoryServices)
|
|
{
|
|
_boxTMHistoryServices = boxTMHistoryServices;
|
|
_temperatureHistoryServices = temperatureHistoryServices;
|
|
}
|
|
|
|
public void Execute()
|
|
{
|
|
while (true)
|
|
{
|
|
Task.Run(async () =>
|
|
{
|
|
await Run();
|
|
});
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
|
|
#region 采集任务处理
|
|
/// <summary>
|
|
/// 采集任务处理
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task Run()
|
|
{
|
|
try
|
|
{
|
|
DateTime dt=DateTime.Now;
|
|
Console.WriteLine($"开始读取测温数据》起始时间:{dt}");
|
|
var list = _temperatureHistoryServices.QueryTemperatureHistory(dt);
|
|
Console.WriteLine($"时间:{dt};读取数据个数:{list.Count()}");
|
|
Console.WriteLine($"读取到的数据:{list.ToJson()}");
|
|
|
|
List<BoxTemperatureMeasurementHistory> historyList = new List<BoxTemperatureMeasurementHistory>();
|
|
foreach (var item in list)
|
|
{
|
|
BoxTemperatureMeasurementHistory dest = new BoxTemperatureMeasurementHistory();
|
|
dest.LineNo = item.Line_No;
|
|
dest.Gongwno = item.Gongwno;
|
|
dest.Cpno = item.Cpno;
|
|
dest.Cpmodel = item.CpModel;
|
|
dest.Factorymodel = item.FactoryModel;
|
|
dest.Voltage = item.Voltage;
|
|
dest.Point2 = item.Point2;
|
|
dest.TestTime = item.TestTime;
|
|
dest.TestedTime = item.TestedTime;
|
|
dest.Etemp = item.Etemp;
|
|
dest.BeginDatetime = item.BeginDateTime;
|
|
dest.CpResult = item.CpResult;
|
|
dest.EndDateTime = item.EndDateTime;
|
|
dest.UserName = item.UserName;
|
|
dest.Remark = item.Remark;
|
|
dest.TestNo = item.TestNo;
|
|
dest.Temp_Mes = item.Temp_Mes;
|
|
dest.Power_Mes = item.Power_Mes;
|
|
dest.Part_Mes = item.Part_Mes;
|
|
dest.ErrorCode_Mes = item.ErrorCode_Mes;
|
|
dest.T1Name = item.T1Name;
|
|
dest.T2Name = item.T2Name;
|
|
dest.T3Name = item.T3Name;
|
|
dest.T4Name = item.T4Name;
|
|
dest.T5Name = item.T5Name;
|
|
dest.T6Name = item.T6Name;
|
|
dest.IsOrder = item.IsOrder;
|
|
dest.LowV_Time = item.LowV_Time;
|
|
dest.LowV_PowerMin = item.LowV_PowerMin;
|
|
dest.LowV_PowerMax = item.LowV_PowerMax;
|
|
dest.LowV_PowerFact = item.LowV_PowerFact;
|
|
dest.LowVoltage = item.LowVoltage;
|
|
historyList.Add(dest);
|
|
}
|
|
|
|
Console.WriteLine($"映射个数:{historyList.Count()}");
|
|
var result = await _boxTMHistoryServices.AddAsync(historyList);
|
|
if (result > 0)
|
|
{
|
|
if (list == null) return;
|
|
list.ForEach(x => x.flag = 1);
|
|
await _temperatureHistoryServices.UpdateAsync(list);
|
|
|
|
Console.WriteLine("保存测温系统成功");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error($"测温数据处理异常:{ex.Message}");
|
|
Console.WriteLine($"测温数据处理异常:{ex.Message}");
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|