using AutoMapper;
using Kean.Domain.Stock.Commands;
using Kean.Domain.Stock.Models;
using Kean.Domain.Stock.Repositories;
using Kean.Domain.Stock.SharedServices.Proxies;
using Kean.Infrastructure.Soap.Hithium.Models;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Kean.Domain.Stock.CommandHandlers
{
///
/// 命令处理程序
///
public sealed class SendOutToHiWMSCommandHandler : CommandHandler
{
private readonly ILogger _logger; // 日志
private readonly Kean.Infrastructure.Soap.Hithium.WmsAPIService _wmsService; // 海辰WMS
private readonly ICommandBus _commandBus; // 命令总线
private readonly TaskProxy _taskProxy; // 任务域
private readonly IStockRepository _stockRepository; // 存储仓库
private readonly MessageProxy _messageProxy; // 仓储域
private readonly INotification _notifications; // 总线通知
///
/// 依赖注入
///
public SendOutToHiWMSCommandHandler(
ILogger logger,
Kean.Infrastructure.Soap.Hithium.WmsAPIService wmsService,
ICommandBus commandBus,
IStockRepository stockRepository,
MessageProxy messageProxy,
INotification notifications,
TaskProxy taskProxy)
{
_logger = logger;
_wmsService = wmsService;
_commandBus = commandBus;
_taskProxy = taskProxy;
_messageProxy = messageProxy;
_stockRepository = stockRepository;
_notifications = notifications;
}
///
/// 处理程序
///
public override async Task Handle(SendOutToHiWMSCommand command, CancellationToken cancellationToken)
{
if (command.ValidationResult.IsValid)
{
bool bFeedback = false;
if (string.IsNullOrEmpty(command.RequestNo))
{
bFeedback = false;
}
if (bFeedback)
{
Feedback feedback = new Feedback();
feedback.requestNo = command.RequestNo;
feedback.barcode = command.Barcode;
feedback.feedbackStatus = command.FeedbackStatus;
feedback.message = command.Message;
//@=@ W1固定值 postUser
feedback.postUser = "ASRS";
//var sResult = string.Empty;
if (command.Transaction == "Infeed" || command.Transaction == "Bypass")
{
//sResult = await _wmsService.FeedbackIn("FeedbackIn", JsonConvert.SerializeObject(feedback, Formatting.Indented), command.Barcode, command.RequestNo);
_= _wmsService.FeedbackIn("INVENTORY", JsonConvert.SerializeObject(feedback, Formatting.Indented), command.Barcode, command.RequestNo, command.FeedbackStatus);
}
if (command.Transaction == "ApplyOut" || command.Transaction == "Outfeed")
{
//sResult = await _wmsService.FeedbackOut("FeedbackOut", JsonConvert.SerializeObject(feedback, Formatting.Indented), command.Barcode, command.RequestNo);
_= _wmsService.FeedbackOut("OUTBOUND", JsonConvert.SerializeObject(feedback, Formatting.Indented), command.Barcode, command.RequestNo, command.FeedbackStatus);
}
//Kean.Infrastructure.Soap.Hithium.Models.Result result = JsonConvert.DeserializeObject(sResult);
//if (result.code == "0")
//{
//}
//else
//{
// //await _taskProxy.SetErrorStateForDir(command.Barcode, "WmsResultFail", result.ReturnMsg);
// //await _commandBus.Notify("TaskState", $"膜卷号({r.Bill})出库过账失败,原因:{result.ReturnMsg}", "WmsResultFail",
// // cancellationToken: cancellationToken);
// //return;
//}
}
}
else
{
await _commandBus.Notify(command.ValidationResult,
cancellationToken: cancellationToken);
}
}
}
}