using DS.Module.Core; using DS.Module.Core.Extensions; using DS.WMS.Common.Data; using DS.WMS.Core.CarModule.Entity; using DS.WMS.Core.OpenApiModule.Dtos; using DS.WMS.Core.OpenApiModule.Entity; using DS.WMS.Core.OpenApiModule.Interface; using DS.WMS.Core.SecurityModule.Dtos; using DS.WMS.Core.SecurityModule.Entity; 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(); /// /// /// /// public OpenService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); } /// /// 处理海康高温报警联动事件 /// /// /// public async Task HKDealHighTemperature(LinkEventNotify data) { var events = data.Params.Events; try { //开启事务 await db.Ado.BeginTranAsync(); foreach (var item in events) { var hkEvent = item.Adapt(); //取值联动结果 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(); // eventDetail.EventId = hkEvent.EventId; // eventDetail.EventDetailId = Guid.NewGuid(); // eventDetail.RelationId = id; // await db.Insertable(eventDetail).ExecuteCommandAsync(); #region 温度信息 var thermometryData = JsonConvert.DeserializeObject(detail.Data.ToString()); var thermometryInfo = thermometryData.Thermometry[0]; if (thermometryInfo.AlarmLevel == 1) { var thermometry = thermometryData.Adapt(); 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("温度报警回调失败!" + ",请联系管理员!"); } } /// /// 处理海康越界侦测报警 /// /// /// public async Task HKDealLineDetection(LinkEventNotify data) { var events = data.Params.Events; try { //开启事务 await db.Ado.BeginTranAsync(); foreach (var item in events) { // var hkEvent = item.Adapt(); //取值联动结果 if (item.Status == 4) { foreach (var detail in item.EventDetails) { var id = Guid.NewGuid(); #region 越界侦测信息 var lineDetectionData = JsonConvert.DeserializeObject(detail.Data.ToString()); var lineDetectionInfo = lineDetectionData.LineDetection[0]; var lineDetection = lineDetectionData.Adapt(); 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("越界侦测报警回调失败!" + ",请联系管理员!"); } } // public async Task> GetInternalCarInfoAsync(string plateNumber) // { // var car = db.Queryable().Where(x => // x.PlateNumber == plateNumber.Trim() && (x.IsTemporaryCar == false || (x.IsTemporaryCar == true && // x.BeginTime <= DateTime.Now && x.EndTime >= DateTime.Now)) && x.Status == 0) // .Select() // .First(); // // if (car.IsNull()) // { // return DataResult.Failed("内部车辆不存在"); // } // // return DataResult.Success("获取数据成功", car); // } }