完善出库闭环和前端作业体验
This commit is contained in:
1 parent
3c6dfda5e5
commit
ce0fd7ec52
21 files changed
+1495
-261
No files matched your search
@@ -42,6 +42,17 @@ public class InboundOrderController : WmsLiteControllerBase
|
||||
public async Task<ActionResult<BusinessResult>> Create([FromBody] InboundOrderCreateRequest request)
|
||||
=> Ok(BusinessResult.Ok(await _service.CreateAsync(request)));
|
||||
|
||||
[HttpPost("create-header")]
|
||||
public async Task<ActionResult<BusinessResult>> CreateHeader([FromBody] OrderHeaderCreateRequest request)
|
||||
=> Ok(BusinessResult.Ok(await _service.CreateHeaderAsync(request)));
|
||||
|
||||
[HttpPost("add-line")]
|
||||
public async Task<ActionResult<BusinessResult>> AddLine([FromBody] InboundOrderAddLineRequest request)
|
||||
{
|
||||
var result = await _service.AddLineAsync(request);
|
||||
return result is null ? Ok(BusinessResult.NotFound("Resource not found.")) : Ok(BusinessResult.Ok(result));
|
||||
}
|
||||
|
||||
[HttpPost("confirm-line")]
|
||||
public async Task<ActionResult<BusinessResult>> ConfirmLine([FromBody] InboundOrderLineConfirmRequest request)
|
||||
{
|
||||
@@ -98,6 +109,17 @@ public class OutboundOrderController : WmsLiteControllerBase
|
||||
public async Task<ActionResult<BusinessResult>> Create([FromBody] OutboundOrderSaveRequest request)
|
||||
=> Ok(BusinessResult.Ok(await _service.CreateAsync(request)));
|
||||
|
||||
[HttpPost("create-header")]
|
||||
public async Task<ActionResult<BusinessResult>> CreateHeader([FromBody] OrderHeaderCreateRequest request)
|
||||
=> Ok(BusinessResult.Ok(await _service.CreateHeaderAsync(request)));
|
||||
|
||||
[HttpPost("add-line")]
|
||||
public async Task<ActionResult<BusinessResult>> AddLine([FromBody] OutboundOrderAddLineRequest request)
|
||||
{
|
||||
var result = await _service.AddLineAsync(request);
|
||||
return result is null ? Ok(BusinessResult.NotFound("Resource not found.")) : Ok(BusinessResult.Ok(result));
|
||||
}
|
||||
|
||||
[HttpPost("pending")]
|
||||
public async Task<ActionResult<BusinessResult>> Pending([FromBody] OrderActionRequest request)
|
||||
{
|
||||
@@ -111,6 +133,20 @@ public class OutboundOrderController : WmsLiteControllerBase
|
||||
var result = await _service.ConfirmAsync(request);
|
||||
return result is null ? Ok(BusinessResult.NotFound("Resource not found.")) : Ok(BusinessResult.Ok(result));
|
||||
}
|
||||
|
||||
[HttpPost("pick-task/confirm")]
|
||||
public async Task<ActionResult<BusinessResult>> ConfirmPickTask([FromBody] PickTaskActionRequest request)
|
||||
{
|
||||
var result = await _service.ConfirmPickTaskAsync(request);
|
||||
return result is null ? Ok(BusinessResult.NotFound("Resource not found.")) : Ok(BusinessResult.Ok(result));
|
||||
}
|
||||
|
||||
[HttpPost("cancel")]
|
||||
public async Task<ActionResult<BusinessResult>> Cancel([FromBody] OrderActionRequest request)
|
||||
{
|
||||
var result = await _service.CancelAsync(request);
|
||||
return result is null ? Ok(BusinessResult.NotFound("Resource not found.")) : Ok(BusinessResult.Ok(result));
|
||||
}
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using FluentMigrator;
|
||||
|
||||
namespace WmsLite.Api.Database.Migrations;
|
||||
|
||||
[Migration(16, "Outbound pick task operation fields")]
|
||||
public class OutboundPickTaskOperationFields0016 : Migration
|
||||
{
|
||||
public override void Up()
|
||||
{
|
||||
if (!Schema.Table("outbound_pick_task").Exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Schema.Table("outbound_pick_task").Column("picker_user_id").Exists())
|
||||
{
|
||||
Alter.Table("outbound_pick_task")
|
||||
.AddColumn("picker_user_id").AsString(128).Nullable();
|
||||
}
|
||||
|
||||
if (!Schema.Table("outbound_pick_task").Column("picked_time").Exists())
|
||||
{
|
||||
Alter.Table("outbound_pick_task")
|
||||
.AddColumn("picked_time").AsDateTime().Nullable();
|
||||
}
|
||||
|
||||
if (!Schema.Table("outbound_pick_task").Column("exception_reason").Exists())
|
||||
{
|
||||
Alter.Table("outbound_pick_task")
|
||||
.AddColumn("exception_reason").AsString(512).Nullable();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
if (!Schema.Table("outbound_pick_task").Exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Schema.Table("outbound_pick_task").Column("exception_reason").Exists())
|
||||
{
|
||||
Delete.Column("exception_reason").FromTable("outbound_pick_task");
|
||||
}
|
||||
|
||||
if (Schema.Table("outbound_pick_task").Column("picked_time").Exists())
|
||||
{
|
||||
Delete.Column("picked_time").FromTable("outbound_pick_task");
|
||||
}
|
||||
|
||||
if (Schema.Table("outbound_pick_task").Column("picker_user_id").Exists())
|
||||
{
|
||||
Delete.Column("picker_user_id").FromTable("outbound_pick_task");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ public abstract class OrderSaveRequestBase
|
||||
public Dictionary<string, object>? Attrs { get; set; }
|
||||
}
|
||||
|
||||
public class OrderHeaderCreateRequest : OrderSaveRequestBase
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class OrderPagedQueryBase : BasePagedQuery
|
||||
{
|
||||
[StringLength(128)]
|
||||
@@ -36,6 +40,36 @@ public class OrderActionRequest
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
public class InboundOrderAddLineRequest
|
||||
{
|
||||
[Range(1, long.MaxValue)]
|
||||
public long OrderId { get; set; }
|
||||
|
||||
[Required]
|
||||
public InboundOrderLineSaveRequest Line { get; set; } = new();
|
||||
}
|
||||
|
||||
public class OutboundOrderAddLineRequest
|
||||
{
|
||||
[Range(1, long.MaxValue)]
|
||||
public long OrderId { get; set; }
|
||||
|
||||
[Required]
|
||||
public OutboundOrderLineRequest Line { get; set; } = new();
|
||||
}
|
||||
|
||||
public class PickTaskActionRequest
|
||||
{
|
||||
[Range(1, long.MaxValue)]
|
||||
public long Id { get; set; }
|
||||
|
||||
[Range(typeof(decimal), "0.000001", "9999999999999999")]
|
||||
public decimal? PickedQty { get; set; }
|
||||
|
||||
[StringLength(512)]
|
||||
public string? ExceptionReason { get; set; }
|
||||
}
|
||||
|
||||
public class InventoryOrderLineRequest
|
||||
{
|
||||
[Required]
|
||||
@@ -123,15 +157,8 @@ public class StocktakeOrderLineRequest : InventoryOrderLineRequest
|
||||
}
|
||||
|
||||
/// <summary>?????????????????? JSON?</summary>
|
||||
public class InboundOrderCreateRequest
|
||||
public class InboundOrderCreateRequest : OrderSaveRequestBase
|
||||
{
|
||||
[StringLength(64)]
|
||||
public string? BizType { get; set; }
|
||||
|
||||
[StringLength(512)]
|
||||
public string? Remark { get; set; }
|
||||
|
||||
[MinLength(1)]
|
||||
public List<InboundOrderLineSaveRequest> Lines { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -188,7 +215,6 @@ public class InboundConfirmLineResultDto
|
||||
|
||||
public class OutboundOrderSaveRequest : OrderSaveRequestBase
|
||||
{
|
||||
[MinLength(1)]
|
||||
public List<OutboundOrderLineRequest> Lines { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -219,9 +245,8 @@ public class OutboundOrderLineRequest
|
||||
[Range(typeof(decimal), "0.000001", "9999999999999999")]
|
||||
public decimal Qty { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(32)]
|
||||
public string Unit { get; set; } = string.Empty;
|
||||
public string? Unit { get; set; }
|
||||
|
||||
public Dictionary<string, object>? Attrs { get; set; }
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ public class OutboundPickTaskViewDto
|
||||
|
||||
public decimal PickedQty { get; set; }
|
||||
|
||||
public string? PickerUserId { get; set; }
|
||||
|
||||
public DateTime? PickedTime { get; set; }
|
||||
|
||||
public string? ExceptionReason { get; set; }
|
||||
|
||||
public string Unit { get; set; } = string.Empty;
|
||||
|
||||
public PickTaskStatus TaskStatus { get; set; }
|
||||
|
||||
@@ -23,5 +23,8 @@ public enum InventoryMovementType
|
||||
Unfreeze = 6,
|
||||
|
||||
[Description("Adjust")]
|
||||
Adjust = 7
|
||||
Adjust = 7,
|
||||
|
||||
[Description("PendingOutboundRelease")]
|
||||
PendingOutboundRelease = 8
|
||||
}
|
||||
@@ -46,6 +46,15 @@ public class OutboundPickTask : BaseEntity
|
||||
[SugarColumn(ColumnName = "picked_qty", IsNullable = false, DefaultValue = "0")]
|
||||
public decimal PickedQty { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "picker_user_id", Length = 128, IsNullable = true)]
|
||||
public string? PickerUserId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "picked_time", IsNullable = true)]
|
||||
public DateTime? PickedTime { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "exception_reason", Length = 512, IsNullable = true)]
|
||||
public string? ExceptionReason { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "unit", Length = 32, IsNullable = false)]
|
||||
public string Unit { get; set; } = string.Empty;
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ Development 见 `appsettings.Development.json` 中 `Jwt` 节。生产环境请
|
||||
| 0012 | `sys_user` 表与种子账号 |
|
||||
| 0013 | 入库单号计数器 `order_no_counter` |
|
||||
| 0014 | 业务唯一约束(partial unique index) |
|
||||
| 0015 | 出库库存分配与拣货任务 |
|
||||
| 0016 | 出库拣货任务操作字段 |
|
||||
|
||||
## 启动
|
||||
|
||||
@@ -103,8 +105,28 @@ GET /api/Auth/me # 需 Bearer
|
||||
GET /api/Health # 匿名
|
||||
POST /api/Warehouse/paged-list
|
||||
POST /api/SysDictionary/map
|
||||
POST /api/InboundOrder/create-header
|
||||
POST /api/InboundOrder/add-line
|
||||
POST /api/OutboundOrder/create-header
|
||||
POST /api/OutboundOrder/add-line
|
||||
POST /api/OutboundOrder/pending
|
||||
POST /api/OutboundOrder/pick-task/confirm
|
||||
POST /api/OutboundOrder/confirm
|
||||
POST /api/OutboundOrder/cancel
|
||||
```
|
||||
|
||||
### 单据接口约定
|
||||
|
||||
- 入库、出库支持先创建 Draft 单头,再追加明细:
|
||||
- `POST /api/InboundOrder/create-header`
|
||||
- `POST /api/InboundOrder/add-line`
|
||||
- `POST /api/OutboundOrder/create-header`
|
||||
- `POST /api/OutboundOrder/add-line`
|
||||
- 出库物料行的 `unit` 可不传,服务端会按物料主数据单位写入;若客户端传入单位,必须与物料主数据一致。
|
||||
- 出库转待拣会按仓库、库区、物料和可选指定库位分配库存并生成拣货任务。
|
||||
- `POST /api/OutboundOrder/pick-task/confirm` 用于确认单个拣货任务,记录拣货人、拣货时间、已拣数量和异常原因。
|
||||
- `POST /api/OutboundOrder/cancel` 仅允许取消待处理出库单,会释放 `PendingOutboundQty` 并取消未出库任务。
|
||||
|
||||
未带 Token 访问业务接口返回 **HTTP 401**(JSON:`{ "success": false, "code": "401", ... }`)。
|
||||
|
||||
## 项目结构
|
||||
|
||||
@@ -16,6 +16,8 @@ public interface IInventoryMovementService
|
||||
|
||||
Task ConfirmOutboundAsync(Inventory inventory, decimal qty, string? bizNo = null, string? remark = null);
|
||||
|
||||
Task ReleasePendingOutboundAsync(Inventory inventory, decimal qty, string? bizNo = null, string? remark = null);
|
||||
|
||||
Task FreezeAsync(Inventory inventory, decimal qty, string? bizNo = null, string? remark = null);
|
||||
|
||||
Task UnfreezeAsync(Inventory inventory, decimal qty, string? bizNo = null, string? remark = null);
|
||||
|
||||
@@ -11,8 +11,12 @@ public interface IInboundOrderService
|
||||
|
||||
Task<List<InventoryOrderLineViewDto>?> GetLinesAsync(long orderId, string tenantId, string ownerCode);
|
||||
|
||||
Task<OrderViewDto> CreateHeaderAsync(OrderHeaderCreateRequest request);
|
||||
|
||||
Task<OrderViewDto> CreateAsync(InboundOrderCreateRequest request);
|
||||
|
||||
Task<InventoryOrderLineViewDto?> AddLineAsync(InboundOrderAddLineRequest request);
|
||||
|
||||
Task<InboundConfirmLineResultDto?> ConfirmLineAsync(InboundOrderLineConfirmRequest request);
|
||||
}
|
||||
|
||||
@@ -24,11 +28,19 @@ public interface IOutboundOrderService
|
||||
|
||||
Task<List<OutboundPickTaskViewDto>?> GetPickTasksAsync(long orderId, string tenantId, string ownerCode);
|
||||
|
||||
Task<OrderViewDto> CreateHeaderAsync(OrderHeaderCreateRequest request);
|
||||
|
||||
Task<OrderViewDto> CreateAsync(OutboundOrderSaveRequest request);
|
||||
|
||||
Task<InventoryOrderLineViewDto?> AddLineAsync(OutboundOrderAddLineRequest request);
|
||||
|
||||
Task<OrderViewDto?> PendingAsync(OrderActionRequest request);
|
||||
|
||||
Task<OutboundPickTaskViewDto?> ConfirmPickTaskAsync(PickTaskActionRequest request);
|
||||
|
||||
Task<OrderViewDto?> ConfirmAsync(OrderActionRequest request);
|
||||
|
||||
Task<OrderViewDto?> CancelAsync(OrderActionRequest request);
|
||||
}
|
||||
|
||||
public interface ITransferOrderService
|
||||
|
||||
@@ -95,6 +95,21 @@ public class InventoryMovementService : IInventoryMovementService
|
||||
await WriteTransactionAsync(before, inventory, InventoryMovementType.OutboundConfirm, -qty, bizNo, remark);
|
||||
}
|
||||
|
||||
public async Task ReleasePendingOutboundAsync(Inventory inventory, decimal qty, string? bizNo = null, string? remark = null)
|
||||
{
|
||||
EnsurePositive(qty);
|
||||
if (inventory.PendingOutboundQty < qty)
|
||||
{
|
||||
throw new BusinessException("PendingOutboundQty is not enough to release.");
|
||||
}
|
||||
|
||||
var before = Clone(inventory);
|
||||
inventory.PendingOutboundQty -= qty;
|
||||
inventory.InventoryStatus = ResolveStatus(inventory);
|
||||
await _inventoryRepository.UpdateAsync(inventory);
|
||||
await WriteTransactionAsync(before, inventory, InventoryMovementType.PendingOutboundRelease, -qty, bizNo, remark);
|
||||
}
|
||||
|
||||
public async Task FreezeAsync(Inventory inventory, decimal qty, string? bizNo = null, string? remark = null)
|
||||
{
|
||||
EnsurePositive(qty);
|
||||
|
||||
@@ -284,48 +284,49 @@ public class InboundOrderService : OrderServiceBase, IInboundOrderService
|
||||
{
|
||||
var tenantId = _userContext.TenantId.Trim();
|
||||
var ownerCode = _userContext.OwnerCode.Trim();
|
||||
var orderNo = await _orderNumberGenerator.NextInboundOrderNoAsync(tenantId, ownerCode);
|
||||
|
||||
var order = new InboundOrder
|
||||
{
|
||||
TenantId = tenantId,
|
||||
OwnerCode = ownerCode,
|
||||
OrderNo = orderNo,
|
||||
BizType = request.BizType?.Trim(),
|
||||
Remark = request.Remark?.Trim(),
|
||||
Attrs = null,
|
||||
OrderStatus = OrderStatus.Draft
|
||||
};
|
||||
await _orderRepository.InsertAsync(order);
|
||||
var order = await CreateHeaderCoreAsync(tenantId, ownerCode, request);
|
||||
|
||||
for (var i = 0; i < request.Lines.Count; i++)
|
||||
{
|
||||
var line = request.Lines[i];
|
||||
await ValidateInboundLineMasterDataAsync(tenantId, ownerCode, line);
|
||||
await _lineRepository.InsertAsync(new InboundOrderLine
|
||||
{
|
||||
TenantId = order.TenantId,
|
||||
OwnerCode = order.OwnerCode,
|
||||
OrderId = order.Id,
|
||||
LineNo = i + 1,
|
||||
InventoryKind = line.InventoryKind,
|
||||
MaterialCode = line.InventoryKind == InventoryKind.Material ? line.MaterialCode?.Trim() : null,
|
||||
ContainerCode = null,
|
||||
WarehouseCode = line.WarehouseCode.Trim(),
|
||||
AreaCode = line.AreaCode.Trim(),
|
||||
LocationCode = null,
|
||||
Qty = line.Qty,
|
||||
ReceivedQty = 0,
|
||||
LineStatus = OrderLineStatus.Open,
|
||||
Unit = null,
|
||||
Attrs = line.Attrs
|
||||
});
|
||||
await InsertInboundLineAsync(order, request.Lines[i], i + 1);
|
||||
}
|
||||
|
||||
return MapOrder(order, order.OrderNo, order.BizType, order.OrderStatus, order.Remark, order.Attrs);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OrderViewDto> CreateHeaderAsync(OrderHeaderCreateRequest request)
|
||||
{
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
{
|
||||
var order = await CreateHeaderCoreAsync(
|
||||
_userContext.TenantId.Trim(),
|
||||
_userContext.OwnerCode.Trim(),
|
||||
request);
|
||||
return MapOrder(order, order.OrderNo, order.BizType, order.OrderStatus, order.Remark, order.Attrs);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<InventoryOrderLineViewDto?> AddLineAsync(InboundOrderAddLineRequest request)
|
||||
{
|
||||
var order = await _orderRepository.GetByIdAsync(
|
||||
request.OrderId,
|
||||
_userContext.TenantId.Trim(),
|
||||
_userContext.OwnerCode.Trim());
|
||||
if (order is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
{
|
||||
EnsureDraft(order.OrderStatus);
|
||||
var lines = await _lineRepository.GetByOrderIdAsync(order.Id);
|
||||
var line = await InsertInboundLineAsync(order, request.Line, lines.Count + 1);
|
||||
return MapInventoryLine(line);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<InboundConfirmLineResultDto?> ConfirmLineAsync(InboundOrderLineConfirmRequest request)
|
||||
{
|
||||
var tenantId = _userContext.TenantId.Trim();
|
||||
@@ -530,6 +531,47 @@ public class InboundOrderService : OrderServiceBase, IInboundOrderService
|
||||
return string.Equals(aa, bb, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private async Task<InboundOrder> CreateHeaderCoreAsync(string tenantId, string ownerCode, OrderSaveRequestBase request)
|
||||
{
|
||||
var order = new InboundOrder
|
||||
{
|
||||
TenantId = tenantId,
|
||||
OwnerCode = ownerCode,
|
||||
OrderNo = await _orderNumberGenerator.NextInboundOrderNoAsync(tenantId, ownerCode),
|
||||
BizType = request.BizType?.Trim(),
|
||||
Remark = request.Remark?.Trim(),
|
||||
Attrs = request.Attrs,
|
||||
OrderStatus = OrderStatus.Draft
|
||||
};
|
||||
await _orderRepository.InsertAsync(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
private async Task<InboundOrderLine> InsertInboundLineAsync(InboundOrder order, InboundOrderLineSaveRequest line, int lineNo)
|
||||
{
|
||||
await ValidateInboundLineMasterDataAsync(order.TenantId, order.OwnerCode, line);
|
||||
var entity = new InboundOrderLine
|
||||
{
|
||||
TenantId = order.TenantId,
|
||||
OwnerCode = order.OwnerCode,
|
||||
OrderId = order.Id,
|
||||
LineNo = lineNo,
|
||||
InventoryKind = line.InventoryKind,
|
||||
MaterialCode = line.InventoryKind == InventoryKind.Material ? line.MaterialCode?.Trim() : null,
|
||||
ContainerCode = null,
|
||||
WarehouseCode = line.WarehouseCode.Trim(),
|
||||
AreaCode = line.AreaCode.Trim(),
|
||||
LocationCode = null,
|
||||
Qty = line.Qty,
|
||||
ReceivedQty = 0,
|
||||
LineStatus = OrderLineStatus.Open,
|
||||
Unit = null,
|
||||
Attrs = line.Attrs
|
||||
};
|
||||
await _lineRepository.InsertAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private async Task ValidateInboundLineMasterDataAsync(string tenantId, string ownerCode, InboundOrderLineSaveRequest line)
|
||||
{
|
||||
var t = tenantId.Trim();
|
||||
@@ -573,6 +615,7 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
private readonly IOutboundOrderLineRepository _lineRepository;
|
||||
private readonly IOutboundPickTaskRepository _pickTaskRepository;
|
||||
private readonly ILocationRepository _locationRepository;
|
||||
private readonly IMaterialRepository _materialRepository;
|
||||
private readonly IInventoryAllocationService _allocationService;
|
||||
private readonly IOrderNumberGenerator _orderNumberGenerator;
|
||||
private readonly ICurrentUserContext _userContext;
|
||||
@@ -583,6 +626,7 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
IOutboundOrderLineRepository lineRepository,
|
||||
IOutboundPickTaskRepository pickTaskRepository,
|
||||
ILocationRepository locationRepository,
|
||||
IMaterialRepository materialRepository,
|
||||
IInventoryAllocationService allocationService,
|
||||
IOrderNumberGenerator orderNumberGenerator,
|
||||
IInventoryRepository inventoryRepository,
|
||||
@@ -594,6 +638,7 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
_lineRepository = lineRepository;
|
||||
_pickTaskRepository = pickTaskRepository;
|
||||
_locationRepository = locationRepository;
|
||||
_materialRepository = materialRepository;
|
||||
_allocationService = allocationService;
|
||||
_orderNumberGenerator = orderNumberGenerator;
|
||||
_userContext = userContext;
|
||||
@@ -643,54 +688,49 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
{
|
||||
var tenantId = _userContext.TenantId.Trim();
|
||||
var ownerCode = _userContext.OwnerCode.Trim();
|
||||
var orderNo = string.IsNullOrWhiteSpace(request.OrderNo)
|
||||
? await _orderNumberGenerator.NextOutboundOrderNoAsync(tenantId, ownerCode)
|
||||
: request.OrderNo.Trim();
|
||||
|
||||
if (await _orderRepository.GetByOrderNoAsync(tenantId, ownerCode, orderNo) is not null)
|
||||
{
|
||||
throw new BusinessException($"Outbound order '{orderNo}' already exists.");
|
||||
}
|
||||
|
||||
var order = new OutboundOrder
|
||||
{
|
||||
TenantId = tenantId,
|
||||
OwnerCode = ownerCode,
|
||||
OrderNo = orderNo,
|
||||
BizType = request.BizType?.Trim(),
|
||||
Remark = request.Remark?.Trim(),
|
||||
Attrs = request.Attrs,
|
||||
OrderStatus = OrderStatus.Draft
|
||||
};
|
||||
await _orderRepository.InsertAsync(order);
|
||||
var order = await CreateHeaderCoreAsync(tenantId, ownerCode, request);
|
||||
|
||||
for (var i = 0; i < request.Lines.Count; i++)
|
||||
{
|
||||
var line = request.Lines[i];
|
||||
await _lineRepository.InsertAsync(new OutboundOrderLine
|
||||
{
|
||||
TenantId = order.TenantId,
|
||||
OwnerCode = order.OwnerCode,
|
||||
OrderId = order.Id,
|
||||
LineNo = i + 1,
|
||||
InventoryKind = line.InventoryKind,
|
||||
MaterialCode = line.InventoryKind == InventoryKind.Material ? line.MaterialCode?.Trim() : null,
|
||||
ContainerCode = line.InventoryKind == InventoryKind.EmptyContainer ? line.ContainerCode?.Trim() : null,
|
||||
WarehouseCode = line.WarehouseCode.Trim(),
|
||||
AreaCode = line.AreaCode.Trim(),
|
||||
LocationCode = line.LocationCode?.Trim(),
|
||||
Qty = line.Qty,
|
||||
ReceivedQty = 0,
|
||||
LineStatus = OrderLineStatus.Open,
|
||||
Unit = line.Unit.Trim(),
|
||||
Attrs = line.Attrs
|
||||
});
|
||||
await InsertOutboundLineAsync(order, request.Lines[i], i + 1);
|
||||
}
|
||||
|
||||
return MapOrder(order, order.OrderNo, order.BizType, order.OrderStatus, order.Remark, order.Attrs);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OrderViewDto> CreateHeaderAsync(OrderHeaderCreateRequest request)
|
||||
{
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
{
|
||||
var order = await CreateHeaderCoreAsync(
|
||||
_userContext.TenantId.Trim(),
|
||||
_userContext.OwnerCode.Trim(),
|
||||
request);
|
||||
return MapOrder(order, order.OrderNo, order.BizType, order.OrderStatus, order.Remark, order.Attrs);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<InventoryOrderLineViewDto?> AddLineAsync(OutboundOrderAddLineRequest request)
|
||||
{
|
||||
var order = await _orderRepository.GetByIdAsync(
|
||||
request.OrderId,
|
||||
_userContext.TenantId.Trim(),
|
||||
_userContext.OwnerCode.Trim());
|
||||
if (order is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
{
|
||||
EnsureDraft(order.OrderStatus);
|
||||
var lines = await _lineRepository.GetByOrderIdAsync(order.Id);
|
||||
var line = await InsertOutboundLineAsync(order, request.Line, lines.Count + 1);
|
||||
return MapInventoryLine(line);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OrderViewDto?> PendingAsync(OrderActionRequest request)
|
||||
{
|
||||
var order = await _orderRepository.GetByIdAsync(request.Id, _userContext.TenantId.Trim(), _userContext.OwnerCode.Trim());
|
||||
@@ -703,6 +743,11 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
{
|
||||
EnsureDraft(order.OrderStatus);
|
||||
var lines = await _lineRepository.GetByOrderIdAsync(order.Id);
|
||||
if (lines.Count == 0)
|
||||
{
|
||||
throw new BusinessException("Outbound order must have at least one line before picking.");
|
||||
}
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var existingTasks = await _pickTaskRepository.GetByOrderLineIdAsync(line.Id);
|
||||
@@ -796,17 +841,14 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
if (task.TaskStatus != PickTaskStatus.Open)
|
||||
if (task.TaskStatus != PickTaskStatus.Picked)
|
||||
{
|
||||
throw new BusinessException("Only open pick tasks can be confirmed.");
|
||||
throw new BusinessException("All outbound pick tasks must be picked before outbound confirmation.");
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -822,6 +864,102 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OutboundPickTaskViewDto?> ConfirmPickTaskAsync(PickTaskActionRequest request)
|
||||
{
|
||||
var task = await _pickTaskRepository.GetByIdAsync(
|
||||
request.Id,
|
||||
_userContext.TenantId.Trim(),
|
||||
_userContext.OwnerCode.Trim());
|
||||
if (task is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
{
|
||||
if (task.TaskStatus != PickTaskStatus.Open)
|
||||
{
|
||||
throw new BusinessException("Only open pick tasks can be picked.");
|
||||
}
|
||||
|
||||
var order = await _orderRepository.GetByIdAsync(task.OrderId, task.TenantId, task.OwnerCode)
|
||||
?? throw new BusinessException("Outbound order not found.");
|
||||
EnsurePending(order.OrderStatus);
|
||||
|
||||
var pickedQty = request.PickedQty ?? task.Qty;
|
||||
if (pickedQty != task.Qty)
|
||||
{
|
||||
throw new BusinessException("Short picking is not supported yet. Please pick the full task quantity.");
|
||||
}
|
||||
|
||||
task.PickedQty = pickedQty;
|
||||
task.PickerUserId = _userContext.UserId;
|
||||
task.PickedTime = DateTime.Now;
|
||||
task.ExceptionReason = string.IsNullOrWhiteSpace(request.ExceptionReason)
|
||||
? null
|
||||
: request.ExceptionReason.Trim();
|
||||
task.TaskStatus = PickTaskStatus.Picked;
|
||||
await _pickTaskRepository.UpdateAsync(task);
|
||||
|
||||
return MapPickTask(task);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OrderViewDto?> CancelAsync(OrderActionRequest request)
|
||||
{
|
||||
var order = await _orderRepository.GetByIdAsync(request.Id, _userContext.TenantId.Trim(), _userContext.OwnerCode.Trim());
|
||||
if (order is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await _tx.ExecuteAsync(async () =>
|
||||
{
|
||||
if (order.OrderStatus == OrderStatus.Completed)
|
||||
{
|
||||
throw new BusinessException("Completed outbound orders cannot be cancelled.");
|
||||
}
|
||||
|
||||
if (order.OrderStatus == OrderStatus.Cancelled)
|
||||
{
|
||||
return MapOrder(order, order.OrderNo, order.BizType, order.OrderStatus, order.Remark, order.Attrs);
|
||||
}
|
||||
|
||||
var tasks = await _pickTaskRepository.GetByOrderIdAsync(order.Id);
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
if (task.TaskStatus == PickTaskStatus.Cancelled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var inventory = await InventoryRepository.GetByIdAsync(task.InventoryId, order.TenantId, order.OwnerCode)
|
||||
?? throw new BusinessException("Allocated inventory not found.");
|
||||
await InventoryMovementService.ReleasePendingOutboundAsync(
|
||||
inventory,
|
||||
task.Qty,
|
||||
order.OrderNo,
|
||||
"Outbound order cancelled.");
|
||||
|
||||
task.TaskStatus = PickTaskStatus.Cancelled;
|
||||
task.ExceptionReason = "Outbound order cancelled.";
|
||||
await _pickTaskRepository.UpdateAsync(task);
|
||||
}
|
||||
|
||||
var lines = await _lineRepository.GetByOrderIdAsync(order.Id);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
line.LineStatus = OrderLineStatus.Open;
|
||||
line.ReceivedQty = 0;
|
||||
await _lineRepository.UpdateAsync(line);
|
||||
}
|
||||
|
||||
order.OrderStatus = OrderStatus.Cancelled;
|
||||
await _orderRepository.UpdateAsync(order);
|
||||
return MapOrder(order, order.OrderNo, order.BizType, order.OrderStatus, order.Remark, order.Attrs);
|
||||
});
|
||||
}
|
||||
|
||||
private static OutboundPickTaskViewDto MapPickTask(OutboundPickTask task)
|
||||
{
|
||||
return new OutboundPickTaskViewDto
|
||||
@@ -840,11 +978,106 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
|
||||
LocationCode = task.LocationCode,
|
||||
Qty = task.Qty,
|
||||
PickedQty = task.PickedQty,
|
||||
PickerUserId = task.PickerUserId,
|
||||
PickedTime = task.PickedTime,
|
||||
ExceptionReason = task.ExceptionReason,
|
||||
Unit = task.Unit,
|
||||
TaskStatus = task.TaskStatus,
|
||||
Attrs = task.Attrs
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<OutboundOrder> CreateHeaderCoreAsync(string tenantId, string ownerCode, OrderSaveRequestBase request)
|
||||
{
|
||||
var orderNo = string.IsNullOrWhiteSpace(request.OrderNo)
|
||||
? await _orderNumberGenerator.NextOutboundOrderNoAsync(tenantId, ownerCode)
|
||||
: request.OrderNo.Trim();
|
||||
|
||||
if (await _orderRepository.GetByOrderNoAsync(tenantId, ownerCode, orderNo) is not null)
|
||||
{
|
||||
throw new BusinessException($"Outbound order '{orderNo}' already exists.");
|
||||
}
|
||||
|
||||
var order = new OutboundOrder
|
||||
{
|
||||
TenantId = tenantId,
|
||||
OwnerCode = ownerCode,
|
||||
OrderNo = orderNo,
|
||||
BizType = request.BizType?.Trim(),
|
||||
Remark = request.Remark?.Trim(),
|
||||
Attrs = request.Attrs,
|
||||
OrderStatus = OrderStatus.Draft
|
||||
};
|
||||
await _orderRepository.InsertAsync(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
private async Task<OutboundOrderLine> InsertOutboundLineAsync(OutboundOrder order, OutboundOrderLineRequest line, int lineNo)
|
||||
{
|
||||
var unit = await ResolveOutboundLineUnitAsync(order.TenantId, order.OwnerCode, line);
|
||||
var entity = new OutboundOrderLine
|
||||
{
|
||||
TenantId = order.TenantId,
|
||||
OwnerCode = order.OwnerCode,
|
||||
OrderId = order.Id,
|
||||
LineNo = lineNo,
|
||||
InventoryKind = line.InventoryKind,
|
||||
MaterialCode = line.InventoryKind == InventoryKind.Material ? line.MaterialCode?.Trim() : null,
|
||||
ContainerCode = line.InventoryKind == InventoryKind.EmptyContainer ? line.ContainerCode?.Trim() : null,
|
||||
WarehouseCode = line.WarehouseCode.Trim(),
|
||||
AreaCode = line.AreaCode.Trim(),
|
||||
LocationCode = line.LocationCode?.Trim(),
|
||||
Qty = line.Qty,
|
||||
ReceivedQty = 0,
|
||||
LineStatus = OrderLineStatus.Open,
|
||||
Unit = unit,
|
||||
Attrs = line.Attrs
|
||||
};
|
||||
await _lineRepository.InsertAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private async Task<string> ResolveOutboundLineUnitAsync(string tenantId, string ownerCode, OutboundOrderLineRequest line)
|
||||
{
|
||||
switch (line.InventoryKind)
|
||||
{
|
||||
case InventoryKind.Material:
|
||||
if (string.IsNullOrWhiteSpace(line.MaterialCode))
|
||||
{
|
||||
throw new BusinessException("MaterialCode is required for material lines.");
|
||||
}
|
||||
|
||||
var material = await _materialRepository.GetByCodeAsync(tenantId, ownerCode, line.MaterialCode.Trim())
|
||||
?? throw new BusinessException($"Material '{line.MaterialCode}' not found.");
|
||||
var masterUnit = material.Unit.Trim();
|
||||
if (string.IsNullOrWhiteSpace(masterUnit))
|
||||
{
|
||||
throw new BusinessException($"Material '{line.MaterialCode}' has no unit in master data.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(line.Unit)
|
||||
&& !string.Equals(line.Unit.Trim(), masterUnit, StringComparison.Ordinal))
|
||||
{
|
||||
throw new BusinessException("Line unit does not match material master unit.");
|
||||
}
|
||||
|
||||
return masterUnit;
|
||||
case InventoryKind.EmptyContainer:
|
||||
if (string.IsNullOrWhiteSpace(line.ContainerCode))
|
||||
{
|
||||
throw new BusinessException("ContainerCode is required for empty container lines.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(line.Unit))
|
||||
{
|
||||
throw new BusinessException("Unit is required for empty container lines.");
|
||||
}
|
||||
|
||||
return line.Unit.Trim();
|
||||
default:
|
||||
throw new BusinessException("Unsupported inventory kind.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferOrderService : OrderServiceBase, ITransferOrderService
|
||||
|
||||
Reference in new issue
Block a user