|
|
|
@ -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}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|