You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
6.6 KiB
163 lines
6.6 KiB
using Kean.Domain.Task.Commands;
|
|
using Kean.Domain.Task.Events;
|
|
using Kean.Domain.Task.Models;
|
|
using Kean.Domain.Task.Repositories;
|
|
using Kean.Domain.Task.SharedServices.Proxies;
|
|
using Kean.Infrastructure.Soap.Hithium.Models;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Threading;
|
|
|
|
namespace Kean.Domain.Task.EventHandlers
|
|
{
|
|
/// <summary>
|
|
/// 上架后上传信息
|
|
/// </summary>
|
|
[EventHandlerIndex(8)]
|
|
public sealed class CompleteSuccessEventHandler_WMS : EventHandler<CompleteSuccessEvent>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly IStockRepository _stockRepository; // 存储仓库
|
|
private readonly MaterialProxy _materialProxy; // 物料服务
|
|
private readonly IWarehouseRepository _warehouseRepository; // 仓库
|
|
private readonly Kean.Infrastructure.Soap.Hithium.WmsAPIService _wmsService; // MES
|
|
private readonly ILogger<CompleteSuccessEventHandler_WMS> _logger; // 日志
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public CompleteSuccessEventHandler_WMS(
|
|
IStockRepository stockRepository,
|
|
MaterialProxy materialProxy,
|
|
IWarehouseRepository warehouseRepository,
|
|
Kean.Infrastructure.Soap.Hithium.WmsAPIService wmsService,
|
|
ILogger<CompleteSuccessEventHandler_WMS> logger,
|
|
ICommandBus commandBus)
|
|
{
|
|
_stockRepository = stockRepository;
|
|
_materialProxy = materialProxy;
|
|
_wmsService = wmsService;
|
|
_warehouseRepository = warehouseRepository;
|
|
_logger = logger;
|
|
_commandBus = commandBus;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
public override async System.Threading.Tasks.Task Handle(CompleteSuccessEvent @event, CancellationToken cancellationToken)
|
|
{
|
|
//获取目标位置
|
|
Warehouse warehouse;
|
|
if (@event.Tag.StartsWith("Warehouse:"))
|
|
{
|
|
warehouse = await _warehouseRepository.GetWarehouse(Convert.ToInt32(@event.Tag[10..]));
|
|
}
|
|
else
|
|
{
|
|
await _commandBus.Notify(nameof(@event.Tag), $"无法解析库房信息", @event.Tag,
|
|
cancellationToken: cancellationToken);
|
|
return;
|
|
}
|
|
|
|
//获取stock
|
|
var stockLines = await _stockRepository.GetLines(@event.Barcode);
|
|
foreach (var r in stockLines)
|
|
{
|
|
//校验本地库存 1-本地 2-联机
|
|
if (r.IS_LOCAL.Equals("1"))
|
|
{
|
|
_logger.LogInformation($"上架后上传信息:托盘条码[{@event.Barcode}],膜卷号[{r.Bill}],本地库存[{r.IS_LOCAL}]不上传信息");
|
|
return;
|
|
}
|
|
//校验是否入海辰WMS 1-是;0-否
|
|
if (r.IS_WMS.Equals("1"))
|
|
{
|
|
_logger.LogInformation($"上架后上传信息:托盘条码[{@event.Barcode}],膜卷号[{r.Bill}],已经入库海辰WMS[{r.IS_WMS}]不上传信息");
|
|
return;
|
|
}
|
|
|
|
//@=@ 上传次数
|
|
//if (Convert.ToInt32(r.UPLOAD_NUM) < 2)
|
|
//{
|
|
//}
|
|
var sGoods = await _materialProxy.GetMaterial(r.Id, string.Empty, false);
|
|
Models.Material goods = JsonConvert.DeserializeObject<Models.Material>(sGoods);
|
|
|
|
WMSParamIn wmsParamIn = JsonConvert.DeserializeObject<WMSParamIn>(warehouse.Remark);
|
|
wmsParamIn.batchNo = r.Bill;
|
|
wmsParamIn.materialCode = goods.Code;
|
|
wmsParamIn.materialName = goods.Name;
|
|
wmsParamIn.unit = r.MES_UNIT;
|
|
wmsParamIn.quantity = Convert.ToDecimal(r.QUALIFIED_NUM);
|
|
wmsParamIn.workOrderNo = r.WORKORDER_NO;
|
|
//wmsParamIn.whlCode
|
|
//wmsParamIn.factory
|
|
wmsParamIn.lineCode = r.LINE_CODE;
|
|
wmsParamIn.lineName = r.LINE_NAME;
|
|
wmsParamIn.productDate = Convert.ToDateTime(r.ManufacturingDate).ToString("yyyy-MM-dd HH:mm:ss");
|
|
wmsParamIn.postUserName = r.POSTUSER;
|
|
|
|
var sResult = await _wmsService.Invoke("CreateSemiProductStock", JsonConvert.SerializeObject(wmsParamIn), @event.Barcode, string.Empty);
|
|
|
|
Kean.Infrastructure.Soap.Hithium.Models.Result result = JsonConvert.DeserializeObject<Kean.Infrastructure.Soap.Hithium.Models.Result>(sResult);
|
|
if (!result.Success)
|
|
{
|
|
}
|
|
|
|
|
|
}
|
|
|
|
////@==@ 调用MES 库存调拨
|
|
//InventoryTransfer inventoryTransfer = JsonConvert.DeserializeObject<InventoryTransfer>(@event.Tag);
|
|
|
|
////所在的站点 site
|
|
////目标库位
|
|
//if (@event.Cell == 190000)
|
|
//{
|
|
// inventoryTransfer.slTarget = "C3VF(阳极)";
|
|
//}
|
|
//if (@event.Cell == 290000)
|
|
//{
|
|
// inventoryTransfer.slTarget = "C3VG(阴极)";
|
|
//}
|
|
|
|
////过账人
|
|
////inventoryTransfer.postUser = @event.Tag;
|
|
|
|
//foreach (var m in @event.Lines)
|
|
//{
|
|
// ////源库位
|
|
// //inventoryTransfer.slSource = m.Supplier;
|
|
|
|
// //库存列表
|
|
// inventoryTransfer.inventoryList.Add(m.Bill);
|
|
//}
|
|
//var startTimestamp = DateTime.Now;
|
|
//string paramIn = JsonConvert.SerializeObject(inventoryTransfer);
|
|
//var sOut = await _mesService.Invoke("WarehouseInventoryTransfer", paramIn, @event.Barcode, @event.RequestNo);
|
|
//var endTimestamp = DateTime.Now;
|
|
//Result result = JsonConvert.DeserializeObject<Result>(sOut);
|
|
|
|
//if (!result.code.Equals("0"))
|
|
//{
|
|
// await _commandBus.Notify("InterfaceRecord", $"{result.message}", JsonConvert.SerializeObject(new
|
|
// {
|
|
// DIRECTION = "WMS->MES",
|
|
// METHOD = "WarehouseInventoryTransfer",
|
|
// BARCODE = @event.Barcode,
|
|
// REQUEST_NO = @event.RequestNo,
|
|
// START_TIME = startTimestamp,
|
|
// END_TIME = endTimestamp,
|
|
// CREATE_TIME = endTimestamp,
|
|
// PARAM_IN = paramIn,
|
|
// PARAM_OUT = sOut,
|
|
// RESULT = result.code
|
|
// }), cancellationToken: cancellationToken);
|
|
// return;
|
|
//}
|
|
}
|
|
}
|
|
}
|