From 15fbfecfa5a6023ea62d957e115920668cd03c84 Mon Sep 17 00:00:00 2001 From: FanLian Date: Tue, 20 Jun 2023 09:15:17 +0800 Subject: [PATCH] =?UTF-8?q?http=20post=EF=BC=8CWareHouseService=E5=B0=91?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AA}=EF=BC=8C=E8=A1=A5=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarehouseMgr/Tnb.WarehouseMgr/FileName.cs | 12 ++ .../Tnb.WarehouseMgr/WareHouseService.cs | 1 + .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 2 +- .../Tnb.WarehouseMgr/WmsCarryUnbindService.cs | 2 +- .../Tnb.WarehouseMgr/WmsPDADeliveryService.cs | 1 - .../Tnb.WarehouseMgr/WmsPDAFeedingService.cs | 196 ++++++++++++++++++ 6 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/FileName.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsPDAFeedingService.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr/FileName.cs b/WarehouseMgr/Tnb.WarehouseMgr/FileName.cs new file mode 100644 index 00000000..cceec65c --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/FileName.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr +{ + internal class FileName + { + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 52b0f055..ebf0852b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -479,6 +479,7 @@ namespace Tnb.WarehouseMgr await _db.Ado.CommitTranAsync(); } + } catch (Exception ex) { await _db.Ado.RollbackTranAsync(); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index dc9017b6..b208f687 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -51,7 +51,7 @@ namespace Tnb.WarehouseMgr _billRullService = billRullService; OverideFuncs.CreateAsync = CarryBind; } - + private async Task CarryBind(VisualDevModelDataCrInput input) { var isOk = false; diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs index 083cda11..2635baee 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs @@ -51,7 +51,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; OverideFuncs.CreateAsync = CarryUnbind; } - + [HttpPost] private async Task CarryUnbind(VisualDevModelDataCrInput input) { var isOk = false; diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs index 181110f0..2ecb1828 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs @@ -62,7 +62,6 @@ namespace Tnb.WarehouseMgr /// /// /// - [HttpGet] public async Task GetUnStoreLocationListByCarryId([FromRoute] string carryId) { var items = await _db.Queryable().LeftJoin((a, b) => a.location_id == b.id) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAFeedingService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAFeedingService.cs new file mode 100644 index 00000000..c38cd6f9 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAFeedingService.cs @@ -0,0 +1,196 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Enums; +using JNPF.Common.Security; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.FriendlyException; +using JNPF.Logging; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.Common.Utils; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Enums; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + /// + /// 载具服务 + /// + [OverideVisualDev(ModuleId)] + public class WmsPDAFeedingService : BaseWareHouseService, IWmsCarryService, IWmsFeedingService + { + private const string ModuleId = "26188532491557"; + private readonly ISqlSugarClient _db; + private readonly IUserManager _userManager; + private readonly IBillRullService _billRullService; + private readonly WmsCarryService _wmsCarryService; + private static Dictionary dicMaterial = new Dictionary(); + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public WmsPDAFeedingService(ISqlSugarRepository repository, IUserManager userManager, IBillRullService billRullService,WmsCarryService wmsCarryService) + { + _db = repository.AsSugarClient(); + _userManager = userManager; + _billRullService = billRullService; + _wmsCarryService = wmsCarryService; + OverideFuncs.CreateAsync = WmsPDAFeeding; + } + [HttpPost] + private async Task WmsPDAFeeding(VisualDevModelDataCrInput input) + { + var isOk = false; + try + { + await _db.Ado.BeginTranAsync(); + var oldCarryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; + var newCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; + var oldCarry = await _db.Queryable().FirstAsync(it => it.id == oldCarryId); + var newCarry = await _db.Queryable().FirstAsync(it => it.id == newCarryId); + if (oldCarry != null && newCarry != null) + { + ExChangeCarryInput carryInput = new() { old_carry_id = oldCarry.id, new_carry_id = newCarry.id }; + isOk = await _updateSubCarry(carryInput); + isOk = await _updateSubCarry(carryInput); + isOk = await _updateSubCarry(carryInput); + + + newCarry.status = oldCarry.status; + newCarry.carry_status = oldCarry.carry_status; + newCarry.location_id = oldCarry.location_id; + newCarry.location_code = oldCarry.location_code; + newCarry.is_lock = oldCarry.is_lock; + newCarry.out_status = oldCarry.out_status; + newCarry.is_check = oldCarry.is_check; + newCarry.bale_num = oldCarry.bale_num; + newCarry.collocation_scheme_id = oldCarry.collocation_scheme_id; + newCarry.collocation_scheme_code = oldCarry.collocation_scheme_code; + newCarry.source_id = oldCarry.source_id; + newCarry.source_code = oldCarry.source_code; + newCarry.create_id = _userManager.UserId; + newCarry.create_time = DateTime.Now; + var row = await _db.Updateable(newCarry).ExecuteCommandAsync(); + WmsCarryReplaceH wmsCarryReplaceH = oldCarry.Adapt(); + wmsCarryReplaceH.id = SnowflakeIdHelper.NextId(); + wmsCarryReplaceH.org_id = oldCarry.org_id; + wmsCarryReplaceH.bill_code = await _billRullService.GetBillNumber(WmsCarryConst.WMS_CARRY_REPLACE_ENCODE); + wmsCarryReplaceH.carry_id = oldCarry.id; + wmsCarryReplaceH.carry_code = oldCarry.carry_code; + wmsCarryReplaceH.newcarry_id = newCarry.id; + wmsCarryReplaceH.newcarry_code = newCarry.carry_code; + row = await _db.Insertable(wmsCarryReplaceH).ExecuteCommandAsync(); + row = await UpdateNullCarry(oldCarry); + isOk = (row > 0); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); + } + else + { + if (oldCarry == null) + { + throw new AppFriendlyException("没有可用的旧载具", 500); + } + if (newCarry == null) + { + throw new AppFriendlyException("没有可用的新载具", 500); + } + + } + await _db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + Log.Error("载具更换失败", ex); + await _db.Ado.RollbackTranAsync(); + throw; + } + return isOk; + } + + public async Task UpdateNullCarry(WmsCarryH carryObj) + { + var row = -1; + try + { + carryObj.status = 0; + carryObj.carry_status = "0"; + carryObj.location_id = null; + carryObj.location_code = null; + carryObj.out_status = "0"; + carryObj.is_check = 0; + carryObj.status = 1; + carryObj.bale_num = null; + carryObj.collocation_scheme_id = null; + carryObj.collocation_scheme_code = null; + carryObj.source_id = null; + carryObj.source_code = null; + row = await _db.Updateable(carryObj).ExecuteCommandAsync(); + } + catch (Exception ex) + { + + } + return row; + } + + private async Task _updateSubCarry(ExChangeCarryInput input) where T : BaseEntity, IWmsCarryEntity, new() + { + var row = -1; + var items = await _db.Queryable().Where(it => it.carry_id == input.old_carry_id).ToListAsync(); + if (items?.Count > 0) + { + List newItems = DeepCopyHelper.DeepCopyList(items); + if (newItems?.Count > 0) + { + newItems.ForEach(x => + { + x.id = SnowflakeIdHelper.NextId(); + x.carry_id = input.new_carry_id; + + }); + row = await _db.Insertable(newItems).ExecuteCommandAsync(); + } + if (row > 0) + { + row = await _db.Deleteable(items).ExecuteCommandAsync(); + } + } + return (row > 0); + } + + + + /// + /// 根据载具Id获取载具条码记录 + /// + /// + /// + + public async Task GetCarryCodeList([FromRoute] string carryId) + { + if (dicMaterial.Count < 1) + { + dicMaterial = await _db.Queryable().ToDictionaryAsync(x => x.id, x => x.name); + } + var items = await _db.Queryable().Where(a => a.carry_id == carryId) + .Select(a => new CarryCodeDetailOutput + { + barcode = a.barcode, + code_batch = a.code_batch, + codeqty = a.codeqty, + material_code = a.material_code, + material_id = a.material_id, + unit_id = a.unit_id, + }) + .Mapper(it => it.material_name = dicMaterial.ContainsKey(it.material_id) ? dicMaterial[it.material_id].ToString()! : "") + .ToListAsync(); + return items; + } + } +}