From 3eb8252e55c0429d4d204119dc8defd248f12cdb Mon Sep 17 00:00:00 2001 From: zhougf Date: Fri, 27 Dec 2024 12:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0updateversion=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=20=E5=81=9A=E4=B9=90=E8=A7=82=E9=94=81=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B5=8B=E8=AF=95=E5=87=BA=E5=BA=93=E5=8D=95=E5=88=86?= =?UTF-8?q?=E8=A7=A3=EF=BC=8C=E5=92=8C=E5=87=BA=E5=BA=93=E6=8B=A3=E8=B4=A7?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=A7=84=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HHWMS.Web/Areas/Api/IWCSController.cs | 15 +- .../Controllers/ShipmentHeaderController.cs | 12 + .../ShipmentHeaderVMs/ShipmentHeaderListVM.cs | 5 +- .../ShipmentHeaderVMs/ShipmentHeaderVM.cs | 291 ++++++ .../Views/ShipmentHeader/PickRoute.cshtml | 899 ++++++++++++++++++ HHWMS.Web/HHWMS.Web.csproj | 1 - HHWMS.Web/Models/Inventory/Inventory.cs | 2 + HHWMS.Web/Models/Receipt/ReceiptDetail.cs | 2 + HHWMS.Web/Models/Receipt/ReceiptHeader.cs | 2 + HHWMS.Web/Models/Shipment/ShipmentDetail.cs | 3 + HHWMS.Web/Models/Shipment/ShipmentHeader.cs | 2 + 11 files changed, 1224 insertions(+), 10 deletions(-) create mode 100644 HHWMS.Web/Areas/Shipment/Views/ShipmentHeader/PickRoute.cshtml diff --git a/HHWMS.Web/Areas/Api/IWCSController.cs b/HHWMS.Web/Areas/Api/IWCSController.cs index 0fbc08d..f66f5f2 100644 --- a/HHWMS.Web/Areas/Api/IWCSController.cs +++ b/HHWMS.Web/Areas/Api/IWCSController.cs @@ -4,7 +4,6 @@ using AutoMapper; using HHWMS.Web.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using SqlSugar; using WalkingTec.Mvvm.Core; namespace HHWMS.Web @@ -19,12 +18,12 @@ namespace HHWMS.Web [Route("api/[controller]/[action]"), ApiExplorerSettings(GroupName = "User")] public class IWCSController : ApiController { - private readonly IUnitWork _unitwork; + private readonly IUnitWork _unitWork; private readonly IMapper _mapper; - public IWCSController(IUnitWork unitwork, IMapper mapper) + public IWCSController(IUnitWork unitWork, IMapper mapper) { - _unitwork = unitwork; + _unitWork = unitWork; _mapper = mapper; } @@ -149,16 +148,16 @@ namespace HHWMS.Web private IActionResult UpdateLocationAndContainer(string locationCode, string palletNo) { - var location = _unitwork.Find(x => x.Code == locationCode).FirstOrDefault(); + var location = _unitWork.Find(x => x.Code == locationCode).FirstOrDefault(); location.ContainerCode = palletNo; location.Status = LocationStatus.任务锁; - _unitwork.Update(location); + _unitWork.Update(location); - var container = _unitwork.Find(x => x.Code == palletNo).FirstOrDefault(); + var container = _unitWork.Find(x => x.Code == palletNo).FirstOrDefault(); if (container != null) { container.LocationCode = location.Code; - _unitwork.Update(container); + _unitWork.Update(container); } return ApiResult(new { LocationCode = location.Code }); diff --git a/HHWMS.Web/Areas/Shipment/Controllers/ShipmentHeaderController.cs b/HHWMS.Web/Areas/Shipment/Controllers/ShipmentHeaderController.cs index 73e3474..47186be 100644 --- a/HHWMS.Web/Areas/Shipment/Controllers/ShipmentHeaderController.cs +++ b/HHWMS.Web/Areas/Shipment/Controllers/ShipmentHeaderController.cs @@ -248,5 +248,17 @@ namespace HHWMS.Web.Controllers } return FFResult().RefreshGrid().Message("启动成功!"); } + + public ActionResult Analyse(string id) + { + var vm = Wtm.CreateVM(id); + return PartialView(vm); + } + + public ActionResult PickRoute(string id) + { + var vm = Wtm.CreateVM(id); + return PartialView(vm); + } } } diff --git a/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderListVM.cs b/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderListVM.cs index 63ca739..034bfeb 100644 --- a/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderListVM.cs +++ b/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderListVM.cs @@ -20,7 +20,10 @@ namespace HHWMS.Web { this.MakeAction("ShipmentHeader","StartOut",Localizer["ShipmentHeader.StartOut"],"",GridActionParameterTypesEnum.SingleId,"shipment"), this.MakeAction("ShipmentHeader","Analyse",Localizer["ShipmentHeader.Analyse"],Localizer["ShipmentHeader.Analyse"],GridActionParameterTypesEnum.SingleId,"shipment") - .SetShowInRow().SetHideOnToolBar().SetButtonClass("layui-btn-Warm").SetSize(1200,800), + .SetShowInRow().SetHideOnToolBar().SetButtonClass("layui-btn-Warm").SetMax(), + this.MakeAction("ShipmentHeader","PickRoute",Localizer["ShipmentHeader.PickRoute"],Localizer["ShipmentHeader.PickRoute"],GridActionParameterTypesEnum.SingleId,"shipment") + .SetShowInRow().SetHideOnToolBar().SetButtonClass("layui-btn-Warm").SetMax(), + this.MakeAction("ShipmentHeader","ShelfInv",Localizer["ShipmentHeader.ShelfInv"],Localizer["ShipmentHeader.ShelfInv"],GridActionParameterTypesEnum.SingleId,"shipment") .SetShowInRow().SetHideOnToolBar().SetButtonClass("layui-btn-Warm").SetSize(1200,800), diff --git a/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderVM.cs b/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderVM.cs index 43c7c81..b7be97e 100644 --- a/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderVM.cs +++ b/HHWMS.Web/Areas/Shipment/ViewModels/ShipmentHeaderVMs/ShipmentHeaderVM.cs @@ -7,6 +7,8 @@ using WalkingTec.Mvvm.Core; using WalkingTec.Mvvm.Core.Extensions; using HHWMS.Web; using HHWMS.Web.Models; +using Microsoft.AspNetCore.Mvc; +using Z.EntityFramework.Plus; namespace HHWMS.Web { @@ -14,6 +16,7 @@ namespace HHWMS.Web { public ShipmentDetailListVM Details = new ShipmentDetailListVM(); public List ShipTypes { get; set; } + public ShipmentHeaderVM() { } @@ -32,6 +35,148 @@ namespace HHWMS.Web }).ToList(); } + /// + /// 分解出库单 + /// + /// 处理结果 + public ResponseResult DecomposeShipment() + { + try + { + using var transaction = DC.BeginTransaction(); + try + { + var details = DC.Set() + .Where(x => x.HeaderId == Entity.ID && x.Status != ShipStatusEnum.分配完成) + .ToList(); + + if (!details.Any()) + { + return ResponseResult.Error("没有需要分配的出库单明细"); + } + + foreach (var detail in details) + { + var availableInventories = DC.Set() + .Where(x => x.MaterialCode == detail.MaterialCode + && x.TaskStatus == InventoryTaskStatus.无任务 + && x.Qty > x.TaskQty + ) + .OrderBy(x => x.CreateTime) + .ToList(); + + decimal remainingQty = (decimal)(detail.Qty - (detail.DividedQty ?? 0)); + decimal dividedQty = 0; + + foreach (var inventory in availableInventories) + { + if (remainingQty <= 0) break; + + var currentInventory = DC.Set() + .FirstOrDefault(x => x.ID == inventory.ID); + + if (currentInventory == null || currentInventory.UpdateVersion != inventory.UpdateVersion) + { + continue; + } + + decimal availableQty = (decimal)(currentInventory.Qty - (currentInventory.TaskQty ?? 0)); + if (availableQty <= 0) continue; + + decimal qtyToDivide = Math.Min(remainingQty, availableQty); + + // 更新库存分配数量 + currentInventory.TaskQty = (currentInventory.TaskQty ?? 0) + qtyToDivide; + currentInventory.Status = InventoryTaskStatus.任务中; + currentInventory.UpdateVersion++; + DC.UpdateEntity(currentInventory); + + remainingQty -= qtyToDivide; + dividedQty += qtyToDivide; + + /*var allocation = new InventoryAllocation + { + InventoryId = currentInventory.ID, + ShipmentDetailId = detail.ID, + DividedQty = qtyToDivide, + Status = ShipStatusEnum.分配完成.ToString() + }; + DC.AddEntity(allocation);*/ + } + + if (dividedQty > 0) + { + var currentDetail = DC.Set() + .FirstOrDefault(x => x.ID == detail.ID); + + if (currentDetail != null && currentDetail.UpdateVersion == detail.UpdateVersion) + { + currentDetail.DividedQty = (currentDetail.DividedQty ?? 0) + dividedQty; + currentDetail.Status = currentDetail.DividedQty >= currentDetail.Qty ? + ShipStatusEnum.分配完成 : + ShipStatusEnum.分配中; + currentDetail.UpdateVersion++; + DC.UpdateEntity(currentDetail); + } + } + } + + var currentHeader = DC.Set() + .FirstOrDefault(x => x.ID == Entity.ID); + + if (currentHeader != null && currentHeader.UpdateVersion == Entity.UpdateVersion) + { + var allDetails = DC.Set() + .Where(x => x.HeaderId == Entity.ID) + .ToList(); + + bool allDivided = allDetails.All(x => x.Status == ShipStatusEnum.分配完成); + + currentHeader.FirstStatus = allDivided ? + ShipStatusEnum.分配完成 : + ShipStatusEnum.分配中; + currentHeader.UpdateVersion++; + DC.UpdateEntity(currentHeader); + } + + DC.SaveChanges(); + transaction.Commit(); + + var unallocatedDetails = details.Where(x => x.Status != ShipStatusEnum.分配完成).ToList(); + if (unallocatedDetails.Any()) + { + var errorMsg = string.Join("\n", unallocatedDetails.Select(x => + $"物料{x.MaterialCode}缺少{x.Qty - (x.DividedQty ?? 0)}个")); + return ResponseResult.Error($"部分物料库存不足,请检查:\n{errorMsg}"); + } + + return ResponseResult.Success(new + { + message = "出库单分解完成", + headerId = Entity.ID, + status = Entity.FirstStatus, + allocatedDetails = details.Select(x => new + { + x.ID, + x.MaterialCode, + x.Qty, + DividedQty = x.DividedQty, + x.Status + }).ToList() + }); + } + catch (Exception ex) + { + transaction.Rollback(); + throw new Exception($"处理出库单时发生错误: {ex.Message}"); + } + } + catch (Exception ex) + { + return ResponseResult.Error($"分解出库单失败:{ex.Message}"); + } + } + public override void DoAdd() { base.DoAdd(); @@ -46,5 +191,151 @@ namespace HHWMS.Web { base.DoDelete(); } + + /// + /// 获取分配库存对应的货架列表 + /// + /// 货架列表 + public ResponseResult> GetAllocatedLocations() + { + try + { + // 获取已分配的出库单明细 + var details = DC.Set() + .Where(x => x.HeaderId == Entity.ID + && (x.Status == ShipStatusEnum.分配完成 || x.Status == ShipStatusEnum.分配中)) + .ToList(); + + if (!details.Any()) + { + return ResponseResult>.Error("没有已分配的出库单明细"); + } + + // 获取明细对应的所有库存记录 + var allocatedInventories = DC.Set() + .Where(x => x.TaskStatus == InventoryTaskStatus.任务中 + && details.Select(d => d.MaterialCode).Contains(x.MaterialCode)) + .ToList(); + + // 获取去重后的货架编码列表 + var locations = allocatedInventories + .Where(x => !string.IsNullOrEmpty(x.LocationCode)) + .Select(x => x.LocationCode) + .Distinct() + .OrderBy(x => x) + .ToList(); + + if (!locations.Any()) + { + return ResponseResult>.Error("未找到相关库存的货架信息"); + } + + // 返回货架列表,并包含统计信息 + return ResponseResult>.Success(locations); + } + catch (Exception ex) + { + return ResponseResult>.Error($"获取货架列表失败:{ex.Message}"); + } + } + + /// + /// 获取分配库存的详细信息 + /// + /// 库存详细信息 + public ResponseResult> GetAllocatedInventoryDetails() + { + try + { + // 获取已分配的出库单明细 + var details = DC.Set() + .Where(x => x.HeaderId == Entity.ID + && (x.Status == ShipStatusEnum.分配完成 || x.Status == ShipStatusEnum.分配中)) + .ToList(); + + if (!details.Any()) + { + return ResponseResult>.Error("没有已分配的出库单明细"); + } + + // 获取明细对应的所有库存记录,并按货架分组 + var inventoryGroups = DC.Set() + .Where(x => x.TaskStatus == InventoryTaskStatus.任务中 + && details.Select(d => d.MaterialCode).Contains(x.MaterialCode)) + .GroupBy(x => x.LocationCode) + .Select(g => new InventoryLocationInfo + { + LocationCode = g.Key, + Inventories = g.Select(inv => new InventoryInfo + { + MaterialCode = inv.MaterialCode, + MaterialName = inv.MaterialName, + Qty = (decimal)inv.Qty, + TaskQty = inv.TaskQty ?? 0, + BatchCode = inv.Batch + }).ToList() + }) + .OrderBy(x => x.LocationCode) + .ToList(); + + if (!inventoryGroups.Any()) + { + return ResponseResult>.Error("未找到相关库存信息"); + } + + return ResponseResult>.Success(inventoryGroups); + } + catch (Exception ex) + { + return ResponseResult>.Error($"获取库存详细信息失败:{ex.Message}"); + } + } + + /// + /// 库存位置信息 + /// + public class InventoryLocationInfo + { + /// + /// 货架编码 + /// + public string LocationCode { get; set; } + + /// + /// 该货架上的库存列表 + /// + public List Inventories { get; set; } + } + + /// + /// 库存信息 + /// + public class InventoryInfo + { + /// + /// 物料编码 + /// + public string MaterialCode { get; set; } + + /// + /// 物料名称 + /// + public string MaterialName { get; set; } + + /// + /// 总数量 + /// + public decimal Qty { get; set; } + + /// + /// 任务数量 + /// + public decimal TaskQty { get; set; } + + /// + /// 批次号 + /// + public string BatchCode { get; set; } + } } } diff --git a/HHWMS.Web/Areas/Shipment/Views/ShipmentHeader/PickRoute.cshtml b/HHWMS.Web/Areas/Shipment/Views/ShipmentHeader/PickRoute.cshtml new file mode 100644 index 0000000..1a5ff49 --- /dev/null +++ b/HHWMS.Web/Areas/Shipment/Views/ShipmentHeader/PickRoute.cshtml @@ -0,0 +1,899 @@ +@model HHWMS.Web.ShipmentHeaderVM + + + +
+
+
+

