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; /// /// ingredientsChenck 投料校验 /// [Route("api/[controller]")] [ApiController] public class IngCheckController { private ILogger _logger; private AppConfig _appConfig; private IMcsBinToMaterService _mcsBinToMaterService; /// /// /// /// public IngCheckController(ILogger logger, IMcsBinToMaterService mcsBinToMaterService, AppConfig appConfig) { _logger = logger; _mcsBinToMaterService = mcsBinToMaterService; _appConfig = appConfig; } /// /// 大料投料校验 /// /// /// [HttpPost("BigMaterial")] public ApiResponse BigMaterialCheck(IngredientInfo? ingredientInfo) { var result = new ApiResponse(); try { if (ingredientInfo != null) { _logger.LogInformation($"大料验证参数:{JsonSerializer.Serialize(ingredientInfo)}"); var info = _mcsBinToMaterService.GetMcsBinToMaterByBinNo(ingredientInfo.EquipId, ingredientInfo.CanNumber); if (info != null) { if (info.MatCode == ingredientInfo.MaterialBarcode) { result.SetSuccess($"大料校验成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); } 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; } /// /// 小料投料校验 /// /// /// [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; } }