Commit ea5dfad7 by zxw

去除redis数据写入

mqtt不记录连接断开数据
parent 162e7717
......@@ -7373,11 +7373,11 @@ namespace JunmpPoliceStation.Controllers
sizeList.AddRange(UpdateEpc.Select(x => x.EquipmentSizecode).ToList());
_unitOfWork.CalcThreshold(sizeList.Distinct().ToList(), orgId, warehouseId);
//更新redis上货架相关数据
if (!ChannelExtension.UpdateShelfAndInventoryToRedis(_unitOfWork, warehouseId, out string msg))
{
_logger.LogError("更新redis上货架相关数据失败:" + msg);
}
////更新redis上货架相关数据
//if (!ChannelExtension.UpdateShelfAndInventoryToRedis(_unitOfWork, warehouseId, out string msg))
//{
// _logger.LogError("更新redis上货架相关数据失败:" + msg);
//}
return JsonManager.ReturnSuccessResponse(resultEpc);
}
......
......@@ -139,62 +139,62 @@ namespace JunmpPoliceStation.Extensions
public void OnMqttServerClientConnected(MqttServerClientConnectedEventArgs e)
{
using (var scope = Startup.ServiceLocator.Instance.CreateScope())
{
var dbContext = scope.ServiceProvider.GetService<JunmppolicesqlContext>();
//using (var scope = Startup.ServiceLocator.Instance.CreateScope())
//{
// var dbContext = scope.ServiceProvider.GetService<JunmppolicesqlContext>();
dbContext?.ApiMqttMessages.Add(new ApiMqttMessage
{
Id = Guid.NewGuid().ToString(),
CreateTime = DateTime.Now,
DeviceNo = e.ClientId,
DeviceType = e.ClientId.Substring(0, 2),
Topic = "Connected",
Payload = $"客户端[{e.ClientId}]已连接"
});
dbContext?.SaveChanges();
}
// dbContext?.ApiMqttMessages.Add(new ApiMqttMessage
// {
// Id = Guid.NewGuid().ToString(),
// CreateTime = DateTime.Now,
// DeviceNo = e.ClientId,
// DeviceType = e.ClientId.Substring(0, 2),
// Topic = "Connected",
// Payload = $"客户端[{e.ClientId}]已连接"
// });
// dbContext?.SaveChanges();
//}
//Console.WriteLine($"客户端[{e.ClientId}]已连接");
}
public void OnMqttServerClientDisconnected(MqttServerClientDisconnectedEventArgs e)
{
using (var scope = Startup.ServiceLocator.Instance.CreateScope())
{
var dbContext = scope.ServiceProvider.GetService<JunmppolicesqlContext>();
//using (var scope = Startup.ServiceLocator.Instance.CreateScope())
//{
// var dbContext = scope.ServiceProvider.GetService<JunmppolicesqlContext>();
dbContext?.ApiMqttMessages.Add(new ApiMqttMessage
{
Id = Guid.NewGuid().ToString(),
CreateTime = DateTime.Now,
DeviceNo = e.ClientId,
DeviceType = e.ClientId.Substring(0, 2),
Topic = "Disconnected",
Payload = $"客户端[{e.ClientId}]已断开连接!"
});
dbContext?.SaveChanges();
}
// dbContext?.ApiMqttMessages.Add(new ApiMqttMessage
// {
// Id = Guid.NewGuid().ToString(),
// CreateTime = DateTime.Now,
// DeviceNo = e.ClientId,
// DeviceType = e.ClientId.Substring(0, 2),
// Topic = "Disconnected",
// Payload = $"客户端[{e.ClientId}]已断开连接!"
// });
// dbContext?.SaveChanges();
//}
//Console.WriteLine($"客户端[{e.ClientId}]已断开连接!");
}
public void OnMqttServerClientSubscribedTopic(MqttServerClientSubscribedTopicEventArgs e)
{
using (var scope = Startup.ServiceLocator.Instance.CreateScope())
{
var dbContext = scope.ServiceProvider.GetService<JunmppolicesqlContext>();
//using (var scope = Startup.ServiceLocator.Instance.CreateScope())
//{
// var dbContext = scope.ServiceProvider.GetService<JunmppolicesqlContext>();
var message = new ApiMqttMessage
{
Id = Guid.NewGuid().ToString(),
CreateTime = DateTime.Now,
DeviceNo = e.ClientId,
DeviceType = e.ClientId.Substring(0, 2),
Topic = e.TopicFilter.Topic,
Payload = $"客户端[{e.ClientId}]已成功订阅主题[{e.TopicFilter}]!"
};
dbContext?.ApiMqttMessages.Add(message);
dbContext?.SaveChanges();
}
// var message = new ApiMqttMessage
// {
// Id = Guid.NewGuid().ToString(),
// CreateTime = DateTime.Now,
// DeviceNo = e.ClientId,
// DeviceType = e.ClientId.Substring(0, 2),
// Topic = e.TopicFilter.Topic,
// Payload = $"客户端[{e.ClientId}]已成功订阅主题[{e.TopicFilter}]!"
// };
// dbContext?.ApiMqttMessages.Add(message);
// dbContext?.SaveChanges();
//}
//Console.WriteLine($"客户端[{e.ClientId}]已成功订阅主题[{e.TopicFilter}]!");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论