This commit is contained in:
qianjiawei
2023-11-07 16:16:50 +08:00
parent 1dbb17f103
commit f76a04059d
6 changed files with 319 additions and 44 deletions

View File

@@ -2,6 +2,7 @@
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Tnb.Common.Redis;
using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Entities.Enums;
using Tnb.ProductionMgr.Interfaces;
@@ -11,25 +12,24 @@ namespace Tnb.ProductionMgr
//redis定时获取数采数据
public class RedisBackGround : IHostedService, IDisposable
{
private readonly Timer? packtimer;
private readonly Timer? limittimer;
private readonly RedisCache _redisCache;
private Timer? ZSpacktimer;
private Timer? JCpacktimer;
private Timer? limittimer;
private readonly RedisData _redisData;
private readonly IPrdInstockService _prdInstockService;
public RedisBackGround(RedisCache redisCache, IPrdInstockService prdInstockService)
public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService)
{
_redisCache = redisCache;
_redisData = redisData;
_prdInstockService = prdInstockService;
}
//获取注塑装箱状态
private void GetZSPackStatus(object state)
{
// Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
// Console.WriteLine($"获取注塑装箱状态");
string[] strs = new string[1] { "TY4C-ZHUSU1" };
string sign = "agvMode";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisCache.HGetAll(s).Result;
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
@@ -40,7 +40,7 @@ namespace Tnb.ProductionMgr
JObject? res = JsonConvert.DeserializeObject<JObject>(kv.Value);
if (res != null && res["Value"] != null)
{
if (int.Parse(res["Value"]!.ToString()) is not ((int)Eagvmode.) or not ((int)Eagvmode.))
if (int.Parse(res["Value"]!.ToString()) is not ((int)Eagvmode.) and not ((int)Eagvmode.))
{
InstockInput instockInput = new()
{
@@ -55,13 +55,11 @@ namespace Tnb.ProductionMgr
//获取挤出装箱状态
private void GetJCPackStatus(object state)
{
// Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
// Console.WriteLine($"获取挤出装箱状态");
string[] strs = new string[1] { "TY4C-SHUSONG-JC" };
string sign = "AGVFullCall";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisCache.HGetAll(s).Result;
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
@@ -87,13 +85,17 @@ namespace Tnb.ProductionMgr
//获取限位状态
private void GetLimitStatus(object state)
{
// Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
// Console.WriteLine($"获取限位状态");
/*
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine($"获取挤出装箱状态");
string data = _redisData.GetHash("TY4C-SHUSONG-JC", "AGVFullCall").Result;
Console.WriteLine(data);*/
/*
string[] strs = new string[1] { "TY4C-WAIBAO" };
string sign = "AGVCall";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisCache.HGetAll(s).Result;
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
@@ -110,17 +112,19 @@ namespace Tnb.ProductionMgr
}
}
}
}
}*/
}
public void Dispose()
{
packtimer?.Dispose();
ZSpacktimer?.Dispose();
JCpacktimer?.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));
// ZSpacktimer = new Timer(GetZSPackStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));
// JCpacktimer = new Timer(GetJCPackStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));
// limittimer = new Timer(GetLimitStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)

View File

@@ -5,6 +5,7 @@ using JNPF.FriendlyException;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Tnb.Common.Redis;
using Tnb.ProductionMgr.Interfaces;
namespace Tnb.ProductionMgr
@@ -16,11 +17,10 @@ namespace Tnb.ProductionMgr
[Route("api/[area]/[controller]/[action]")]
public class RedisDataService : IRedisDataService, IDynamicApiController, ITransient
{
private readonly RedisCache _redisCache;
public RedisDataService(RedisCache redisCache)
private readonly RedisData _redisData;
public RedisDataService(RedisData redisData)
{
_redisCache = redisCache;
_redisData = redisData;
}
/// <summary>
/// 根据机号获取重量
@@ -28,31 +28,13 @@ namespace Tnb.ProductionMgr
[HttpPost]
public async Task<dynamic> GetWeight(string device, string jihao)
{
bool flag = await _redisCache.HashExist(device, jihao);
bool flag = await _redisData.HashExist(device, jihao);
if (!flag)
{
throw Oops.Bah("没有找到" + device + "----" + jihao + "的数据");
}
string data = await _redisCache.GetHash(device, jihao);
string data = await _redisData.GetHash(device, jihao);
JObject? res = JsonConvert.DeserializeObject<JObject>(data);
/*
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 = res != null && res["Value"] != null ? decimal.Parse(res["Value"]!.ToString()) : throw Oops.Bah("数据格式错误");
return result;
}