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.Common.Dtos.VisualDev;
using JNPF.FriendlyException; using JNPF.FriendlyException;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NetTaste; using NetTaste;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Qiniu.Util; using Qiniu.Util;
using SqlSugar; using SqlSugar;
using Tnb.Common.Extension;
using Tnb.Common.Redis; using Tnb.Common.Redis;
using Tnb.Common.Utils; using Tnb.Common.Utils;
using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities;
@@ -19,6 +21,7 @@ using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Entities.Enums; using Tnb.ProductionMgr.Entities.Enums;
using Tnb.ProductionMgr.Interfaces; using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Configs;
using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Interfaces; using Tnb.WarehouseMgr.Interfaces;
@@ -34,6 +37,7 @@ namespace Tnb.ProductionMgr
private readonly IPrdInstockService _prdInstockService; private readonly IPrdInstockService _prdInstockService;
private readonly ISqlSugarRepository<RedisReadConfig> _repository; private readonly ISqlSugarRepository<RedisReadConfig> _repository;
private readonly IWmsPDAScanInStockService _wmsPDAScanInStock; private readonly IWmsPDAScanInStockService _wmsPDAScanInStock;
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository, IWmsPDAScanInStockService wmsPDAScanInStock) public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository, IWmsPDAScanInStockService wmsPDAScanInStock)
{ {
_redisData = redisData; _redisData = redisData;
@@ -136,6 +140,7 @@ namespace Tnb.ProductionMgr
string codedata = _redisData.GetHash(strs[0], strs[2]).Result; string codedata = _redisData.GetHash(strs[0], strs[2]).Result;
JObject? coderes = JsonConvert.DeserializeObject<JObject>(codedata); JObject? coderes = JsonConvert.DeserializeObject<JObject>(codedata);
string coderesult = coderes != null && coderes["Value"] != null ? coderes.Value<string>("Value")! : ""; 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(); var DistaskH = _repository.AsSugarClient().Queryable<WmsDistaskH>().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID).First();
if (DistaskH != null) if (DistaskH != null)
{ {
@@ -158,27 +163,66 @@ namespace Tnb.ProductionMgr
//扫码入库 //扫码入库
private void ScanInStock(object state) private void ScanInStock(object state)
{ {
var carry_code = "TestLX0001";//从数采读取载具 Dictionary<string, string[]> getdic = new Dictionary<string, string[]>();
WmsCarryH? carry = _repository.AsSugarClient().Queryable<WmsCarryH>().Single(it => it.carry_code == carry_code); getdic.Add("BGWRKYCL02", new string[] { "CP8", "AllowGetFullBox1", "code1", "PutDoneEmptyBox","false" });
if (carry != null) 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>(); string codedata = _redisData.GetHash(strs[0], strs[2]).Result;
input.data.Add("barcode", carry_code); JObject? coderes = JsonConvert.DeserializeObject<JObject>(codedata);
input.data.Add("codeqty", WmsCarryCode.codeqty);//条码数量 string coderesult = coderes != null && coderes["Value"] != null ? coderes.Value<string>("Value")! : "";
input.data.Add("material_code", WmsCarryCode.material_code); WmsCarryH? carry = _repository.AsSugarClient().Queryable<WmsCarryH>().Single(it => it.carry_code == coderesult);
input.data.Add("extras", carry.location_code!);//location_code if (carry != null)
input.data.Add("warehouse_id", WmsCarryCode.warehouse_id!); {
input.data.Add("bill_code", "");//采购收货单号 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())
input.data.Add("code_batch", WmsCarryCode.code_batch!);//批次 continue;
input.data.Add("material_specification", WmsCarryCode.material_specification!);//规格型号 var WmsCarryCode = _repository.AsSugarClient().Queryable<WmsCarryCode>().Single(it => it.carry_id == carry.id);
input.data.Add("container_no", WmsCarryCode.container_no!);//箱号 if (WmsCarryCode != null)
input.data.Add("material_id", WmsCarryCode.material_id); {
input.data.Add("id", null); VisualDevModelDataCrInput input = new VisualDevModelDataCrInput();
_wmsPDAScanInStock.ScanInStockByRedis(input); 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(); Readtimer?.Dispose();
CheckGettimer?.Dispose(); CheckGettimer?.Dispose();
Scantimer?.Dispose();
} }
public Task StartAsync(CancellationToken cancellationToken) public Task StartAsync(CancellationToken cancellationToken)
{ {
// Readtimer = new Timer(GetRedisData, 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(60)); CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(10));
// Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(300)); Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(20));
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)

View File

@@ -273,35 +273,13 @@ namespace Tnb.WarehouseMgr
/// 判断CTU是否可以取货 /// 判断CTU是否可以取货
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost]
[HttpGet]
[AllowAnonymous] [AllowAnonymous]
public async Task<dynamic> CheckGet() public async Task Test()
{ {
try var a = _db.Queryable<WmsDistaskH>().Where(p => p.id == "31900194166806").First();
{ await SsxControl(a, "UNLOAD");
Dictionary<string, string[]> getdic = new Dictionary<string, string[]>();
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<JObject>(data);
bool result = res != null && res["Value"] != null ? res.Value<bool>("Value") : false;
if (result)
{
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")! : "";
return new { flag =true, code = coderesult };
}
else
{
return new { flag = false, code = "" };
}
}
catch (Exception ex)
{
throw new AppFriendlyException($"接口请求异常", 500);
}
} }
public async Task SsxControl(WmsDistaskH disTask, string action) public async Task SsxControl(WmsDistaskH disTask, string action)
{ {
@@ -309,6 +287,7 @@ namespace Tnb.WarehouseMgr
Dictionary<string, string[]> getdic = new Dictionary<string, string[]>(); Dictionary<string, string[]> getdic = new Dictionary<string, string[]>();
getdic.Add("SSX-021-005", new string[] { "YTCS", "FullOut_CS05Done", "true" }); getdic.Add("SSX-021-005", new string[] { "YTCS", "FullOut_CS05Done", "true" });
putdic.Add("SSX-011-006", new string[] { "YTCS", "EmptyIn_CS06Done", "true" }); putdic.Add("SSX-011-006", new string[] { "YTCS", "EmptyIn_CS06Done", "true" });
putdic.Add("YCLCKBGW", new string[] { "CP8", "PutDoneEmptyBox", "true" });
if (action == "LOAD")//取货 if (action == "LOAD")//取货
{ {
if (getdic.Keys.Contains(disTask.startlocation_code)) if (getdic.Keys.Contains(disTask.startlocation_code))
@@ -321,7 +300,8 @@ namespace Tnb.WarehouseMgr
["TagName"] = strarr[1], ["TagName"] = strarr[1],
["Value"] = strarr[2], ["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<string, string>(), dicCommand);
Logger.Information($"SsxControlLOAD:{str}"); Logger.Information($"SsxControlLOAD:{str}");
} }
} }
@@ -337,7 +317,8 @@ namespace Tnb.WarehouseMgr
["TagName"] = strarr[1], ["TagName"] = strarr[1],
["Value"] = strarr[2], ["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<string, string>(), dicCommand);
Logger.Information($"SsxControlUNLOAD:{str}"); Logger.Information($"SsxControlUNLOAD:{str}");
} }
} }

View File

@@ -57,6 +57,7 @@ public class Startup : AppStartup
services.AddOverideVisualDev(); services.AddOverideVisualDev();
//定时任务 //定时任务
SnowflakeIdHelper.InitYitIdWorker();
services.AddHostedService<TimedTaskBackgroundService>(); services.AddHostedService<TimedTaskBackgroundService>();
services.AddSingleton<BackgroundService, TimedTaskBackgroundService>(sp => new TimedTaskBackgroundService()); services.AddSingleton<BackgroundService, TimedTaskBackgroundService>(sp => new TimedTaskBackgroundService());
@@ -112,7 +113,6 @@ public class Startup : AppStartup
endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
}); });
SnowflakeIdHelper.InitYitIdWorker();
bool isStartTimeJob = App.GetConfig<bool>("IsStartTimeJob"); bool isStartTimeJob = App.GetConfig<bool>("IsStartTimeJob");
if (isStartTimeJob) if (isStartTimeJob)