change - 全景图像文件复制到指定路径

master
wenjy 1 month ago
parent bd532fa1e9
commit 944990ea8e

@ -36,6 +36,11 @@ namespace SlnMesnac.Config
/// 日志文件路径
/// </summary>
public string logPath { get; set; }
/// <summary>
/// 图像路径
/// </summary>
public string imagePath { get; set; }
/// <summary>
/// Sql连接配置

@ -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<ScanLogModel>? ScanLogSocketAction;
public Action<ScanStatusSocket>? ScanStatusSocketAction;
private ILogger<ApiServer> _logger;
private AppConfig _appConfig;
public ApiServer(IScanLogService scanService, IBaseCodeService baseCodeService, IBaseLogService baseLogService, ILogger<ApiServer> logger)
public ApiServer(IScanLogService scanService, IBaseCodeService baseCodeService, IBaseLogService baseLogService, ILogger<ApiServer> 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
}
/// <summary>
/// 标签处理逻辑算法
/// </summary>
/// <param name="hk"></param>
/// <param name="result"></param>
/// <exception cref="InvalidOperationException"></exception>
private void FilterBuffer(ref Hk hk,out string result)
{
try
@ -335,6 +351,54 @@ namespace SlnMesnac.TouchSocket
throw new InvalidOperationException($"标签处理逻辑异常:{ex.Message}");
}
}
/// <summary>
/// 将全景图像复制到指定路径下
/// </summary>
/// <param name="sourceImagePath"></param>
/// <param name="fileName"></param>
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}");
}
}
}
}

@ -9,6 +9,7 @@
"AllowedHosts": "*",
"AppConfig": {
"logPath": "F:\\桌面\\RFID+ATR识别项目\\日志信息",
"imagePath": "F:\\图片\\Camera Roll",
"SqlConfig": [
{
"configId": "mes",

Loading…
Cancel
Save