|
|
|
using System.Text.Json;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using SlnMesnac.Config;
|
|
|
|
using SlnMesnac.Model.dto;
|
|
|
|
using SlnMesnac.Plc;
|
|
|
|
using SlnMesnac.Repository.service;
|
|
|
|
|
|
|
|
namespace SlnMesnac.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// ingredientsChenck 投料校验
|
|
|
|
/// </summary>
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
[ApiController]
|
|
|
|
public class IngCheckController
|
|
|
|
{
|
|
|
|
private ILogger<IngCheckController> _logger;
|
|
|
|
private AppConfig _appConfig;
|
|
|
|
private IMcsBinToMaterService _mcsBinToMaterService;
|
|
|
|
private IWmsTaskOutService _wmsTaskOutService;
|
|
|
|
|
|
|
|
private PlcPool _plcPool;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
public IngCheckController(ILogger<IngCheckController> logger,
|
|
|
|
IMcsBinToMaterService mcsBinToMaterService,
|
|
|
|
AppConfig appConfig,
|
|
|
|
IWmsTaskOutService wmsTaskOutService,
|
|
|
|
PlcPool plcPool)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_mcsBinToMaterService = mcsBinToMaterService;
|
|
|
|
_appConfig = appConfig;
|
|
|
|
_wmsTaskOutService = wmsTaskOutService;
|
|
|
|
_plcPool = plcPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 上辅机投料校验
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ingredientInfo"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("BigMaterial")]
|
|
|
|
public ApiResponse BigMaterialCheck(IngredientInfo? ingredientInfo)
|
|
|
|
{
|
|
|
|
var result = new ApiResponse();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (ingredientInfo != null)
|
|
|
|
{
|
|
|
|
_logger.LogInformation($"上辅机验证参数:{JsonSerializer.Serialize(ingredientInfo)}");
|
|
|
|
var mcsInfo = _mcsBinToMaterService.GetMcsBinToMaterByBinNo(1, ingredientInfo.CanNumber);
|
|
|
|
if (mcsInfo != null)
|
|
|
|
{
|
|
|
|
var wmsInfo = _wmsTaskOutService.GetWmsTaskOutBySerialNum(ingredientInfo.MaterialBarcode);
|
|
|
|
|
|
|
|
if (mcsInfo.MatCode.Contains(wmsInfo.MaterNo))
|
|
|
|
{
|
|
|
|
result.SetSuccess($"上辅机校验成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
|
|
|
|
|
if (ingredientInfo.IsOpen == 1)
|
|
|
|
{
|
|
|
|
var openFlag = _plcPool.GetPlcByKey("mcs").writeInt32ByAddress(_appConfig.mcsOpenAddr,ingredientInfo.CanNumber);
|
|
|
|
if (openFlag)
|
|
|
|
{
|
|
|
|
_logger.LogInformation($"上辅机开仓指令下发成功!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_logger.LogError("上辅机开仓指令下发失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//保存数据
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.SetFailure($"上辅机校验失败,物料不匹配,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.SetFailure($"上辅机校验失败,根据料罐获取对应信息为空,时间:{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>
|
|
|
|
/// 小料投料校验
|
|
|
|
/// </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>
|
|
|
|
/// 下发开仓指令
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="address"></param>
|
|
|
|
/// <param name="canNumber"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private bool SendOpenInstructions(string plcType, string address, int canNumber)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
result = _plcPool.GetPlcByKey(plcType).writeInt32ByAddress(address,canNumber);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_logger.LogError($"开仓指令下发异常:{e.Message}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|