From 02dafc3c745c7a49555d81738a5389285652cdf8 Mon Sep 17 00:00:00 2001 From: qianjiawei <1184704771@qq.com> Date: Fri, 2 Feb 2024 10:29:12 +0800 Subject: [PATCH] bug --- .../Tnb.ProductionMgr/RedisBackGround.cs | 85 ++++++++++++++----- .../Tnb.WarehouseMgr/WareHouseService.cs | 39 +++------ apihost/Tnb.API.Entry/Startup.cs | 2 +- 3 files changed, 76 insertions(+), 50 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 1bffebbf..b6497f72 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -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 _repository; private readonly IWmsPDAScanInStockService _wmsPDAScanInStock; + private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build(); public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository 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(codedata); string coderesult = coderes != null && coderes["Value"] != null ? coderes.Value("Value")! : ""; + coderesult = coderesult.Replace("\r", ""); var DistaskH = _repository.AsSugarClient().Queryable().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().Single(it => it.carry_code == carry_code); - if (carry != null) + Dictionary getdic = new Dictionary(); + getdic.Add("BGWRKYCL02", new string[] { "CP8", "AllowGetFullBox1", "code1", "PutDoneEmptyBox","false" }); + foreach (var key in getdic.Keys) { - var WmsCarryCode = _repository.AsSugarClient().Queryable().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(data); + bool result = res != null && res["Value"] != null ? res.Value("Value") : false; + if (result) + { + Dictionary dicCommand = new(StringComparer.OrdinalIgnoreCase) + { + ["DevName"] = strs[0], + ["token"] = _eleCtlCfg.token, + ["TagName"] = strs[3], + ["Value"] = strs[4], + }; + HttpClientHelper.GetAsync(_eleCtlCfg.WriteTagUrl, new Dictionary(), dicCommand).Wait(); - VisualDevModelDataCrInput input = new VisualDevModelDataCrInput(); - input.data = new Dictionary(); - 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(codedata); + string coderesult = coderes != null && coderes["Value"] != null ? coderes.Value("Value")! : ""; + WmsCarryH? carry = _repository.AsSugarClient().Queryable().Single(it => it.carry_code == coderesult); + if (carry != null) + { + if (_repository.AsSugarClient().Queryable().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().Single(it => it.carry_id == carry.id); + if (WmsCarryCode != null) + { + VisualDevModelDataCrInput input = new VisualDevModelDataCrInput(); + input.data = new Dictionary(); + 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) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 56d9785e..4e75ac29 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -273,35 +273,13 @@ namespace Tnb.WarehouseMgr /// 判断CTU是否可以取货 /// /// - [HttpPost] + + [HttpGet] [AllowAnonymous] - public async Task CheckGet() + public async Task Test() { - try - { - Dictionary getdic = new Dictionary(); - getdic.Add("SSX-021-005", new string[] { "YTCS", "AllowFullOut_CS05", "LiftCode" }); - - var strs = getdic.First().Value; - string data = await _redisData.GetHash(strs[0], strs[1]); - JObject? res = JsonConvert.DeserializeObject(data); - bool result = res != null && res["Value"] != null ? res.Value("Value") : false; - if (result) - { - string codedata = _redisData.GetHash(strs[0], strs[2]).Result; - JObject? coderes = JsonConvert.DeserializeObject(codedata); - string coderesult = coderes != null && coderes["Value"] != null ? coderes.Value("Value")! : ""; - return new { flag =true, code = coderesult }; - } - else - { - return new { flag = false, code = "" }; - } - } - catch (Exception ex) - { - throw new AppFriendlyException($"接口请求异常", 500); - } + var a = _db.Queryable().Where(p => p.id == "31900194166806").First(); + await SsxControl(a, "UNLOAD"); } public async Task SsxControl(WmsDistaskH disTask, string action) { @@ -309,6 +287,7 @@ namespace Tnb.WarehouseMgr Dictionary getdic = new Dictionary(); getdic.Add("SSX-021-005", new string[] { "YTCS", "FullOut_CS05Done", "true" }); putdic.Add("SSX-011-006", new string[] { "YTCS", "EmptyIn_CS06Done", "true" }); + putdic.Add("YCLCKBGW", new string[] { "CP8", "PutDoneEmptyBox", "true" }); if (action == "LOAD")//取货 { if (getdic.Keys.Contains(disTask.startlocation_code)) @@ -321,7 +300,8 @@ namespace Tnb.WarehouseMgr ["TagName"] = strarr[1], ["Value"] = strarr[2], }; - var str= await HttpClientHelper.GetAsync(_eleCtlCfg.WriteTagUrl, pars: dicCommand); + Logger.Information($"SsxControlLOAD:{dicCommand}"); + var str= await HttpClientHelper.GetAsync(_eleCtlCfg.WriteTagUrl, new Dictionary(), dicCommand); Logger.Information($"SsxControlLOAD:{str}"); } } @@ -337,7 +317,8 @@ namespace Tnb.WarehouseMgr ["TagName"] = strarr[1], ["Value"] = strarr[2], }; - var str = await HttpClientHelper.GetAsync(_eleCtlCfg.WriteTagUrl, pars: dicCommand); + Logger.Information($"SsxControlUNLOAD:{dicCommand}"); + var str = await HttpClientHelper.GetAsync(_eleCtlCfg.WriteTagUrl, new Dictionary(), dicCommand); Logger.Information($"SsxControlUNLOAD:{str}"); } } diff --git a/apihost/Tnb.API.Entry/Startup.cs b/apihost/Tnb.API.Entry/Startup.cs index 707d96b2..d8ac9877 100644 --- a/apihost/Tnb.API.Entry/Startup.cs +++ b/apihost/Tnb.API.Entry/Startup.cs @@ -57,6 +57,7 @@ public class Startup : AppStartup services.AddOverideVisualDev(); //定时任务 + SnowflakeIdHelper.InitYitIdWorker(); services.AddHostedService(); services.AddSingleton(sp => new TimedTaskBackgroundService()); @@ -112,7 +113,6 @@ public class Startup : AppStartup endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); - SnowflakeIdHelper.InitYitIdWorker(); bool isStartTimeJob = App.GetConfig("IsStartTimeJob"); if (isStartTimeJob)