From b51ba798274bee2439e0ae815ec1fa2bbf6b7808 Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期五, 13 九月 2024 08:50:23 +0800
Subject: [PATCH] 写入值

---
 Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs |   66 ++++++++++++++++++++++++++------
 1 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
index aba81e5..27f6373 100644
--- a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
+++ b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
@@ -1,11 +1,6 @@
-锘�// Admin.NET 椤圭洰鐨勭増鏉冦�佸晢鏍囥�佷笓鍒╁拰鍏朵粬鐩稿叧鏉冨埄鍧囧彈鐩稿簲娉曞緥娉曡鐨勪繚鎶ゃ�備娇鐢ㄦ湰椤圭洰搴旈伒瀹堢浉鍏虫硶寰嬫硶瑙勫拰璁稿彲璇佺殑瑕佹眰銆�
-//
-// 鏈」鐩富瑕侀伒寰� MIT 璁稿彲璇佸拰 Apache 璁稿彲璇侊紙鐗堟湰 2.0锛夎繘琛屽垎鍙戝拰浣跨敤銆傝鍙瘉浣嶄簬婧愪唬鐮佹爲鏍圭洰褰曚腑鐨� LICENSE-MIT 鍜� LICENSE-APACHE 鏂囦欢銆�
-//
-// 涓嶅緱鍒╃敤鏈」鐩粠浜嬪嵄瀹冲浗瀹跺畨鍏ㄣ�佹壈涔辩ぞ浼氱З搴忋�佷镜鐘粬浜哄悎娉曟潈鐩婄瓑娉曞緥娉曡绂佹鐨勬椿鍔紒浠讳綍鍩轰簬鏈」鐩簩娆″紑鍙戣�屼骇鐢熺殑涓�鍒囨硶寰嬬籂绾峰拰璐d换锛屾垜浠笉鎵挎媴浠讳綍璐d换锛�
+锘縰sing Admin.NET.Core.Service;
+using Microsoft.AspNetCore.SignalR;
 
-using Admin.NET.Core.Service;
-using Microsoft.AspNetCore.Http;
 namespace WCS.Application;
 
 /// <summary>
@@ -15,9 +10,13 @@
 public class WcsAlarmInfoService : IDynamicApiController, ITransient
 {
     private readonly SqlSugarRepository<WcsAlarmInfo> _wcsAlarmInfoRep;
-    public WcsAlarmInfoService(SqlSugarRepository<WcsAlarmInfo> wcsAlarmInfoRep)
+    private readonly 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>
@@ -30,17 +29,18 @@
     [DisplayName("鍒嗛〉鏌ヨ鎶ヨ淇℃伅琛�")]
     public async Task<SqlSugarPagedList<WcsAlarmInfoOutput>> Page(PageWcsAlarmInfoInput input)
     {
-		input.SearchKey = input.SearchKey?.Trim();
+        input.SearchKey = input.SearchKey?.Trim();
         var query = _wcsAlarmInfoRep.AsQueryable()
             .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u =>
                 u.PlcIP.Contains(input.SearchKey)
-                || u.Type.Contains(input.SearchKey)
             )
             .WhereIF(!string.IsNullOrWhiteSpace(input.PlcIP), u => u.PlcIP.Contains(input.PlcIP.Trim()))
-            .WhereIF(!string.IsNullOrWhiteSpace(input.Type), u => u.Type.Contains(input.Type.Trim()))
+            .WhereIF(input.Status.HasValue, u => u.Status == input.Status)
+            .WhereIF(input.Type.HasValue, u => u.Type == input.Type)
             .Select<WcsAlarmInfoOutput>();
-		return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
+        return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
     }
+
 
     /// <summary>
     /// 澧炲姞鎶ヨ淇℃伅琛�
@@ -53,6 +53,7 @@
     public async Task<long> Add(AddWcsAlarmInfoInput input)
     {
         var entity = input.Adapt<WcsAlarmInfo>();
+        entity.Status = YesNoEnum.N;
         await _wcsAlarmInfoRep.InsertAsync(entity);
         return entity.Id;
     }
@@ -109,11 +110,50 @@
     [DisplayName("鑾峰彇鎶ヨ淇℃伅琛ㄥ垪琛�")]
     public async Task<List<WcsAlarmInfoOutput>> List([FromQuery] PageWcsAlarmInfoInput input)
     {
-        return await _wcsAlarmInfoRep.AsQueryable().Select<WcsAlarmInfoOutput>().ToListAsync();
+        return await _wcsAlarmInfoRep.AsQueryable()
+            .WhereIF(!input.Status.IsNullOrEmpty(), s => s.Status == input.Status)
+            .Select<WcsAlarmInfoOutput>().ToListAsync();
     }
 
 
+    /// <summary>
+    /// 澶嶄綅鎶ヨ
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    [HttpPost]
+    [ApiDescriptionSettings(Name = "Reset")]
+    [DisplayName("澶嶄綅鎶ヨ")]
+    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.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();
 
+    }
 
 
 }

--
Gitblit v1.8.0