Redis获取数采数据

This commit is contained in:
qianjiawei
2023-11-03 15:42:51 +08:00
parent 821358621c
commit e12cc45299
5 changed files with 118 additions and 14 deletions

View File

@@ -13,7 +13,5 @@ namespace Tnb.ProductionMgr.Interfaces
/// 根据机号获取重量
/// </summary>
Task<dynamic> GetWeight(string key, string field);
}
}

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF.Common.Cache;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using UAParser;
using Tnb.ProductionMgr.Interfaces;
using Tnb.ProductionMgr.Entities.Dto;
namespace Tnb.ProductionMgr
{
//redis定时获取数采数据
public class RedisBackGround : IHostedService, IDisposable
{
private Timer? packtimer;
private Timer? limittimer;
private readonly RedisCache _redisCache;
private readonly IPrdInstockService _prdInstockService;
public RedisBackGround(RedisCache redisCache, IPrdInstockService prdInstockService)
{
_redisCache = redisCache;
_prdInstockService = prdInstockService;
}
//获取装箱状态
private void GetPackStatus(object state)
{
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine($"获取装箱状态");
/*
var data = _redisCache.GetHash("TY4C-JICHU", "weight_4").Result;
var res = JsonConvert.DeserializeObject<JObject>(data);
if (res != null && res["Value"] != null)
{
InstockInput instockInput = new InstockInput();
instockInput.equip_code = res["Value"]!.ToString();
_prdInstockService.InstockTypeOne(instockInput);
Console.WriteLine(decimal.Parse(res["Value"]!.ToString()));
}*/
}
//获取限位状态
private void GetLimitStatus(object state)
{
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine($"获取限位状态");
/*
var data = _redisCache.GetHash("TY4C-JICHU", "weight_4").Result;
var res = JsonConvert.DeserializeObject<JObject>(data);
if (res != null && res["Value"] != null)
{
InstockInput instockInput = new InstockInput();
instockInput.equip_code = res["Value"]!.ToString();
_prdInstockService.InstockTypeOne(instockInput);
Console.WriteLine(decimal.Parse(res["Value"]!.ToString()));
}*/
}
public void Dispose()
{
packtimer?.Dispose();
limittimer?.Dispose();
}
public Task StartAsync(CancellationToken cancellationToken)
{
// packtimer = new Timer(GetPackStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));
// limittimer = new Timer(GetLimitStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}

File diff suppressed because one or more lines are too long