193 lines
7.1 KiB
C#
193 lines
7.1 KiB
C#
using JSMachine.WMS.Business.RcsCallBack.IService;
|
||||
|
|
using JSMachine.WMS.RPC.ErpRPC.Dto.Out;
|
|||
|
|
using JSMachine.WMS.RPC.RcsRPC.Dto.In;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using JSMachine.WMS.RPC.RcsRPC.Dto;
|
|||
|
|
using JSMachine.WMS.Business.StockIn.IService;
|
|||
|
|
using JSMachine.WMS.RPC.ErpRPC.Dto.In.XRBusinessResult;
|
|||
|
|
using JSMachine.WMS.RPC.ErpRPC.Dto.Out.XRBusinessResult;
|
|||
|
|
using JSMachine.WMS.Business.StockOut.IService;
|
|||
|
|
using JSMachine.WMS.Infrastructure.Helper;
|
|||
|
|
using Newtonsoft.Json;
|
|||
|
|
using JSMachine.WMS.App.Dto.Enum;
|
|||
|
|
using JSMachine.WMS.RPC.ErpRPC.Dto.In;
|
|||
|
|
using Microsoft.IdentityModel.Tokens;
|
|||
|
|
using JSMachine.WMS.App.IService;
|
|||
|
|
using JSMachine.WMS.App.Dto;
|
|||
|
|
using JSMachine.WMS.Common.Cache;
|
|||
|
|
using JSMachine.WMS.Application.IService;
|
|||
|
|
using JSMachine.WMS.Application.Dto;
|
|||
|
|
using JSMachine.WMS.Domain.Entity.Enums;
|
|||
|
|
|
|||
|
|
namespace JSMachine.WMS.WebHost.Controllers
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// WMS 核心业务接口,接收 RCS、PDA 和 ERP 请求并委托给对应业务服务。
|
|||
|
|
/// </summary>
|
|||
|
|
public class WmsController : ControllerBase
|
|||
|
|
{
|
|||
|
|
private IStockInService _stockInService;
|
|||
|
|
private IOperationLogService _operationLogService;
|
|||
|
|
private IStockOutService _stockOutService;
|
|||
|
|
/// <summary>创建 WMS 核心业务控制器。</summary>
|
|||
|
|
/// <param name="stockInService">入库业务服务。</param>
|
|||
|
|
/// <param name="stockOutService">出库业务服务。</param>
|
|||
|
|
/// <param name="operationLogService">操作日志服务。</param>
|
|||
|
|
public WmsController(
|
|||
|
|
IStockInService stockInService,
|
|||
|
|
IStockOutService stockOutService,
|
|||
|
|
IOperationLogService operationLogService)
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
_stockInService = stockInService;
|
|||
|
|
_stockOutService = stockOutService;
|
|||
|
|
_operationLogService = operationLogService;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region 通过提供接口,给Rcs调用,获取AGV上报的任务状态
|
|||
|
|
/// <summary>
|
|||
|
|
/// Rcs上传agv作业执行状态
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="callBackWmsParam"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[Route("api/Wms/PostAgvExcutionStatus")]
|
|||
|
|
[HttpPost]
|
|||
|
|
public async Task<RcsApiResult> PostAgvExcutionStatus([FromBody] AgvExcutionInfo agvExcutionInfo)
|
|||
|
|
{
|
|||
|
|
LogHelper.Info($"收到Rcs上报的小车执行状态信息,任务Id {agvExcutionInfo.OrderId},当前状态 {agvExcutionInfo.Status}");
|
|||
|
|
|
|||
|
|
_ = _operationLogService.Add(new OperationLogDto
|
|||
|
|
{
|
|||
|
|
OperationSource = OperationSource.RCS,
|
|||
|
|
OperationType = OperationType.RcsCallBack,
|
|||
|
|
NewObject = JsonConvert.SerializeObject(agvExcutionInfo)
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (agvExcutionInfo == null || string.IsNullOrEmpty(agvExcutionInfo.OrderId))
|
|||
|
|
{
|
|||
|
|
return await Task.FromResult(new RcsApiResult { code = 500, data = "参数不合法" });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
RcsCallbackCache.RcsCallbackQueue.Enqueue(agvExcutionInfo);
|
|||
|
|
|
|||
|
|
return await Task.FromResult(new RcsApiResult()
|
|||
|
|
{
|
|||
|
|
code = 1000,
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region PDA入库
|
|||
|
|
/// <summary>接收 PDA 入库请求并创建入库业务任务。</summary>
|
|||
|
|
/// <param name="pdaInParam">PDA 提交的入库参数。</param>
|
|||
|
|
/// <returns>标准化入库处理结果。</returns>
|
|||
|
|
[Route("api/wms/StockInByPda")]
|
|||
|
|
[HttpPost]
|
|||
|
|
public async Task<ApiResult<bool>> StockInByPda([FromBody] PDAInParam pdaInParam)
|
|||
|
|
{
|
|||
|
|
_ = _operationLogService.Add(new OperationLogDto
|
|||
|
|
{
|
|||
|
|
OperationSource = OperationSource.PDA,
|
|||
|
|
OperationType = OperationType.StockIn,
|
|||
|
|
NewObject = JsonConvert.SerializeObject(pdaInParam)
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
ApiResult<bool> apiResult = new();
|
|||
|
|
|
|||
|
|
string msg = await _stockInService.StockIn(pdaInParam);
|
|||
|
|
if (string.IsNullOrEmpty(msg))
|
|||
|
|
{
|
|||
|
|
apiResult.ResultCode = "200";
|
|||
|
|
apiResult.Data = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
apiResult.ResultCode = "500";
|
|||
|
|
apiResult.Data = false;
|
|||
|
|
apiResult.ErrorMsg = msg;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return apiResult;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 销售出库/生产退库
|
|||
|
|
private static readonly SemaphoreSlim _requestSemaphore = new(1, 1);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 销售出库/生产退库
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="erpSaleOutParam"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[Route("api/erp/out")]
|
|||
|
|
[HttpPost]
|
|||
|
|
public async Task<XRResultDto> Out([FromBody] StockOutParam erpSaleOutParam)
|
|||
|
|
{
|
|||
|
|
await _requestSemaphore.WaitAsync();
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
LogHelper.Info($"收到erp出库请求,请求方IP {HttpContext.Connection.RemoteIpAddress}," +
|
|||
|
|
$"原始参数信息 {JsonConvert.SerializeObject(erpSaleOutParam)}");
|
|||
|
|
|
|||
|
|
_ = _operationLogService.Add(new OperationLogDto
|
|||
|
|
{
|
|||
|
|
OperationSource = OperationSource.ERP,
|
|||
|
|
OperationType = erpSaleOutParam.transport==4 ? OperationType.ProductionOut : OperationType.SaleOut,
|
|||
|
|
NewObject = JsonConvert.SerializeObject(erpSaleOutParam)
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
XRResultDto apiResult = new();
|
|||
|
|
string errMsg = await _stockOutService.Stockout(erpSaleOutParam);
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(errMsg))
|
|||
|
|
{
|
|||
|
|
apiResult.success = true;
|
|||
|
|
apiResult.status = 200;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
apiResult.success = false;
|
|||
|
|
apiResult.status = 500;
|
|||
|
|
apiResult.errors = errMsg;
|
|||
|
|
}
|
|||
|
|
return apiResult;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
LogHelper.Error(ex);
|
|||
|
|
return new XRResultDto { status = 500, success = false, errors = "WMS服务端发生未知错误" };
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
_requestSemaphore.Release();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 出库撤单
|
|||
|
|
/// <summary>
|
|||
|
|
/// 出库撤单
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="cancelOrderParam"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[Route("api/erp/retreat")]
|
|||
|
|
[HttpPost]
|
|||
|
|
public async Task<XRNewResultDto<int>> ErpCancelOrder([FromBody] ErpCancelOrderParam cancelOrderParam)
|
|||
|
|
{
|
|||
|
|
LogHelper.Info($"收到erp出库撤单请求,请求方IP {HttpContext.Connection.RemoteIpAddress}," +
|
|||
|
|
$"原始参数信息 {JsonConvert.SerializeObject(cancelOrderParam)}");
|
|||
|
|
|
|||
|
|
_ = _operationLogService.Add(new OperationLogDto
|
|||
|
|
{
|
|||
|
|
OperationSource = OperationSource.ERP,
|
|||
|
|
OperationType = OperationType.StockOutCancel,
|
|||
|
|
NewObject = JsonConvert.SerializeObject(cancelOrderParam)
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
return await _stockOutService.ErpCancelOrder(cancelOrderParam);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|