using FreeRedis; using MessagePack.Resolvers; using MessagePack; using Microsoft.AspNetCore.Mvc; using WMS.BZWeb.Extensions; using WCS.Protocol.HJ.DataStructure; namespace WMS.BZWeb.Areas.CPManager.Controllers { [Area("CPManager")] public class DeviceInfoController : MvcControllerBase { private readonly RedisClient _CPRedis; public DeviceInfoController(IServiceProvider serviceProvider ) { MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block); var redisDict = serviceProvider.GetRequiredService>(); if (redisDict.Any()) { _CPRedis = redisDict["CPRedis"]; _CPRedis.Serialize = obj => MessagePackSerializer.Serialize(obj);// JsonConvert.SerializeObject(obj); _CPRedis.DeserializeRaw = (bytes, type) => MessagePackSerializer.Deserialize(type, bytes);// JsonConvert.DeserializeObject(json, type); } } public IActionResult StationDetail() { return View(); } public ActionResult GetDeviceData(string keyValue) { if (string.IsNullOrEmpty(keyValue)) { return Fail("设备编号不能为空!"); } var deviceDataPack = _CPRedis.Get("DeviceDataPack"); //DeviceDataPack dp = new DeviceDataPack(); if (deviceDataPack != null && deviceDataPack.StationDatas != null && deviceDataPack.StationDatas.Datas != null && deviceDataPack.StationDatas.Datas.Count() > 0) { var data = deviceDataPack.StationDatas.Datas.FirstOrDefault(o => o.Code == keyValue); if (data != null) { var result = data.GetAttributesDBDetail(); return Success(result); } } if (deviceDataPack != null && deviceDataPack.SRMDatas != null && deviceDataPack.SRMDatas.Datas != null && deviceDataPack.SRMDatas.Datas.Count() > 0) { var data = deviceDataPack.SRMDatas.Datas.FirstOrDefault(o => o.Code == keyValue?.ToUpper()); if (data != null) { var result = data.GetAttributesDBDetail(); return Success(result); } } return Fail("没有数据!"); } } }