From 944990ea8e8d40f44eeff1e222f167dafc176e6f Mon Sep 17 00:00:00 2001 From: wenjy Date: Wed, 9 Oct 2024 13:47:06 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E5=85=A8=E6=99=AF=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E6=96=87=E4=BB=B6=E5=A4=8D=E5=88=B6=E5=88=B0=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Config/AppConfig.cs | 5 +++ SlnMesnac.TouchSocket/ApiServer.cs | 70 ++++++++++++++++++++++++++++-- SlnMesnac.WPF/appsettings.json | 1 + 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index 1cfc66e..565b1b4 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -36,6 +36,11 @@ namespace SlnMesnac.Config /// 日志文件路径 /// public string logPath { get; set; } + + /// + /// 图像路径 + /// + public string imagePath { get; set; } /// /// Sql连接配置 diff --git a/SlnMesnac.TouchSocket/ApiServer.cs b/SlnMesnac.TouchSocket/ApiServer.cs index 0a5e818..c16a6a8 100644 --- a/SlnMesnac.TouchSocket/ApiServer.cs +++ b/SlnMesnac.TouchSocket/ApiServer.cs @@ -1,10 +1,13 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Numerics; using System.Text; +using System.Web; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; +using SlnMesnac.Config; using SlnMesnac.Model.domain; using SlnMesnac.Repository.service; using SlnMesnac.Repository.service.LogImpl; @@ -22,20 +25,23 @@ namespace SlnMesnac.TouchSocket private readonly IBaseCodeService _baseCodeService; - readonly IBaseLogService _baseLogService; + private readonly IBaseLogService _baseLogService; public Action? ScanLogSocketAction; public Action? ScanStatusSocketAction; private ILogger _logger; + private AppConfig _appConfig; - public ApiServer(IScanLogService scanService, IBaseCodeService baseCodeService, IBaseLogService baseLogService, ILogger logger) + + public ApiServer(IScanLogService scanService, IBaseCodeService baseCodeService, IBaseLogService baseLogService, ILogger logger,AppConfig appConfig) { _scanService = scanService; _baseCodeService = baseCodeService; _baseLogService = baseLogService; _logger=logger; + _appConfig=appConfig; } @@ -76,8 +82,12 @@ namespace SlnMesnac.TouchSocket log.Content = hk.ToJsonString(); try { + //标签处理逻辑算法 FilterBuffer(ref hk, out string result); + //复制共享图像到指定路径 + CopyImageWithDateFolder(hk.url, result,out string destinationImagePath); + string isOk = string.Empty; if(result != "多条码" && result != "noread" && result != "NoRead" && !string.IsNullOrEmpty(result)) @@ -98,7 +108,7 @@ namespace SlnMesnac.TouchSocket ocr = hk.ocr, rfid = hk.rfid, timestamp = hk.timestamp, - url = hk.url, + url = destinationImagePath, isOk = isOk, result = result }; @@ -238,6 +248,12 @@ namespace SlnMesnac.TouchSocket } + /// + /// 标签处理逻辑算法 + /// + /// + /// + /// private void FilterBuffer(ref Hk hk,out string result) { try @@ -335,6 +351,54 @@ namespace SlnMesnac.TouchSocket throw new InvalidOperationException($"标签处理逻辑异常:{ex.Message}"); } } + + /// + /// 将全景图像复制到指定路径下 + /// + /// + /// + private void CopyImageWithDateFolder(string sourceImagePath,string fileName,out string destinationImagePath) + { + try + { + + if(string.IsNullOrEmpty(sourceImagePath)) + { + throw new ArgumentNullException("全景图像路径为空"); + } + + if (string.IsNullOrEmpty(fileName)) + { + throw new ArgumentNullException("自定义全景图像文件名称为空"); + } + + string destinationBasePath = _appConfig.imagePath; + + DateTime now = DateTime.Now; + string dateFolder = now.Year + "-" + now.Month + "-" + now.Day; + + string destinationFolder = Path.Combine(destinationBasePath, dateFolder); + if (!Directory.Exists(destinationFolder)) + { + Directory.CreateDirectory(destinationFolder); + } + + string sourceFileName = Path.GetFileName(sourceImagePath); + string extension = Path.GetExtension(sourceImagePath); + + string newFileName = now.ToString("yyyyMMddHHmmss") + "-" + fileName + extension; + + destinationImagePath = Path.Combine(destinationFolder, newFileName); + + File.Copy(sourceImagePath, destinationImagePath, true); + + File.Delete(sourceImagePath); + } + catch (Exception ex) + { + throw new InvalidOperationException($"将全景图像复制到指定路径处理异常:{ex.Message}"); + } + } } } diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index 15cfd32..992163d 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -9,6 +9,7 @@ "AllowedHosts": "*", "AppConfig": { "logPath": "F:\\桌面\\RFID+ATR识别项目\\日志信息", + "imagePath": "F:\\图片\\Camera Roll", "SqlConfig": [ { "configId": "mes",