From ce6a232b55646e8d39cb0b4861ee363608b6f9aa Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期五, 06 九月 2024 10:48:26 +0800
Subject: [PATCH] 服务状态读数据库;报警复位功能

---
 Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
index e2eef27..27f6373 100644
--- a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
+++ b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
@@ -1,4 +1,5 @@
-锘縰sing Microsoft.AspNetCore.SignalR;
+锘縰sing Admin.NET.Core.Service;
+using Microsoft.AspNetCore.SignalR;
 
 namespace WCS.Application;
 
@@ -10,10 +11,12 @@
 {
     private readonly SqlSugarRepository<WcsAlarmInfo> _wcsAlarmInfoRep;
     private readonly IHubContext<PlcHub, IPlcHub> _plcHubContext;
-    public WcsAlarmInfoService(SqlSugarRepository<WcsAlarmInfo> wcsAlarmInfoRep, IHubContext<PlcHub, IPlcHub> plcHubContext)
+    private readonly SysDictDataService _dictDataService;
+    public WcsAlarmInfoService(SqlSugarRepository<WcsAlarmInfo> wcsAlarmInfoRep, IHubContext<PlcHub, IPlcHub> plcHubContext, SysDictDataService dictDataService)
     {
         _wcsAlarmInfoRep = wcsAlarmInfoRep;
         _plcHubContext = plcHubContext;
+        _dictDataService = dictDataService;
     }
 
     /// <summary>
@@ -121,13 +124,35 @@
     [HttpPost]
     [ApiDescriptionSettings(Name = "Reset")]
     [DisplayName("澶嶄綅鎶ヨ")]
-    public async Task Reset()
+    public async Task Reset(ResetInput input)
     {
         //娴嬭瘯鎺ㄦ暟鎹敤鐨�
-        await _plcHubContext.Clients.All.PublicAlarm(new List<WcsAlarmInfo>() { new WcsAlarmInfo() { Id = 100, StationNum = "260", AlarmCode = "MB102", AlarmName = "鏈夌墿鍝侀伄鎸�", AlarmTime = DateTime.Now, Status = YesNoEnum.N } });
+        //await _plcHubContext.Clients.All.PublicAlarm(new List<WcsAlarmInfo>() { new WcsAlarmInfo() { Id = 100, StationNum = "260", AlarmCode = "MB102", AlarmName = "鏈夌墿鍝侀伄鎸�", AlarmTime = DateTime.Now, Status = YesNoEnum.Y } });
         //await _plcHubContext.Clients.All.PublicAlarm(new WcsAlarmInfo() { Id = 100, StationNum = "260", AlarmCode = "MB102", AlarmName = "鏈夌墿鍝侀伄鎸�", AlarmTime = DateTime.Now, Status = YesNoEnum.Y });
+        var modPlc = await _wcsAlarmInfoRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.Text == (input.layer.ToString() + "灞傛墭鐩樿緭閫佺嚎")).FirstAsync();
+        if (modPlc == null)
+            throw Oops.Bah("鏈壘鍒拌緭閫佺嚎PLC");
+        var listDict = await _dictDataService.GetDataList("reset_alarm");
+        var value = listDict.FirstOrDefault(s => s.Code == input.layer.ToString());
+        if (value == null)
+            throw Oops.Bah("鏈壘鍒板浣嶅湴鍧�锛岃鍦ㄥ瓧鍏哥鐞嗕腑璁剧疆");
+        PLCUtil modUtil = new PLCUtil(modPlc);
+        switch (input.layer)
+        {
+            case 1:
+                break;
+            case 2:
+                {
+                    modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, value.Value, "1");
+                }
+                break;
+            case 3:
+                break;
+            default:
+                break;
+        }
+        modUtil.Close();
 
-        //throw Oops.Bah("寮�鍙戜腑");
     }
 
 

--
Gitblit v1.8.0