You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
6.2 KiB
C#
155 lines
6.2 KiB
C#
using DS.Module.Core;
|
|
using DS.WMS.Common.Data;
|
|
using DS.WMS.Core.OpenApiModule.Entity;
|
|
using DS.WMS.Core.OpenApiModule.Interface;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.OpenApiModule.Method;
|
|
|
|
public class OpenService : IOpenService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public OpenService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理海康高温报警联动事件
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult> HKDealHighTemperature(LinkEventNotify data)
|
|
{
|
|
var events = data.Params.Events;
|
|
try
|
|
{
|
|
//开启事务
|
|
await db.Ado.BeginTranAsync();
|
|
foreach (var item in events)
|
|
{
|
|
var hkEvent = item.Adapt<tb_HKEvent>();
|
|
//取值联动结果
|
|
if (hkEvent.Status == 4)
|
|
{
|
|
hkEvent.LinkageAcion = "";
|
|
hkEvent.LinkageResult = "";
|
|
// await db.Insertable(hkEvent).ExecuteCommandAsync();
|
|
foreach (var detail in item.EventDetails)
|
|
{
|
|
var id = Guid.NewGuid();
|
|
// var eventDetail = detail.Adapt<tb_HKEventDetail>();
|
|
// eventDetail.EventId = hkEvent.EventId;
|
|
// eventDetail.EventDetailId = Guid.NewGuid();
|
|
// eventDetail.RelationId = id;
|
|
// await db.Insertable(eventDetail).ExecuteCommandAsync();
|
|
|
|
#region 温度信息
|
|
|
|
var thermometryData = JsonConvert.DeserializeObject<ThermometryData>(detail.Data.ToString());
|
|
var thermometryInfo = thermometryData.Thermometry[0];
|
|
if (thermometryInfo.AlarmLevel == 1)
|
|
{
|
|
var thermometry = thermometryData.Adapt<tb_HKThermometry>();
|
|
thermometry.RelationId = id;
|
|
thermometry.AlarmLevel = thermometryInfo.AlarmLevel;
|
|
thermometry.AlarmFilterTime = thermometryInfo.AlarmFilterTime;
|
|
thermometry.AlarmRule = thermometryInfo.AlarmRule;
|
|
thermometry.AlarmType = thermometryInfo.AlarmType;
|
|
thermometry.AlertFilterTime = thermometryInfo.AlertFilterTime;
|
|
thermometry.CurTemperature = thermometryInfo.CurTemperature;
|
|
thermometry.RuleTemperature = thermometryInfo.RuleTemperature;
|
|
thermometry.ThermometryUnit = thermometryInfo.ThermometryUnit;
|
|
thermometry.ToleranceTemperature = thermometryInfo.ToleranceTemperature;
|
|
|
|
await db.Insertable(thermometry).ExecuteCommandAsync();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
|
|
await db.Ado.CommitTranAsync();
|
|
return DataResult.Successed("温度报警回调成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await db.Ado.RollbackTranAsync();
|
|
Logger.Log(LogLevel.Error,
|
|
DateTime.Now.ToString() + ex.ToString());
|
|
Logger.Log(LogLevel.Info,
|
|
DateTime.Now.ToString() + JsonConvert.SerializeObject(data));
|
|
return DataResult.Failed("温度报警回调失败!" + ",请联系管理员!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理海康越界侦测报警
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult> HKDealLineDetection(LinkEventNotify data)
|
|
{
|
|
var events = data.Params.Events;
|
|
try
|
|
{
|
|
//开启事务
|
|
await db.Ado.BeginTranAsync();
|
|
foreach (var item in events)
|
|
{
|
|
// var hkEvent = item.Adapt<tb_HKEvent>();
|
|
//取值联动结果
|
|
if (item.Status == 4)
|
|
{
|
|
foreach (var detail in item.EventDetails)
|
|
{
|
|
var id = Guid.NewGuid();
|
|
|
|
#region 越界侦测信息
|
|
|
|
var lineDetectionData = JsonConvert.DeserializeObject<LineDetectionData>(detail.Data.ToString());
|
|
var lineDetectionInfo = lineDetectionData.LineDetection[0];
|
|
|
|
var lineDetection = lineDetectionData.Adapt<tb_HKLineDetection>();
|
|
lineDetection.RelationId = id;
|
|
lineDetection.Direction = lineDetectionInfo.Direction;
|
|
lineDetection.PlaneHeight = lineDetectionInfo.PlaneHeight;
|
|
lineDetection.DetectionTarget = lineDetectionInfo.DetectionTarget;
|
|
lineDetection.Rate = lineDetectionInfo.Rate;
|
|
lineDetection.Duration = lineDetectionInfo.Duration;
|
|
lineDetection.SensitivityLevel = lineDetectionInfo.SensitivityLevel;
|
|
|
|
await db.Insertable(lineDetection).ExecuteCommandAsync();
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
await db.Ado.CommitTranAsync();
|
|
return DataResult.Successed("越界侦测报警回调成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await db.Ado.RollbackTranAsync();
|
|
Logger.Log(LogLevel.Error,
|
|
DateTime.Now.ToString() + ex.ToString());
|
|
Logger.Log(LogLevel.Info,
|
|
DateTime.Now.ToString() + JsonConvert.SerializeObject(data));
|
|
return DataResult.Failed("越界侦测报警回调失败!" + ",请联系管理员!");
|
|
}
|
|
}
|
|
} |