From 9129277f96de50462e0ffeca6bdec1a0383436b6 Mon Sep 17 00:00:00 2001 From: FanLian Date: Fri, 16 Jun 2023 15:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BD=BD=E5=85=B7=E8=A7=A3?= =?UTF-8?q?=E7=BB=91,=E8=BD=BD=E5=85=B7=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 44 ++- .../WmsCarryReplaceService.cs | 250 +++++++++--------- .../Tnb.WarehouseMgr/WmsCarryUnbindService.cs | 30 ++- .../WmsPDACarryReplaceService.cs | 176 ++++++++++++ 4 files changed, 363 insertions(+), 137 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index 647e5794..7d486bf9 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -57,7 +57,7 @@ namespace Tnb.WarehouseMgr private async Task CarryBind(VisualDevModelDataCrInput input) { - + var isOk = false; try { await _db.Ado.BeginTranAsync(); @@ -66,19 +66,45 @@ namespace Tnb.WarehouseMgr await _runService.Create(templateEntity, input); if (input == null) throw new ArgumentNullException(nameof(input)); - var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarrybindH.carry_id)].ToString()); - var subCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarrybindH.membercarry_id)].ToString()); - //更新主载具明细表,增加新的数据 - var insert_id = await _db.Insertable(new WmsCarryD { + var carryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; + var subCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; + var carry = await _db.Queryable().FirstAsync(it => it.id == carryId); + var subCarry = await _db.Queryable().FirstAsync(it => it.id == subCarryId); + WmsCarrybindH wmsCarrybindH = carry.Adapt(); + if (carryId != null && subCarryId != null) + { + wmsCarrybindH.id = SnowflakeIdHelper.NextId(); + wmsCarrybindH.org_id = carry.org_id; + wmsCarrybindH.carry_id = carry.id; + wmsCarrybindH.membercarry_id = subCarry.id; + wmsCarrybindH.membercarry_code = subCarry.carry_code; + wmsCarrybindH.loc = input.data[nameof(WmsCarrybindH.loc)].ParseToInt(1); + wmsCarrybindH.create_id = _userManager.UserId; + wmsCarrybindH.create_time = DateTime.Now; + var row = await _db.Insertable(wmsCarrybindH).ExecuteCommandAsync(); + carry.carry_status = "1"; + row = await _db.Updateable(carry).ExecuteCommandAsync(); + subCarry.carry_status = "1"; + row = await _db.Updateable(subCarry).ExecuteCommandAsync(); + isOk = (row > 0); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); + + } + /* //更新主载具明细表,增加新的数据 + var row = await _db.Insertable(new WmsCarryD { + id = SnowflakeIdHelper.NextId(), + org_id = carry.org_id, carry_id = carry.id, membercarry_id = subCarry.id, membercarry_code = subCarry.carry_code, - loc = input.data[nameof(WmsCarrybindH.loc)].ToString() + loc = input.data[nameof(WmsCarrybindH.loc)].ToString(), + create_id = _userManager.UserId, + create_time = DateTime.Now }) .ExecuteCommandAsync(); - if (insert_id<=0) throw Oops.Oh(ErrorCode.COM1000); - - await _db.Ado.CommitTranAsync(); + if (row <= 0) throw Oops.Oh(ErrorCode.COM1000); + _db.Updateable().SetColumns(it=>it.carry_status == "1").Where(it=>it.id == input.data[nameof(WmsCarrybindH.carry_id)].ToString());*/ + await _db.Ado.CommitTranAsync(); } catch (Exception ex) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs index d11b4122..bd3368d2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryReplaceService.cs @@ -1,169 +1,175 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using JNPF.Common.Contracts; using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; -using JNPF.Common.Extension; 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 JNPF.VisualDev.Entitys; -using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; -using Tnb.BasicData.Entities; +using Tnb.Common.Utils; using Tnb.WarehouseMgr.Entities; -using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr { /// - /// 载具移出 + /// 载具服务 /// - [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYREPLACE_ID)] - public class WmsCarryReplaceService : BaseWareHouseService + [OverideVisualDev(ModuleId)] + public class WmsCarryReplaceService : BaseWareHouseService, IWmsCarryService { + private const string ModuleId = "26188532491557"; private readonly ISqlSugarClient _db; - private readonly IRunService _runService; - private readonly IVisualDevService _visualDevService; - private readonly IWareHouseService _wareHouseService; - private readonly IBillRullService _billRullService; private readonly IUserManager _userManager; - public WmsCarryReplaceService( - ISqlSugarRepository repository, - IRunService runService, - IVisualDevService visualDevService, - IWareHouseService wareHouseService, - IUserManager userManager, - IBillRullService billRullService) + private readonly IBillRullService _billRullService; + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public WmsCarryReplaceService(ISqlSugarRepository repository, IUserManager userManager, IBillRullService billRullService) { _db = repository.AsSugarClient(); - _runService = runService; - _visualDevService = visualDevService; - _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; OverideFuncs.CreateAsync = CarryReplace; } - private async Task CarryReplace(VisualDevModelDataCrInput input) + /// + /// 更换载具 + /// + /// + /// 输入参数: + ///
{ + ///
old_carry_id:老载具id + ///
new_carry_id:新载具ID + ///
} + /// + /// + /// + [HttpPost] + public async Task CarryReplace(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); - VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYMOOUTSTK_ID, true); - await _runService.Create(templateEntity, input); - if (input == null) throw new ArgumentNullException(nameof(input)); - var oldCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryReplaceH.carry_id)].ToString()); - var newCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryReplaceH.newcarry_id)].ToString()); - if (oldCarry.carrystd_id != newCarry.carrystd_id) - { - string errorMessege = "新老载具规格应相同"; - throw Oops.Oh(errorMessege); - } - if (oldCarry.carrystd_id == newCarry.carrystd_id) - { - var isOk = await _db.Updateable().SetColumns(it => it.carry_id == newCarry.id).Where(it => it.carry_id == oldCarry.id).ExecuteCommandHasChangeAsync(); - if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - isOk = await _db.Updateable().SetColumns(it => it.carry_id == newCarry.id).Where(it => it.carry_id == oldCarry.id).ExecuteCommandHasChangeAsync(); + 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); + } - /* - * db.Updateable(WmsCarryD).SetColumns(it => it.carry_id == newCarry.id).Where(it=>it.carry_id == oldCarry.id).ExecuteCommand(); - */ - - /* //入库取终点 - //var OutStockStrategyInput = new OutStockStrategyQuery { carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)].ToString(), Size = 1 }; - //var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsMoveOutstock.carry_id)].ToString()); - WmsPointH sPoint = null; - WmsPointH ePoint = null; - if (input.data.ContainsKey(nameof(WmsPointH.location_id))) - { - ePoint = await _db.Queryable().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString()); - } - if (carry != null) - { - sPoint = await _db.Queryable().FirstAsync(it => it.location_id == carry.location_id); - } - - if (sPoint != null && ePoint != null) - { - var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); - //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) - if (points?.Count > 0) - { - if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500); - var preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it => - { - var sPoint = it.FirstOrDefault(); - var ePoint = it.LastOrDefault(); - - WmsPretaskH preTask = new(); - preTask.org_id = _userManager.User.OrganizeId; - preTask.startlocation_id = sPoint?.location_id; - preTask.startlocation_code = sPoint?.location_code; - preTask.endlocation_id = ePoint?.location_id; - preTask.endlocation_code = ePoint?.location_code; - preTask.start_floor = sPoint?.floor.ToString(); - preTask.end_floor = ePoint?.floor.ToString(); - preTask.bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(); - preTask.status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID; - preTask.biz_type = WmsWareHouseConst.BIZTYPE_WMSMOOUTSTK_ID; - preTask.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID; - preTask.carry_id = input.data[nameof(preTask.carry_id)]?.ToString()!; - preTask.carry_code = input.data[nameof(preTask.carry_code)]?.ToString()!; - preTask.area_id = sPoint?.area_id; - preTask.area_code = it.Key; - preTask.require_id = input.data["ReturnIdentity"].ToString(); - preTask.require_code = input.data[nameof(preTask.bill_code)]?.ToString()!; - preTask.create_id = _userManager.UserId; - preTask.create_time = DateTime.Now; - return preTask; - }).ToList(); - var isOk = await _wareHouseService.GenPreTask(preTasks); - if (isOk) - { - var preTaskUpInput = new GenPreTaskUpInput(); - preTaskUpInput.RquireId = input.data["ReturnIdentity"].ToString(); - preTaskUpInput.CarryId = input.data[nameof(WmsCarryD.carry_id)]?.ToString()!; - preTaskUpInput.CarryStartLocationId = points.FirstOrDefault().location_id; - preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault().location_code; - preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList(); - preTaskUpInput.PreTaskRecords = preTasks.Adapt>(); - preTaskUpInput.PreTaskRecords.ForEach(x => x.id = SnowflakeIdHelper.NextId()); - await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, null, null); - - } - } - - }*/ - - + } await _db.Ado.CommitTranAsync(); } catch (Exception ex) { + Log.Error("载具更换失败", ex); await _db.Ado.RollbackTranAsync(); throw; } - return Task.FromResult(true); + return isOk; } - /* public override async Task ModifyAsync(WareHouseUpInput input) + + public async Task UpdateNullCarry(WmsCarryH carryObj) { - if (input == null) throw new ArgumentNullException(nameof(input)); - var isOk = await _db.Updateable().SetColumns(it => new WmsCarryReplaceH { status = input.bizTypeId }).Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync(); - if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - }*/ + 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); + } } -} +} \ No newline at end of file diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs index 947b0646..6ffdd5b1 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs @@ -57,7 +57,7 @@ namespace Tnb.WarehouseMgr private async Task CarryUnbind(VisualDevModelDataCrInput input) { - + var isOk = false; try { await _db.Ado.BeginTranAsync(); @@ -66,12 +66,30 @@ namespace Tnb.WarehouseMgr await _runService.Create(templateEntity, input); if (input == null) throw new ArgumentNullException(nameof(input)); - var carry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryunbindH.carry_id)].ToString()); - var subCarry = await _db.Queryable().FirstAsync(it => it.id == input.data[nameof(WmsCarryunbindH.membercarry_id)].ToString()); + var carryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; + var subCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; + var carry = await _db.Queryable().FirstAsync(it => it.id == carryId); + var subCarry = await _db.Queryable().FirstAsync(it => it.id == subCarryId); + //WmsCarryunbindH wmsCarryUnbindH = carry.Adapt(); + if (carryId != null && subCarryId != null) + { + //wmsCarryUnbindH.id = SnowflakeIdHelper.NextId(); + //wmsCarryUnbindH.org_id = carry.org_id; + //wmsCarryUnbindH.carry_id = carry.id; + //wmsCarryUnbindH.membercarry_id = subCarry.id; + //wmsCarryUnbindH.membercarry_code = subCarry.carry_code; + //wmsCarryUnbindH.loc = input.data[nameof(WmsCarryunbindH.loc)].ParseToInt(1); + //wmsCarryUnbindH.create_id = _userManager.UserId; + //wmsCarryUnbindH.create_time = DateTime.Now; + var row = await _db.Deleteable().Where(it=>it.carry_id == subCarry.id).ExecuteCommandAsync(); + carry.carry_status = "0"; + row = await _db.Updateable(carry).ExecuteCommandAsync(); + subCarry.carry_status = "0"; + row = await _db.Updateable(subCarry).ExecuteCommandAsync(); + isOk = (row > 0); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); - - var deleteQty = await _db.Deleteable().Where(it => it.carry_id == carry.id ).ExecuteCommandAsync(); - if (deleteQty <= 0) throw Oops.Oh(ErrorCode.COM1002); + } await _db.Ado.CommitTranAsync(); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs new file mode 100644 index 00000000..e8b7e20a --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryReplaceService.cs @@ -0,0 +1,176 @@ +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.Common.Utils; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Attributes; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Enums; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + /// + /// 载具服务 + /// + [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYREPLACEPDA_ID)] + public class WmsPDACarryReplaceService : BaseWareHouseService, IWmsCarryService + { + //private const string ModuleId = "26188532491557"; + private readonly ISqlSugarClient _db; + private readonly IUserManager _userManager; + private readonly IBillRullService _billRullService; + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + public WmsPDACarryReplaceService(ISqlSugarRepository repository, IUserManager userManager, IBillRullService billRullService) + { + _db = repository.AsSugarClient(); + _userManager = userManager; + _billRullService = billRullService; + OverideFuncs.CreateAsync = PDACarryReplace; + } + + /// + /// 更换载具 + /// + /// + /// 输入参数: + ///
{ + ///
old_carry_id:老载具id + ///
new_carry_id:新载具ID + ///
} + /// + /// + /// + [HttpPost] + public async Task PDACarryReplace(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); + } + } +} \ No newline at end of file