Redis获取数采数据
This commit is contained in:
@@ -13,7 +13,5 @@ namespace Tnb.ProductionMgr.Interfaces
|
||||
/// 根据机号获取重量
|
||||
/// </summary>
|
||||
Task<dynamic> GetWeight(string key, string field);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
77
ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs
Normal file
77
ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs
Normal 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
@@ -23,6 +23,7 @@ using Senparc.Weixin;
|
||||
using Senparc.Weixin.Entities;
|
||||
using Senparc.Weixin.RegisterServices;
|
||||
using SqlSugar;
|
||||
using Tnb.ProductionMgr;
|
||||
using Tnb.WarehouseMgr;
|
||||
|
||||
namespace JNPF.API.Entry;
|
||||
@@ -66,7 +67,7 @@ public class Startup : AppStartup
|
||||
|
||||
//定时任务
|
||||
services.AddHostedService<TimedTaskBackgroundService>();
|
||||
|
||||
services.AddHostedService<RedisBackGround>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -224,12 +224,20 @@ public class RedisCache : ICache, ISingleton
|
||||
long second = RedisHelper.PTtl(key);
|
||||
return DateTime.Now.AddMilliseconds(second);
|
||||
}
|
||||
public string GetHash(string key, string field)
|
||||
public Task<string> GetHash(string key, string field)
|
||||
{
|
||||
return RedisHelper.HGet(key, field);
|
||||
return RedisHelper.HGetAsync(key, field);
|
||||
}
|
||||
public bool HashExist(string key, string field)
|
||||
public Task<bool> HashExist(string key, string field)
|
||||
{
|
||||
return RedisHelper.HExists(key, field);
|
||||
return RedisHelper.HExistsAsync(key, field);
|
||||
}
|
||||
public Task<Dictionary<string, string>> HGetAll(string key)
|
||||
{
|
||||
return RedisHelper.HGetAllAsync(key);
|
||||
}
|
||||
public Task<bool> HSet(string key, string field, string value)
|
||||
{
|
||||
return RedisHelper.HSetAsync(key, field,value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user