123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- 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<Dictionary<string, RedisClient>>();
- 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>("DeviceDataPack");
-
- //var len = _PTRedis.LLen("Packs");
- //var deviceDataPack = _PTRedis.LIndex<DeviceDataPack>("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<StationData>(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<SRMData>(o => o.Code == keyValue?.ToUpper());
- if (data != null)
- {
- var result = data.GetAttributesDBDetail();
- return Success(result);
- }
- }
- return Fail("没有数据!");
- }
- // InOutStationDto
- public ActionResult GetInOutStationStatus(string queryJson)
- {
- List<InOutStationDto> inOutStationDtos = new List<InOutStationDto>();
- var deviceDataPack = _PTRedis.Get<DeviceDataPack>("DeviceDataPack");
- //var len = _PTRedis.LLen("Packs");
- //var deviceDataPack = _PTRedis.LIndex<DeviceDataPack>("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<PinKuQueryDto>(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<StationData>(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);
- }
- }
- }
|