|
|
|
@ -9,33 +9,22 @@ using Infrastructure.Helpers;
|
|
|
|
|
using OpenAuth.App.ServiceApp.Response;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using OpenAuth.App.ServiceApp.DroneDocking.Request;
|
|
|
|
|
using DocumentFormat.OpenXml.Office.CustomUI;
|
|
|
|
|
using DocumentFormat.OpenXml.EMMA;
|
|
|
|
|
using OpenAuth.App.ServiceApp.DroneDocking.Response;
|
|
|
|
|
using DocumentFormat.OpenXml.Math;
|
|
|
|
|
using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
|
|
|
|
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
|
|
|
|
using Org.BouncyCastle.Ocsp;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
|
|
|
|
|
|
|
|
|
using SQLitePCL;
|
|
|
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
using Infrastructure.CloudSdk.minio;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using OpenAuth.WebApi;
|
|
|
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
|
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
|
using Org.BouncyCastle.Crypto.Digests;
|
|
|
|
|
using Org.BouncyCastle.Utilities.Encoders;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.App.ServiceApp.DroneDocking
|
|
|
|
|
{
|
|
|
|
@ -46,8 +35,9 @@ namespace OpenAuth.App.ServiceApp.DroneDocking
|
|
|
|
|
private readonly ISqlSugarClient _client;
|
|
|
|
|
private readonly MinioService _minioService;
|
|
|
|
|
private readonly MqttClientManager _mqttClientManager;
|
|
|
|
|
private readonly IHostEnvironment _env;
|
|
|
|
|
|
|
|
|
|
public DroneDockApp(EncryptionHelper helper, IConfiguration configuration, ISqlSugarClient client,
|
|
|
|
|
public DroneDockApp(EncryptionHelper helper, IHostEnvironment env, IConfiguration configuration, ISqlSugarClient client,
|
|
|
|
|
MinioService minioService, MqttClientManager mqttClientManager, ISugarUnitOfWork<SugarDbContext> unitWork,
|
|
|
|
|
ISimpleClient<DroneDocktask> repository, IAuth auth) : base(unitWork, repository, auth)
|
|
|
|
|
{
|
|
|
|
@ -56,6 +46,7 @@ namespace OpenAuth.App.ServiceApp.DroneDocking
|
|
|
|
|
_client = client;
|
|
|
|
|
_minioService = minioService;
|
|
|
|
|
_mqttClientManager = mqttClientManager;
|
|
|
|
|
_env = env;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -970,6 +961,18 @@ namespace OpenAuth.App.ServiceApp.DroneDocking
|
|
|
|
|
public async Task<Response<string>> UploadFile(AirPortUploadDbReq req)
|
|
|
|
|
{
|
|
|
|
|
Response<string> Response = new Response<string>();
|
|
|
|
|
//db包校验
|
|
|
|
|
// 首先检查文件是否存在
|
|
|
|
|
if (!File.Exists(req.filePath))
|
|
|
|
|
{
|
|
|
|
|
Response.Result = $"错误: 文件 '{req.filePath}' 不存在";
|
|
|
|
|
Response.Code = 500;
|
|
|
|
|
return Response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var filePath = req.filePath;
|
|
|
|
|
var uploadUrl = req.fileUrl;
|
|
|
|
|
var fileName = req.filename;
|
|
|
|
@ -1063,17 +1066,25 @@ namespace OpenAuth.App.ServiceApp.DroneDocking
|
|
|
|
|
//拼接字符串
|
|
|
|
|
string filepath = configuration.GetSection("DroneDocking:DbFile").Value;
|
|
|
|
|
string filename = "";
|
|
|
|
|
string signname = "";
|
|
|
|
|
if (string.IsNullOrEmpty(task.taskname))
|
|
|
|
|
{
|
|
|
|
|
filename = task.taskid.ToString() + ".db";
|
|
|
|
|
signname= task.taskid.ToString() + ".sign";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
filename += task.taskname + ".db";
|
|
|
|
|
signname = task.taskname + ".sign";
|
|
|
|
|
}
|
|
|
|
|
filepath = Path.Combine(filepath, filename);
|
|
|
|
|
|
|
|
|
|
//获取任务详情数据
|
|
|
|
|
if (File.Exists(filepath))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(filepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取任务详情数据
|
|
|
|
|
var filigtlist = _client.Queryable<DroneDocktaskdetail>().Where(r => r.taskid == taskid).ToList();
|
|
|
|
|
|
|
|
|
|
//var sqliteconnect = configuration.GetSection("DroneDocking:DbFile").Value;
|
|
|
|
@ -1284,60 +1295,119 @@ namespace OpenAuth.App.ServiceApp.DroneDocking
|
|
|
|
|
sqliteConn.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取上传及下载地址
|
|
|
|
|
AirPortUploadReq airPortUploadReq = new AirPortUploadReq();
|
|
|
|
|
airPortUploadReq.code = "AirportData";
|
|
|
|
|
airPortUploadReq.regioncode = filigtlist[0].xzqdm;
|
|
|
|
|
List<string> filesname = new List<string>();
|
|
|
|
|
filesname.Add(filename);
|
|
|
|
|
airPortUploadReq.filenames = filesname;
|
|
|
|
|
var result = await getUploadFilePath(airPortUploadReq);
|
|
|
|
|
|
|
|
|
|
var jsonstr = result.Result;
|
|
|
|
|
JArray jObject = JArray.Parse(jsonstr);
|
|
|
|
|
var liststr = jObject[0].Value<JObject>();
|
|
|
|
|
var write = liststr["writeurl"].ToString(); //文件上传地址
|
|
|
|
|
var read = liststr["readurl"].ToString(); //文件下载地址
|
|
|
|
|
//上传文件
|
|
|
|
|
AirPortUploadDbReq req = new AirPortUploadDbReq();
|
|
|
|
|
req.fileUrl = write;
|
|
|
|
|
req.filePath = filepath;
|
|
|
|
|
req.filename = filename;
|
|
|
|
|
|
|
|
|
|
// 获取文件大小
|
|
|
|
|
FileInfo fileInfo = new FileInfo(filepath);
|
|
|
|
|
long fileSize = fileInfo.Length;
|
|
|
|
|
|
|
|
|
|
//获取文件哈希值
|
|
|
|
|
byte[] res = ComputeFileSm3Hash(filepath);
|
|
|
|
|
string hash = Hex.ToHexString(res).ToUpper();
|
|
|
|
|
|
|
|
|
|
//数据写入数据库
|
|
|
|
|
using (var uow = base.UnitWork.CreateContext())
|
|
|
|
|
// 添加短暂延迟以确保文件句柄被释放
|
|
|
|
|
await Task.Delay(500);
|
|
|
|
|
// 确定临时文件夹路径,例如使用Web根路径下的temp文件夹
|
|
|
|
|
string tempFolderPath = Path.Combine(_env.ContentRootPath, "temp");
|
|
|
|
|
|
|
|
|
|
// 如果temp文件夹不存在,则创建
|
|
|
|
|
if (!Directory.Exists(tempFolderPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(tempFolderPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建临时文件的完整路径
|
|
|
|
|
string tempFilePath = Path.Combine(tempFolderPath, filename);
|
|
|
|
|
|
|
|
|
|
// 复制文件
|
|
|
|
|
File.Copy(filepath, tempFilePath, true);
|
|
|
|
|
|
|
|
|
|
// 创建进程对象
|
|
|
|
|
Process process = new Process();
|
|
|
|
|
|
|
|
|
|
// 配置进程启动参数
|
|
|
|
|
process.StartInfo.FileName = configuration.GetSection("DroneDocking:JYMUrl").Value;
|
|
|
|
|
process.StartInfo.Arguments = $"checkdb -f \"{tempFilePath}\" --pwd hopetry"; // "/c" 表示执行后关闭命令行
|
|
|
|
|
process.StartInfo.RedirectStandardOutput = true; // 重定向输出
|
|
|
|
|
process.StartInfo.UseShellExecute = false; // 不使用系统外壳
|
|
|
|
|
process.StartInfo.CreateNoWindow = true; // 不创建窗口
|
|
|
|
|
|
|
|
|
|
// 启动进程
|
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
|
|
// 读取输出
|
|
|
|
|
string output = process.StandardOutput.ReadToEnd();
|
|
|
|
|
process.WaitForExit(); // 等待进程结束
|
|
|
|
|
//File.Delete(tempFilePath);
|
|
|
|
|
if (output.IndexOf("签章成功") > 0)
|
|
|
|
|
{
|
|
|
|
|
DbfineInfo dbfine = new DbfineInfo();
|
|
|
|
|
dbfine.id = Guid.NewGuid().ToString();
|
|
|
|
|
dbfine.taskid = taskidsheng;
|
|
|
|
|
dbfine.regioncode = filigtlist[0].xzqdm;
|
|
|
|
|
dbfine.extension = ".db";
|
|
|
|
|
dbfine.attachment_count = 1;
|
|
|
|
|
dbfine.size = (int)fileSize;
|
|
|
|
|
dbfine.count = 3;
|
|
|
|
|
dbfine.url = read;
|
|
|
|
|
dbfine.hash = hash;
|
|
|
|
|
dbfine.key = "hopetry";
|
|
|
|
|
var info = await uow.DbfineInfo.InsertAsync(dbfine);
|
|
|
|
|
if (info == false)
|
|
|
|
|
string signpath = Path.Combine(tempFolderPath, signname);
|
|
|
|
|
|
|
|
|
|
#region 获取签章中内容
|
|
|
|
|
// 检查文件是否存在
|
|
|
|
|
if (!File.Exists(signpath))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("上传信息写入数据库失败");
|
|
|
|
|
throw new FileNotFoundException($"签名文件不存在: {signpath}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uow.Commit();
|
|
|
|
|
Console.WriteLine(info);
|
|
|
|
|
}
|
|
|
|
|
// 读取文件内容
|
|
|
|
|
string jsonContent = File.ReadAllText(signpath);
|
|
|
|
|
|
|
|
|
|
//上传db包
|
|
|
|
|
await UploadFile(req);
|
|
|
|
|
// 解析JSON
|
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
PropertyNameCaseInsensitive = true, // 忽略属性名称大小写
|
|
|
|
|
AllowTrailingCommas = true, // 允许尾随逗号
|
|
|
|
|
ReadCommentHandling = JsonCommentHandling.Skip // 跳过注释
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SignFileContent signData = JsonSerializer.Deserialize<SignFileContent>(jsonContent, options);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//获取上传及下载地址
|
|
|
|
|
AirPortUploadReq airPortUploadReq = new AirPortUploadReq();
|
|
|
|
|
airPortUploadReq.code = "AirportData";
|
|
|
|
|
airPortUploadReq.regioncode = filigtlist[0].xzqdm;
|
|
|
|
|
List<string> filesname = new List<string>();
|
|
|
|
|
filesname.Add(filename);
|
|
|
|
|
airPortUploadReq.filenames = filesname;
|
|
|
|
|
var result = await getUploadFilePath(airPortUploadReq);
|
|
|
|
|
|
|
|
|
|
var jsonstr = result.Result;
|
|
|
|
|
JArray jObject = JArray.Parse(jsonstr);
|
|
|
|
|
var liststr = jObject[0].Value<JObject>();
|
|
|
|
|
var write = liststr["writeurl"].ToString(); //文件上传地址
|
|
|
|
|
var read = liststr["readurl"].ToString(); //文件下载地址
|
|
|
|
|
//上传文件
|
|
|
|
|
AirPortUploadDbReq req = new AirPortUploadDbReq();
|
|
|
|
|
req.fileUrl = write;
|
|
|
|
|
req.filePath = filepath;
|
|
|
|
|
req.filename = filename;
|
|
|
|
|
|
|
|
|
|
//数据写入数据库
|
|
|
|
|
using (var uow = base.UnitWork.CreateContext())
|
|
|
|
|
{
|
|
|
|
|
DbfineInfo dbfine = new DbfineInfo();
|
|
|
|
|
dbfine.id = Guid.NewGuid().ToString();
|
|
|
|
|
dbfine.taskid = taskidsheng;
|
|
|
|
|
dbfine.regioncode = filigtlist[0].xzqdm;
|
|
|
|
|
dbfine.extension = ".db";
|
|
|
|
|
dbfine.attachment_count = Convert.ToInt32(signData.Count);
|
|
|
|
|
dbfine.size = Convert.ToInt32(signData.Size);
|
|
|
|
|
dbfine.count = totalcount;
|
|
|
|
|
dbfine.url = read;
|
|
|
|
|
dbfine.hash = signData.Hash;
|
|
|
|
|
dbfine.key = "hopetry";
|
|
|
|
|
dbfine.sign = signData.Sign;
|
|
|
|
|
dbfine.timestamp= Convert.ToInt32(signData.Timestamp);
|
|
|
|
|
var info = await uow.DbfineInfo.InsertAsync(dbfine);
|
|
|
|
|
if (info == false)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("上传信息写入数据库失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uow.Commit();
|
|
|
|
|
Console.WriteLine(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//上传db包
|
|
|
|
|
await UploadFile(req);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("验签失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算文件SM3哈希值的辅助方法
|
|
|
|
|