From 296c618bf5afc89d7f09b32dfa418a67b87b8aa5 Mon Sep 17 00:00:00 2001 From: qianjiawei <1184704771@qq.com> Date: Mon, 18 Dec 2023 17:17:48 +0800 Subject: [PATCH] 11 --- .../Tnb.ProductionMgr/RedisBackGround.cs | 162 +++++------------- .../Tnb.ProductionMgr.csproj | 2 +- .../Dto/Inputs/CarryMaterialBindInput.cs | 25 +++ .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 43 ++++- .../Tnb.WarehouseMgr/WmsInStockService.cs | 4 +- 5 files changed, 111 insertions(+), 125 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 918607a7..f6bf324f 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -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 _repository; - public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository repository) + private readonly IWmsPDAScanInStockService _wmsPDAScanInStock; + public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository 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(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("Value"))) { InstockInput instockInput = new() @@ -132,14 +137,14 @@ 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")! : ""; - var DistaskH= _repository.AsSugarClient().Queryable().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID).First(); + var DistaskH = _repository.AsSugarClient().Queryable().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().Single(it => it.carry_code == carry_code); + if (carry != null) + { + var WmsCarryCode = _repository.AsSugarClient().Queryable().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 dic = _redisData.HGetAll(s).Result; - foreach (KeyValuePair kv in dic) - { - if (!kv.Key.Contains(sign)) - { - continue; - } - JObject? res = JsonConvert.DeserializeObject(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 dic = _redisData.HGetAll(s).Result; - foreach (KeyValuePair kv in dic) - { - if (!kv.Key.Contains(sign)) - { - continue; - } - JObject? res = JsonConvert.DeserializeObject(kv.Value); - if (res != null && res["Value"] != null) - { - if (res.Value("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 dic = _redisData.HGetAll(s).Result; - foreach (KeyValuePair kv in dic) - { - if (!kv.Key.Contains(sign)) - { - continue; - } - JObject? res = JsonConvert.DeserializeObject(kv.Value); - if (res != null && res["Value"] != null) - { - if (res.Value("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(); + 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) diff --git a/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj b/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj index fde22e81..fd26adc3 100644 --- a/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj +++ b/ProductionMgr/Tnb.ProductionMgr/Tnb.ProductionMgr.csproj @@ -16,7 +16,7 @@ - + diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs new file mode 100644 index 00000000..8a705e74 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Dto.Inputs +{ + public class CarryMaterialBindInput + { + public string? carrycode { get; set; } + public List details { get; set; } + } + public class CarryMaterialDetail + { + public string? material_id { get; set; } + public string? material_code { get; set; } + public string? barcode { get; set; } + public string? code_batch { get; set; } + public string? codeqty { get; set; } + public int is_out { get; set; } + public string? unit_id { get; set; } + + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index 07759054..972edab9 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -1,4 +1,5 @@ -using JNPF.Common.Core.Manager; +using System.Dynamic; +using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; @@ -8,9 +9,14 @@ using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Interfaces; +using Mapster; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using Senparc.Weixin.MP.AdvancedAPIs.Card; using SqlSugar; using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; @@ -41,6 +47,7 @@ namespace Tnb.WarehouseMgr _userManager = userManager; _billRullService = billRullService; OverideFuncs.CreateAsync = CarryBind; + } [NonAction] public async Task CarryBind(VisualDevModelDataCrInput input) @@ -129,8 +136,42 @@ namespace Tnb.WarehouseMgr return Task.FromResult(true); } + [HttpPost] + public async Task GetInfoByCode(string code) + { + var data = await _db.Queryable().Where(p => p.barcode == code).FirstAsync(); + if(data==null) + throw new AppFriendlyException("没有条码信息", 500); + var result = data.Adapt(); + return result; + } + [HttpPost] + public async Task CarryMaterialBind(CarryMaterialBindInput input) + { + try + { + WmsCarryH? carry = await _db.Queryable().SingleAsync(it => it.carry_code == input.carrycode); + List WmsCarryCodes = new List(); + foreach (var detail in input.details) + { + var WmsCarryCode = detail.Adapt(); + WmsCarryCode.id = SnowflakeIdHelper.NextId(); + WmsCarryCode.carry_id = carry.id; + WmsCarryCode.is_out = 0; + WmsCarryCodes.Add(WmsCarryCode); + } + if (WmsCarryCodes.Count > 0) + await _db.Insertable(WmsCarryCodes).ExecuteCommandAsync(); + } + catch (Exception) + { + throw new AppFriendlyException("绑定失败", 500); + } + } + + /* public override async Task ModifyAsync(WareHouseUpInput input) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs index 53035e22..fe3c8664 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs @@ -595,13 +595,13 @@ namespace Tnb.WarehouseMgr public class CustomEqualityComparer : EqualityComparer { - public bool Equals(WmsTempCode? x, WmsTempCode? y) + public override bool Equals(WmsTempCode? x, WmsTempCode? y) { // 判断两个对象是否相等的逻辑 return x?.barcode == y?.barcode && x?.require_id == y?.require_id; } - public int GetHashCode([DisallowNull] WmsTempCode obj) + public override int GetHashCode([DisallowNull] WmsTempCode obj) { // 使用多个属性来计算哈希码 int hashCode = obj.barcode?.GetHashCode() ?? 0;