Files
tnb.server/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs
2023-11-03 15:42:51 +08:00

77 lines
2.8 KiB
C#

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;
}
}
}