DeviceInfoController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using FreeRedis;
  2. using MessagePack.Resolvers;
  3. using MessagePack;
  4. using Microsoft.AspNetCore.Mvc;
  5. using WCS.Entity.Protocol.DataStructure;
  6. using WMS.BZWeb.Extensions;
  7. using WCS.Entity.Protocol.Protocol.DataStructure;
  8. using WMS.BZModels.Dto.PT.SysConDtos;
  9. using WMS.BZModels;
  10. using System.Reflection;
  11. using WCS.Entity.Protocol.Station;
  12. using System.ComponentModel;
  13. using Newtonsoft.Json;
  14. using NPOI.POIFS.Crypt.Dsig;
  15. namespace WMS.BZWeb.Areas.PTManager.Controllers
  16. {
  17. [Area("PTManager")]
  18. public class DeviceInfoController : MvcControllerBase
  19. {
  20. //, "1017", "1018", "1019", "1020", "1021", "1022", "1023", "1024"
  21. private string[] devices = new string[] { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009", "1010", "1011", "1012", "1013", "1014", "1015", "1016" };
  22. private readonly RedisClient _PTRedis;
  23. public DeviceInfoController(IServiceProvider serviceProvider)
  24. {
  25. MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block);
  26. var redisDict = serviceProvider.GetRequiredService<Dictionary<string, RedisClient>>();
  27. if (redisDict.Any())
  28. {
  29. _PTRedis = redisDict["PTRedis"];
  30. _PTRedis.Serialize = obj => MessagePackSerializer.Serialize(obj);// JsonConvert.SerializeObject(obj);
  31. _PTRedis.DeserializeRaw = (bytes, type) => MessagePackSerializer.Deserialize(type, bytes);// JsonConvert.DeserializeObject(json, type);
  32. }
  33. }
  34. public IActionResult StationDetail()
  35. {
  36. return View();
  37. }
  38. public ActionResult GetDeviceData(string keyValue)
  39. {
  40. if (string.IsNullOrEmpty(keyValue))
  41. {
  42. return Fail("设备编号不能为空!");
  43. }
  44. var deviceDataPack = _PTRedis.Get<DeviceDataPack>("DeviceDataPack");
  45. //var len = _PTRedis.LLen("Packs");
  46. //var deviceDataPack = _PTRedis.LIndex<DeviceDataPack>("Packs", len - 1);
  47. //DeviceDataPack dp = new DeviceDataPack();
  48. if (deviceDataPack != null && deviceDataPack.StationDatas != null && deviceDataPack.StationDatas.Datas != null
  49. && deviceDataPack.StationDatas.Datas.Count() > 0)
  50. {
  51. var data = deviceDataPack.StationDatas.Datas.FirstOrDefault<StationData>(o => o.Code == keyValue);
  52. if (data != null)
  53. {
  54. var result = data.GetAttributesDBDetail();
  55. return Success(result);
  56. }
  57. }
  58. if (deviceDataPack != null && deviceDataPack.SRMDatas != null && deviceDataPack.SRMDatas.Datas != null
  59. && deviceDataPack.SRMDatas.Datas.Count() > 0)
  60. {
  61. var data = deviceDataPack.SRMDatas.Datas.FirstOrDefault<SRMData>(o => o.Code == keyValue?.ToUpper());
  62. if (data != null)
  63. {
  64. var result = data.GetAttributesDBDetail();
  65. return Success(result);
  66. }
  67. }
  68. return Fail("没有数据!");
  69. }
  70. // InOutStationDto
  71. public ActionResult GetInOutStationStatus(string queryJson)
  72. {
  73. List<InOutStationDto> inOutStationDtos = new List<InOutStationDto>();
  74. var deviceDataPack = _PTRedis.Get<DeviceDataPack>("DeviceDataPack");
  75. //var len = _PTRedis.LLen("Packs");
  76. //var deviceDataPack = _PTRedis.LIndex<DeviceDataPack>("Packs", len - 1);
  77. //DeviceDataPack dp = new DeviceDataPack();
  78. if (deviceDataPack != null && deviceDataPack.StationDatas != null && deviceDataPack.StationDatas.Datas != null
  79. && deviceDataPack.StationDatas.Datas.Count() > 0)
  80. {
  81. var query = new PinKuQueryDto();
  82. if (!string.IsNullOrEmpty(queryJson))
  83. {
  84. query = JsonConvert.DeserializeObject<PinKuQueryDto>(queryJson) ?? new PinKuQueryDto();
  85. }
  86. if (!string.IsNullOrWhiteSpace(query.KeyWord))
  87. {
  88. var datas = deviceDataPack.StationDatas.Datas.Where (o => o.Code .Contains( query.KeyWord) ).ToList();
  89. if (datas != null && datas.Any())
  90. {
  91. foreach ( var data in datas )
  92. {
  93. if(!devices.Contains(data.Code)) { continue; }
  94. inOutStationDtos.Add(new InOutStationDto()
  95. {
  96. StatusName = data.D520.GoodsStart.ToString(),
  97. PHStatusName = data.D523.Status.GetDescription(),
  98. WareHouseName = "盘条",
  99. Code = data.Code,
  100. Name = data.Code,
  101. });
  102. }
  103. }
  104. }
  105. else
  106. {
  107. for (var i = 0; i < devices.Length; i++)
  108. {
  109. var data = deviceDataPack.StationDatas.Datas.FirstOrDefault<StationData>(o => o.Code == devices[i]);
  110. if (data != null)
  111. {
  112. inOutStationDtos.Add(new InOutStationDto()
  113. {
  114. StatusName = data.D520.GoodsStart.ToString(),
  115. PHStatusName = data.D523.Status.GetDescription(),
  116. WareHouseName = "盘条",
  117. Code = data.Code,
  118. Name = data.Code,
  119. });
  120. }
  121. }
  122. }
  123. }
  124. return Success(inOutStationDtos);
  125. }
  126. }
  127. }