From ee4bbf62fe684621583cd46a98ceb6bb36ecc5e2 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 10 Jul 2023 14:58:52 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs | 2 +- WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs index 27d2533a..729a1728 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs @@ -253,7 +253,7 @@ namespace Tnb.WarehouseMgr //入库申请条码明细表 List instockcodes = input.instockcodes; //如果数据不全, - if (instock.IsNull() || instock.carry_id.IsNullOrWhiteSpace() || instock.location_id.IsNullOrWhiteSpace() || instockds?.Count < 1 || instockcodes?.Count < 1) + if ((instock?.carry_id.IsNullOrWhiteSpace() ?? true) || (instock?.location_id.IsNullOrWhiteSpace() ?? true) || instockds?.Count < 1 || instockcodes?.Count < 1) { //报错, 提示数据不全。 throw new AppFriendlyException("数据不全!", 500); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs index afe444a5..3330140a 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs @@ -199,7 +199,7 @@ namespace Tnb.WarehouseMgr } catch (Exception) { - await _db.Ado.RollbackTranAsync(); + await _db.Ado.RollbackTranAsync(); throw; } return Task.FromResult(true); @@ -216,12 +216,12 @@ namespace Tnb.WarehouseMgr if (kittingOut != null) { var locaion = await _db.Queryable().SingleAsync(it => it.id == kittingOut.location_id); - if (locaion != null && locaion.is_type.ToEnum() != EnumLocationType.存储库位) + if (locaion?.is_type.ToEnum() != EnumLocationType.存储库位) { kittingOut.status = WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID; - + } - else + else { kittingOut.status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID; } From 0b99644eea91bf40583bbd42279535466777e728 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 11 Jul 2023 11:35:02 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B6=88=E9=99=A4warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.WarehouseMgr/WmsInStockService.cs | 44 ++++++++++--------- .../Options/ConfigureSwaggerUIOptions.cs | 37 ++++++++++++++++ 2 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 common/Tnb.Common/Options/ConfigureSwaggerUIOptions.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs index 729a1728..84064d4e 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs @@ -85,7 +85,7 @@ namespace Tnb.WarehouseMgr [HttpPost] public async Task BarCodePrint(BarCodePrintInput input) { - if (input == null) throw new ArgumentNullException("input"); + if (input == null) throw new ArgumentNullException(nameof(input)); if (input.BillIds == null || input.BillIds.Count == 0) throw new ArgumentException($"parameter {nameof(input.BillIds)} not be null or zero"); try { @@ -161,28 +161,30 @@ namespace Tnb.WarehouseMgr private Task CreateInstock(WmsInstockD detail, int no) { - WmsTempCode barCode = new(); - barCode.org_id = detail.org_id; - barCode.material_id = detail.material_id; - barCode.material_code = detail.material_code; var code = $"{detail.material_code}{detail.code_batch}{no.ToString().PadLeft(4, '0')}"; - barCode.barcode = code; - barCode.code_batch = detail.code_batch; - barCode.codeqty = detail.pr_qty!.Value; - barCode.unit_id = detail.unit_id; - barCode.is_lock = 0; - barCode.is_end = 0; - barCode.require_id = detail.bill_id; - barCode.require_code = _dicBillCodes.ContainsKey(detail.bill_id) ? _dicBillCodes[detail.bill_id]?.ToString() : ""; - barCode.create_id = _userManager.UserId; - barCode.create_time = DateTime.Now; + WmsTempCode barCode = new() + { + org_id = detail.org_id, + material_id = detail.material_id, + material_code = detail.material_code, + barcode = code, + code_batch = detail.code_batch, + codeqty = detail.pr_qty!.Value, + unit_id = detail.unit_id, + is_lock = 0, + is_end = 0, + require_id = detail.bill_id, + require_code = _dicBillCodes.ContainsKey(detail.bill_id) ? _dicBillCodes[detail.bill_id]?.ToString() : "", + create_id = _userManager.UserId, + create_time = DateTime.Now + }; return Task.FromResult(barCode); } public override async Task ModifyAsync(WareHouseUpInput input) { - if (input == null) throw new ArgumentNullException("input"); + if (input == null) throw new ArgumentNullException(nameof(input)); //更具distaskCode的barcode 更新 instockcode 的 is_end 为 1 try { @@ -351,7 +353,7 @@ namespace Tnb.WarehouseMgr List pretaskCodes = new(); foreach (var pt in preTasks) { - if (instockCOdes.Count() > 0) + if (instockCOdes.Count > 0) { foreach (var jo in instockCOdes) { @@ -377,9 +379,9 @@ namespace Tnb.WarehouseMgr var preTaskUpInput = new GenPreTaskUpInput(); preTaskUpInput.RquireId = instock.id; preTaskUpInput.CarryId = instock.carry_id!; - preTaskUpInput.CarryStartLocationId = points.FirstOrDefault()!.location_id!; - preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault()!.location_code!; - preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList()!; + preTaskUpInput.CarryStartLocationId = points.FirstOrDefault()?.location_id; + preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault()?.location_code; + preTaskUpInput.LocationIds = (points?.Select(x => x.location_id)?.ToList() ?? Enumerable.Empty().ToList()) as List; //创建预任务操作记录 var operBillId = string.Empty; @@ -393,7 +395,7 @@ namespace Tnb.WarehouseMgr preTaskUpInput.PreTaskRecord = handleH; } //创建预任务条码操作记录 - if (instockcodes != null && instockcodes.Count() > 0) + if (instockcodes?.Count > 0) { foreach (var jo in instockcodes) { diff --git a/common/Tnb.Common/Options/ConfigureSwaggerUIOptions.cs b/common/Tnb.Common/Options/ConfigureSwaggerUIOptions.cs new file mode 100644 index 00000000..2b17b266 --- /dev/null +++ b/common/Tnb.Common/Options/ConfigureSwaggerUIOptions.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Options; +using Swashbuckle.AspNetCore.SwaggerUI; + +namespace Tnb.Common.Options +{ + public class ConfigureSwaggerUIOptions : IConfigureOptions + { + private readonly IWebHostEnvironment _hostingEnvironment; + + public ConfigureSwaggerUIOptions(IWebHostEnvironment hostingEnvironment) + { + _hostingEnvironment = hostingEnvironment; + } + + public void Configure(SwaggerUIOptions options) + { + // Configure SwaggerUI options + + options.DefaultModelExpandDepth(2); + options.DefaultModelRendering(ModelRendering.Example); + options.DocExpansion(DocExpansion.List); + options.EnableDeepLinking(); + options.DisplayOperationId(); + options.EnableFilter(); + options.MaxDisplayedTags(5); + options.ShowExtensions(); + } + } + +} From dd049ceeed2b73af076096af5a0b42363b2ccf13 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Tue, 11 Jul 2023 14:39:34 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=A4=87=E4=BB=B6=E9=A2=86=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Consts/CodeTemplateConst.cs | 5 + .../Entity/EqpSparePartsInstockD.cs | 52 +++++++ .../Entity/EqpSparePartsInstockH.cs | 82 +++++++++++ .../Entity/EqpSparePartsRequisitionD.cs | 47 ++++++ .../Entity/EqpSparePartsRequisitionH.cs | 87 ++++++++++++ .../IEqpSparePartsRequisitionHService.cs | 10 ++ .../EqpSparePartsRequisitionHService.cs | 134 ++++++++++++++++++ 7 files changed, 417 insertions(+) create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs create mode 100644 EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs create mode 100644 EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs diff --git a/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs index a62d9c12..96890e79 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs @@ -19,5 +19,10 @@ namespace Tnb.BasicData /// 生产任务单号单据模板编码 /// public const string PRDMOTASK_CODE = "ProductionPlanAndSchedule"; + + /// + /// 备件领用 + /// + public const string SPAREPARTSREQUISITION_CODE = "SparePartsRequisition"; } } \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs new file mode 100644 index 00000000..9797a1a9 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs @@ -0,0 +1,52 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.EquipMgr.Entities; + +/// +/// 备件入库子表 +/// +[SugarTable("eqp_spare_parts_instock_d")] +public partial class EqpSparePartsInstockD : BaseEntity +{ + public EqpSparePartsInstockD() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 备件入库单id + /// + public string? instock_id { get; set; } + + /// + /// 备件id + /// + public string? spare_parts_id { get; set; } + + /// + /// 入库数量 + /// + public int quantity { get; set; } + + /// + /// 库位id + /// + public string? location_id { get; set; } + + /// + /// 质保开始时间 + /// + public DateTime? warranty_start_time { get; set; } + + /// + /// 质保结束时间 + /// + public DateTime? warranty_end_time { get; set; } + + /// + /// 已领数量 + /// + public int use_quantity { get; set; } + +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs new file mode 100644 index 00000000..46754943 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs @@ -0,0 +1,82 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.EquipMgr.Entities; + +/// +/// 备件入库 +/// +[SugarTable("eqp_spare_parts_instock_h")] +public partial class EqpSparePartsInstockH : BaseEntity +{ + public EqpSparePartsInstockH() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 入库单编号 + /// + public string? code { get; set; } + + /// + /// 入库时间 + /// + public string? instock_time { get; set; } + + /// + /// 入库人员 + /// + public string? instock_id { get; set; } + + /// + /// 库位号 + /// + public string? location_id { get; set; } + + /// + /// 备件id + /// + public string? spare_parts_id { get; set; } + + /// + /// 描述 + /// + public string? descrip { get; set; } + + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改用户 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 所属组织 + /// + public string? org_id { get; set; } + + /// + /// 流程任务Id + /// + public string? f_flowtaskid { get; set; } + + /// + /// 流程引擎Id + /// + public string? f_flowid { get; set; } + +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs new file mode 100644 index 00000000..e3fef537 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs @@ -0,0 +1,47 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.EquipMgr.Entities; + +/// +/// 备件领用子表 +/// +[SugarTable("eqp_spare_parts_requisition_d")] +public partial class EqpSparePartsRequisitionD : BaseEntity +{ + public EqpSparePartsRequisitionD() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 备件id + /// + public string spare_parts_id { get; set; } = string.Empty; + + /// + /// 批号 + /// + public string? batch { get; set; } + + /// + /// 数量 + /// + public int quantity { get; set; } + + /// + /// 备件领用主表id + /// + public string spare_parts_requisition_id { get; set; } = string.Empty; + + /// + /// 设备id + /// + public string? equip_id { get; set; } + + /// + /// 备件入库id + /// + public string? instock_detail_id { get; set; } + +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs new file mode 100644 index 00000000..2eac0c08 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs @@ -0,0 +1,87 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.EquipMgr.Entities; + +/// +/// 备件领用主表 +/// +[SugarTable("eqp_spare_parts_requisition_h")] +public partial class EqpSparePartsRequisitionH : BaseEntity +{ + public EqpSparePartsRequisitionH() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 领用单编号 + /// + public string? code { get; set; } + + /// + /// 作用设备id + /// + public string? equip_id { get; set; } + + /// + /// 使用部门 + /// + public string? department { get; set; } + + /// + /// 领用目的 + /// + public string? requisition_purpose { get; set; } + + /// + /// 库位号 + /// + public string? location_id { get; set; } + + /// + /// 备件id + /// + public string? spare_parts_id { get; set; } + + /// + /// 领用人 + /// + public string? recipient_id { get; set; } + + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改用户 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 所属组织 + /// + public string? org_id { get; set; } + + /// + /// 流程任务Id + /// + public string? f_flowtaskid { get; set; } + + /// + /// 流程引擎Id + /// + public string? f_flowid { get; set; } + +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs b/EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs new file mode 100644 index 00000000..85b1bb7a --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs @@ -0,0 +1,10 @@ +namespace Tnb.EquipMgr.Interfaces +{ + /// + /// 备品备件领用服务 + /// + public interface IEqpSparePartsRequisitionHService + { + + } +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs b/EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs new file mode 100644 index 00000000..66a40260 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs @@ -0,0 +1,134 @@ +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.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; +using Microsoft.AspNetCore.Mvc; +using Microsoft.ClearScript.Util.Web; +using SqlSugar; +using Tnb.EquipMgr.Entities; +using Tnb.EquipMgr.Entities.Dto; +using Tnb.EquipMgr.Interfaces; + +namespace Tnb.EquipMgr +{ + /// + /// 备品备件领用服务 + /// + [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + [OverideVisualDev(ModuleId)] + public class EqpSparePartsRequisitionHService : IEqpSparePartsRequisitionHService, IOverideVisualDevService,IDynamicApiController, ITransient + { + private const string ModuleId = "27338205223957"; + private readonly ISqlSugarRepository _repository; + private readonly IVisualDevService _visualDevService; + private readonly IRunService _runService; + private readonly IUserManager _userManager; + private readonly IBillRullService _billRuleService; + + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + + public EqpSparePartsRequisitionHService(ISqlSugarRepository repository, + IRunService runService, + IVisualDevService visualDevService, + IBillRullService billRuleService, + IUserManager userManager) + { + _repository = repository; + _visualDevService = visualDevService; + _runService = runService; + _userManager = userManager; + _billRuleService = billRuleService; + OverideFuncs.CreateAsync = Create; + } + + private async Task Create(VisualDevModelDataCrInput input) + { + var db = _repository.AsSugarClient(); + DbResult result = await db.Ado.UseTranAsync(async () => + { + // VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); + // await _runService.Create(templateEntity, input); + var code = await _billRuleService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.SPAREPARTSREQUISITION_CODE); + EqpSparePartsRequisitionH eqpSparePartsRequisitionH = new EqpSparePartsRequisitionH() + { + code = code, + equip_id = input.data.ContainsKey("equip_id") ? input.data["equip_id"].ToString() : "", + department = input.data.ContainsKey("department") ? input.data["department"].ToString() : "", + recipient_id = input.data.ContainsKey("recipient_id") ? input.data["recipient_id"].ToString() : "", + requisition_purpose = input.data.ContainsKey("requisition_purpose") ? input.data["requisition_purpose"].ToString() : "", + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId, + }; + + await db.Insertable(eqpSparePartsRequisitionH).ExecuteCommandAsync(); + + if (input.data.TryGetValue("tablefield120", out var value)) + { + var details = value.ToObject>>(); + List eqpSparePartsList = new List(); + List eqpSparePartsRequisitionDs = new List(){}; + foreach (var detail in details) + { + string instockDetailId = detail.ContainsKey("instock_detail_id") ? detail["instock_detail_id"] : ""; + string sparePartsId = detail.ContainsKey("spare_parts_id") ? detail["spare_parts_id"] : ""; + int quantity = Convert.ToInt32(detail.ContainsKey("quantity") ? detail["quantity"] : ""); + + eqpSparePartsRequisitionDs.Add(new EqpSparePartsRequisitionD + { + instock_detail_id = instockDetailId, + spare_parts_id = sparePartsId, + quantity = quantity, + equip_id = eqpSparePartsRequisitionH.equip_id, + spare_parts_requisition_id = eqpSparePartsRequisitionH.id, + }); + + if (await db.Queryable() + .AnyAsync(x => x.id == instockDetailId && (x.quantity - x.use_quantity - quantity) >= 0)) + { + eqpSparePartsList.Add(new EqpEquipSpareParts + { + equip_id = input.data["equip_id"]?.ToString() ?? "", + spare_parts_id = sparePartsId, + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId + }); + + await db.Updateable() + .SetColumns(x => x.use_quantity == x.use_quantity + quantity) + .Where(x => x.id == instockDetailId).ExecuteCommandAsync(); + } + else + { + throw new Exception("库存不够"); + } + + } + + if (eqpSparePartsRequisitionDs.Count > 0) + { + await db.Insertable(eqpSparePartsRequisitionDs).ExecuteCommandAsync(); + } + + if (eqpSparePartsList.Count > 0) + { + await db.Insertable(eqpSparePartsList).ExecuteCommandAsync(); + } + } + + }); + + if (!result.IsSuccess) throw Oops.Bah(result.ErrorMessage); + return result.IsSuccess ? "保存成功" : result.ErrorMessage; + } + } +} \ No newline at end of file From 252ae13496241df71731946cda3227648bb42b8c Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Tue, 11 Jul 2023 15:36:23 +0800 Subject: [PATCH 4/5] bug --- BasicData/Tnb.BasicData/BasMbomService.cs | 559 +++++++++--------- .../Tnb.ProductionMgr/PrdMoTaskService.cs | 28 +- 2 files changed, 296 insertions(+), 291 deletions(-) diff --git a/BasicData/Tnb.BasicData/BasMbomService.cs b/BasicData/Tnb.BasicData/BasMbomService.cs index 48152663..787c8bbf 100644 --- a/BasicData/Tnb.BasicData/BasMbomService.cs +++ b/BasicData/Tnb.BasicData/BasMbomService.cs @@ -237,280 +237,281 @@ namespace Tnb.BasicData }) .ToListAsync(); } - /// - /// 保存生产bom - /// - /// - /// - [HttpPost] - public async Task SaveData(MbomSaveDataInput mbomSaveDataInput) - { - ErrorCode errorCode = ErrorCode.COM1008; - DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => - { - //新增 - if (string.IsNullOrEmpty(mbomSaveDataInput.id)) - { - string mbomId = SnowflakeIdHelper.NextId(); - string orgId = _userManager.GetUserInfo().Result.organizeId; - BasMbom mbom = new BasMbom() - { - id = mbomId, - org_id = orgId, - material_id = mbomSaveDataInput.material_id, - num = mbomSaveDataInput.num, - unit_id = mbomSaveDataInput.unit_id, - version = mbomSaveDataInput.version, - start_time = mbomSaveDataInput.start_time, - end_time = mbomSaveDataInput.end_time, - ebom_id = mbomSaveDataInput.ebom_id, - route_id = mbomSaveDataInput.route_id, - is_first = mbomSaveDataInput.is_first, - remark = mbomSaveDataInput.remark, - create_id = _userManager.UserId, - create_time = DateTime.Now, - - }; - - if (await _repository.IsAnyAsync(x => - x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version)) - { - errorCode = ErrorCode.COM1004; - throw Oops.Oh(ErrorCode.COM1004); - } - await _repository.InsertAsync(mbom); - List processes = new List(); - List inputs = new List(); - List outputs = new List(); - - if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null) - { - int index = 0; - foreach (var process in mbomSaveDataInput.processes) - { - string mbomProcessId = SnowflakeIdHelper.NextId(); - processes.Add(new BasMbomProcess() - { - id = mbomProcessId, - org_id = orgId, - mbom_id = mbomId, - process_id = process?.process_id ?? "", - preparation_time = process?.preparation_time ?? 0, - station = process?.station ?? "", - byproduct_status = process?.byproduct_status ?? 0, - production_method = process?.production_method, - route_detail_id = process?.route_detail_id ?? "", - ordinal = ++index, - is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0, - - }); - - if (process!.inputs != null) - { - foreach (var input in process.inputs) - { - string inputId = SnowflakeIdHelper.NextId(); - inputs.Add(new BasMbomInput() - { - id = inputId, - mbom_id = mbomId, - mbom_process_id = mbomProcessId, - process_id = process?.process_id ?? "", - material_id = input.material_id, - num = input.num, - org_id = orgId, - }); - } - } - - if (process.outputs != null) - { - foreach (var output in process.outputs) - { - string outputId = SnowflakeIdHelper.NextId(); - outputs.Add(new BasMbomOutput() - { - id = outputId, - mbom_id = mbomId, - mbom_process_id = mbomProcessId, - process_id = process?.process_id ?? "", - material_id = output.material_id, - num = output.num, - org_id = orgId, - }); - } - } - } - } - - if (processes.Count > 0) - { - await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync(); - } - - if (inputs.Count > 0) - { - await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync(); - } - - if (outputs.Count > 0) - { - await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync(); - } - } - else//修改 - { - if (await _repository.IsAnyAsync(x => - x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id)) - { - errorCode = ErrorCode.COM1004; - throw Oops.Oh(ErrorCode.COM1004); - } - - string orgId = _userManager.GetUserInfo().Result.organizeId; - if (mbomSaveDataInput != null) - { - await _repository.UpdateAsync(x => new BasMbom() - { - // org_id = orgId, - material_id = mbomSaveDataInput.material_id, - num = mbomSaveDataInput.num, - unit_id = mbomSaveDataInput.unit_id, - version = mbomSaveDataInput.version, - start_time = mbomSaveDataInput.start_time, - end_time = mbomSaveDataInput.end_time, - ebom_id = mbomSaveDataInput.ebom_id, - route_id = mbomSaveDataInput.route_id, - is_first = mbomSaveDataInput.is_first, - remark = mbomSaveDataInput.remark, - modify_id = _userManager.UserId, - modify_time = DateTime.Now, - - }, x => x.id == mbomSaveDataInput.id); - } - // List processes = new List(); - List inputs = new List(); - List outputs = new List(); - - if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null) - { - foreach (var process in mbomSaveDataInput.processes) - { - string mbomProcessId = process.id; - // string mbomProcessId = SnowflakeIdHelper.NextId(); - // processes.Add(new BasMbomProcess() - // { - // id = mbomProcessId, - // org_id = orgId ?? "", - // mbom_id = mbomSaveDataInput?.id ?? "", - // process_id = process?.process_id ?? "", - // preparation_time = process?.preparation_time ?? 0, - // station = process.station, - // byproduct_status = process.byproduct_status, - // production_method = process.production_method, - // route_detail_id = process.route_detail_id, - // - // }); - - decimal preparation_time = process?.preparation_time ?? 0; - await _repository.AsSugarClient().Updateable() - .SetColumns(x => x.preparation_time == preparation_time) - .SetColumns(x => x.station == process!.station) - .SetColumns(x => x.byproduct_status == process!.byproduct_status) - .SetColumns(x => x.production_method == process!.production_method) - .Where(x => x.id == process!.id).ExecuteCommandAsync(); - - if (process!.inputs != null) - { - foreach (var input in process.inputs) - { - string inputId = SnowflakeIdHelper.NextId(); - inputs.Add(new BasMbomInput() - { - id = inputId, - mbom_id = mbomSaveDataInput?.id ?? "", - mbom_process_id = mbomProcessId, - process_id = process?.process_id ?? "", - material_id = input.material_id, - num = input.num, - org_id = orgId, - }); - } - } - - if (process.outputs != null) - { - foreach (var output in process.outputs) - { - string outputId = SnowflakeIdHelper.NextId(); - outputs.Add(new BasMbomOutput() - { - id = outputId, - mbom_id = mbomSaveDataInput?.id ?? "", - mbom_process_id = mbomProcessId, - process_id = process?.process_id ?? "", - material_id = output.material_id, - num = output.num, - org_id = orgId, - }); - } - } - - } - } - - if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id)) - { - // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync(); - await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync(); - await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync(); - } - // if (processes.Count > 0) - // { - // await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync(); - // } - - if (inputs.Count > 0) - { - await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync(); - } - - if (outputs.Count > 0) - { - await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync(); - } - } - - }); - - if (!result.IsSuccess) - { - if (!string.IsNullOrEmpty(mbomSaveDataInput.id)) - { - if (errorCode != ErrorCode.COM1004) - { - throw Oops.Oh(ErrorCode.COM1001); - } - else - { - throw Oops.Oh(errorCode); - } - } - else - { - if (errorCode != ErrorCode.COM1004) - { - throw Oops.Oh(ErrorCode.COM1000); - } - else - { - throw Oops.Oh(errorCode); - } - } - - } - return result.IsSuccess ? "保存成功" : result.ErrorMessage; - } + + // /// + // /// 保存生产bom + // /// + // /// + // /// + // [HttpPost] + // public async Task SaveData(MbomSaveDataInput mbomSaveDataInput) + // { + // ErrorCode errorCode = ErrorCode.COM1008; + // DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => + // { + // //新增 + // if (string.IsNullOrEmpty(mbomSaveDataInput.id)) + // { + // string mbomId = SnowflakeIdHelper.NextId(); + // string orgId = _userManager.GetUserInfo().Result.organizeId; + // BasMbom mbom = new BasMbom() + // { + // id = mbomId, + // org_id = orgId, + // material_id = mbomSaveDataInput.material_id, + // num = mbomSaveDataInput.num, + // unit_id = mbomSaveDataInput.unit_id, + // version = mbomSaveDataInput.version, + // start_time = mbomSaveDataInput.start_time, + // end_time = mbomSaveDataInput.end_time, + // ebom_id = mbomSaveDataInput.ebom_id, + // route_id = mbomSaveDataInput.route_id, + // is_first = mbomSaveDataInput.is_first, + // remark = mbomSaveDataInput.remark, + // create_id = _userManager.UserId, + // create_time = DateTime.Now, + // + // }; + // + // if (await _repository.IsAnyAsync(x => + // x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version)) + // { + // errorCode = ErrorCode.COM1004; + // throw Oops.Oh(ErrorCode.COM1004); + // } + // await _repository.InsertAsync(mbom); + // List processes = new List(); + // List inputs = new List(); + // List outputs = new List(); + // + // if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null) + // { + // int index = 0; + // foreach (var process in mbomSaveDataInput.processes) + // { + // string mbomProcessId = SnowflakeIdHelper.NextId(); + // processes.Add(new BasMbomProcess() + // { + // id = mbomProcessId, + // org_id = orgId, + // mbom_id = mbomId, + // process_id = process?.process_id ?? "", + // preparation_time = process?.preparation_time ?? 0, + // station = process?.station ?? "", + // byproduct_status = process?.byproduct_status ?? 0, + // production_method = process?.production_method, + // route_detail_id = process?.route_detail_id ?? "", + // ordinal = ++index, + // is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0, + // + // }); + // + // if (process!.inputs != null) + // { + // foreach (var input in process.inputs) + // { + // string inputId = SnowflakeIdHelper.NextId(); + // inputs.Add(new BasMbomInput() + // { + // id = inputId, + // mbom_id = mbomId, + // mbom_process_id = mbomProcessId, + // process_id = process?.process_id ?? "", + // material_id = input.material_id, + // num = input.num, + // org_id = orgId, + // }); + // } + // } + // + // if (process.outputs != null) + // { + // foreach (var output in process.outputs) + // { + // string outputId = SnowflakeIdHelper.NextId(); + // outputs.Add(new BasMbomOutput() + // { + // id = outputId, + // mbom_id = mbomId, + // mbom_process_id = mbomProcessId, + // process_id = process?.process_id ?? "", + // material_id = output.material_id, + // num = output.num, + // org_id = orgId, + // }); + // } + // } + // } + // } + // + // if (processes.Count > 0) + // { + // await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync(); + // } + // + // if (inputs.Count > 0) + // { + // await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync(); + // } + // + // if (outputs.Count > 0) + // { + // await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync(); + // } + // } + // else//修改 + // { + // if (await _repository.IsAnyAsync(x => + // x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id)) + // { + // errorCode = ErrorCode.COM1004; + // throw Oops.Oh(ErrorCode.COM1004); + // } + // + // string orgId = _userManager.GetUserInfo().Result.organizeId; + // if (mbomSaveDataInput != null) + // { + // await _repository.UpdateAsync(x => new BasMbom() + // { + // // org_id = orgId, + // material_id = mbomSaveDataInput.material_id, + // num = mbomSaveDataInput.num, + // unit_id = mbomSaveDataInput.unit_id, + // version = mbomSaveDataInput.version, + // start_time = mbomSaveDataInput.start_time, + // end_time = mbomSaveDataInput.end_time, + // ebom_id = mbomSaveDataInput.ebom_id, + // route_id = mbomSaveDataInput.route_id, + // is_first = mbomSaveDataInput.is_first, + // remark = mbomSaveDataInput.remark, + // modify_id = _userManager.UserId, + // modify_time = DateTime.Now, + // + // }, x => x.id == mbomSaveDataInput.id); + // } + // // List processes = new List(); + // List inputs = new List(); + // List outputs = new List(); + // + // if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null) + // { + // foreach (var process in mbomSaveDataInput.processes) + // { + // string mbomProcessId = process.id; + // // string mbomProcessId = SnowflakeIdHelper.NextId(); + // // processes.Add(new BasMbomProcess() + // // { + // // id = mbomProcessId, + // // org_id = orgId ?? "", + // // mbom_id = mbomSaveDataInput?.id ?? "", + // // process_id = process?.process_id ?? "", + // // preparation_time = process?.preparation_time ?? 0, + // // station = process.station, + // // byproduct_status = process.byproduct_status, + // // production_method = process.production_method, + // // route_detail_id = process.route_detail_id, + // // + // // }); + // + // decimal preparation_time = process?.preparation_time ?? 0; + // await _repository.AsSugarClient().Updateable() + // .SetColumns(x => x.preparation_time == preparation_time) + // .SetColumns(x => x.station == process!.station) + // .SetColumns(x => x.byproduct_status == process!.byproduct_status) + // .SetColumns(x => x.production_method == process!.production_method) + // .Where(x => x.id == process!.id).ExecuteCommandAsync(); + // + // if (process!.inputs != null) + // { + // foreach (var input in process.inputs) + // { + // string inputId = SnowflakeIdHelper.NextId(); + // inputs.Add(new BasMbomInput() + // { + // id = inputId, + // mbom_id = mbomSaveDataInput?.id ?? "", + // mbom_process_id = mbomProcessId, + // process_id = process?.process_id ?? "", + // material_id = input.material_id, + // num = input.num, + // org_id = orgId, + // }); + // } + // } + // + // if (process.outputs != null) + // { + // foreach (var output in process.outputs) + // { + // string outputId = SnowflakeIdHelper.NextId(); + // outputs.Add(new BasMbomOutput() + // { + // id = outputId, + // mbom_id = mbomSaveDataInput?.id ?? "", + // mbom_process_id = mbomProcessId, + // process_id = process?.process_id ?? "", + // material_id = output.material_id, + // num = output.num, + // org_id = orgId, + // }); + // } + // } + // + // } + // } + // + // if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id)) + // { + // // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync(); + // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync(); + // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync(); + // } + // // if (processes.Count > 0) + // // { + // // await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync(); + // // } + // + // if (inputs.Count > 0) + // { + // await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync(); + // } + // + // if (outputs.Count > 0) + // { + // await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync(); + // } + // } + // + // }); + // + // if (!result.IsSuccess) + // { + // if (!string.IsNullOrEmpty(mbomSaveDataInput.id)) + // { + // if (errorCode != ErrorCode.COM1004) + // { + // throw Oops.Oh(ErrorCode.COM1001); + // } + // else + // { + // throw Oops.Oh(errorCode); + // } + // } + // else + // { + // if (errorCode != ErrorCode.COM1004) + // { + // throw Oops.Oh(ErrorCode.COM1000); + // } + // else + // { + // throw Oops.Oh(errorCode); + // } + // } + // + // } + // return result.IsSuccess ? "保存成功" : result.ErrorMessage; + // } /// /// 保存生产bom @@ -573,13 +574,13 @@ namespace Tnb.BasicData preparation_time = process?.preparation_time ?? 0, station = process?.station ?? "", byproduct_status = process!.byproduct_status, - production_method = process!.production_method, - route_detail_id = process!.route_detail_id, + production_method = process.production_method, + route_detail_id = process.route_detail_id, ordinal = ++index, - is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0, + is_last = string.IsNullOrEmpty(process.next_process_no) ? 1 : 0, no = process!.no, - last_process_no = process!.last_process_no, - next_process_no = process!.next_process_no, + last_process_no = process.last_process_no, + next_process_no = process.next_process_no, }); diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index f78051c0..4ac5daf9 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -1278,20 +1278,24 @@ namespace Tnb.ProductionMgr .SetColumns(x => x.reported_work_qty == x.reported_work_qty + input.reported_qty) .Where(x => x.id == input.mo_task_id).ExecuteCommandAsync(); } - var mbomProcess = await db.Queryable().SingleAsync(x => x.id == prdMoTask.mbom_process_id); - if (mbomProcess.is_last==1 && prdMoTask != null && !string.IsNullOrEmpty(prdMoTask.parent_id)) + + if (prdMoTask.schedule_type == 2 && !string.IsNullOrEmpty(prdMoTask.mbom_process_id)) { - var parentMoTask = await db.Queryable().SingleAsync(x => x.id == prdMoTask.parent_id); - if (parentMoTask?.last_process_complete_qty == null) + var mbomProcess = await db.Queryable().SingleAsync(x => x.id == prdMoTask.mbom_process_id); + if (mbomProcess.is_last==1 && prdMoTask != null && !string.IsNullOrEmpty(prdMoTask.parent_id)) { - await db.Updateable() - .SetColumns(x => x.last_process_complete_qty == input.reported_qty) - .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync(); - }else if (parentMoTask?.last_process_complete_qty != null) - { - await db.Updateable() - .SetColumns(x => x.last_process_complete_qty == x.last_process_complete_qty + input.reported_qty) - .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync(); + var parentMoTask = await db.Queryable().SingleAsync(x => x.id == prdMoTask.parent_id); + if (parentMoTask?.last_process_complete_qty == null) + { + await db.Updateable() + .SetColumns(x => x.last_process_complete_qty == input.reported_qty) + .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync(); + }else if (parentMoTask?.last_process_complete_qty != null) + { + await db.Updateable() + .SetColumns(x => x.last_process_complete_qty == x.last_process_complete_qty + input.reported_qty) + .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync(); + } } } From 3a27e4cc15c4d681ddb6672bb7cea71b5e9becf8 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 11 Jul 2023 16:14:56 +0800 Subject: [PATCH 5/5] 1 --- .../WmsEmptyInstockService.cs | 10 +- .../Tnb.WarehouseMgr/WmsOutStockService.cs | 314 +++++++++--------- .../Tnb.WarehouseMgr/WmsSetSortingService.cs | 7 +- 3 files changed, 164 insertions(+), 167 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs index 62f3cc8b..43d26e7b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs @@ -171,7 +171,7 @@ namespace Tnb.WarehouseMgr [HttpPost] public async Task MesEmptyCarryInStock(MESEmptyCarryInStockInput input) { - if(input.IsNull())throw new ArgumentNullException("input"); + if (input.IsNull()) throw new ArgumentNullException("input"); try { var carry = await _db.Queryable().SingleAsync(it => it.carry_code == input.carry_code); @@ -186,16 +186,16 @@ namespace Tnb.WarehouseMgr var cols = new List(); var dic = new Dictionary(); dic[nameof(WmsEmptyInstock.id)] = SnowflakeIdHelper.NextId(); - dic[nameof(WmsEmptyInstock.org_id)] = input.org_id; + dic[nameof(WmsEmptyInstock.org_id)] = input.org_id ?? _userManager.User.OrganizeId; dic[nameof(WmsEmptyInstock.location_id)] = location.id; dic[nameof(WmsEmptyInstock.bill_code)] = await _billRullService.GetBillNumber(WmsWareHouseConst.WMS_EMPTYINSTK_ENCODE); dic[nameof(WmsEmptyInstock.status)] = WmsWareHouseConst.BILLSTATUS_ADD_ID; dic[nameof(WmsEmptyInstock.carry_id)] = carry.id; - dic[nameof(WmsEmptyInstock.carry_code)] = input.carry_code; + dic[nameof(WmsEmptyInstock.carry_code)] = input.carry_code!; dic[nameof(WmsEmptyInstock.biz_type)] = WmsWareHouseConst.BIZTYPE_WMSEMPTYINSTOCK_ID; - dic[nameof(WmsEmptyInstock.create_id)] = input.create_id; + dic[nameof(WmsEmptyInstock.create_id)] = input.create_id ?? _userManager.UserId; dic[nameof(WmsEmptyInstock.create_time)] = DateTime.Now; - dic[nameof(WmsEmptyInstock.warehouse_id)] = input.warehouse_id; + dic[nameof(WmsEmptyInstock.warehouse_id)] = input.warehouse_id!; VisualDevModelDataCrInput visualDevModelDataCrInput = new() { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs index 20732d0c..ae48c1ad 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs @@ -293,11 +293,11 @@ namespace Tnb.WarehouseMgr { await _db.Ado.BeginTranAsync(); //出库申请主表 - WmsOutstockH outstock = input.outstock!; + WmsOutstockH? outstock = input.outstock; //出库申请明细表 - List outstockDs = input.outstockDs!; + List? outstockDs = input.outstockDs; //如果数据不全, - if (outstock.IsNull() || outstock.location_id.IsNullOrWhiteSpace() || outstockDs?.Count < 1) + if ((outstock?.location_id.IsNullOrWhiteSpace() ?? true) || outstockDs?.Count < 1) { //报错, 提示数据不全。 throw new AppFriendlyException("数据不全!", 500); @@ -326,164 +326,164 @@ namespace Tnb.WarehouseMgr var loc = await _db.Queryable().SingleAsync(it => it.id == outstock.location_id.ToString()); var carryIds = new List(); //tablefield120 出库物料明细 - var outStockDList = outstockDs.ToObject>(); - if (outStockDList?.Count > 0) + var outStockDList = outstockDs.ToObject>(); + if (outStockDList?.Count > 0) + { + List carryMats = new(); + List carryCodes = new(); + foreach (var os in outStockDList) { - List carryMats = new(); - List carryCodes = new(); - foreach (var os in outStockDList) + var carryCodesPart = await _db.Queryable().InnerJoin((a, b) => a.id == b.carry_id).InnerJoin((a, b, c) => a.location_id == c.id) + .Where((a, b, c) => b.material_id == os.material_id && a.is_lock == 0 && !string.IsNullOrEmpty(a.location_id) && a.status == (int)EnumCarryStatus.占用 && c.is_type == ((int)EnumLocationType.存储库位).ToString()) + .WhereIF(!string.IsNullOrEmpty(os.code_batch), (a, b) => b.code_batch == os.code_batch) + .Select() + .ToListAsync(); + if (carryCodesPart?.Count > 0) { - var carryCodesPart = await _db.Queryable().InnerJoin((a, b) => a.id == b.carry_id).InnerJoin((a, b, c) => a.location_id == c.id) - .Where((a, b, c) => b.material_id == os.material_id && a.is_lock == 0 && !string.IsNullOrEmpty(a.location_id) && a.status == (int)EnumCarryStatus.占用 && c.is_type == ((int)EnumLocationType.存储库位).ToString()) - .WhereIF(!string.IsNullOrEmpty(os.code_batch), (a, b) => b.code_batch == os.code_batch) - .Select() - .ToListAsync(); - if (carryCodesPart?.Count > 0) - { - carryCodes.AddRange(carryCodesPart); - var codeQty = carryCodes.Sum(x => x.codeqty); - if (codeQty < os.pr_qty) - { - throw new AppFriendlyException($"需要出库[{os.pr_qty}],实际库存{codeQty},数量不足", 500); - } - List curCarryCodes = new(); - for (int i = 0; i < carryCodesPart.Count; i++) - { - if (os.pr_qty > carryCodesPart[i].codeqty) - { - os.pr_qty -= carryCodesPart[i].codeqty; - curCarryCodes.Add(carryCodesPart[i]); - } - else if (os.pr_qty <= carryCodesPart[i].codeqty) - { - carryCodesPart[i].codeqty = os.pr_qty; - curCarryCodes.Add(carryCodesPart[i]); - break; - } - } - var partCarryMats = curCarryCodes.Adapt>(); - for (int i = 0; i < partCarryMats.Count; i++) - { - partCarryMats[i].need_qty = carryCodesPart[i].codeqty; - } - carryMats.AddRange(partCarryMats); + carryCodes.AddRange(carryCodesPart); + var codeQty = carryCodes.Sum(x => x.codeqty); + if (codeQty < os.pr_qty) + { + throw new AppFriendlyException($"需要出库[{os.pr_qty}],实际库存{codeQty},数量不足", 500); } + List curCarryCodes = new(); + for (int i = 0; i < carryCodesPart.Count; i++) + { + if (os.pr_qty > carryCodesPart[i].codeqty) + { + os.pr_qty -= carryCodesPart[i].codeqty; + curCarryCodes.Add(carryCodesPart[i]); + } + else if (os.pr_qty <= carryCodesPart[i].codeqty) + { + carryCodesPart[i].codeqty = os.pr_qty; + curCarryCodes.Add(carryCodesPart[i]); + break; + } + } + var partCarryMats = curCarryCodes.Adapt>(); + for (int i = 0; i < partCarryMats.Count; i++) + { + partCarryMats[i].need_qty = carryCodesPart[i].codeqty; + } + carryMats.AddRange(partCarryMats); } - if (carryMats.Count > 0) - { - carryMats.ForEach(x => x.id = SnowflakeIdHelper.NextId()); - carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch }) - .Select(x => - { - WmsCarryMat? carryMat = x.FirstOrDefault()!; - carryMat.need_qty = x.Sum(d => d.need_qty); - return carryMat; - }) - .ToList(); - await _db.Insertable(carryMats).ExecuteCommandAsync(); - var dic = carryMats.DistinctBy(x => x.carry_id).ToDictionary(x => x.carry_id, x => x.need_qty); - var allOutIds = new List(); - var sortingOutIds = new List(); - foreach (var pair in dic) - { - var codes = carryCodes.FindAll(x => x.carry_id == pair.Key); - if (codes?.Count > 0) - { - if (pair.Value == codes.Sum(d => d.codeqty)) - { - allOutIds.Add(pair.Key); - } - else - { - sortingOutIds.Add(pair.Key); - } - } - } - carryIds = allOutIds.Concat(sortingOutIds).ToList(); - await _db.Updateable().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString() }).Where(it => allOutIds.Contains(it.id)).ExecuteCommandAsync(); - await _db.Updateable().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.分拣出).ToString() }).Where(it => sortingOutIds.Contains(it.id)).ExecuteCommandAsync(); - } - var carrys = await _db.Queryable().Where(it => carryIds.Contains(it.id)).ToListAsync(); - if (carrys?.Count > 0) - { - List preTasks = new(); - List locIds = new(); - foreach (var carry in carrys) - { - WmsPointH sPoint = null!; - WmsPointH ePoint = null!; - sPoint = await _db.Queryable().FirstAsync(it => it.location_id == carry.location_id); - ePoint = await _db.Queryable().FirstAsync(it => it.location_id == outstock.location_id.ToString()); - - if (sPoint != null && ePoint != null) - { - var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); - locIds.AddRange(points.Select(x => x.location_id).ToList()!); - //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) - if (points?.Count > 0) - { - if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500); - var curPreTasks = 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() - { - org_id = _userManager.User.OrganizeId, - startlocation_id = sPoint?.location_id!, - startlocation_code = sPoint?.location_code!, - endlocation_id = ePoint?.location_id!, - endlocation_code = ePoint?.location_code!, - start_floor = sPoint?.floor.ToString(), - end_floor = ePoint?.floor.ToString(), - bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(), - status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID, - biz_type = WmsWareHouseConst.BIZTYPE_WMSOUTSTOCK_ID, - task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID, - carry_id = carry.id, - carry_code = carry.carry_code, - area_id = sPoint?.area_id!, - area_code = it.Key, - require_id = outstock.id.ToString() - }; - preTask.require_code = outstock.bill_code?.ToString()!; - preTask.create_id = _userManager.UserId; - preTask.create_time = DateTime.Now; - return preTask; - }).ToList(); - if (loc.is_sign == 0) - { - curPreTasks[^1].is_sign = 0; // 修改最后一个元素的是否签收值 - } - preTasks.AddRange(curPreTasks); - - } - } - } - List pretaskCodes = new(); - foreach (var pt in preTasks) - { - var partCodes = carryCodes.FindAll(x => x.carry_id == pt.carry_id).Distinct().ToList(); - var curPreTaskCodes = partCodes.Adapt>(); - curPreTaskCodes.ForEach(x => - { - x.id = SnowflakeIdHelper.NextId(); - x.bill_id = pt.id; - x.create_time = DateTime.Now; - }); - pretaskCodes.AddRange(curPreTaskCodes); - } - var isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes); - GenPreTaskUpInput genPreTaskAfterUpInput = new(); - genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList(); - genPreTaskAfterUpInput.LocationIds = new HashSet(locIds).ToList(); - await _wareHouseService.GenInStockTaskHandleAfter(genPreTaskAfterUpInput, it => new WmsCarryH { is_lock = 1 }, it => new BasLocation { is_lock = 1 }); - } - else throw new AppFriendlyException("库存不足", 500); } - else throw new AppFriendlyException($"请输入物料明细", 500); + if (carryMats.Count > 0) + { + carryMats.ForEach(x => x.id = SnowflakeIdHelper.NextId()); + carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch }) + .Select(x => + { + WmsCarryMat? carryMat = x.FirstOrDefault()!; + carryMat.need_qty = x.Sum(d => d.need_qty); + return carryMat; + }) + .ToList(); + await _db.Insertable(carryMats).ExecuteCommandAsync(); + var dic = carryMats.DistinctBy(x => x.carry_id).ToDictionary(x => x.carry_id, x => x.need_qty); + var allOutIds = new List(); + var sortingOutIds = new List(); + foreach (var pair in dic) + { + var codes = carryCodes.FindAll(x => x.carry_id == pair.Key); + if (codes?.Count > 0) + { + if (pair.Value == codes.Sum(d => d.codeqty)) + { + allOutIds.Add(pair.Key); + } + else + { + sortingOutIds.Add(pair.Key); + } + } + } + carryIds = allOutIds.Concat(sortingOutIds).ToList(); + await _db.Updateable().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString() }).Where(it => allOutIds.Contains(it.id)).ExecuteCommandAsync(); + await _db.Updateable().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.分拣出).ToString() }).Where(it => sortingOutIds.Contains(it.id)).ExecuteCommandAsync(); + } + var carrys = await _db.Queryable().Where(it => carryIds.Contains(it.id)).ToListAsync(); + if (carrys?.Count > 0) + { + List preTasks = new(); + List locIds = new(); + foreach (var carry in carrys) + { + WmsPointH sPoint = null!; + WmsPointH ePoint = null!; + sPoint = await _db.Queryable().FirstAsync(it => it.location_id == carry.location_id); + ePoint = await _db.Queryable().FirstAsync(it => it.location_id == outstock.location_id.ToString()); + + if (sPoint != null && ePoint != null) + { + var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); + locIds.AddRange(points.Select(x => x.location_id).ToList()!); + //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) + if (points?.Count > 0) + { + if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500); + var curPreTasks = 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() + { + org_id = _userManager.User.OrganizeId, + startlocation_id = sPoint?.location_id!, + startlocation_code = sPoint?.location_code!, + endlocation_id = ePoint?.location_id!, + endlocation_code = ePoint?.location_code!, + start_floor = sPoint?.floor.ToString(), + end_floor = ePoint?.floor.ToString(), + bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(), + status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID, + biz_type = WmsWareHouseConst.BIZTYPE_WMSOUTSTOCK_ID, + task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID, + carry_id = carry.id, + carry_code = carry.carry_code, + area_id = sPoint?.area_id!, + area_code = it.Key, + require_id = outstock.id.ToString() + }; + preTask.require_code = outstock.bill_code?.ToString()!; + preTask.create_id = _userManager.UserId; + preTask.create_time = DateTime.Now; + return preTask; + }).ToList(); + if (loc.is_sign == 0) + { + curPreTasks[^1].is_sign = 0; // 修改最后一个元素的是否签收值 + } + preTasks.AddRange(curPreTasks); + + } + } + } + List pretaskCodes = new(); + foreach (var pt in preTasks) + { + var partCodes = carryCodes.FindAll(x => x.carry_id == pt.carry_id).Distinct().ToList(); + var curPreTaskCodes = partCodes.Adapt>(); + curPreTaskCodes.ForEach(x => + { + x.id = SnowflakeIdHelper.NextId(); + x.bill_id = pt.id; + x.create_time = DateTime.Now; + }); + pretaskCodes.AddRange(curPreTaskCodes); + } + var isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes); + GenPreTaskUpInput genPreTaskAfterUpInput = new(); + genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList(); + genPreTaskAfterUpInput.LocationIds = new HashSet(locIds).ToList(); + await _wareHouseService.GenInStockTaskHandleAfter(genPreTaskAfterUpInput, it => new WmsCarryH { is_lock = 1 }, it => new BasLocation { is_lock = 1 }); + } + else throw new AppFriendlyException("库存不足", 500); + } + else throw new AppFriendlyException($"请输入物料明细", 500); await _db.Ado.CommitTranAsync(); } @@ -498,9 +498,7 @@ namespace Tnb.WarehouseMgr public override async Task ModifyAsync(WareHouseUpInput input) { - if (input == null) throw new ArgumentNullException("input"); - - + if (input == null) throw new ArgumentNullException(nameof(input)); try { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs index 929bd41f..d48c1ac6 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs @@ -113,13 +113,12 @@ namespace Tnb.WarehouseMgr carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch }) .Select(x => { - WmsCarryMat? carryMat = x.FirstOrDefault()!; + WmsCarryMat? carryMat = x.FirstOrDefault(); carryMat.need_qty = x.Sum(d => d.need_qty); return carryMat; }) .ToList(); await _db.Insertable(carryMats).ExecuteCommandAsync(); - var dic = carryMats.DistinctBy(x => x.carry_id).ToDictionary(x => x.carry_id, x => x.need_qty); carryIds = carryMats.Select(x => x.carry_id).Distinct().ToList(); await _db.Updateable().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString(), collocation_scheme_id = singleSorting.collocation_scheme_id, collocation_scheme_code = singleSorting.collocation_scheme_code }).Where(it => carryIds.Contains(it.id)).ExecuteCommandAsync(); @@ -280,10 +279,10 @@ namespace Tnb.WarehouseMgr } } await _db.Updateable(curSortingDetails).ExecuteCommandAsync(); - if(curSortingDetails.All(it=>it.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID)) + if (curSortingDetails.All(it => it.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID)) { - await _db.Updateable().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync(); + await _db.Updateable().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync(); } var carry = await _db.Queryable().SingleAsync(it => it.id == carryId); if (carry != null)