You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
7.8 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
using TouchSocket.Core;
namespace SlnMesnac.Controllers;
/// <summary>
/// ingredientsChenck 投料校验
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class IngCheckController
{
private ILogger<IngCheckController> _logger;
private AppConfig _appConfig;
private PlcPool _plcPool;
private IMcsBinToMaterService _mcsBinToMaterService;
private IWmsTaskOutService _wmsTaskOutService;
private IMcsMaterialInfoService _mcsMaterialInfoService;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
/// <param name="mcsBinToMaterService"></param>
/// <param name="appConfig"></param>
/// <param name="wmsTaskOutService"></param>
/// <param name="plcPool"></param>
/// <param name="mcsMaterialInfoService"></param>
public IngCheckController(ILogger<IngCheckController> logger,
IMcsBinToMaterService mcsBinToMaterService,
AppConfig appConfig,
IWmsTaskOutService wmsTaskOutService,
PlcPool plcPool,
IMcsMaterialInfoService mcsMaterialInfoService)
{
_logger = logger;
_mcsBinToMaterService = mcsBinToMaterService;
_appConfig = appConfig;
_wmsTaskOutService = wmsTaskOutService;
_plcPool = plcPool;
_mcsMaterialInfoService = mcsMaterialInfoService;
}
/// <summary>
/// 根据物料条码获取MCS物料信息
/// </summary>
/// <param name="MaterialBarcode"></param>
/// <returns></returns>
[HttpGet("GetMcsMaterialInfo/{MaterialBarcode}")]
public ApiResponse GetMcsMaterialInfo(string MaterialBarcode)
{
var result = new ApiResponse();
try
{
do
{
WmsTaskOut wmsInfo = this.GetWmsTaskOutBySerialNum(MaterialBarcode);
if (wmsInfo == null)
{
result.SetFailure($"物料信息获取失败,根据物料条码获取物料编号为空,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
break;
}
var info = _mcsMaterialInfoService.GetMcsMaterialInfoByMatCode(wmsInfo.MaterNo);
if(info == null)
{
result.SetFailure($"物料信息获取失败根据物料编号获取MCS物料信息为空时间{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
else
{
result.SetSuccess(JsonSerializer.Serialize(info));
}
} while (false);
}
catch(Exception e)
{
result.SetException(e, "物料信息获取异常");
_logger.LogError($"物料信息获取异常:{e.Message}");
}
return result;
}
/// <summary>
/// 上辅机投料校验
/// </summary>
/// <param name="ingredientInfo"></param>
/// <returns></returns>
[HttpPost("BigMaterial")]
public ApiResponse BigMaterialCheck(IngredientInfo? ingredientInfo)
{
var result = new ApiResponse();
try
{
do
{
if (ingredientInfo == null)
{
result.SetSuccess($"上辅机校验失败,缺少必要参数,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
break;
}
_logger.LogInformation($"上辅机验证参数:{JsonSerializer.Serialize(ingredientInfo)}");
McsBinToMater mcsInfo = _mcsBinToMaterService.GetMcsBinToMaterByBinNo(ingredientInfo.EquipId, ingredientInfo.CanNumber);
if (mcsInfo == null)
{
result.SetFailure($"上辅机校验失败,根据料罐获取对应信息为空,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
break;
}
WmsTaskOut wmsInfo = this.GetWmsTaskOutBySerialNum(ingredientInfo.MaterialBarcode);
if (wmsInfo == null)
{
result.SetFailure($"上辅机校验失败,根据物料条码获取物料信息为空,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
break;
}
if (mcsInfo.MatCode.Contains(wmsInfo.MaterNo))
{
result.SetSuccess($"上辅机校验成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
else
{
result.SetFailure($"上辅机校验失败,物料不匹配,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
break;
}
if (ingredientInfo.IsOpen == 1)
{
var openFlag = _plcPool.GetPlcByKey("mcs").writeValueByAddress(mcsInfo.BinNo,_appConfig.mcsOpenAddr);
if (openFlag)
{
_logger.LogInformation($"上辅机开仓指令下发成功");
result.SetSuccess($"上辅机校验成功,开仓指令下发成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
else
{
_logger.LogInformation("上辅机开仓指令下发失败");
result.SetSuccess($"上辅机校验成功,开仓指令下发失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
break;
}
}
//保存数据
} while (false);
}
catch (Exception e)
{
result.SetException(e,"上辅机投料校验异常");
_logger.LogError($"上辅机投料校验异常:{e.Message}");
}
return result;
}
/// <summary>
/// 小料投料校验
/// </summary>
/// <param name="ingredientInfo"></param>
/// <returns></returns>
[HttpPost("SmallMaterial")]
public ApiResponse SmallMaterialCheck(IngredientInfo? ingredientInfo)
{
var result = new ApiResponse();
try
{
if (ingredientInfo != null)
{
_logger.LogInformation($"小料验证参数:{JsonSerializer.Serialize(ingredientInfo)}");
result.SetSuccess($"小料校验成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
else
{
result.SetSuccess($"小料校验失败,缺少必要参数,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
catch (Exception e)
{
result.SetException(e,"小料投料校验异常");
_logger.LogError($"小料投料校验异常:{e.Message}");
}
return result;
}
/// <summary>
/// 根据物料条码获取WMS出库记录反馈信息
/// </summary>
/// <param name="MaterialBarcode"></param>
/// <returns></returns>
private WmsTaskOut GetWmsTaskOutBySerialNum(string MaterialBarcode)
{
WmsTaskOut? result = null;
try
{
result = _wmsTaskOutService.GetWmsTaskOutBySerialNum(MaterialBarcode);
_logger.LogInformation($"根据物料条码:{MaterialBarcode};获取WMS出库记录{JsonSerializer.Serialize(result)},时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
catch (Exception ex)
{
_logger.LogError($"根据物料条码:{MaterialBarcode};获取WMS出库记录异常{ex.Message}");
}
return result;
}
}