|
|
|
|
using Admin.Core.IService;
|
|
|
|
|
using Admin.Core.Model;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Serilog;
|
|
|
|
|
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 ITestedCodeMESServices _codeMESServices;
|
|
|
|
|
private readonly ITemperatureHistoryServices _temperatureHistoryServices;
|
|
|
|
|
|
|
|
|
|
bool flag = true;
|
|
|
|
|
public AucamTemperatureMeasurementService(ITemperatureHistoryServices temperatureHistoryServices,
|
|
|
|
|
ITestedCodeMESServices codeMESServices)
|
|
|
|
|
{
|
|
|
|
|
_codeMESServices = codeMESServices;
|
|
|
|
|
_temperatureHistoryServices = temperatureHistoryServices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Run();
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 采集任务处理
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 采集任务处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async void Run()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
flag = false;
|
|
|
|
|
|
|
|
|
|
DateTime dt;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"【{DateTime.Now}】开始读取测温数据");
|
|
|
|
|
string sql = "select top 1 * from TemperatureHistory order by SyncDate desc";
|
|
|
|
|
var allList= await _temperatureHistoryServices.QuerySqlAsync(sql,null);
|
|
|
|
|
if (allList == null || allList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
dt = DateTime.Now.AddMinutes(-5);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TemperatureHistory maxHistory = allList.First();
|
|
|
|
|
if (maxHistory.SyncDate.ToString()==null)
|
|
|
|
|
{
|
|
|
|
|
dt = Convert.ToDateTime(maxHistory.EndDateTime);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dt = Convert.ToDateTime(maxHistory.SyncDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var historyList = _codeMESServices.QueryTemperatureHistory(dt);
|
|
|
|
|
|
|
|
|
|
var query = (from a in historyList
|
|
|
|
|
select new TemperatureHistory
|
|
|
|
|
{
|
|
|
|
|
Line_No = a.Line_No,
|
|
|
|
|
Gongwno = a.Gongwno,
|
|
|
|
|
CpNo = a.CpNo,
|
|
|
|
|
CpModel = a.CpModel,
|
|
|
|
|
FactoryModel = a.FactoryModel,
|
|
|
|
|
Voltage = a.Voltage,
|
|
|
|
|
Point2 = a.Point2,
|
|
|
|
|
TestTime = a.TestTime,
|
|
|
|
|
TestedTime = a.TestedTime,
|
|
|
|
|
Etemp = a.Etemp,
|
|
|
|
|
BeginDateTime = a.BeginDateTime,
|
|
|
|
|
CpResult = a.CpResult,
|
|
|
|
|
EndDateTime = a.EndDateTime,
|
|
|
|
|
UserName = a.UserName,
|
|
|
|
|
Remark = a.Remark,
|
|
|
|
|
TestNo = a.TestNo,
|
|
|
|
|
Temp_Mes = a.Temp_Mes,
|
|
|
|
|
Power_Mes = a.Power_Mes,
|
|
|
|
|
Part_Mes = a.Part_Mes,
|
|
|
|
|
ErrorCode_Mes = a.ErrorCode_Mes,
|
|
|
|
|
T1Name = a.T1Name,
|
|
|
|
|
T2Name = a.T2Name,
|
|
|
|
|
T3Name = a.T3Name,
|
|
|
|
|
T4Name = a.T4Name,
|
|
|
|
|
T5Name = a.T5Name,
|
|
|
|
|
T6Name = a.T6Name,
|
|
|
|
|
IsOrder = a.IsOrder,
|
|
|
|
|
LowV_Time = a.LowV_Time,
|
|
|
|
|
LowV_PowerMin = a.LowV_PowerMin,
|
|
|
|
|
LowV_PowerMax = a.LowV_PowerMax,
|
|
|
|
|
LowV_PowerFact = a.LowV_PowerFact,
|
|
|
|
|
LowVoltage = a.LowVoltage,
|
|
|
|
|
SyncDate = dt
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
if (query == null|| query.Count==0) return;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"【{DateTime.Now}】读取数据个数:{historyList.Count()}");
|
|
|
|
|
var result = await _temperatureHistoryServices.AddAsync(query);
|
|
|
|
|
if (result > 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"【{DateTime.Now}】保存测温数据成功!保存数量:{query.Count}");
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(50000);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"【{DateTime.Now}】 {ex.Message}");
|
|
|
|
|
logHelper.Error(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
finally { flag = true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"测温数据处理异常:{ex.Message}");
|
|
|
|
|
Console.WriteLine($"测温数据处理异常:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|