This commit is contained in:
qianjiawei
2023-12-18 17:17:48 +08:00
parent dc784077f0
commit 296c618bf5
5 changed files with 111 additions and 125 deletions

View File

@@ -4,6 +4,7 @@ using System.Security.Policy;
using Aop.Api.Domain;
using JNPF;
using JNPF.Common.Cache;
using JNPF.Common.Dtos.VisualDev;
using JNPF.FriendlyException;
using Microsoft.Extensions.Hosting;
using NetTaste;
@@ -19,32 +20,36 @@ using Tnb.ProductionMgr.Entities.Enums;
using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.ProductionMgr
{
//redis定时获取数采数据
public class RedisBackGround : IHostedService, IDisposable
{
private Timer? Readtimer;
private Timer? Readtimer;
private Timer? CheckGettimer;
private Timer? Scantimer;
private readonly RedisData _redisData;
private readonly IPrdInstockService _prdInstockService;
private readonly ISqlSugarRepository<RedisReadConfig> _repository;
public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository)
private readonly IWmsPDAScanInStockService _wmsPDAScanInStock;
public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository, IWmsPDAScanInStockService wmsPDAScanInStock)
{
_redisData = redisData;
_prdInstockService = prdInstockService;
_repository = repository;
_repository = repository;
_wmsPDAScanInStock = wmsPDAScanInStock;
}
//获取redis数据
private void GetRedisData(object state)
{
var _redisReadConfigs = _repository.AsQueryable().Where(p => p.enabled == 1).ToList();
var _redisReadConfigs = _repository.AsQueryable().Where(p => p.enabled == 1).ToList();
foreach (var config in _redisReadConfigs)
{
try
{
var json= _redisData.GetHash(config.dev_name!, config.tag_name!).Result;
var json = _redisData.GetHash(config.dev_name!, config.tag_name!).Result;
JObject? res = JsonConvert.DeserializeObject<JObject>(json);
if (config.data_type == (int)DataType.INT)
{
@@ -62,7 +67,7 @@ namespace Tnb.ProductionMgr
}
else if (config.check_type == (int)CheckType.)
{
int[] ints= Array.ConvertAll(config.data!.Replace("[","").Replace("]","").Split(",",StringSplitOptions.RemoveEmptyEntries),int.Parse);
int[] ints = Array.ConvertAll(config.data!.Replace("[", "").Replace("]", "").Split(",", StringSplitOptions.RemoveEmptyEntries), int.Parse);
if (ints.Contains(res.Value<int>("Value")))
{
InstockInput instockInput = new()
@@ -132,14 +137,14 @@ namespace Tnb.ProductionMgr
string codedata = _redisData.GetHash(strs[0], strs[2]).Result;
JObject? coderes = JsonConvert.DeserializeObject<JObject>(codedata);
string coderesult = coderes != null && coderes["Value"] != null ? coderes.Value<string>("Value")! : "";
var DistaskH= _repository.AsSugarClient().Queryable<WmsDistaskH>().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID).First();
var DistaskH = _repository.AsSugarClient().Queryable<WmsDistaskH>().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID).First();
dynamic reqBody = new ExpandoObject();
reqBody.taskCode = DistaskH.bill_code;
reqBody.slotCode = key;
reqBody.containerCode = coderesult;
CancellationTokenSource Ctu = new();
//{"code":500,"msg":"成功!"}
dynamic respBody = HttpClientHelper.PostStreamAsync("http://192.168.11.104:1880/wcs/notify/cargo", reqBody, Ctu.Token).Result;
dynamic respBody = HttpClientHelper.PostStreamAsync("http://192.168.11.104:1880/wcs/notify/cargo", reqBody, Ctu.Token).Result;
Ctu.Dispose();
}
}
@@ -149,120 +154,34 @@ namespace Tnb.ProductionMgr
}
}
}
//扫码入库
private void ScanInStock(object state)
{
var carry_code = "carry_code";
WmsCarryH? carry = _repository.AsSugarClient().Queryable<WmsCarryH>().Single(it => it.carry_code == carry_code);
if (carry != null)
{
var WmsCarryCode = _repository.AsSugarClient().Queryable<WmsCarryCode>().Single(it => it.carry_id == carry.id);
//获取注塑装箱状态
private void GetZSPackStatus(object state)
{
try
{
string[] strs = new string[1] { "TY4C-ZHUSU1" };
string sign = "agvMode";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
{
continue;
}
JObject? res = JsonConvert.DeserializeObject<JObject>(kv.Value);
if (res != null && res["Value"] != null)
{
if (int.Parse(res["Value"]!.ToString()) is not ((int)Eagvmode.) and not ((int)Eagvmode.))
{
InstockInput instockInput = new()
{
equip_code = res["DevName"]!.ToString(),
label_code = res["TagName"]!.ToString()
};
_prdInstockService.InstockTypeOne(instockInput);
}
}
}
}
}
catch (Exception)
{
}
}
//获取挤出装箱状态
private void GetJCPackStatus(object state)
{
try
{
string[] strs = new string[1] { "TY4C-SHUSONG-JC" };
string sign = "AGVFullCall";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
{
continue;
}
JObject? res = JsonConvert.DeserializeObject<JObject>(kv.Value);
if (res != null && res["Value"] != null)
{
if (res.Value<bool>("Value"))
{
InstockInput instockInput = new()
{
equip_code = res["DevName"]!.ToString(),
label_code = res["TagName"]!.ToString()
};
_prdInstockService.InstockTypeOne(instockInput);
}
}
}
}
}
catch (Exception)
{
}
}
//获取限位状态
private void GetLimitStatus(object state)
{
/*
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine($"获取挤出装箱状态");
string data = _redisData.GetHash("TY4C-SHUSONG-JC", "AGVFullCall").Result;
Console.WriteLine(data);*/
try
{
string[] strs = new string[1] { "TY4C-WAIBAO" };
string sign = "AGVCall";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
{
continue;
}
JObject? res = JsonConvert.DeserializeObject<JObject>(kv.Value);
if (res != null && res["Value"] != null)
{
if (res.Value<bool>("Value"))
{
InstockInput instockInput = new()
{
equip_code = res["DevName"]!.ToString(),
label_code = res["TagName"]!.ToString()
};
_prdInstockService.InstockOutPack(instockInput);
}
}
}
}
}
catch (Exception)
{
VisualDevModelDataCrInput input = new VisualDevModelDataCrInput();
input.data = new Dictionary<string, object>();
input.data.Add("barcode", carry_code);
input.data.Add("codeqty", WmsCarryCode.codeqty);//条码数量
input.data.Add("material_code", WmsCarryCode.material_code);
input.data.Add("extras", WmsCarryCode.location_code);//location_code
input.data.Add("warehouse_id", WmsCarryCode.warehouse_id!);
input.data.Add("bill_code", "");//采购收货单号
input.data.Add("code_batch", WmsCarryCode.code_batch!);//批次
input.data.Add("material_specification", WmsCarryCode.material_specification!);//规格型号
input.data.Add("container_no", WmsCarryCode.container_no!);//箱号
input.data.Add("material_id", WmsCarryCode.material_id);
input.data.Add("id", null);
_wmsPDAScanInStock.ScanInStock(input);
}
}
public void Dispose()
{
Readtimer?.Dispose();
@@ -270,8 +189,9 @@ namespace Tnb.ProductionMgr
}
public Task StartAsync(CancellationToken cancellationToken)
{
// Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)

View File

@@ -16,7 +16,7 @@
<ProjectReference Include="..\..\QcMgr\Tnb.QcMgr.Interfaces\Tnb.QcMgr.Interfaces.csproj" />
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Entities\Tnb.WarehouseMgr.Entities.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Interfaces\Tnb.WarehouseMgr.Interfaces.csproj" />
<ProjectReference Include="..\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />
</ItemGroup>