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.

233 lines
9.2 KiB
C#

5 months ago
using DS.Module.CaiNiaoApi;
using DS.Module.CaiNiaoApi.CaiNiaoReq;
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();
5 months ago
private readonly ISendCaiNiaoMsgService _iSendCaiNiaoMsgService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public OpenService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
5 months ago
_iSendCaiNiaoMsgService= _serviceProvider.GetRequiredService<ISendCaiNiaoMsgService>();
}
/// <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("越界侦测报警回调失败!" + ",请联系管理员!");
}
}
5 months ago
/// <summary>
/// 车辆监控回调
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public async Task<DataResult> HKDealCarMonitor(CarEventNotify 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)
{
var detail = item.Data;
#region 车辆过车信息
//正常过车
if (detail.IllegalType == 0)
{
var rec = new CarInRecordReq
{
ParkingLotCode = detail.MonitorIndexCode,
CarInTime = detail.CrossTime,
CarInPic = detail.PicUrl.VehiclePicUrl,
LaneCode = detail.MonitorIndexCode,
ParkingRecordId = detail.EventIndex,
CarNum = detail.PlateNo,
};
await _iSendCaiNiaoMsgService.SendCarInRecord(rec);
}
#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<DataResult<InternalCarInfoViewModel>> GetInternalCarInfoAsync(string plateNumber)
// {
// var car = db.Queryable<tb_InternalCar>().Where(x =>
// x.PlateNumber == plateNumber.Trim() && (x.IsTemporaryCar == false || (x.IsTemporaryCar == true &&
// x.BeginTime <= DateTime.Now && x.EndTime >= DateTime.Now)) && x.Status == 0)
// .Select<InternalCarInfoViewModel>()
// .First();
//
// if (car.IsNull())
// {
// return DataResult<InternalCarInfoViewModel>.Failed("内部车辆不存在");
// }
//
// return DataResult<InternalCarInfoViewModel>.Success("获取数据成功", car);
// }
}