Commit ea5dfad7 by zxw

去除redis数据写入

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