最优拣货路径

+
+ 总距离:{{state.totalDistance}} 格 + 拣货点数:{{state.pickingPoints}} 个 +
+
+ + {{index + 1}}. {{loc}} + + +
+
+
+ +
+
+
+ + diff --git a/HHWMS.Web/HHWMS.Web.csproj b/HHWMS.Web/HHWMS.Web.csproj index 972e31b..377d3ad 100644 --- a/HHWMS.Web/HHWMS.Web.csproj +++ b/HHWMS.Web/HHWMS.Web.csproj @@ -29,7 +29,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/HHWMS.Web/Models/Inventory/Inventory.cs b/HHWMS.Web/Models/Inventory/Inventory.cs index 792bba1..549edb8 100644 --- a/HHWMS.Web/Models/Inventory/Inventory.cs +++ b/HHWMS.Web/Models/Inventory/Inventory.cs @@ -95,5 +95,7 @@ namespace HHWMS.Web.Models [Display(Name = "Inventory.Flag", Description = "格数")] public int Flag { get; set; } + + public int UpdateVersion { get; set; } } } diff --git a/HHWMS.Web/Models/Receipt/ReceiptDetail.cs b/HHWMS.Web/Models/Receipt/ReceiptDetail.cs index 1cdd840..72ddc1a 100644 --- a/HHWMS.Web/Models/Receipt/ReceiptDetail.cs +++ b/HHWMS.Web/Models/Receipt/ReceiptDetail.cs @@ -75,5 +75,7 @@ namespace HHWMS.Web.Models [Display(Name = "Receipt.Status", Description = "状态")] public ReceiptStatusEnum? Status { get; set; } + + public int UpdateVersion { get; set; } } } diff --git a/HHWMS.Web/Models/Receipt/ReceiptHeader.cs b/HHWMS.Web/Models/Receipt/ReceiptHeader.cs index 0839d6c..d8a4c81 100644 --- a/HHWMS.Web/Models/Receipt/ReceiptHeader.cs +++ b/HHWMS.Web/Models/Receipt/ReceiptHeader.cs @@ -53,5 +53,7 @@ namespace HHWMS.Web.Models [Display(Name = "_Admin.Remark", Description = "备注")] public string Remark { get; set; } + + public int UpdateVersion { get; set; } } } diff --git a/HHWMS.Web/Models/Shipment/ShipmentDetail.cs b/HHWMS.Web/Models/Shipment/ShipmentDetail.cs index 72bef7c..ced0c3f 100644 --- a/HHWMS.Web/Models/Shipment/ShipmentDetail.cs +++ b/HHWMS.Web/Models/Shipment/ShipmentDetail.cs @@ -80,5 +80,8 @@ namespace HHWMS.Web.Models [Display(Name = "Receipt.Status", Description = "状态")] [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")] public ShipStatusEnum? Status { get; set; } + + public int UpdateVersion { get; set; } + } } diff --git a/HHWMS.Web/Models/Shipment/ShipmentHeader.cs b/HHWMS.Web/Models/Shipment/ShipmentHeader.cs index a78fe84..8d5353e 100644 --- a/HHWMS.Web/Models/Shipment/ShipmentHeader.cs +++ b/HHWMS.Web/Models/Shipment/ShipmentHeader.cs @@ -49,5 +49,7 @@ namespace HHWMS.Web.Models [Display(Name = "_Admin.Remark", Description = "备注")] public string Remark { get; set; } + + public int UpdateVersion { get; set; } } }