From 2b8b337ada00324640974e179b95162af543d3fc Mon Sep 17 00:00:00 2001 From: Wen JY Date: Thu, 25 Jan 2024 09:51:47 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Config/AppConfig.cs | 8 ++++- SlnMesnac.Config/PlcConfig.cs | 33 +++++++++++++++++++++ SlnMesnac/Controllers/IngCheckController.cs | 29 ++++++++++-------- SlnMesnac/appsettings.json | 18 ++++++++++- 4 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 SlnMesnac.Config/PlcConfig.cs diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index 19030b3..891e31a 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Options; using System; +using System.Collections.Generic; namespace SlnMesnac.Config { @@ -22,7 +23,12 @@ namespace SlnMesnac.Config /// MCS 数据库连接字符串 /// public string mcsConnStr { get; set; } - + + /// + /// PLC连接配置 + /// + public List plcConfig { get; set; } + public AppConfig Value => this; } } diff --git a/SlnMesnac.Config/PlcConfig.cs b/SlnMesnac.Config/PlcConfig.cs new file mode 100644 index 0000000..9bb8d31 --- /dev/null +++ b/SlnMesnac.Config/PlcConfig.cs @@ -0,0 +1,33 @@ +namespace SlnMesnac.Config +{ + /// + /// PLC配置,通过AppConfig进行获取 + /// + public class PlcConfig + { + /// + /// PLC配置ID + /// + public int configId { get; set; } + + /// + /// PIC类型 + /// + public string plcType { get; set; } + + /// + /// PLC IP + /// + public string plcIp { get; set; } + + /// + /// PLC Port + /// + public int plcPort { get; set; } + + /// + /// PLC Key + /// + public string plcKey { get; set; } + } +} \ No newline at end of file diff --git a/SlnMesnac/Controllers/IngCheckController.cs b/SlnMesnac/Controllers/IngCheckController.cs index 38309b2..49ea9ad 100644 --- a/SlnMesnac/Controllers/IngCheckController.cs +++ b/SlnMesnac/Controllers/IngCheckController.cs @@ -1,5 +1,6 @@ using System.Text.Json; using Microsoft.AspNetCore.Mvc; +using SlnMesnac.Config; using SlnMesnac.Model.dto; using SlnMesnac.Repository.service; @@ -13,16 +14,18 @@ namespace SlnMesnac.Controllers; public class IngCheckController { private ILogger _logger; + private AppConfig _appConfig; private IMcsBinToMaterService _mcsBinToMaterService; /// /// /// /// - public IngCheckController(ILogger logger,IMcsBinToMaterService mcsBinToMaterService) + public IngCheckController(ILogger logger,IMcsBinToMaterService mcsBinToMaterService,AppConfig appConfig) { _logger = logger; _mcsBinToMaterService = mcsBinToMaterService; + _appConfig = appConfig; } /// @@ -31,17 +34,14 @@ public class IngCheckController /// /// [HttpPost("BigMaterial")] - public ApiResponse BigMaterialCheck(IngredientInfo ingredientInfo) + public ApiResponse BigMaterialCheck(IngredientInfo? ingredientInfo) { var result = new ApiResponse(); - try { - if (ingredientInfo != null) { - string json = JsonSerializer.Serialize(ingredientInfo); - _logger.LogInformation($"大料验证参数:{json}"); + _logger.LogInformation($"大料验证参数:{JsonSerializer.Serialize(ingredientInfo)}"); var info = _mcsBinToMaterService.GetMcsBinToMaterByBinNo(ingredientInfo.EquipId, ingredientInfo.CanNumber); if (info != null) { @@ -55,6 +55,10 @@ public class IngCheckController result.SetFailure($"大料校验失败,物料不匹配,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); } } + else + { + result.SetFailure($"大料校验失败,根据料罐获取对应信息异常,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + } } else @@ -66,7 +70,7 @@ public class IngCheckController catch (Exception e) { result.SetException(e,"大料投料校验异常"); - _logger.LogError("大料投料校验异常",e); + _logger.LogError($"大料投料校验异常:{e.Message}"); } return result; @@ -78,7 +82,7 @@ public class IngCheckController /// /// [HttpPost("SmallMaterial")] - public ApiResponse SmallMaterialCheck(IngredientInfo ingredientInfo) + public ApiResponse SmallMaterialCheck(IngredientInfo? ingredientInfo) { var result = new ApiResponse(); @@ -87,20 +91,19 @@ public class IngCheckController { if (ingredientInfo != null) { - string json = JsonSerializer.Serialize(ingredientInfo); - _logger.LogInformation($"小料验证参数:{json}"); - result.SetSuccess($"校验成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + _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")}"); + result.SetSuccess($"小料校验失败,缺少必要参数,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); } } catch (Exception e) { - Console.WriteLine(e); result.SetException(e,"小料投料校验异常"); + _logger.LogError($"小料投料校验异常:{e.Message}"); } return result; diff --git a/SlnMesnac/appsettings.json b/SlnMesnac/appsettings.json index 82e15a0..1a56d02 100644 --- a/SlnMesnac/appsettings.json +++ b/SlnMesnac/appsettings.json @@ -10,6 +10,22 @@ "AppConfig": { "logPath": "/Users/wenxiansheng/Desktop/日常代码/杜肯新材料程序设计/Durk.SlnMesnac/SlnMesnac/bin/Debug/net6.0", "mcsConnStr": "server=58.63.214.27,23313;uid=dkmes;pwd=Duken123;database=mesnac_MCS_ShareDB", - "mesConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma" + "mesConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma", + "PlcConfig":[ + { + "configId": 1, + "plcType": "MelsecBinaryPlc", + "plcIp": "127.0.0.1", + "plcPort": 102, + "plcKey": "mcs" + }, + { + "configId": 2, + "plcType": "MelsecBinaryPlc", + "plcIp": "127.0.0.1", + "plcPort": 102, + "plcKey": "cwss" + } + ] } }