71 lines
2.6 KiB
71 lines
2.6 KiB
using AutoMapper;
|
|
using Kean.Domain.Task.Commands;
|
|
using Kean.Domain.Task.Enums;
|
|
using Kean.Domain.Task.Events;
|
|
using Kean.Domain.Task.Models;
|
|
using Kean.Domain.Task.Repositories;
|
|
using Kean.Domain.Task.SharedServices.Proxies;
|
|
using Kean.Infrastructure.Configuration;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
|
|
namespace Kean.Domain.Task.CommandHandlers
|
|
{
|
|
/// <summary>
|
|
/// 创建下架命令处理程序
|
|
/// </summary>
|
|
public sealed class ReportCommandHandler : CommandHandler<ReportCommand>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly INotification _notifications; // 总线通知
|
|
private readonly IMapper _mapper; // 模型映射
|
|
private readonly ITaskRepository _taskRepository; // 任务仓库
|
|
private readonly IWarehouseRepository _warehouseRepository; // 库房仓库
|
|
private readonly BarcodeInterpreter _barcodeInterpreter; // 条码解释器
|
|
private readonly BarcodeValidator _barcodeValidator; // 条码验证器
|
|
private readonly StockProxy _stockProxy; // 仓储域代理
|
|
|
|
//private readonly IStockRepository _stockRepository;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public ReportCommandHandler(
|
|
ICommandBus commandBus,
|
|
INotification notifications,
|
|
IMapper mapper,
|
|
ITaskRepository taskRepository,
|
|
IWarehouseRepository warehouseRepository,
|
|
//IStockRepository stockRepository,
|
|
BarcodeInterpreter barcodeInterpreter,
|
|
BarcodeValidator barcodeValidator,
|
|
StockProxy stockProxy)
|
|
{
|
|
_commandBus = commandBus;
|
|
_notifications = notifications;
|
|
_mapper = mapper;
|
|
_taskRepository = taskRepository;
|
|
_warehouseRepository = warehouseRepository;
|
|
_barcodeInterpreter = barcodeInterpreter;
|
|
_barcodeValidator = barcodeValidator;
|
|
_stockProxy = stockProxy;
|
|
|
|
//_stockRepository = stockRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
public override async System.Threading.Tasks.Task Handle(ReportCommand command, CancellationToken cancellationToken)
|
|
{
|
|
// 创建任务
|
|
var task = _mapper.Map<Models.Task>(command);
|
|
task.Type = TaskType.Report;
|
|
task.Original = (int)command.Destination;
|
|
task.Timestamp = DateTime.Now;
|
|
Output(nameof(command.Id), await _taskRepository.CreateTask(task));
|
|
|
|
}
|
|
}
|
|
}
|