From c45c3542a30a9ced5b4256e201f3240e546dca9d Mon Sep 17 00:00:00 2001 From: qianjiawei <1184704771@qq.com> Date: Wed, 20 Dec 2023 09:39:34 +0800 Subject: [PATCH] Bug --- .../Tnb.ProductionMgr/PrdOutstockService.cs | 170 +++++++++++++++--- .../Tnb.ProductionMgr/RedisBackGround.cs | 2 +- .../Tnb.WarehouseMgr/WmsOutStockService.cs | 21 ++- .../Tnb.WarehouseMgr/WmsPDADeliveryService.cs | 15 +- 4 files changed, 180 insertions(+), 28 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs index 41c2048d..d618574b 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs @@ -45,7 +45,7 @@ namespace Tnb.ProductionMgr private readonly IBillRullService _billRullService; public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); - public PrdOutstockService(ISqlSugarRepository repository, IOrganizeService organizeService, IBillRullService billRullService,IRunService runService, IUserManager userManager, IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService) + public PrdOutstockService(ISqlSugarRepository repository, IOrganizeService organizeService, IBillRullService billRullService, IRunService runService, IUserManager userManager, IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService) { _db = repository.AsSugarClient(); _runService = runService; @@ -98,7 +98,7 @@ namespace Tnb.ProductionMgr string domain = _userManager.Domain; Dictionary header = new() { - ["Authorization"] = App.HttpContext!=null ? App.HttpContext.Request.Headers["Authorization"] : "" + ["Authorization"] = App.HttpContext != null ? App.HttpContext.Request.Headers["Authorization"] : "" }; string sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header); Log.Information(sendResult); @@ -190,7 +190,7 @@ namespace Tnb.ProductionMgr string domain = _userManager.Domain; Dictionary header = new() { - ["Authorization"] = App.HttpContext!=null ? App.HttpContext.Request.Headers["Authorization"] : "" + ["Authorization"] = App.HttpContext != null ? App.HttpContext.Request.Headers["Authorization"] : "" }; string sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header); Log.Information(sendResult); @@ -266,12 +266,12 @@ namespace Tnb.ProductionMgr MESCreateOutstockInput input = new MESCreateOutstockInput(); input.outstock = new MESWmsOutstockHInput(); input.outstockDs = new List(); - - PrdMoTask prdMoTask = await db.Queryable().SingleAsync(x=>x.id==materialOutstockInput.mo_task_id); - BasLocation location = await db.Queryable().Where(x=>x.location_code==materialOutstockInput.location_code).FirstAsync(); + + PrdMoTask prdMoTask = await db.Queryable().SingleAsync(x => x.id == materialOutstockInput.mo_task_id); + BasLocation location = await db.Queryable().Where(x => x.location_code == materialOutstockInput.location_code).FirstAsync(); if (location == null) throw Oops.Bah("未找到库位"); string locationId = location.id; - + PrdOutstockH prdOutstockH = new() { bill_code = await _billRullService.GetBillNumber(CodeTemplateConst.PRDOUTSTOCK_CODE), @@ -287,17 +287,17 @@ namespace Tnb.ProductionMgr input.outstock.source_code = prdOutstockH.bill_code; input.outstock.source_id = prdOutstockH.id; OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(materialOutstockInput.workstation_id, DictConst.RegionCategoryWorklineCode); - + List materialIds = materialOutstockInput.details.Select(x => x.material_id).ToList(); - List basMaterials = await db.Queryable().Where(x=>materialIds.Contains(x.id)).ToListAsync(); - Dictionary unitIdDic = await db.Queryable() + List basMaterials = await db.Queryable().Where(x => materialIds.Contains(x.id)).ToListAsync(); + Dictionary unitIdDic = await db.Queryable() .LeftJoin((a, b) => b.EnCode == DictConst.MeasurementUnit) .LeftJoin((a, b, c) => b.Id == c.DictionaryTypeId && a.unit_id == c.EnCode) - .Where((a,b,c)=>materialIds.Contains(a.id)) - .Select((a, b, c) => new + .Where((a, b, c) => materialIds.Contains(a.id)) + .Select((a, b, c) => new { key = a.id, - value = c.Id + value = c.Id }) .ToDictionaryAsync(x => x.key, x => x.value); @@ -306,18 +306,18 @@ namespace Tnb.ProductionMgr input.outstockDs.Add(new MESWmsOutstockDInput() { material_id = item.material_id, - material_code = basMaterials.First(x=>x.id==item.material_id).code, + material_code = basMaterials.First(x => x.id == item.material_id).code, pr_qty = item.num, unit_id = unitIdDic[item.material_id].ToString() }); } - + string domain = _userManager.Domain; Dictionary header = new Dictionary() { - ["Authorization"] = App.HttpContext!=null ? App.HttpContext.Request.Headers["Authorization"] : "" + ["Authorization"] = App.HttpContext != null ? App.HttpContext.Request.Headers["Authorization"] : "" }; - var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK,JsonConvert.SerializeObject(input),header); + var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header); Log.Information(sendResult); AuthResponse authResponse = JsonConvert.DeserializeObject(sendResult); @@ -346,16 +346,141 @@ namespace Tnb.ProductionMgr prdOutstockDs.Add(new PrdOutstockD() { material_id = item.material_id, - material_code = basMaterials.First(x=>x.id==item.material_id).code, - material_name = basMaterials.First(x=>x.id==item.material_id).name, + material_code = basMaterials.First(x => x.id == item.material_id).code, + material_name = basMaterials.First(x => x.id == item.material_id).name, pr_qty = item.num, unit_id = unitIdDic[item.material_id].ToString(), outstock_id = prdOutstockH.id, source_id = prdMoTask.mo_task_code }); } - - DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => + + DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => + { + await _repository.InsertAsync(prdOutstockH); + if (prdOutstockDs.Count > 0) + { + await db.Insertable(prdOutstockDs).ExecuteCommandAsync(); + } + }); + + if (!result.IsSuccess) + { + throw Oops.Bah(result.ErrorMessage); + } + + } + return await Task.FromResult(true); + } + catch (Exception e) + { + Console.WriteLine(e); + Log.Error(e.Message); + throw Oops.Bah(e.Message); + } + } + + + [HttpPost] + public async Task MaterialOutstockTest(MaterialOutstockInput materialOutstockInput) + { + try + { + var db = _repository.AsSugarClient(); + string warehouse_id = "1";//一楼原材料仓 + + MESCreateOutstockInput input = new MESCreateOutstockInput(); + input.outstock = new MESWmsOutstockHInput(); + input.outstockDs = new List(); + + BasLocation location = await db.Queryable().Where(x => x.location_code == materialOutstockInput.location_code).FirstAsync(); + if (location == null) throw Oops.Bah("未找到库位"); + string locationId = location.id; + + PrdOutstockH prdOutstockH = new() + { + bill_code = await _billRullService.GetBillNumber(CodeTemplateConst.PRDOUTSTOCK_CODE), + }; + + input.outstock.bill_type = DictConst.SHENGCHANLINGLIAO; + // input.outstock.bill_date = visualDevModelDataCrInput.data.ContainsKey("bill_date") ? Convert.ToDateTime(visualDevModelDataCrInput.data["bill_date"].ToString()) : DateTime.Now; + input.outstock.bill_date = DateTime.Now; + input.outstock.org_id = _userManager.GetUserInfo().Result.organizeId; + input.outstock.warehouse_id = warehouse_id; + input.outstock.create_id = _userManager.UserId; + input.outstock.location_code = location?.location_code ?? ""; + input.outstock.source_code = prdOutstockH.bill_code; + input.outstock.source_id = prdOutstockH.id; + OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(materialOutstockInput.workstation_id, DictConst.RegionCategoryWorklineCode); + + List materialIds = materialOutstockInput.details.Select(x => x.material_id).ToList(); + List basMaterials = await db.Queryable().Where(x => materialIds.Contains(x.id)).ToListAsync(); + Dictionary unitIdDic = await db.Queryable() + .LeftJoin((a, b) => b.EnCode == DictConst.MeasurementUnit) + .LeftJoin((a, b, c) => b.Id == c.DictionaryTypeId && a.unit_id == c.EnCode) + .Where((a, b, c) => materialIds.Contains(a.id)) + .Select((a, b, c) => new + { + key = a.id, + value = c.Id + }) + .ToDictionaryAsync(x => x.key, x => x.value); + + foreach (var item in materialOutstockInput.details) + { + input.outstockDs.Add(new MESWmsOutstockDInput() + { + material_id = item.material_id, + material_code = basMaterials.First(x => x.id == item.material_id).code, + pr_qty = item.num, + unit_id = unitIdDic[item.material_id].ToString() + }); + } + + string domain = _userManager.Domain; + Dictionary header = new Dictionary() + { + ["Authorization"] = App.HttpContext != null ? App.HttpContext.Request.Headers["Authorization"] : "" + }; + var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header); + Log.Information(sendResult); + + AuthResponse authResponse = JsonConvert.DeserializeObject(sendResult); + if (authResponse.code != 200) + { + throw Oops.Bah(authResponse.msg); + } + else + { + prdOutstockH.bill_type = DictConst.SHENGCHANLINGLIAO; + prdOutstockH.type = "2"; + prdOutstockH.warehouse_id = warehouse_id; + prdOutstockH.location_code = materialOutstockInput.location_code; + prdOutstockH.create_id = _userManager.UserId; + prdOutstockH.org_id = _userManager.GetUserInfo().Result.organizeId; + prdOutstockH.bill_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + prdOutstockH.create_time = DateTime.Now; + prdOutstockH.workstation_id = materialOutstockInput.workstation_id; + prdOutstockH.workline = workline?.Id ?? ""; + prdOutstockH.status = DictConst.OUTSTOCKSTATUSADD; + prdOutstockH.mo_task_id = ""; + + List prdOutstockDs = new List(); + foreach (var item in materialOutstockInput.details) + { + prdOutstockDs.Add(new PrdOutstockD() + { + material_id = item.material_id, + material_code = basMaterials.First(x => x.id == item.material_id).code, + material_name = basMaterials.First(x => x.id == item.material_id).name, + pr_qty = item.num, + unit_id = unitIdDic[item.material_id].ToString(), + outstock_id = prdOutstockH.id, + source_id = "" + }); + } + + DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => { await _repository.InsertAsync(prdOutstockH); if (prdOutstockDs.Count > 0) @@ -380,4 +505,5 @@ namespace Tnb.ProductionMgr } } } -} \ No newline at end of file +} + \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index f6bf324f..991f642f 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -157,7 +157,7 @@ namespace Tnb.ProductionMgr //扫码入库 private void ScanInStock(object state) { - var carry_code = "carry_code"; + var carry_code = "carry_code";//从数采读取 WmsCarryH? carry = _repository.AsSugarClient().Queryable().Single(it => it.carry_code == carry_code); if (carry != null) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs index c5b5a42d..04b8dfb1 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs @@ -618,7 +618,7 @@ namespace Tnb.WarehouseMgr .ToListAsync(); if (carryCodesPart?.Count > 0) { - decimal codeQty = carryCodes.Sum(x => x.codeqty); + decimal codeQty = carryCodesPart.Sum(x => x.codeqty); if (codeQty < os.pr_qty) { throw new AppFriendlyException($"需要出库[{os.pr_qty}],实际库存{codeQty},数量不足", 500); @@ -708,12 +708,22 @@ namespace Tnb.WarehouseMgr if (sPoint != null && ePoint != null) { - List points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); + List points = new List(); + try + { + points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); + } + catch (Exception) + { + points.Add(sPoint); + points.Add(ePoint); + + } locIds.AddRange(points.Select(x => x.location_id).ToList()!); //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) if (points?.Count > 0) { - if (points.Count <= 2) + if (points.Count < 2) { throw new AppFriendlyException("该路径不存在", 500); } @@ -730,6 +740,11 @@ namespace Tnb.WarehouseMgr startlocation_code = sPoint?.location_code ?? string.Empty, endlocation_id = ePoint?.location_id ?? string.Empty, endlocation_code = ePoint?.location_code ?? string.Empty, + startpoint_id = sPoint.id, + startpoint_code = sPoint.point_code, + endpoint_id = ePoint.id, + endpoint_code = ePoint.point_code, + start_floor = sPoint?.floor.ToString(), end_floor = ePoint?.floor.ToString(), bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(), diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs index 24414da1..2254ca58 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs @@ -117,11 +117,22 @@ namespace Tnb.WarehouseMgr if (sPoint != null && ePoint != null) { - List points = await _wareHouseService!.PathAlgorithms(sPoint.id, ePoint.id); + List points=new List(); + try + { + points = await _wareHouseService!.PathAlgorithms(sPoint.id, ePoint.id); + } + catch (Exception) + { + points.Add(sPoint); + points.Add(ePoint); + + + } //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) if (points?.Count > 0) { - if (points.Count <= 2) + if (points.Count < 2) { throw new AppFriendlyException("该路径不存在", 500); }