using FreeRedis; using MessagePack.Resolvers; using MessagePack; using Microsoft.AspNetCore.Mvc; using WCS.Entity.Protocol.DataStructure; using WMS.BZWeb.Extensions; using WCS.Entity.Protocol.Protocol.DataStructure; using WMS.BZModels.Dto.PT.SysConDtos; using WMS.BZModels; using System.Reflection; using WCS.Entity.Protocol.Station; using System.ComponentModel; using Newtonsoft.Json; using NPOI.POIFS.Crypt.Dsig; namespace WMS.BZWeb.Areas.PTManager.Controllers { [Area("PTManager")] public class DeviceInfoController : MvcControllerBase { //, "1017", "1018", "1019", "1020", "1021", "1022", "1023", "1024" private string[] devices = new string[] { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009", "1010", "1011", "1012", "1013", "1014", "1015", "1016" }; private readonly RedisClient _PTRedis; public DeviceInfoController(IServiceProvider serviceProvider) { MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block); var redisDict = serviceProvider.GetRequiredService>(); if (redisDict.Any()) { _PTRedis = redisDict["PTRedis"]; _PTRedis.Serialize = obj => MessagePackSerializer.Serialize(obj);// JsonConvert.SerializeObject(obj); _PTRedis.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 = _PTRedis.Get("DeviceDataPack"); //var len = _PTRedis.LLen("Packs"); //var deviceDataPack = _PTRedis.LIndex("Packs", len - 1); //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("没有数据!"); } // InOutStationDto public ActionResult GetInOutStationStatus(string queryJson) { List inOutStationDtos = new List(); var deviceDataPack = _PTRedis.Get("DeviceDataPack"); //var len = _PTRedis.LLen("Packs"); //var deviceDataPack = _PTRedis.LIndex("Packs", len - 1); //DeviceDataPack dp = new DeviceDataPack(); if (deviceDataPack != null && deviceDataPack.StationDatas != null && deviceDataPack.StationDatas.Datas != null && deviceDataPack.StationDatas.Datas.Count() > 0) { var query = new PinKuQueryDto(); if (!string.IsNullOrEmpty(queryJson)) { query = JsonConvert.DeserializeObject(queryJson) ?? new PinKuQueryDto(); } if (!string.IsNullOrWhiteSpace(query.KeyWord)) { var datas = deviceDataPack.StationDatas.Datas.Where (o => o.Code .Contains( query.KeyWord) ).ToList(); if (datas != null && datas.Any()) { foreach ( var data in datas ) { if(!devices.Contains(data.Code)) { continue; } inOutStationDtos.Add(new InOutStationDto() { StatusName = data.D520.GoodsStart.ToString(), PHStatusName = data.D523.Status.GetDescription(), WareHouseName = "盘条", Code = data.Code, Name = data.Code, }); } } } else { for (var i = 0; i < devices.Length; i++) { var data = deviceDataPack.StationDatas.Datas.FirstOrDefault(o => o.Code == devices[i]); if (data != null) { inOutStationDtos.Add(new InOutStationDto() { StatusName = data.D520.GoodsStart.ToString(), PHStatusName = data.D523.Status.GetDescription(), WareHouseName = "盘条", Code = data.Code, Name = data.Code, }); } } } } return Success(inOutStationDtos); } } }