Compare commits
No commits in common. "30d8d953a0f00c6a7ef3d7f2d806a402c13c41f3" and "6927c9048cb5547a2d82f61b08a411b1f851d119" have entirely different histories.
30d8d953a0
...
6927c9048c
|
@ -1,20 +0,0 @@
|
|||
using MasstransferInfrastructure.Database.Sqlite;
|
||||
|
||||
namespace MasstransferExporter.DataExporter;
|
||||
|
||||
/// <summary>
|
||||
/// 坐标信息业务类
|
||||
/// </summary>
|
||||
public class CoordinateService
|
||||
{
|
||||
private static readonly SqliteHelper Db = SqliteHelper.GetInstance();
|
||||
|
||||
/// <summary>
|
||||
/// 坐标信息导出
|
||||
/// </summary>
|
||||
public static void CoordinateExporter()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
using System.Drawing;
|
||||
using MasstransferCommon.Model.Constant;
|
||||
using MasstransferCommunicate.Minio;
|
||||
using MasstransferCommunicate.Mqtt.Client;
|
||||
using MasstransferExporter.DataExporter.Model;
|
||||
using MasstransferExporter.ImageExporter.Model;
|
||||
using MasstransferInfrastructure.Database.Sqlite;
|
||||
|
||||
namespace MasstransferExporter.ImageExporter;
|
||||
|
||||
public class ImageService
|
||||
{
|
||||
private static readonly MinioHelper Minio = MinioHelper.GetInstance();
|
||||
|
||||
private static readonly SqliteHelper Helper = SqliteHelper.GetInstance();
|
||||
|
||||
private const string BasePath = "masstransfer";
|
||||
|
||||
private static SystemParams? GetSystemParams()
|
||||
{
|
||||
return Helper.Query<SystemParams>("select * from system_params limit 1")
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对图片生产缩略图
|
||||
/// </summary>
|
||||
private static void GenerateThumbnail(DirectoryInfo dir)
|
||||
{
|
||||
// 获取文件夹下所有文件的信息
|
||||
var fs = dir.GetFiles();
|
||||
|
||||
if (fs != null && fs.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var file in fs)
|
||||
{
|
||||
if (file.Name.EndsWith(".bmp") && !file.Name.Contains("_thumbnail"))
|
||||
{
|
||||
// 判断是否已经存在缩略图,如果存在的话,则跳过生成过程
|
||||
var thumbnailFilePath = file.FullName.Replace(".bmp", "_thumbnail.bmp");
|
||||
if (!File.Exists(thumbnailFilePath))
|
||||
{
|
||||
GenerateThumbnail(file.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 递归遍历当前目录下的所有文件夹
|
||||
foreach (var subdir in dir.GetDirectories()) GenerateThumbnail(subdir);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成缩略图
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
static void GenerateThumbnail(string filePath)
|
||||
{
|
||||
using (var image = Image.FromFile(filePath))
|
||||
{
|
||||
var thumbnailWidth = 410;
|
||||
var thumbnailHeight = 300;
|
||||
var thumbnail = image.GetThumbnailImage(thumbnailWidth, thumbnailHeight, () => false, IntPtr.Zero);
|
||||
|
||||
var directory = Path.GetDirectoryName(filePath);
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var extension = Path.GetExtension(filePath);
|
||||
var newFileName = $"{fileNameWithoutExt}_thumbnail{extension}";
|
||||
|
||||
var newFilePath = Path.Combine(directory, newFileName);
|
||||
thumbnail.Save(newFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 上传图片
|
||||
/// </summary>
|
||||
public static async void ImageExporter()
|
||||
{
|
||||
var yesterday = DateTime.Today.AddDays(-1);
|
||||
|
||||
await ImageExporter(yesterday);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出图片文件
|
||||
/// </summary>
|
||||
/// <param name="dateTime"></param>
|
||||
/// <param name="isThumbnail"></param>
|
||||
private static async Task ImageExporter(DateTime dateTime, bool isThumbnail = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var systemParams = GetSystemParams();
|
||||
var imageStoragePath =
|
||||
systemParams!.ImageStoragePath ?? Environment.GetEnvironmentVariable("USERPROFILE");
|
||||
|
||||
var date = dateTime.ToString("yyyyMMdd");
|
||||
|
||||
var dir = Path.Combine(imageStoragePath, BasePath, date);
|
||||
|
||||
if (!Directory.Exists(dir)) return;
|
||||
|
||||
var dirInfo = new DirectoryInfo(dir);
|
||||
|
||||
// 对图片进行压缩
|
||||
GenerateThumbnail(dirInfo);
|
||||
|
||||
// 文件保存路径的规则是 {user BasePath}/masstransfer/images/{yyyyMMdd}/{batchCode}/wafer/{waferCode}/{timestamp}.bmp
|
||||
var files = dirInfo.GetDirectories();
|
||||
foreach (var batchDir in files)
|
||||
{
|
||||
var types = batchDir.GetDirectories();
|
||||
foreach (var type in types)
|
||||
{
|
||||
var codeDirs = type.GetDirectories();
|
||||
foreach (var codeDir in codeDirs)
|
||||
{
|
||||
var images = codeDir.GetFiles();
|
||||
|
||||
images = isThumbnail
|
||||
? images.Where(x => x.Name.EndsWith("_thumbnail.bmp")).ToArray()
|
||||
: images.Where(x => !x.Name.EndsWith("_thumbnail.bmp")).ToArray();
|
||||
|
||||
foreach (var image in images)
|
||||
{
|
||||
var fileName = $"123456/{codeDir.Name}/{batchDir.Name}/{type.Name}/{image.Name}";
|
||||
|
||||
var path = image.FullName;
|
||||
|
||||
await Minio.UploadFileAsync("image", fileName, path);
|
||||
}
|
||||
|
||||
var data = new ImageExportData()
|
||||
{
|
||||
BatchNumber = batchDir.Name,
|
||||
BizNumber = codeDir.Name,
|
||||
ImageType = type.Name,
|
||||
PicType = isThumbnail ? "thumbnail" : "raw"
|
||||
};
|
||||
|
||||
// 上传完成后发布通知
|
||||
await MessageQueueHelper.Publish(Topics.ImageUpload, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"图片导出失败,{e}");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
namespace MasstransferExporter.ImageExporter.Model;
|
||||
|
||||
public class ImageExportData
|
||||
{
|
||||
public string PicType { get; set; }
|
||||
|
||||
public string BizNumber { get; set; }
|
||||
|
||||
public string BatchNumber { get; set; }
|
||||
|
||||
public string ImageType { get; set; }
|
||||
}
|
|
@ -32,7 +32,7 @@ public class LogFileExporter
|
|||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var fileName = $"123456/{TimeUtil.FormatTime(yesterday, "yyyyMMdd")}/{level}/{file.Name}";
|
||||
var fileName = $"123456/{TimeUtil.FormatTime(yesterday, "yyyy-MM-dd")}/{level}/{file.Name}";
|
||||
|
||||
await _minio.UploadFileAsync("log", fileName, file.FullName);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
<PackageReference Include="Serilog" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||
<PackageReference Include="System.Management" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -36,4 +35,8 @@
|
|||
<None Remove="obj\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="ImageExporter\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using MasstransferCommunicate.Mqtt.Client;
|
||||
using MasstransferExporter.ImageExporter;
|
||||
using MasstransferExporter.DataExporter;
|
||||
using MasstransferInfrastructure.Mqtt.Model;
|
||||
|
||||
class Program
|
||||
|
@ -15,7 +15,7 @@ class Program
|
|||
|
||||
await MessageQueueHelper.InitConnect(options);
|
||||
|
||||
ImageService.ImageExporter();
|
||||
await SystemParamsService.SystemParamsExporter();
|
||||
|
||||
|
||||
Console.WriteLine("按任意键退出");
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using MasstransferCommon.Model.Constant;
|
||||
using MasstransferCommon.Scheduler;
|
||||
using MasstransferCommunicate.Mqtt.Client;
|
||||
using MasstransferCommon.Scheduler;
|
||||
|
||||
namespace MasstransferExporter.Stat;
|
||||
|
||||
|
@ -17,10 +15,8 @@ public class HeartbeatExporter
|
|||
JobScheduler.AddTask("HeartbeatExporter#StartHeartBeat", HeartBeat, 10000);
|
||||
}
|
||||
|
||||
public static async void HeartBeat()
|
||||
private static void HeartBeat()
|
||||
{
|
||||
var data = new Dictionary<string, DateTime>();
|
||||
data["timestamp"] = DateTime.Now;
|
||||
await MessageQueueHelper.Publish(Topics.HeartBeat, data);
|
||||
|
||||
}
|
||||
}
|
|
@ -60,13 +60,11 @@ public class MinioHelper
|
|||
await _client.MakeBucketAsync(new MakeBucketArgs().WithBucket(bucketName));
|
||||
}
|
||||
|
||||
var response = await _client.PutObjectAsync(new PutObjectArgs()
|
||||
await _client.PutObjectAsync(new PutObjectArgs()
|
||||
.WithBucket(bucketName)
|
||||
.WithObject(fileName)
|
||||
.WithFileName(filePath));
|
||||
|
||||
Console.WriteLine(response);
|
||||
|
||||
return $"{bucketName}/{fileName}";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue