添加上传坐标数据的功能
This commit is contained in:
parent
e20129a4c1
commit
7edb347ec7
|
@ -1,119 +1,207 @@
|
|||
using MasstransferCommon.Atrributes;
|
||||
using MasstransferCommon.Model.Constant;
|
||||
using MasstransferCommon.Model.Constant;
|
||||
using MasstransferCommon.Utils;
|
||||
using MasstransferCommunicate.Minio;
|
||||
using MasstransferCommunicate.Mqtt.Client;
|
||||
using MasstransferExporter.DataExporter.Model;
|
||||
using MasstransferInfrastructure.Database.Sqlite;
|
||||
using Masuit.Tools;
|
||||
|
||||
namespace MasstransferExporter.DataExporter;
|
||||
|
||||
/// <summary>
|
||||
/// 坐标信息业务类
|
||||
/// </summary>
|
||||
public class CoordinateService : Instant
|
||||
public class CoordinateService
|
||||
{
|
||||
private static readonly SqliteHelper Db = SqliteHelper.GetInstance();
|
||||
|
||||
private static MinioHelper _minio = MinioHelper.GetInstance();
|
||||
private static readonly MinioHelper Minio = MinioHelper.GetInstance();
|
||||
|
||||
/// <summary>
|
||||
/// 坐标信息导出
|
||||
/// 每5秒钟自动上报一次当前时间内的坐标信息
|
||||
/// </summary>
|
||||
public static async void CoordinateExporter()
|
||||
public static Task CoordinateExporter()
|
||||
{
|
||||
await MarkPointExporter();
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var temp = Path.Combine(Environment.CurrentDirectory, "temp");
|
||||
|
||||
// 先清理上次的临时空间
|
||||
if (Directory.Exists(temp))
|
||||
{
|
||||
Directory.Delete(temp, true);
|
||||
}
|
||||
|
||||
// 然后创建临时目录
|
||||
Directory.CreateDirectory(temp);
|
||||
|
||||
var endTime = DateTime.Now;
|
||||
var startTime = endTime.AddDays(-5);
|
||||
|
||||
WaferCoordinateExporter(startTime, endTime);
|
||||
SubstrateCoordinateExporter(startTime, endTime);
|
||||
PathCoordinateExporter(startTime, endTime);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传mark点坐标文件
|
||||
/// </summary>
|
||||
private static async Task MarkPointExporter()
|
||||
private static async Task MarkPointExporter(string batchCode, string substrateCode)
|
||||
{
|
||||
var formula = FormulaService.GetSelectedFormula();
|
||||
|
||||
if (formula == null) return;
|
||||
|
||||
var benchSetting = FormulaService.GetWorkBenchSettingByFormulaId(formula.Id);
|
||||
|
||||
if (benchSetting == null) return;
|
||||
|
||||
// 将mark点转为json,写到临时文件
|
||||
var coordinates = new Dictionary<string, double>
|
||||
var path = Path.Combine(Environment.CurrentDirectory, "temp", "mark.json");
|
||||
try
|
||||
{
|
||||
{ "SolderJointX1", benchSetting.SolderJointX1 },
|
||||
{ "SolderJointY1", benchSetting.SolderJointY1 },
|
||||
{ "SolderJointX2", benchSetting.SolderJointX2 },
|
||||
{ "SolderJointY2", benchSetting.SolderJointY2 },
|
||||
{ "SolderJointX3", benchSetting.SolderJointX3 },
|
||||
{ "SolderJointY3", benchSetting.SolderJointY3 }
|
||||
};
|
||||
var formula = FormulaService.GetSelectedFormula();
|
||||
|
||||
var json = JsonUtil.ToJson(coordinates);
|
||||
if (formula == null) return;
|
||||
|
||||
var path = Path.Combine(Environment.CurrentDirectory, "mark.json");
|
||||
var benchSetting = FormulaService.GetWorkBenchSettingByFormulaId(formula.Id);
|
||||
|
||||
await File.WriteAllTextAsync(path, json);
|
||||
if (benchSetting == null) return;
|
||||
|
||||
var fileName = $"{Constants.SN}/20230301/20230301/mark/mark.json";
|
||||
// 将mark点转为json,写到临时文件
|
||||
var coordinates = new Dictionary<string, double>
|
||||
{
|
||||
{ "SolderJointX1", benchSetting.SolderJointX1 },
|
||||
{ "SolderJointY1", benchSetting.SolderJointY1 },
|
||||
{ "SolderJointX2", benchSetting.SolderJointX2 },
|
||||
{ "SolderJointY2", benchSetting.SolderJointY2 },
|
||||
{ "SolderJointX3", benchSetting.SolderJointX3 },
|
||||
{ "SolderJointY3", benchSetting.SolderJointY3 }
|
||||
};
|
||||
|
||||
await _minio.UploadFileAsync("coordinate", fileName, path);
|
||||
var json = JsonUtil.ToJson(coordinates);
|
||||
|
||||
// 上传完成后删除本地的文件
|
||||
File.Delete(path);
|
||||
await File.WriteAllTextAsync(path, json);
|
||||
|
||||
var data = new CoordinateData()
|
||||
var fileName = $"{Constants.SN}/{batchCode}/{substrateCode}/mark/mark.json";
|
||||
|
||||
await Minio.UploadFileAsync("coordinate", fileName, path);
|
||||
|
||||
// 上传完成后删除本地的文件
|
||||
File.Delete(path);
|
||||
|
||||
var data = new CoordinateData()
|
||||
{
|
||||
FileType = "MARK",
|
||||
BatchNumber = batchCode,
|
||||
BizNumber = substrateCode
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FileType = "MARK",
|
||||
BatchNumber = "20230301",
|
||||
BizNumber = "20230301"
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传wafer坐标文件
|
||||
/// </summary>
|
||||
private async void WaferCoordinateExporter()
|
||||
private static async void WaferCoordinateExporter(DateTime startTime, DateTime endTime)
|
||||
{
|
||||
var data = new CoordinateData()
|
||||
// 找出当前时间段内所有的晶环信息
|
||||
var wafers = Db.Query<Wafer>("SELECT * FROM wafers WHERE create_time >= ? AND create_time <= ?", startTime,
|
||||
endTime);
|
||||
|
||||
foreach (var wafer in wafers)
|
||||
{
|
||||
FileType = "WAFER",
|
||||
BatchNumber = "20230301",
|
||||
BizNumber = "20230301"
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
var path = Path.Combine(Environment.CurrentDirectory, "temp", $"{wafer.Id}.json");
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(path, wafer.CoordinateJson);
|
||||
|
||||
var fileName = $"{Constants.SN}/{wafer.BatchCode}/{wafer.WaferCode}/wafer/wafer.json";
|
||||
|
||||
await Minio.UploadFileAsync("coordinate", fileName, path);
|
||||
|
||||
var data = new CoordinateData()
|
||||
{
|
||||
FileType = "WAFER",
|
||||
BatchNumber = wafer.BatchCode,
|
||||
BizNumber = wafer.WaferCode
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传基板坐标文件
|
||||
/// </summary>
|
||||
private async void SubstrateCoordinateExporter()
|
||||
private static async void SubstrateCoordinateExporter(DateTime startTime, DateTime endTime)
|
||||
{
|
||||
var data = new CoordinateData()
|
||||
// 找出当前时间段内的基板信息
|
||||
var substrates = Db.Query<Substrate>("SELECT * FROM substrates WHERE create_time >= ? AND create_time <= ?",
|
||||
startTime, endTime);
|
||||
foreach (var substrate in substrates)
|
||||
{
|
||||
FileType = "PCB",
|
||||
BatchNumber = "20230301",
|
||||
BizNumber = "20230301"
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
var path = Path.Combine(Environment.CurrentDirectory, "temp", $"{substrate.Id}.json");
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(path, substrate.CoordinateJson);
|
||||
|
||||
var fileName = $"{Constants.SN}/{substrate.BatchNo}/{substrate.SubstrateCode}/pcb/pcb.json";
|
||||
|
||||
await Minio.UploadFileAsync("coordinate", fileName, path);
|
||||
|
||||
var data = new CoordinateData()
|
||||
{
|
||||
FileType = "PCB",
|
||||
BatchNumber = substrate.BatchNo,
|
||||
BizNumber = substrate.SubstrateCode
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
|
||||
|
||||
// 上传mark 点坐标信息
|
||||
await MarkPointExporter(substrate.BatchNo, substrate.SubstrateCode);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传动打路径坐标文件
|
||||
/// </summary>
|
||||
private async void PathCoordinateExporter()
|
||||
private static async void PathCoordinateExporter(DateTime startTime, DateTime endTime)
|
||||
{
|
||||
var data = new CoordinateData()
|
||||
{
|
||||
FileType = "ROUTE",
|
||||
BatchNumber = "20230301",
|
||||
BizNumber = "20230301"
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
}
|
||||
// 找出当前时间段内的打路径信息
|
||||
var records = Db.Query<StrikeRecord>("SELECT * FROM strike_records WHERE create_time >= ? AND create_time <= ?",
|
||||
startTime, endTime);
|
||||
|
||||
public void Initialized()
|
||||
{
|
||||
foreach (var record in records)
|
||||
{
|
||||
var path = Path.Combine(Environment.CurrentDirectory, "temp", $"{record.Id}.json");
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(path, record.ToJsonString());
|
||||
|
||||
var fileName = $"{Constants.SN}/{record.BatchNo}/{record.SubstrateCode}/route/{record.Id}.json";
|
||||
|
||||
await Minio.UploadFileAsync("coordinate", fileName, path);
|
||||
|
||||
var data = new CoordinateData()
|
||||
{
|
||||
FileType = "ROUTE",
|
||||
BatchNumber = record.BatchNo,
|
||||
BizNumber = record.SubstrateCode
|
||||
};
|
||||
await MessageQueueHelper.Publish(Topics.CoordinateUpload, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ public class FaultRecordService
|
|||
public static async Task FaultRecordDataExporter()
|
||||
{
|
||||
var endTime = DateTime.Now;
|
||||
var startTime = endTime.AddMinutes(-30);
|
||||
var startTime = endTime.AddMinutes(-5);
|
||||
|
||||
// 查询5分钟内的故障记录
|
||||
var sql = "SELECT * FROM fault_records WHERE update_time >= ? AND update_time <= ?";
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using MasstransferCommon.Config;
|
||||
using MasstransferCommon.Events;
|
||||
using MasstransferCommon.Model.Entity;
|
||||
using MasstransferCommon.Scheduler;
|
||||
using MasstransferCommunicate.Mqtt.Client;
|
||||
using MasstransferExporter.DataExporter;
|
||||
using MasstransferExporter.Init;
|
||||
using MasstransferInfrastructure.Database.Sqlite;
|
||||
using MasstransferInfrastructure.Mqtt.Model;
|
||||
|
@ -15,12 +17,10 @@ class Program
|
|||
|
||||
public static async Task Main()
|
||||
{
|
||||
// 进行初始化调用
|
||||
InstantUtil.Init();
|
||||
|
||||
Log.Logger = LogConfiguration.GetLogger();
|
||||
|
||||
Log.Error("Masstransfer Exporter Startup");
|
||||
// 进行初始化调用
|
||||
InstantUtil.Init();
|
||||
|
||||
var mqttParams = Db.Query<MqttParams>("select * from mqtt_params").FirstOrDefault();
|
||||
|
||||
|
@ -38,8 +38,8 @@ class Program
|
|||
// 启动完成后,广播启动通知
|
||||
EventBus<bool>.Publish(EventType.StartUp, true);
|
||||
|
||||
// DelayScheduler.Delay(async () => ImageService.ImageExporter(),
|
||||
// TimeSpan.FromSeconds(5));
|
||||
DelayScheduler.Delay(async () => await CoordinateService.CoordinateExporter(),
|
||||
TimeSpan.FromSeconds(5));
|
||||
|
||||
// 启动与主程序的通信
|
||||
// ProcessHelper.Init();
|
||||
|
|
Loading…
Reference in New Issue