This commit is contained in:
qianjiawei
2024-02-02 10:29:12 +08:00
parent bee26d9a92
commit 02dafc3c74
3 changed files with 76 additions and 50 deletions

View File

@@ -7,11 +7,13 @@ using JNPF.Common.Cache;
using JNPF.Common.Dtos.VisualDev;
using JNPF.FriendlyException;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NetTaste;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Qiniu.Util;
using SqlSugar;
using Tnb.Common.Extension;
using Tnb.Common.Redis;
using Tnb.Common.Utils;
using Tnb.ProductionMgr.Entities;
@@ -19,6 +21,7 @@ using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Entities.Enums;
using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Configs;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Interfaces;
@@ -34,6 +37,7 @@ namespace Tnb.ProductionMgr
private readonly IPrdInstockService _prdInstockService;
private readonly ISqlSugarRepository<RedisReadConfig> _repository;
private readonly IWmsPDAScanInStockService _wmsPDAScanInStock;
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository, IWmsPDAScanInStockService wmsPDAScanInStock)
{
_redisData = redisData;
@@ -136,6 +140,7 @@ 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")! : "";
coderesult = coderesult.Replace("\r", "");
var DistaskH = _repository.AsSugarClient().Queryable<WmsDistaskH>().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID).First();
if (DistaskH != null)
{
@@ -158,27 +163,66 @@ namespace Tnb.ProductionMgr
//扫码入库
private void ScanInStock(object state)
{
var carry_code = "TestLX0001";//从数采读取载具
WmsCarryH? carry = _repository.AsSugarClient().Queryable<WmsCarryH>().Single(it => it.carry_code == carry_code);
if (carry != null)
Dictionary<string, string[]> getdic = new Dictionary<string, string[]>();
getdic.Add("BGWRKYCL02", new string[] { "CP8", "AllowGetFullBox1", "code1", "PutDoneEmptyBox","false" });
foreach (var key in getdic.Keys)
{
var WmsCarryCode = _repository.AsSugarClient().Queryable<WmsCarryCode>().Single(it => it.carry_id == carry.id);
try
{
var strs = getdic.Where(p => p.Key == key).First().Value;
bool flag = _redisData.HashExist(strs[0], strs[1]).Result;
string data = _redisData.GetHash(strs[0], strs[1]).Result;
JObject? res = JsonConvert.DeserializeObject<JObject>(data);
bool result = res != null && res["Value"] != null ? res.Value<bool>("Value") : false;
if (result)
{
Dictionary<string, string> dicCommand = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = strs[0],
["token"] = _eleCtlCfg.token,
["TagName"] = strs[3],
["Value"] = strs[4],
};
HttpClientHelper.GetAsync(_eleCtlCfg.WriteTagUrl, new Dictionary<string, string>(), dicCommand).Wait();
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", carry.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.ScanInStockByRedis(input);
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")! : "";
WmsCarryH? carry = _repository.AsSugarClient().Queryable<WmsCarryH>().Single(it => it.carry_code == coderesult);
if (carry != null)
{
if (_repository.AsSugarClient().Queryable<WmsDistaskH>().Where(p => p.carry_id == carry.id && (p.status == WmsWareHouseConst.TASK_BILL_STATUS_DZX_ID || p.status == WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID || p.status == WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID)).Any())
continue;
var WmsCarryCode = _repository.AsSugarClient().Queryable<WmsCarryCode>().Single(it => it.carry_id == carry.id);
if (WmsCarryCode != null)
{
VisualDevModelDataCrInput input = new VisualDevModelDataCrInput();
input.data = new Dictionary<string, object>();
input.data.Add("barcode", coderesult);
input.data.Add("codeqty", WmsCarryCode.codeqty);//条码数量
input.data.Add("material_code", WmsCarryCode.material_code);
input.data.Add("extras", key);//location_code
input.data.Add("warehouse_id", "1");//TEST
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.ScanInStockByRedis(input);
}
}
}
}
catch (Exception)
{
}
}
}
@@ -187,12 +231,13 @@ namespace Tnb.ProductionMgr
{
Readtimer?.Dispose();
CheckGettimer?.Dispose();
Scantimer?.Dispose();
}
public Task StartAsync(CancellationToken cancellationToken)
{
// Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(60));
// Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(10));
Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(20));
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)