using System.Collections; using JNPF.Common.Cache; using JNPF.Common.Extension; using JNPF.Common.Manager; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.TaskScheduler; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Tnb.ProductionMgr.Interfaces; namespace Tnb.ProductionMgr { /// /// 数据采集 /// [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] public class RedisDataService: IRedisDataService, IDynamicApiController, ITransient { private readonly RedisCache _redisCache; public RedisDataService(RedisCache redisCache) { _redisCache = redisCache; } /// /// 根据机号获取重量 /// [HttpPost] public async Task GetWeight(string device, string jihao) { /* var dic =await _redisCache.HGetAll("TY4C-JICHU"); string a = ""; foreach (var kvp in dic) { a += kvp.Key + "&" + kvp.Value + "$"; } string aa = ""; var ss= aa.Split('$', StringSplitOptions.RemoveEmptyEntries); foreach (var s in ss) { var b = s.Split('&'); await _redisCache.HSet("TY4C-JICHU", b[0], b[1]); }*/ decimal result = 0; bool flag = await _redisCache.HashExist(device, jihao); if (!flag) throw Oops.Bah("没有找到" + device + "----" + jihao + "的数据"); var data = await _redisCache.GetHash(device, jihao); var res = JsonConvert.DeserializeObject(data); if (res != null && res["Value"] != null) { result = decimal.Parse(res["Value"]!.ToString()); } else { throw Oops.Bah("数据格式错误"); } return result; } } }