add test and outbound test
This commit is contained in:
1 parent
38ecbf82e5
commit
7f621dd553
23 files changed
+1301
-26
No files matched your search
@@ -80,6 +80,20 @@ public class OutboundOrderController : WmsLiteControllerBase
|
||||
: Ok(BusinessResult.Ok(list));
|
||||
}
|
||||
|
||||
[HttpGet("{id}/pick-tasks")]
|
||||
public async Task<ActionResult<BusinessResult>> GetPickTasks(string id)
|
||||
{
|
||||
if (!long.TryParse(id.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var orderId))
|
||||
{
|
||||
return Ok(BusinessResult.BadRequest("Invalid id."));
|
||||
}
|
||||
|
||||
var list = await _service.GetPickTasksAsync(orderId, TenantId, OwnerCode);
|
||||
return list is null
|
||||
? Ok(BusinessResult.NotFound("Resource not found."))
|
||||
: Ok(BusinessResult.Ok(list));
|
||||
}
|
||||
|
||||
[HttpPost("create")]
|
||||
public async Task<ActionResult<BusinessResult>> Create([FromBody] OutboundOrderSaveRequest request)
|
||||
=> Ok(BusinessResult.Ok(await _service.CreateAsync(request)));
|
||||
|
||||
@@ -33,12 +33,16 @@ public class AreaWarehouseHierarchy0011 : Migration
|
||||
|
||||
private void SeedAreasAndBackfillZones()
|
||||
{
|
||||
if (!Schema.Table("area").Exists() || !Schema.Table("zone").Exists())
|
||||
if (!Schema.Table("zone").Exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Execute.Sql("""
|
||||
ALTER TABLE zone ADD COLUMN IF NOT EXISTS area_code varchar(64);
|
||||
UPDATE zone SET area_code = 'DEFAULT' WHERE area_code IS NULL;
|
||||
ALTER TABLE zone ALTER COLUMN area_code SET NOT NULL;
|
||||
|
||||
WITH d AS (
|
||||
SELECT DISTINCT tenant_id, owner_code, warehouse_code
|
||||
FROM zone
|
||||
@@ -77,10 +81,6 @@ public class AreaWarehouseHierarchy0011 : Migration
|
||||
WHERE NOT a.is_deleted AND a.tenant_id = d.tenant_id AND a.owner_code = d.owner_code
|
||||
AND a.warehouse_code = d.warehouse_code AND a.code = 'DEFAULT');
|
||||
|
||||
ALTER TABLE zone ADD COLUMN IF NOT EXISTS area_code varchar(64);
|
||||
UPDATE zone SET area_code = 'DEFAULT' WHERE area_code IS NULL;
|
||||
ALTER TABLE zone ALTER COLUMN area_code SET NOT NULL;
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE zone ADD CONSTRAINT uq_zone_wh_area_code UNIQUE (tenant_id, owner_code, warehouse_code, area_code, code);
|
||||
EXCEPTION
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using FluentMigrator;
|
||||
|
||||
namespace WmsLite.Api.Database.Migrations;
|
||||
|
||||
[Migration(15, "Outbound allocation pick tasks")]
|
||||
public class OutboundAllocationPickTasks0015 : Migration
|
||||
{
|
||||
public override void Up()
|
||||
{
|
||||
if (!Schema.Table("outbound_pick_task").Exists())
|
||||
{
|
||||
Create.Table("outbound_pick_task")
|
||||
.WithBaseColumns()
|
||||
.WithColumn("order_id").AsInt64().NotNullable()
|
||||
.WithColumn("order_line_id").AsInt64().NotNullable()
|
||||
.WithColumn("task_no").AsString(128).NotNullable()
|
||||
.WithColumn("inventory_id").AsInt64().NotNullable()
|
||||
.WithColumn("inventory_kind").AsInt32().NotNullable()
|
||||
.WithColumn("material_code").AsString(64).Nullable()
|
||||
.WithColumn("container_code").AsString(64).Nullable()
|
||||
.WithColumn("warehouse_code").AsString(64).NotNullable()
|
||||
.WithColumn("area_code").AsString(64).NotNullable()
|
||||
.WithColumn("zone_code").AsString(64).NotNullable()
|
||||
.WithColumn("location_code").AsString(64).NotNullable()
|
||||
.WithColumn("qty").AsDecimal().NotNullable()
|
||||
.WithColumn("picked_qty").AsDecimal().NotNullable().WithDefaultValue(0)
|
||||
.WithColumn("unit").AsString(32).NotNullable()
|
||||
.WithColumn("task_status").AsInt32().NotNullable()
|
||||
.WithColumn("attrs").AsCustom("jsonb").Nullable();
|
||||
}
|
||||
|
||||
Execute.Sql("""
|
||||
ALTER TABLE outbound_order_line ALTER COLUMN location_code DROP NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_outbound_pick_task_order
|
||||
ON outbound_pick_task (tenant_id, owner_code, order_id, task_no);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_outbound_pick_task_line
|
||||
ON outbound_pick_task (tenant_id, owner_code, order_line_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_outbound_pick_task_inventory
|
||||
ON outbound_pick_task (tenant_id, owner_code, inventory_id);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_outbound_pick_task_no
|
||||
ON outbound_pick_task (tenant_id, owner_code, task_no) WHERE NOT is_deleted;
|
||||
""");
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
Execute.Sql("""
|
||||
DROP INDEX IF EXISTS uq_outbound_pick_task_no;
|
||||
DROP INDEX IF EXISTS idx_outbound_pick_task_inventory;
|
||||
DROP INDEX IF EXISTS idx_outbound_pick_task_line;
|
||||
DROP INDEX IF EXISTS idx_outbound_pick_task_order;
|
||||
""");
|
||||
|
||||
if (Schema.Table("outbound_pick_task").Exists())
|
||||
{
|
||||
Delete.Table("outbound_pick_task");
|
||||
}
|
||||
|
||||
Execute.Sql("""
|
||||
UPDATE outbound_order_line SET location_code = 'DEFAULT' WHERE location_code IS NULL;
|
||||
ALTER TABLE outbound_order_line ALTER COLUMN location_code SET NOT NULL;
|
||||
""");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using WmsLite.Api.Enums;
|
||||
|
||||
namespace WmsLite.Api.Dtos.Inventory;
|
||||
|
||||
public class InventoryAllocationRequest
|
||||
{
|
||||
public string TenantId { get; set; } = string.Empty;
|
||||
|
||||
public string OwnerCode { get; set; } = string.Empty;
|
||||
|
||||
public InventoryKind InventoryKind { get; set; } = InventoryKind.Material;
|
||||
|
||||
public string? MaterialCode { get; set; }
|
||||
|
||||
public string? ContainerCode { get; set; }
|
||||
|
||||
public string WarehouseCode { get; set; } = string.Empty;
|
||||
|
||||
public string AreaCode { get; set; } = string.Empty;
|
||||
|
||||
public string? LocationCode { get; set; }
|
||||
|
||||
public decimal Qty { get; set; }
|
||||
}
|
||||
|
||||
public class InventoryAllocationItem
|
||||
{
|
||||
public required Models.Inventory Inventory { get; init; }
|
||||
|
||||
public decimal Qty { get; init; }
|
||||
}
|
||||
@@ -190,7 +190,41 @@ public class InboundConfirmLineResultDto
|
||||
public class OutboundOrderSaveRequest : OrderSaveRequestBase
|
||||
{
|
||||
[MinLength(1)]
|
||||
public List<InventoryOrderLineRequest> Lines { get; set; } = new();
|
||||
public List<OutboundOrderLineRequest> Lines { get; set; } = new();
|
||||
}
|
||||
|
||||
public class OutboundOrderLineRequest
|
||||
{
|
||||
[Required]
|
||||
[EnumDataType(typeof(InventoryKind))]
|
||||
public InventoryKind InventoryKind { get; set; } = InventoryKind.Material;
|
||||
|
||||
[StringLength(64)]
|
||||
public string? MaterialCode { get; set; }
|
||||
|
||||
[StringLength(64)]
|
||||
public string? ContainerCode { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(64)]
|
||||
public string WarehouseCode { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[StringLength(64)]
|
||||
public string AreaCode { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>可选。为空时由库存分配服务在仓库+库区范围内自动分配;有值时只从指定库位分配。</summary>
|
||||
[StringLength(64)]
|
||||
public string? LocationCode { get; set; }
|
||||
|
||||
[Range(typeof(decimal), "0.000001", "9999999999999999")]
|
||||
public decimal Qty { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(32)]
|
||||
public string Unit { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<string, object>? Attrs { get; set; }
|
||||
}
|
||||
|
||||
public class TransferOrderSaveRequest : OrderSaveRequestBase
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using WmsLite.Api.Enums;
|
||||
|
||||
namespace WmsLite.Api.Dtos.Orders;
|
||||
|
||||
public class OutboundPickTaskViewDto
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
|
||||
public string OrderId { get; set; } = string.Empty;
|
||||
|
||||
public string OrderLineId { get; set; } = string.Empty;
|
||||
|
||||
public string TaskNo { get; set; } = string.Empty;
|
||||
|
||||
public string InventoryId { get; set; } = string.Empty;
|
||||
|
||||
public InventoryKind InventoryKind { get; set; }
|
||||
|
||||
public string? MaterialCode { get; set; }
|
||||
|
||||
public string? ContainerCode { get; set; }
|
||||
|
||||
public string WarehouseCode { get; set; } = string.Empty;
|
||||
|
||||
public string AreaCode { get; set; } = string.Empty;
|
||||
|
||||
public string ZoneCode { get; set; } = string.Empty;
|
||||
|
||||
public string LocationCode { get; set; } = string.Empty;
|
||||
|
||||
public decimal Qty { get; set; }
|
||||
|
||||
public decimal PickedQty { get; set; }
|
||||
|
||||
public string Unit { get; set; } = string.Empty;
|
||||
|
||||
public PickTaskStatus TaskStatus { get; set; }
|
||||
|
||||
public Dictionary<string, object>? Attrs { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace WmsLite.Api.Enums;
|
||||
|
||||
public enum PickTaskStatus
|
||||
{
|
||||
[Description("Open")]
|
||||
Open = 1,
|
||||
|
||||
[Description("Picked")]
|
||||
Picked = 2,
|
||||
|
||||
[Description("Cancelled")]
|
||||
Cancelled = 3
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
using WmsLite.Api.Enums;
|
||||
|
||||
namespace WmsLite.Api.Models;
|
||||
|
||||
[SugarTable("outbound_pick_task")]
|
||||
public class OutboundPickTask : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "order_id", IsNullable = false)]
|
||||
public long OrderId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "order_line_id", IsNullable = false)]
|
||||
public long OrderLineId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "task_no", Length = 128, IsNullable = false)]
|
||||
public string TaskNo { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(ColumnName = "inventory_id", IsNullable = false)]
|
||||
public long InventoryId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "inventory_kind", IsNullable = false)]
|
||||
public InventoryKind InventoryKind { get; set; } = InventoryKind.Material;
|
||||
|
||||
[SugarColumn(ColumnName = "material_code", Length = 64, IsNullable = true)]
|
||||
public string? MaterialCode { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "container_code", Length = 64, IsNullable = true)]
|
||||
public string? ContainerCode { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "warehouse_code", Length = 64, IsNullable = false)]
|
||||
public string WarehouseCode { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(ColumnName = "area_code", Length = 64, IsNullable = false)]
|
||||
public string AreaCode { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(ColumnName = "zone_code", Length = 64, IsNullable = false)]
|
||||
public string ZoneCode { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(ColumnName = "location_code", Length = 64, IsNullable = false)]
|
||||
public string LocationCode { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(ColumnName = "qty", IsNullable = false)]
|
||||
public decimal Qty { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "picked_qty", IsNullable = false, DefaultValue = "0")]
|
||||
public decimal PickedQty { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "unit", Length = 32, IsNullable = false)]
|
||||
public string Unit { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(ColumnName = "task_status", IsNullable = false)]
|
||||
public PickTaskStatus TaskStatus { get; set; } = PickTaskStatus.Open;
|
||||
|
||||
[SugarColumn(ColumnName = "attrs", IsJson = true, ColumnDataType = "jsonb", IsNullable = true)]
|
||||
public Dictionary<string, object>? Attrs { get; set; }
|
||||
}
|
||||
@@ -20,4 +20,14 @@ public interface IInventoryRepository : IBaseRepository<Inventory>
|
||||
InventoryKind inventoryKind,
|
||||
string? materialCode,
|
||||
string? containerCode);
|
||||
|
||||
Task<List<Inventory>> GetAllocatableAsync(
|
||||
string tenantId,
|
||||
string ownerCode,
|
||||
string warehouseCode,
|
||||
string areaCode,
|
||||
InventoryKind inventoryKind,
|
||||
string? materialCode,
|
||||
string? containerCode,
|
||||
string? locationCode = null);
|
||||
}
|
||||
@@ -35,6 +35,13 @@ public interface IOutboundOrderLineRepository : IBaseRepository<OutboundOrderLin
|
||||
Task<List<OutboundOrderLine>> GetByOrderIdAsync(long orderId);
|
||||
}
|
||||
|
||||
public interface IOutboundPickTaskRepository : IBaseRepository<OutboundPickTask>
|
||||
{
|
||||
Task<List<OutboundPickTask>> GetByOrderIdAsync(long orderId);
|
||||
|
||||
Task<List<OutboundPickTask>> GetByOrderLineIdAsync(long orderLineId);
|
||||
}
|
||||
|
||||
public interface ITransferOrderRepository : IBaseRepository<TransferOrder>
|
||||
{
|
||||
Task<TransferOrder?> GetByOrderNoAsync(string tenantId, string ownerCode, string orderNo);
|
||||
|
||||
@@ -107,4 +107,38 @@ public class InventoryRepository : BaseRepository<Inventory>, IInventoryReposito
|
||||
.WhereIF(inventoryKind == InventoryKind.EmptyContainer, x => x.ContainerCode == container)
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Inventory>> GetAllocatableAsync(
|
||||
string tenantId,
|
||||
string ownerCode,
|
||||
string warehouseCode,
|
||||
string areaCode,
|
||||
InventoryKind inventoryKind,
|
||||
string? materialCode,
|
||||
string? containerCode,
|
||||
string? locationCode = null)
|
||||
{
|
||||
var tenant = tenantId.Trim();
|
||||
var owner = ownerCode.Trim();
|
||||
var warehouse = warehouseCode.Trim();
|
||||
var area = areaCode.Trim();
|
||||
var material = string.IsNullOrWhiteSpace(materialCode) ? null : materialCode.Trim();
|
||||
var container = string.IsNullOrWhiteSpace(containerCode) ? null : containerCode.Trim();
|
||||
var location = string.IsNullOrWhiteSpace(locationCode) ? null : locationCode.Trim();
|
||||
|
||||
return await Db.Queryable<Inventory>()
|
||||
.Where(x => !x.IsDeleted
|
||||
&& x.TenantId == tenant
|
||||
&& x.OwnerCode == owner
|
||||
&& x.WarehouseCode == warehouse
|
||||
&& x.AreaCode == area
|
||||
&& x.InventoryKind == inventoryKind
|
||||
&& x.Qty - x.PendingOutboundQty - x.FrozenQty > 0)
|
||||
.WhereIF(inventoryKind == InventoryKind.Material, x => x.MaterialCode == material)
|
||||
.WhereIF(inventoryKind == InventoryKind.EmptyContainer, x => x.ContainerCode == container)
|
||||
.WhereIF(location is not null, x => x.LocationCode == location)
|
||||
.OrderBy(x => x.CreateTime)
|
||||
.OrderBy(x => x.Id)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -178,6 +178,27 @@ public class OutboundOrderLineRepository : OrderLineRepositoryBase<OutboundOrder
|
||||
public Task<List<OutboundOrderLine>> GetByOrderIdAsync(long orderId) => GetByOrderIdCoreAsync(orderId);
|
||||
}
|
||||
|
||||
public class OutboundPickTaskRepository : OrderLineRepositoryBase<OutboundPickTask>, IOutboundPickTaskRepository
|
||||
{
|
||||
public OutboundPickTaskRepository(ISqlSugarClient db, ICurrentUserContext userContext) : base(db, userContext) { }
|
||||
|
||||
public async Task<List<OutboundPickTask>> GetByOrderIdAsync(long orderId)
|
||||
{
|
||||
return await Db.Queryable<OutboundPickTask>()
|
||||
.Where(x => !x.IsDeleted && x.OrderId == orderId)
|
||||
.OrderBy(x => x.TaskNo)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<OutboundPickTask>> GetByOrderLineIdAsync(long orderLineId)
|
||||
{
|
||||
return await Db.Queryable<OutboundPickTask>()
|
||||
.Where(x => !x.IsDeleted && x.OrderLineId == orderLineId)
|
||||
.OrderBy(x => x.TaskNo)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferOrderRepository : OrderRepositoryBase<TransferOrder, TransferOrderPagedQuery>, ITransferOrderRepository
|
||||
{
|
||||
public TransferOrderRepository(ISqlSugarClient db, ICurrentUserContext userContext) : base(db, userContext) { }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using WmsLite.Api.Dtos.Inventory;
|
||||
|
||||
namespace WmsLite.Api.Services.Interfaces;
|
||||
|
||||
public interface IInventoryAllocationService
|
||||
{
|
||||
Task<List<InventoryAllocationItem>> AllocateAsync(InventoryAllocationRequest request);
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public interface IOutboundOrderService
|
||||
|
||||
Task<List<InventoryOrderLineViewDto>?> GetLinesAsync(long orderId, string tenantId, string ownerCode);
|
||||
|
||||
Task<List<OutboundPickTaskViewDto>?> GetPickTasksAsync(long orderId, string tenantId, string ownerCode);
|
||||
|
||||
Task<OrderViewDto> CreateAsync(OutboundOrderSaveRequest request);
|
||||
|
||||
Task<OrderViewDto?> PendingAsync(OrderActionRequest request);
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using WmsLite.Api.Common;
|
||||
using WmsLite.Api.Dtos.Inventory;
|
||||
using WmsLite.Api.Enums;
|
||||
using WmsLite.Api.Repositories.Interfaces;
|
||||
using WmsLite.Api.Services.Interfaces;
|
||||
|
||||
namespace WmsLite.Api.Services;
|
||||
|
||||
public class InventoryAllocationService : IInventoryAllocationService
|
||||
{
|
||||
private readonly IInventoryRepository _inventoryRepository;
|
||||
|
||||
public InventoryAllocationService(IInventoryRepository inventoryRepository)
|
||||
{
|
||||
_inventoryRepository = inventoryRepository;
|
||||
}
|
||||
|
||||
public async Task<List<InventoryAllocationItem>> AllocateAsync(InventoryAllocationRequest request)
|
||||
{
|
||||
if (request.Qty <= 0)
|
||||
{
|
||||
throw new BusinessException("Allocation quantity must be greater than 0.");
|
||||
}
|
||||
|
||||
ValidateStockIdentity(request);
|
||||
|
||||
var candidates = await _inventoryRepository.GetAllocatableAsync(
|
||||
request.TenantId,
|
||||
request.OwnerCode,
|
||||
request.WarehouseCode,
|
||||
request.AreaCode,
|
||||
request.InventoryKind,
|
||||
request.MaterialCode,
|
||||
request.ContainerCode,
|
||||
request.LocationCode);
|
||||
|
||||
var remain = request.Qty;
|
||||
var result = new List<InventoryAllocationItem>();
|
||||
foreach (var inventory in candidates)
|
||||
{
|
||||
var available = inventory.Qty - inventory.PendingOutboundQty - inventory.FrozenQty;
|
||||
if (available <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var allocated = Math.Min(available, remain);
|
||||
result.Add(new InventoryAllocationItem
|
||||
{
|
||||
Inventory = inventory,
|
||||
Qty = allocated
|
||||
});
|
||||
remain -= allocated;
|
||||
if (remain <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (remain > 0)
|
||||
{
|
||||
throw new BusinessException($"Available quantity is not enough. Required: {request.Qty}, short: {remain}.");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void ValidateStockIdentity(InventoryAllocationRequest request)
|
||||
{
|
||||
switch (request.InventoryKind)
|
||||
{
|
||||
case InventoryKind.Material:
|
||||
if (string.IsNullOrWhiteSpace(request.MaterialCode))
|
||||
{
|
||||
throw new BusinessException("MaterialCode is required for material allocation.");
|
||||
}
|
||||
|
||||
break;
|
||||
case InventoryKind.EmptyContainer:
|
||||
if (string.IsNullOrWhiteSpace(request.ContainerCode))
|
||||
{
|
||||
throw new BusinessException("ContainerCode is required for empty container allocation.");
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("Unsupported inventory kind.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using WmsLite.Api.Dtos.Inventory;
|
||||
using WmsLite.Api.Common;
|
||||
using WmsLite.Api.Dtos.Orders;
|
||||
using WmsLite.Api.Enums;
|
||||
@@ -570,14 +571,18 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
private readonly ITransactionRunner _tx;
|
||||
private readonly IOutboundOrderRepository _orderRepository;
|
||||
private readonly IOutboundOrderLineRepository _lineRepository;
|
||||
private readonly IOutboundPickTaskRepository _pickTaskRepository;
|
||||
private readonly ILocationRepository _locationRepository;
|
||||
private readonly IInventoryAllocationService _allocationService;
|
||||
private readonly ICurrentUserContext _userContext;
|
||||
|
||||
public OutboundOrderService(
|
||||
ITransactionRunner tx,
|
||||
IOutboundOrderRepository orderRepository,
|
||||
IOutboundOrderLineRepository lineRepository,
|
||||
IOutboundPickTaskRepository pickTaskRepository,
|
||||
ILocationRepository locationRepository,
|
||||
IInventoryAllocationService allocationService,
|
||||
IInventoryRepository inventoryRepository,
|
||||
IInventoryMovementService inventoryMovementService,
|
||||
ICurrentUserContext userContext) : base(inventoryRepository, inventoryMovementService)
|
||||
@@ -585,7 +590,9 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
_tx = tx;
|
||||
_orderRepository = orderRepository;
|
||||
_lineRepository = lineRepository;
|
||||
_pickTaskRepository = pickTaskRepository;
|
||||
_locationRepository = locationRepository;
|
||||
_allocationService = allocationService;
|
||||
_userContext = userContext;
|
||||
}
|
||||
|
||||
@@ -614,6 +621,19 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
return lines.ConvertAll(x => MapInventoryLine(x));
|
||||
}
|
||||
|
||||
public async Task<List<OutboundPickTaskViewDto>?> GetPickTasksAsync(long orderId, string tenantId, string ownerCode)
|
||||
{
|
||||
var t = _userContext.TenantId.Trim();
|
||||
var o = _userContext.OwnerCode.Trim();
|
||||
if (await _orderRepository.GetByIdAsync(orderId, t, o) is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var tasks = await _pickTaskRepository.GetByOrderIdAsync(orderId);
|
||||
return tasks.ConvertAll(MapPickTask);
|
||||
}
|
||||
|
||||
public async Task<OrderViewDto> CreateAsync(OutboundOrderSaveRequest request)
|
||||
{
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
@@ -649,10 +669,10 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
ContainerCode = line.InventoryKind == InventoryKind.EmptyContainer ? line.ContainerCode?.Trim() : null,
|
||||
WarehouseCode = line.WarehouseCode.Trim(),
|
||||
AreaCode = line.AreaCode.Trim(),
|
||||
LocationCode = line.LocationCode.Trim(),
|
||||
LocationCode = line.LocationCode?.Trim(),
|
||||
Qty = line.Qty,
|
||||
ReceivedQty = 0,
|
||||
LineStatus = OrderLineStatus.Completed,
|
||||
LineStatus = OrderLineStatus.Open,
|
||||
Unit = line.Unit.Trim(),
|
||||
Attrs = line.Attrs
|
||||
});
|
||||
@@ -676,14 +696,70 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
var lines = await _lineRepository.GetByOrderIdAsync(order.Id);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var resolved = await _locationRepository.GetByWarehouseAreaAndLocationCodeAsync(
|
||||
order.TenantId, order.OwnerCode, line.WarehouseCode, line.AreaCode, line.LocationCode!.Trim())
|
||||
?? throw new BusinessException(
|
||||
var existingTasks = await _pickTaskRepository.GetByOrderLineIdAsync(line.Id);
|
||||
if (existingTasks.Count > 0)
|
||||
{
|
||||
throw new BusinessException("Outbound pick tasks already exist.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(line.LocationCode)
|
||||
&& await _locationRepository.GetByWarehouseAreaAndLocationCodeAsync(
|
||||
order.TenantId, order.OwnerCode, line.WarehouseCode, line.AreaCode, line.LocationCode.Trim()) is null)
|
||||
{
|
||||
throw new BusinessException(
|
||||
$"Location '{line.LocationCode}' not found for warehouse '{line.WarehouseCode}' and area '{line.AreaCode}'.");
|
||||
var inventory = await RequireInventoryAsync(
|
||||
order.TenantId, order.OwnerCode, line.InventoryKind, line.MaterialCode, line.ContainerCode,
|
||||
line.WarehouseCode, line.AreaCode, resolved.ZoneCode, line.LocationCode!);
|
||||
await InventoryMovementService.PendingOutboundAsync(inventory, line.Qty, order.OrderNo);
|
||||
}
|
||||
|
||||
var allocations = await _allocationService.AllocateAsync(new InventoryAllocationRequest
|
||||
{
|
||||
TenantId = order.TenantId,
|
||||
OwnerCode = order.OwnerCode,
|
||||
InventoryKind = line.InventoryKind,
|
||||
MaterialCode = line.MaterialCode,
|
||||
ContainerCode = line.ContainerCode,
|
||||
WarehouseCode = line.WarehouseCode,
|
||||
AreaCode = line.AreaCode,
|
||||
LocationCode = line.LocationCode,
|
||||
Qty = line.Qty
|
||||
});
|
||||
|
||||
var taskSeq = 1;
|
||||
foreach (var allocation in allocations)
|
||||
{
|
||||
var inventory = allocation.Inventory;
|
||||
if (string.Compare(inventory.Unit.Trim(), line.Unit?.Trim(), StringComparison.Ordinal) != 0)
|
||||
{
|
||||
throw new BusinessException("Unit does not match allocated inventory.");
|
||||
}
|
||||
|
||||
await InventoryMovementService.PendingOutboundAsync(inventory, allocation.Qty, order.OrderNo);
|
||||
await _pickTaskRepository.InsertAsync(new OutboundPickTask
|
||||
{
|
||||
TenantId = order.TenantId,
|
||||
OwnerCode = order.OwnerCode,
|
||||
OrderId = order.Id,
|
||||
OrderLineId = line.Id,
|
||||
TaskNo = $"{order.OrderNo}-P{line.LineNo:D3}-{taskSeq:D3}",
|
||||
InventoryId = inventory.Id,
|
||||
InventoryKind = inventory.InventoryKind,
|
||||
MaterialCode = inventory.MaterialCode,
|
||||
ContainerCode = inventory.ContainerCode,
|
||||
WarehouseCode = inventory.WarehouseCode,
|
||||
AreaCode = inventory.AreaCode,
|
||||
ZoneCode = inventory.ZoneCode,
|
||||
LocationCode = inventory.LocationCode,
|
||||
Qty = allocation.Qty,
|
||||
PickedQty = 0,
|
||||
Unit = inventory.Unit,
|
||||
TaskStatus = PickTaskStatus.Open,
|
||||
Attrs = line.Attrs
|
||||
});
|
||||
taskSeq++;
|
||||
}
|
||||
|
||||
line.ReceivedQty = allocations.Sum(x => x.Qty);
|
||||
line.LineStatus = OrderLineStatus.Open;
|
||||
await _lineRepository.UpdateAsync(line);
|
||||
}
|
||||
|
||||
order.OrderStatus = OrderStatus.Pending;
|
||||
@@ -703,17 +779,32 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
{
|
||||
EnsurePending(order.OrderStatus);
|
||||
var tasks = await _pickTaskRepository.GetByOrderIdAsync(order.Id);
|
||||
if (tasks.Count == 0)
|
||||
{
|
||||
throw new BusinessException("Outbound pick tasks not found.");
|
||||
}
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
if (task.TaskStatus != PickTaskStatus.Open)
|
||||
{
|
||||
throw new BusinessException("Only open pick tasks can be confirmed.");
|
||||
}
|
||||
|
||||
var inventory = await InventoryRepository.GetByIdAsync(task.InventoryId, order.TenantId, order.OwnerCode)
|
||||
?? throw new BusinessException("Allocated inventory not found.");
|
||||
await InventoryMovementService.ConfirmOutboundAsync(inventory, task.Qty, order.OrderNo);
|
||||
task.PickedQty = task.Qty;
|
||||
task.TaskStatus = PickTaskStatus.Picked;
|
||||
await _pickTaskRepository.UpdateAsync(task);
|
||||
}
|
||||
|
||||
var lines = await _lineRepository.GetByOrderIdAsync(order.Id);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var resolved = await _locationRepository.GetByWarehouseAreaAndLocationCodeAsync(
|
||||
order.TenantId, order.OwnerCode, line.WarehouseCode, line.AreaCode, line.LocationCode!.Trim())
|
||||
?? throw new BusinessException(
|
||||
$"Location '{line.LocationCode}' not found for warehouse '{line.WarehouseCode}' and area '{line.AreaCode}'.");
|
||||
var inventory = await RequireInventoryAsync(
|
||||
order.TenantId, order.OwnerCode, line.InventoryKind, line.MaterialCode, line.ContainerCode,
|
||||
line.WarehouseCode, line.AreaCode, resolved.ZoneCode, line.LocationCode!);
|
||||
await InventoryMovementService.ConfirmOutboundAsync(inventory, line.Qty, order.OrderNo);
|
||||
line.LineStatus = OrderLineStatus.Completed;
|
||||
await _lineRepository.UpdateAsync(line);
|
||||
}
|
||||
|
||||
order.OrderStatus = OrderStatus.Completed;
|
||||
@@ -721,6 +812,30 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
return MapOrder(order, order.OrderNo, order.BizType, order.OrderStatus, order.Remark, order.Attrs);
|
||||
});
|
||||
}
|
||||
|
||||
private static OutboundPickTaskViewDto MapPickTask(OutboundPickTask task)
|
||||
{
|
||||
return new OutboundPickTaskViewDto
|
||||
{
|
||||
Id = FormatSnowflakeId(task.Id),
|
||||
OrderId = FormatSnowflakeId(task.OrderId),
|
||||
OrderLineId = FormatSnowflakeId(task.OrderLineId),
|
||||
TaskNo = task.TaskNo,
|
||||
InventoryId = FormatSnowflakeId(task.InventoryId),
|
||||
InventoryKind = task.InventoryKind,
|
||||
MaterialCode = task.MaterialCode,
|
||||
ContainerCode = task.ContainerCode,
|
||||
WarehouseCode = task.WarehouseCode,
|
||||
AreaCode = task.AreaCode,
|
||||
ZoneCode = task.ZoneCode,
|
||||
LocationCode = task.LocationCode,
|
||||
Qty = task.Qty,
|
||||
PickedQty = task.PickedQty,
|
||||
Unit = task.Unit,
|
||||
TaskStatus = task.TaskStatus,
|
||||
Attrs = task.Attrs
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferOrderService : OrderServiceBase, ITransferOrderService
|
||||
|
||||
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.2.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WmsLite.Api", "WmsLite.Api.csproj", "{79190F7B-E86A-BDB4-78EF-7829B20B85B1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WmsLite.Api.Tests", "..\WmsLite.Api.Tests\WmsLite.Api.Tests.csproj", "{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -27,6 +29,18 @@ Global
|
||||
{79190F7B-E86A-BDB4-78EF-7829B20B85B1}.Release|x64.Build.0 = Release|Any CPU
|
||||
{79190F7B-E86A-BDB4-78EF-7829B20B85B1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{79190F7B-E86A-BDB4-78EF-7829B20B85B1}.Release|x86.Build.0 = Release|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C9E0FB91-E7B1-4C7C-BF92-0DCE257B2DD3}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in new issue
Block a user