验证db包加入代码中

main
洁 任 5 days ago
parent aba79a3ea9
commit 07f2819210

@ -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哈希值的辅助方法

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace OpenAuth.App.ServiceApp.DroneDocking.Response
{
// 定义与JSON结构对应的类
public class SignFileContent
{
[JsonPropertyName("attachment_count")]
public string AttachmentCount { get; set; }
[JsonPropertyName("code")]
public string Code { get; set; }
[JsonPropertyName("count")]
public string Count { get; set; }
[JsonPropertyName("extension")]
public string Extension { get; set; }
[JsonPropertyName("hash")]
public string Hash { get; set; }
[JsonPropertyName("regioncode")]
public string RegionCode { get; set; }
[JsonPropertyName("sign")]
public string Sign { get; set; }
[JsonPropertyName("size")]
public string Size { get; set; }
[JsonPropertyName("timestamp")]
public string Timestamp { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
}
}

@ -67,4 +67,6 @@ public class DbfineInfo
/// </summary>
public string sign { get; set; }
public int? timestamp { get; set; }
}

@ -84,7 +84,8 @@
},
"DroneDocking": {
"Url": "https://wp.tianmu.cloud:5443/zhcfzx",
"DbFile": "Sqlite.db"
"DbFile": "D:\\",
"JYMUrl": "E:\\低空态势感知\\资料\\省对接\\质检\\LandCloud.CGDBPreCheckTool.exe"
},
"AIModelApi":{
"Url": "http://192.168.10.131:9025",

@ -0,0 +1,12 @@
{
"attachment_count": "4",
"code": "AirportData",
"count": "0",
"extension": "db",
"hash": "81B6A5092EE430D7CA7B76A161FFADB46E3482DFF632EBAA1A21CB4DBCE6B5C5",
"regioncode": "370000",
"sign": "32048FEC0D8117C51EBD1F8058BD21F703BFB9EE9FF94190BD661DB1CEA636F6EF9C4CA7F13398DC92472E283D739B14B35B9FDB775ED974F908F7E4F13E20C6",
"size": "26650624",
"timestamp": "1757061411",
"version": "1"
}
Loading…
Cancel
Save