diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs index 8902bb16..5120d04a 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs @@ -736,7 +736,7 @@ namespace Tnb.ProductionMgr } else { - Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbind(new CarryCodeUnbindInput() + Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbindWithoutTran(new CarryCodeUnbindInput() { carry_id = detail.member_carry_id },db); @@ -752,7 +752,7 @@ namespace Tnb.ProductionMgr if (carry.carrystd_id == WmsWareHouseConst.CARRY_ZYXCSTD_ID || carry.carrystd_id == WmsWareHouseConst.CARRY_ZYLJSTD_ID) { - Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbind(new CarryCodeUnbindInput() + Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbindWithoutTran(new CarryCodeUnbindInput() { carry_id = carry.id },db); @@ -772,7 +772,7 @@ namespace Tnb.ProductionMgr if (carry.carrystd_id==WmsWareHouseConst.CARRY_LXSTD_ID || carry.carrystd_id==WmsWareHouseConst.CARRY_LJSTD_ID) { - Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result2 = await _wmsCarryUnbindService.CarryUnbind(new CarryBindInput() + Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result2 = await _wmsCarryUnbindService.CarryUnbindWithoutTran(new CarryBindInput() { org = prdFeedingH.org_id, create_id = prdFeedingH.create_id, diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryUnbindService.cs b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryUnbindService.cs index 406d2fcd..d66a19a0 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryUnbindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryUnbindService.cs @@ -14,6 +14,19 @@ namespace Tnb.WarehouseMgr.Interfaces Task CarryCodeUnbind(CarryCodeUnbindInput input, ISqlSugarClient dbConn = null); Task CarryCodeUnbindCode(CarryCodeUnbindCodeInput input, ISqlSugarClient dbConn = null); - + /// + /// WmsCarryD解绑 传dbConn方法不控制事务 不传dbConn则方法自带事务 + /// + /// + /// + /// + Task CarryUnbindWithoutTran(CarryBindInput input, ISqlSugarClient dbConn = null); + /// + /// WmsCarryCode解绑 传dbConn方法不控制事务 不传dbConn则方法自带事务 + /// + /// + /// + /// + Task CarryCodeUnbindWithoutTran(CarryCodeUnbindInput input, ISqlSugarClient dbConn = null); } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs index 15787604..08dca023 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryUnbindService.cs @@ -287,5 +287,137 @@ namespace Tnb.WarehouseMgr } return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功"); } + + public async Task CarryUnbindWithoutTran(CarryBindInput input, ISqlSugarClient dbConn = null) + { + bool isOk = false; + + ISqlSugarClient db = null; + bool tranFlag = true; + + if (dbConn == null) + { + db = _db; + } + else + { + tranFlag = false; + db = dbConn; + } + + try + { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + WmsCarryH? carry = await db.Queryable().SingleAsync(it => it.id == input.carry_id); + if (carry != null) + { + + // 插入子载具绑定记录 + //VisualDevModelDataCrInput visualDevModelCrInput = new() { data = new Dictionary() }; + //visualDevModelCrInput.data[nameof(WmsCarrybindH.carry_id)] = input.carry_id; + //visualDevModelCrInput.data[nameof(WmsCarrybindH.carry_code)] = input.carry_code; + //visualDevModelCrInput.data[nameof(WmsCarrybindH.membercarry_id)] = input.membercarry_id; + //visualDevModelCrInput.data[nameof(WmsCarrybindH.membercarry_code)] = input.membercarry_code; + //visualDevModelCrInput.data[nameof(WmsCarrybindH.type)] = 0; + //visualDevModelCrInput.data[nameof(WmsCarrybindH.carrystd_id)] = carry.carrystd_id; + //if (!string.IsNullOrEmpty(input.create_id)) + // visualDevModelCrInput.data[nameof(WmsCarrybindH.create_id)] = input.create_id; + + //visualDevModelCrInput.data[nameof(WmsCarrybindH.create_time)] = DateTime.Now; + //visualDevModelCrInput.data[nameof(WmsCarrybindH.loc)] = 1; + //VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYUNBIND_ID, true); + //await _runService.Create(templateEntity, visualDevModelCrInput); + + if (tranFlag) await db.Ado.BeginTranAsync(); + int row = await db.Deleteable().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync(); + //isOk = row > 0; + + //if (!isOk) + //{ + // throw new Exception($"料架id{input.carry_id}载具解绑失败"); + //} + Logger.LogInformation($"【CarryUnbindWithoutTran】料架{carry.carry_code}已解绑,解绑条数{row}"); + + + if (tranFlag) await db.Ado.CommitTranAsync(); + } + else + { + if (carry == null) + { + throw new AppFriendlyException("没有可用的主载具", 500); + } + } + } + catch (Exception ex) + { + Logger.LogError($"【CarryUnbindWithoutTran】 {ex.Message}"); + Logger.LogError($"【CarryUnbindWithoutTran】 {ex.StackTrace}"); + if (tranFlag) await db.Ado.RollbackTranAsync(); + throw Oops.Bah(ex.Message); + } + + return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功"); + } + + public async Task CarryCodeUnbindWithoutTran(CarryCodeUnbindInput input, ISqlSugarClient dbConn = null) + { + bool isOk = false; + + ISqlSugarClient db = null; + bool tranFlag = true; + + if (dbConn == null) + { + db = _db; + } + else + { + tranFlag = false; + db = dbConn; + } + + try + { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + WmsCarryH? carry = await db.Queryable().SingleAsync(it => it.id == input.carry_id); + if (carry != null) + { + if (tranFlag) await db.Ado.BeginTranAsync(); + int row = await db.Deleteable().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync(); + if (tranFlag) await db.Ado.CommitTranAsync(); + isOk = row > 0; + + Logger.LogInformation($"【CarryCodeUnbindWithoutTran】载具{carry.carry_code}已解绑,解绑条数{row}"); + //if (!isOk) + //{ + // throw Oops.Oh(ErrorCode.COM1001); + //} + } + else + { + if (carry == null) + { + throw new AppFriendlyException("没有可用的主载具", 500); + } + } + } + catch (Exception ex) + { + Logger.LogError($"【CarryCodeUnbindWithoutTran】 {ex.Message}"); + Logger.LogError($"【CarryCodeUnbindWithoutTran】 {ex.StackTrace}"); + if (tranFlag) await db.Ado.RollbackTranAsync(); + throw Oops.Bah(ex.Message); + } + return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功"); + } } }