|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Dynamic;
|
|
|
|
@ -19,6 +20,7 @@ using Microsoft.Net.Http.Headers;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using OpenAuth.App.BaseApp.Base;
|
|
|
|
|
using OpenAuth.App.BaseApp.Subscribe;
|
|
|
|
|
using OpenAuth.App.BasicQueryService;
|
|
|
|
|
using OpenAuth.App.Interface;
|
|
|
|
|
using OpenAuth.App.Request;
|
|
|
|
@ -44,6 +46,8 @@ namespace OpenAuth.App.ServiceApp
|
|
|
|
|
private readonly OpenJobApp _openJobApp;
|
|
|
|
|
private readonly ILogger<LasaDronePort> _logger;
|
|
|
|
|
CommonDataManager _commonDataManager;
|
|
|
|
|
private readonly ConcurrentDictionary<string, DateTime> _processedMessages = new();
|
|
|
|
|
private readonly TimeSpan _deduplicationWindow = TimeSpan.FromMinutes(1);
|
|
|
|
|
|
|
|
|
|
public ManageApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaDronePort> repository, IAuth auth,
|
|
|
|
|
MqttClientManager mqttClientManager, CommonDataManager commonDataManager, MinioService minioService,
|
|
|
|
@ -2406,6 +2410,14 @@ namespace OpenAuth.App.ServiceApp
|
|
|
|
|
// 更新
|
|
|
|
|
await db.Updateable(aiInspection).IgnoreNullColumns().ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var aiInspection = Repository
|
|
|
|
|
.ChangeRepository<SugarRepositiry<LasaAiInspection>>()
|
|
|
|
|
.AsQueryable().Where(x => x.TaskId == req.TaskId).First();
|
|
|
|
|
req.AlgoInstanceId = aiInspection.AlgoInstanceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var algoInstances = await db
|
|
|
|
|
.Queryable<LasaAlgoInstance>()
|
|
|
|
|
.Where(x => x.Id == req.AlgoInstanceId)
|
|
|
|
@ -2438,13 +2450,14 @@ namespace OpenAuth.App.ServiceApp
|
|
|
|
|
await db.Updateable(taskRecord).IgnoreNullColumns().ExecuteCommandAsync();
|
|
|
|
|
var tag = await db
|
|
|
|
|
.Queryable<LasaModelLabel>()
|
|
|
|
|
.Where(x => tagsIds.Contains(x.Id))
|
|
|
|
|
.Select(x => x.EnumValue)
|
|
|
|
|
.Where(l => tagsIds.Contains(l.Id))
|
|
|
|
|
.Select(l => l.EnumValue)
|
|
|
|
|
.ToArrayAsync();
|
|
|
|
|
json.tag = new int [0, 1, 2, 3, 4, 5];
|
|
|
|
|
var content = new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json");
|
|
|
|
|
using var httpClient = new HttpClient();
|
|
|
|
|
var response = await httpClient.PostAsync("http://192.168.10.131:9025/start_detection", content);
|
|
|
|
|
_logger.LogDebug($"成功调用{response.IsSuccessStatusCode}");
|
|
|
|
|
db.Ado.CommitTran();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -2465,7 +2478,7 @@ namespace OpenAuth.App.ServiceApp
|
|
|
|
|
var task = new LasaTask()
|
|
|
|
|
{
|
|
|
|
|
Id = taskid,
|
|
|
|
|
// ScheduledEndTime = DateTime.Now,
|
|
|
|
|
// ScheduledEndTime = DateTime.Now,
|
|
|
|
|
CompletedTime = DateTime.Now,
|
|
|
|
|
Status = 5 // 成功
|
|
|
|
|
};
|
|
|
|
@ -2491,5 +2504,148 @@ namespace OpenAuth.App.ServiceApp
|
|
|
|
|
Result = true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsDuplicate(string messageId)
|
|
|
|
|
{
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
// 清理过期消息
|
|
|
|
|
foreach (var kvp in _processedMessages)
|
|
|
|
|
{
|
|
|
|
|
if (now - kvp.Value > _deduplicationWindow)
|
|
|
|
|
{
|
|
|
|
|
_processedMessages.TryRemove(kvp.Key, out _);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查是否已存在
|
|
|
|
|
if (_processedMessages.ContainsKey(messageId))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_processedMessages[messageId] = now;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Response<bool>> TestZhiBao(string message)
|
|
|
|
|
{
|
|
|
|
|
var sn = "8UUXN5400A079H";
|
|
|
|
|
var result = JsonConvert.DeserializeObject<TopicServicesRequest<dynamic>>(message);
|
|
|
|
|
var method = result.method;
|
|
|
|
|
var data = result.data;
|
|
|
|
|
//_logger.LogInformation($"主题:{topic}\n消息:{message}");
|
|
|
|
|
long code = 0;
|
|
|
|
|
var isHandle = IsDuplicate(Md5.Encrypt(message));
|
|
|
|
|
//_logger.LogDebug($"md5: {isHandle} 重复否:{IsDuplicate(Md5.Encrypt(message))} 信息:{message} ");
|
|
|
|
|
if (isHandle)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("跳过处理");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogDebug("航线进度未跳过处理");
|
|
|
|
|
code = data.result; // result
|
|
|
|
|
|
|
|
|
|
var waylineMissionState = (int)data.output.ext.wayline_mission_state;
|
|
|
|
|
string flightId1 = (string)data.output.ext.flight_id;
|
|
|
|
|
var taskAssign1 = GetTaskAssignByFlightId(flightId1);
|
|
|
|
|
// 处理航线进度 ,也有可能是失败
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var step = (int)data.output.progress.current_step;
|
|
|
|
|
_logger.LogDebug($"航线进度:{waylineMissionState} {step} {message}");
|
|
|
|
|
if (step.Equals(25)) // 航线执行
|
|
|
|
|
{
|
|
|
|
|
var task = await Repository.AsSugarClient().Queryable<LasaTask>()
|
|
|
|
|
.FirstAsync(y => y.Id == taskAssign1.TaskId);
|
|
|
|
|
if (task != null && !string.IsNullOrEmpty(task.AIInspection) &&
|
|
|
|
|
task.AIInspection.Equals("true") && string.IsNullOrEmpty(task.PushUrl))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogDebug("执行AI 智能巡检。。。。。");
|
|
|
|
|
var rtmp = "rtmp://box.wisestcity.com:1935/live/55";
|
|
|
|
|
var param =
|
|
|
|
|
@$"{{""bid"": ""{Guid.NewGuid().ToString()}"",""method"": ""live_start_push"",""tid"": ""{Guid.NewGuid().ToString()}"",
|
|
|
|
|
""timestamp"": {DateTimeOffset.Now.ToUnixTimeMilliseconds()},
|
|
|
|
|
""data"": {{
|
|
|
|
|
""url_type"": 1,
|
|
|
|
|
""url"": ""{rtmp}"",
|
|
|
|
|
""video_id"": ""8UUXN5400A079H/165-0-7/normal-0"",
|
|
|
|
|
""video_quality"": 3
|
|
|
|
|
}}
|
|
|
|
|
}}";
|
|
|
|
|
//thing/product/{gateway_sn}/services
|
|
|
|
|
var topicRequest = $"thing/product/{sn}/services";
|
|
|
|
|
var x = RemoveSpecificChars(param);
|
|
|
|
|
_logger.LogDebug($"直播参数:{x}");
|
|
|
|
|
await _mqttClientManager.PublishAsync(topicRequest, x);
|
|
|
|
|
var req = new CallAiModel { TaskId = taskAssign1.TaskId, RtmpUrl = rtmp };
|
|
|
|
|
await CallAiModel(req);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 航线成功
|
|
|
|
|
/*
|
|
|
|
|
if (waylineMissionState.Equals(9)) // 航结结束,更新任务状态
|
|
|
|
|
{
|
|
|
|
|
var task = await Repository.AsSugarClient().Queryable<LasaTask>()
|
|
|
|
|
.FirstAsync(y => y.Id == taskAssign1.TaskId);
|
|
|
|
|
if (!string.IsNullOrEmpty(task.AIInspection) && task.AIInspection.Equals(true) &&
|
|
|
|
|
!string.IsNullOrEmpty(task.PushUrl))
|
|
|
|
|
{
|
|
|
|
|
// todo 停止直播
|
|
|
|
|
// todo 停止 aimodel 运行
|
|
|
|
|
var para = @$"{{
|
|
|
|
|
""bid"": ""{Guid.NewGuid().ToString()}"",
|
|
|
|
|
""data"": {{
|
|
|
|
|
""video_id"": ""8UUXN5400A079H/165-0-7/normal-0""
|
|
|
|
|
}},
|
|
|
|
|
""tid"":""{Guid.NewGuid().ToString()}"",
|
|
|
|
|
""timestamp:"": {DateTimeOffset.Now.ToUnixTimeMilliseconds()},
|
|
|
|
|
""method"": ""live_stop_push""
|
|
|
|
|
}}";
|
|
|
|
|
var topicRequest = $"thing/product/{sn}/services";
|
|
|
|
|
await _mqttClientManager.PublishAsync(topicRequest, RemoveSpecificChars(para));
|
|
|
|
|
using var httpClient = new HttpClient();
|
|
|
|
|
await httpClient.PostAsync("http://192.168.10.131:9025/stop_detection", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var record = new LasaTask()
|
|
|
|
|
{
|
|
|
|
|
Id = taskAssign1.TaskId,
|
|
|
|
|
Status = 5
|
|
|
|
|
};
|
|
|
|
|
// await Repository.AsSugarClient().Updateable(record).IgnoreNullColumns().ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseZhibo(string videoId)
|
|
|
|
|
{
|
|
|
|
|
var sn = "8UUXN5400A079H";
|
|
|
|
|
var para = @$"{{
|
|
|
|
|
""bid"": ""{Guid.NewGuid().ToString()}"",
|
|
|
|
|
""data"": {{
|
|
|
|
|
""video_id"": ""8UUXN5400A079H/165-0-7/normal-0""
|
|
|
|
|
}},
|
|
|
|
|
""tid"":""{Guid.NewGuid().ToString()}"",
|
|
|
|
|
""timestamp:"": {DateTimeOffset.Now.ToUnixTimeMilliseconds()},
|
|
|
|
|
""method"": ""live_stop_push""
|
|
|
|
|
}}";
|
|
|
|
|
var topicRequest = $"thing/product/{sn}/services";
|
|
|
|
|
_mqttClientManager.PublishAsync(topicRequest, para);
|
|
|
|
|
using var httpClient = new HttpClient();
|
|
|
|
|
httpClient.PostAsync("http://192.168.10.131:9025/stop_detection", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string RemoveSpecificChars(string input)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(input))
|
|
|
|
|
return input;
|
|
|
|
|
|
|
|
|
|
var charsToRemove = new char[] { ' ', '\r', '\n', '\t' };
|
|
|
|
|
return string.Concat(input.Where(c => !charsToRemove.Contains(c)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|