From 0968abf3f0be2198e3d6902eb79920db35aa2830 Mon Sep 17 00:00:00 2001 From: FanLian Date: Tue, 20 Jun 2023 17:34:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0PDA=E8=BD=BD=E5=85=B7?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=92=8C=E8=A7=A3=E7=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WmsPDACarryBindService.cs | 132 ++++++++++++++++++ .../WmsPDACarryUnbindService .cs | 108 ++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryUnbindService .cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs new file mode 100644 index 00000000..983dbb47 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Enums; +using JNPF.Common.Extension; +using JNPF.Common.Security; +using JNPF.FriendlyException; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Attributes; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + /// + /// 载具绑定 + /// + [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYBINDPDA_ID)] + public class WmsPDACarryBindService : BaseWareHouseService + { + private readonly ISqlSugarClient _db; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + private readonly IUserManager _userManager; + private readonly IBillRullService _billRullService; + public WmsPDACarryBindService( + ISqlSugarRepository repository, + IRunService runService, + IVisualDevService visualDevService, + IUserManager userManager, + IBillRullService billRullService) + { + _db = repository.AsSugarClient(); + _runService = runService; + _visualDevService = visualDevService; + _userManager = userManager; + _billRullService = billRullService; + OverideFuncs.CreateAsync = PDACarryBind; + } + + private async Task PDACarryBind(VisualDevModelDataCrInput input) + { + var isOk = false; + try + { + await _db.Ado.BeginTranAsync(); + + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYMOOUTSTK_ID, true); + await _runService.Create(templateEntity, input); + + if (input == null) throw new ArgumentNullException(nameof(input)); + 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().SingleAsync(it => it.id == carryId); + var subCarry = await _db.Queryable().SingleAsync(it => it.id == subCarryId); + WmsCarrybindH wmsCarrybindH = carry.Adapt(); + if (carry != null && subCarry != 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(); + var items = await _db.Queryable().Where(it => it.carry_id == subCarryId).ToListAsync(); + for (int i = 0; i < items.Count; i++) + { + WmsCarrybindCode wmsCarrybindCode = new(); + wmsCarrybindCode.id = SnowflakeIdHelper.NextId(); + wmsCarrybindCode.org_id = subCarry.id; + wmsCarrybindCode.carrybind_id = wmsCarrybindH.id; + wmsCarrybindCode.material_id = items[i].material_id; + wmsCarrybindCode.material_code = items[i].material_code; + wmsCarrybindCode.barcode = items[i].barcode; + wmsCarrybindCode.code_batch = items[i].code_batch; + wmsCarrybindCode.codeqty = items[i].codeqty; + wmsCarrybindCode.membercarry_id = subCarry.id; + wmsCarrybindCode.membercarry_code = subCarry.carry_code; + wmsCarrybindCode.unit_id = items[i].unit_id; + wmsCarrybindCode.unit_code = items[i].unit_code; + wmsCarrybindCode.create_id = _userManager.UserId; + wmsCarrybindCode.create_time = DateTime.Now; + row = await _db.Insertable(wmsCarrybindCode).ExecuteCommandAsync(); + } + isOk = (row > 0); + if (!isOk) throw Oops.Oh(ErrorCode.COM1001); + } + else + { + if (carry == null || subCarry == null) + { + throw new AppFriendlyException("没有可用的主载具", 500); + } + } + await _db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await _db.Ado.RollbackTranAsync(); + throw; + } + return Task.FromResult(true); + } + /* public override async Task ModifyAsync(WareHouseUpInput input) + { + 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); + }*/ + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryUnbindService .cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryUnbindService .cs new file mode 100644 index 00000000..d1128ff6 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryUnbindService .cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Enums; +using JNPF.Common.Extension; +using JNPF.Common.Security; +using JNPF.FriendlyException; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Attributes; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + /// + /// 载具解绑 + /// + [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYUNBINDPDA_ID)] + public class WmsPDACarryUnbindService : BaseWareHouseService + { + private readonly ISqlSugarClient _db; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + private readonly IUserManager _userManager; + private readonly IWareHouseService _wareHouseService; + public WmsPDACarryUnbindService( + ISqlSugarRepository repository, + IRunService runService, + IVisualDevService visualDevService, + IWareHouseService wareHouseService, + IUserManager userManager) + { + _db = repository.AsSugarClient(); + _runService = runService; + _visualDevService = visualDevService; + _userManager = userManager; + _wareHouseService = wareHouseService; + OverideFuncs.CreateAsync = PDACarryUnbind; + } + private async Task PDACarryUnbind(VisualDevModelDataCrInput input) + { + var isOk = false; + try + { + await _db.Ado.BeginTranAsync(); + + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYMOOUTSTK_ID, true); + await _runService.Create(templateEntity, input); + + if (input == null) throw new ArgumentNullException(nameof(input)); + 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 (carry != null && subCarry != null) + { + 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); + } + else + { + if (carry == null) + { + throw new AppFriendlyException("没有可用的主载具", 500); + } + if (subCarry == null) + { + throw new AppFriendlyException("没有可用的子载具", 500); + } + } + + await _db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await _db.Ado.RollbackTranAsync(); + throw; + } + return Task.FromResult(true); + } + /* public override async Task ModifyAsync(WareHouseUpInput input) + { + 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); + }*/ + } +}