From bebfcf25bea32eb6d61e1da608adf72e15b3665f Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期三, 28 八月 2024 13:24:32 +0800
Subject: [PATCH] Merge branch 'hwh'

---
 Web/src/views/wcs/wcsDevice/component/editDialog.vue |    4 +
 Admin.NET/WCS.Application/PLC/PLCService.cs          |   50 ++++-------
 Admin.NET/WCS.Application/PLC/PLCJob.cs              |    1 
 Admin.NET/WCS.Application/Hub/TaskLogHub.cs          |   56 ++++++++++++++
 Web/src/views/wcs/wcsTask/signalR.ts                 |   37 +++++++++
 Admin.NET/WCS.Application/PLC/PLCTaskAction.cs       |    4 
 Admin.NET/WCS.Application/Hub/ITaskLogHub.cs         |   25 ++++++
 Web/src/views/wcs/wcsTask/index.vue                  |   49 ++++++++----
 8 files changed, 177 insertions(+), 49 deletions(-)

diff --git a/Admin.NET/WCS.Application/Hub/ITaskLogHub.cs b/Admin.NET/WCS.Application/Hub/ITaskLogHub.cs
new file mode 100644
index 0000000..0b0dd6b
--- /dev/null
+++ b/Admin.NET/WCS.Application/Hub/ITaskLogHub.cs
@@ -0,0 +1,25 @@
+锘�
+namespace WCS.Application;
+public interface ITaskLogHub
+{
+    /// <summary>
+    /// 涓嬪彂浠诲姟
+    /// </summary>
+    /// <param name="context"></param>
+    /// <returns></returns>
+    Task PublicTask(WcsTaskOutput context);
+
+    /// <summary>
+    /// 涓嬪彂浠诲姟鏄庣粏
+    /// </summary>
+    /// <param name="context"></param>
+    /// <returns></returns>
+    Task PublicTaskMonitor(WcsTaskMonitorOutput context);
+
+    /// <summary>
+    /// 鎺ユ敹娑堟伅
+    /// </summary>
+    /// <param name="context"></param>
+    /// <returns></returns>
+    Task ReceiveMessage(object context);
+}
diff --git a/Admin.NET/WCS.Application/Hub/TaskLogHub.cs b/Admin.NET/WCS.Application/Hub/TaskLogHub.cs
new file mode 100644
index 0000000..b4d018c
--- /dev/null
+++ b/Admin.NET/WCS.Application/Hub/TaskLogHub.cs
@@ -0,0 +1,56 @@
+锘縰sing Furion.InstantMessaging;
+using Microsoft.AspNetCore.SignalR;
+
+namespace WCS.Application;
+
+/// <summary>
+/// 浠诲姟鏃ュ織闆嗙嚎鍣�
+/// </summary>
+[MapHub("/hubs/TaskLog")]
+public class TaskLogHub : Hub<ITaskLogHub>
+{
+    private readonly IHubContext<TaskLogHub, ITaskLogHub> _taskLogHubContext;
+
+    public TaskLogHub(IHubContext<TaskLogHub, ITaskLogHub> taskLogHubContext)
+    {
+        _taskLogHubContext = taskLogHubContext;
+    }
+
+    /// <summary>
+    /// 杩炴帴
+    /// </summary>
+    /// <returns></returns>
+    public override async Task OnConnectedAsync()
+    {
+        await base.OnConnectedAsync();
+    }
+
+    /// <summary>
+    /// 鏂紑
+    /// </summary>
+    /// <param name="exception"></param>
+    /// <returns></returns>
+    public override async Task OnDisconnectedAsync(Exception exception)
+    {
+        await base.OnDisconnectedAsync(exception);
+    }
+
+    /// <summary>
+    /// 涓嬪彂浠诲姟
+    /// </summary>
+    /// <returns></returns>
+    public async Task PublicTask(WcsTaskOutput context)
+    {
+        await _taskLogHubContext.Clients.All.PublicTask(context);
+    }
+
+    /// <summary>
+    /// 涓嬪彂浠诲姟鏄庣粏
+    /// </summary>
+    /// <returns></returns>
+    public async Task PublicTaskMonitor(WcsTaskMonitorOutput context)
+    {
+        await _taskLogHubContext.Clients.All.PublicTaskMonitor(context);
+    }
+
+}
diff --git a/Admin.NET/WCS.Application/PLC/PLCJob.cs b/Admin.NET/WCS.Application/PLC/PLCJob.cs
index 3927eca..eb66aae 100644
--- a/Admin.NET/WCS.Application/PLC/PLCJob.cs
+++ b/Admin.NET/WCS.Application/PLC/PLCJob.cs
@@ -1,4 +1,5 @@
 锘縰sing Furion.Schedule;
+using Microsoft.AspNetCore.SignalR;
 using Microsoft.Extensions.Logging;
 
 namespace WCS.Application;
diff --git a/Admin.NET/WCS.Application/PLC/PLCService.cs b/Admin.NET/WCS.Application/PLC/PLCService.cs
index cf5a94c..3b8b3f3 100644
--- a/Admin.NET/WCS.Application/PLC/PLCService.cs
+++ b/Admin.NET/WCS.Application/PLC/PLCService.cs
@@ -1,12 +1,19 @@
 锘�
 using Furion.Logging;
 using IoTClient;
+using Microsoft.AspNetCore.SignalR;
 using System.Data;
 
 namespace WCS.Application;
 public static class PLCService
 {
     private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
+    private static readonly IHubContext<TaskLogHub, ITaskLogHub> _taskLogHubContext;
+
+    static PLCService()
+    {
+        _taskLogHubContext = App.GetService<IHubContext<TaskLogHub, ITaskLogHub>>();
+    }
 
     public static void OnChangeEvent(object sender, EventArgs e)
     {
@@ -107,12 +114,8 @@
                                     modTaskMonitor.InteractiveMsg = "璧峰鍌ㄤ綅涓虹┖!";
 
                                     _db.Insertable(modTaskMonitor).ExecuteCommand();
-
-                                    // 閫氱煡浠诲姟鐣岄潰浠诲姟宸插瓨鍦ㄦ洿鏂� 璇锋洿鏂扮晫闈�
-                                    //if (TaskAction.refresh)
-                                    //{
-                                    //    wSChat.AlarmInformation("1");
-                                    //}
+                                    //涓嬪彂浠诲姟鏃ュ織
+                                    _taskLogHubContext.Clients.All.PublicTaskMonitor(modTaskMonitor.Adapt<WcsTaskMonitorOutput>());
                                     break;
                                 }
                                 //缁橮LC鍐欏叆浠诲姟鏁版嵁
@@ -165,11 +168,8 @@
                                         EndLocat = outStationNum,
                                     };
                                     _db.Insertable(modInsertTaskMonitor).ExecuteCommand();
-                                    // 閫氱煡浠诲姟鐣岄潰浠诲姟宸插瓨鍦ㄦ洿鏂� 璇锋洿鏂扮晫闈�
-                                    //if (TaskAction.refresh)
-                                    //{
-                                    //    wSChat.AlarmInformation("1");
-                                    //}
+                                    //涓嬪彂浠诲姟鏃ュ織
+                                    _taskLogHubContext.Clients.All.PublicTaskMonitor(modInsertTaskMonitor.Adapt<WcsTaskMonitorOutput>());
                                     //淇敼led灞忎俊鎭�
                                     //LedDisplay(modDevice.LedIP, "宸ヤ綅:" + modTask.EndLocate, "鍑哄簱涓� " + $"鍌ㄤ綅鍦板潃锛歿modTask.StartLocate}", "鎵樼洏鍙�:" + modTask.PalletNo);
                                 }
@@ -236,11 +236,8 @@
                             Status = TaskStatusEnum.Complete
                         };
                         _db.Insertable(modTaskMonitor).ExecuteCommand();
-                        //閫氱煡浠诲姟鐣岄潰浠诲姟宸插瓨鍦ㄦ洿鏂� 璇锋洿鏂扮晫闈�
-                        //if (TaskAction.refresh)
-                        //{
-                        //    wSChat.AlarmInformation("1");
-                        //}
+                        //涓嬪彂浠诲姟鏃ュ織
+                        _taskLogHubContext.Clients.All.PublicTaskMonitor(modTaskMonitor.Adapt<WcsTaskMonitorOutput>());
 
                     }
                     else if (modTask.TaskType.Value == TaskTypeEnum.Out)
@@ -277,11 +274,8 @@
                             Status = TaskStatusEnum.Complete
                         };
                         _db.Insertable(modTaskMonitor).ExecuteCommand();
-                        //閫氱煡浠诲姟鐣岄潰浠诲姟宸插瓨鍦ㄦ洿鏂� 璇锋洿鏂扮晫闈�
-                        //if (TaskAction.refresh)
-                        //{
-                        //    wSChat.AlarmInformation("1");
-                        //}
+                        //涓嬪彂浠诲姟鏃ュ織
+                        _taskLogHubContext.Clients.All.PublicTaskMonitor(modTaskMonitor.Adapt<WcsTaskMonitorOutput>());
                     }
                 }
                 break;
@@ -344,11 +338,8 @@
                                         Status = TaskStatusEnum.Complete
                                     };
                                     _db.Insertable(modTaskMonitor).ExecuteCommand();
-                                    // 閫氱煡浠诲姟鐣岄潰浠诲姟宸插瓨鍦ㄦ洿鏂� 璇锋洿鏂扮晫闈�
-                                    //if (TaskAction.refresh)
-                                    //{
-                                    //    wSChat.AlarmInformation("1");
-                                    //}
+                                    //涓嬪彂浠诲姟鏃ュ織
+                                    _taskLogHubContext.Clients.All.PublicTaskMonitor(modTaskMonitor.Adapt<WcsTaskMonitorOutput>());
                                 }
                                 else
                                 {
@@ -427,11 +418,8 @@
                                 };
                                 _db.Insertable(modTaskMonitor).ExecuteCommand();
 
-                                // 閫氱煡浠诲姟鐣岄潰浠诲姟宸插瓨鍦ㄦ洿鏂� 璇锋洿鏂扮晫闈�
-                                //if (TaskAction.refresh)
-                                //{
-                                //    wSChat.AlarmInformation("1");
-                                //}
+                                //涓嬪彂浠诲姟鏃ュ織
+                                _taskLogHubContext.Clients.All.PublicTaskMonitor(modTaskMonitor.Adapt<WcsTaskMonitorOutput>());
                                 //todo:鍨涙満鍑哄簱涓嶇┖璺�
                             }
 
diff --git a/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs b/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
index 0eaf3a5..63086d6 100644
--- a/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
+++ b/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
@@ -1,5 +1,5 @@
-锘縰sing Admin.NET.Core.Service;
-using Furion.Logging;
+锘縰sing Furion.Logging;
+using Microsoft.AspNetCore.SignalR;
 
 namespace WCS.Application;
 public static class PLCTaskAction
diff --git a/Web/src/views/wcs/wcsDevice/component/editDialog.vue b/Web/src/views/wcs/wcsDevice/component/editDialog.vue
index fc839f3..0eed749 100644
--- a/Web/src/views/wcs/wcsDevice/component/editDialog.vue
+++ b/Web/src/views/wcs/wcsDevice/component/editDialog.vue
@@ -138,6 +138,10 @@
 const ruleForm = ref<any>({});
 //鑷娣诲姞鍏朵粬瑙勫垯
 const rules = ref<FormRules>({
+	dbNumber: [{ required: true, message: '璇疯緭鍏B鍖哄煙锛�', trigger: 'blur', },],
+	stationNum: [{ required: true, message: '璇疯緭鍏ュ伐浣嶅彿锛�', trigger: 'blur', },],
+	plcPos: [{ required: true, message: '璇疯緭鍏LC鍋忕Щ閲忥紒', trigger: 'blur', },],
+	wcsPos: [{ required: true, message: '璇疯緭鍏CS鍋忕Щ閲忥紒', trigger: 'blur', },],
 });
 
 // 椤甸潰鍔犺浇鏃�
diff --git a/Web/src/views/wcs/wcsTask/index.vue b/Web/src/views/wcs/wcsTask/index.vue
index eac32a8..5b4534c 100644
--- a/Web/src/views/wcs/wcsTask/index.vue
+++ b/Web/src/views/wcs/wcsTask/index.vue
@@ -4,8 +4,9 @@
       <el-col :span="12" :xs="24" style="display: flex; height: 100%; flex: 1">
         <el-card class="full-table" shadow="hover" ::body-style="{ height: 'calc(100% - 51px)' }">
           <template #header>
-						<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>浠诲姟鏃ュ織
-					</template>
+            <el-icon size="16"
+              style="margin-right: 3px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>浠诲姟鏃ュ織
+          </template>
           <el-form :model="queryParams" ref="queryForm" labelWidth="90">
             <el-row>
               <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
@@ -53,8 +54,8 @@
               </el-col>
             </el-row>
           </el-form>
-          <el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id" @row-click="handleClick"
-            @sort-change="sortChange" border="">
+          <el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id"
+            @row-click="handleClick" @sort-change="sortChange" border="">
             <el-table-column type="index" label="搴忓彿" width="55" align="center" />
             <el-table-column prop="taskNo" label="浠诲姟鍙�" show-overflow-tooltip="" />
             <el-table-column prop="taskType" width="85" label="浠诲姟绫诲瀷" show-overflow-tooltip="">
@@ -104,8 +105,9 @@
       <el-col :span="12" :xs="24" style="display: flex; height: 100%; flex: 1">
         <el-card class="full-table" shadow="hover" :body-style="{ height: 'calc(100% - 51px)' }">
           <template #header>
-						<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>浠诲姟璇︽儏
-					</template>
+            <el-icon size="16"
+              style="margin-right: 3px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>浠诲姟璇︽儏
+          </template>
           <el-form :model="queryParams2" ref="queryForm2" labelWidth="90">
             <el-row>
               <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
@@ -122,7 +124,8 @@
               </el-col>
             </el-row>
           </el-form>
-          <el-table :data="tableData2" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id" border="">
+          <el-table :data="tableData2" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id"
+            border="">
             <el-table-column type="index" label="搴忓彿" width="55" align="center" />
             <el-table-column prop="taskNo" label="浠诲姟鍙�" show-overflow-tooltip="" />
             <el-table-column prop="plcId" label="浜や簰宸ヤ綅鍙�" show-overflow-tooltip="" />
@@ -146,22 +149,18 @@
 
 <script lang="ts" setup="" name="wcsTask">
 import ModifyRecord from '/@/components/table/modifyRecord.vue';
-import { ref } from "vue";
+import { onMounted, reactive, ref } from 'vue';
 import { ElMessageBox, ElMessage } from "element-plus";
 import { auth } from '/@/utils/authFunction';
 
 import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
 import { getDictLabelByVal as dv } from '/@/utils/dict-utils';
-import { formatDate } from '/@/utils/formatTime';
-
 
 import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
 import editDialog from '/@/views/wcs/wcsTask/component/editDialog.vue'
 import { pageWcsTask, deleteWcsTask } from '/@/api/wcs/wcsTask';
 import { pageWcsMonitorTask } from '/@/api/wcs/wcsTaskMonitor';
-import { getAPI } from '/@/utils/axios-utils';
-import { SysEnumApi } from '/@/api-services/api';
-import commonFunction from '/@/utils/commonFunction';
+import { signalR } from './signalR';
 
 const showAdvanceQueryUI = ref(false);
 const printDialogRef = ref();
@@ -183,7 +182,25 @@
 });
 const printWcsTaskTitle = ref("");
 const editWcsTaskTitle = ref("");
-
+//杩炴帴signalR 鐩戝惉鍚庡彴浠诲姟鏃ュ織鍙樻洿
+onMounted(async () => {
+  signalR.off('PublicTask');
+  signalR.on('PublicTask', (data: any) => {
+    console.log(data)
+    if (tableData.value.filter(t => t.id == data.id).length == 0) {
+      tableData.value.unshift(data)
+    }
+  });
+  signalR.off('PublicTaskMonitor');
+  signalR.on('PublicTaskMonitor', async (data: any) => {
+    console.log(data);
+    if (queryParams2.value.taskNo == undefined || queryParams2.value.taskNo == data.taskNo) {
+      if (tableData2.value.filter(t => t.id == data.id).length == 0) {
+        tableData2.value.unshift(data)
+      }
+    }
+  });
+});
 // 鏀瑰彉楂樼骇鏌ヨ鐨勬帶浠舵樉绀虹姸鎬�
 const changeAdvanceQueryUI = () => {
   showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
@@ -239,8 +256,8 @@
 }
 // 鐐瑰嚮琛ㄦ牸
 const handleClick = (row: any, event: any, column: any) => {
-	queryParams2.value.taskNo = row.taskNo;
-	handleQuery2();
+  queryParams2.value.taskNo = row.taskNo;
+  handleQuery2();
 };
 // 鍒犻櫎
 const delWcsTask = (row: any) => {
diff --git a/Web/src/views/wcs/wcsTask/signalR.ts b/Web/src/views/wcs/wcsTask/signalR.ts
new file mode 100644
index 0000000..42c93f8
--- /dev/null
+++ b/Web/src/views/wcs/wcsTask/signalR.ts
@@ -0,0 +1,37 @@
+import * as SignalR from '@microsoft/signalr';
+import { getToken } from '/@/utils/axios-utils';
+
+// 鍒濆鍖朣ignalR瀵硅薄
+const connection = new SignalR.HubConnectionBuilder()
+	.configureLogging(SignalR.LogLevel.Information)
+	.withUrl(`${window.__env__.VITE_API_URL}/hubs/TaskLog?token=${getToken()}`, { transport: SignalR.HttpTransportType.WebSockets, skipNegotiation: true })
+	.withAutomaticReconnect({
+		nextRetryDelayInMilliseconds: () => {
+			return 5000; // 姣�5绉掗噸杩炰竴娆�
+		},
+	})
+	.build();
+
+connection.keepAliveIntervalInMilliseconds = 15 * 1000; // 蹇冭烦妫�娴�15s
+connection.serverTimeoutInMilliseconds = 30 * 60 * 1000; // 瓒呮椂鏃堕棿30m
+
+// 鍚姩杩炴帴
+connection.start().then(() => {
+	console.log('鍚姩杩炴帴task');
+});
+// 鏂紑杩炴帴
+connection.onclose(async () => {
+	console.log('鏂紑杩炴帴task');
+});
+// 閲嶈繛涓�
+connection.onreconnecting(() => {
+	console.log('鏈嶅姟鍣ㄥ凡鏂嚎task');
+});
+// 閲嶈繛鎴愬姛
+connection.onreconnected(() => {
+	console.log('閲嶈繛鎴愬姛task');
+});
+
+connection.on('PublicTask', () => {});
+
+export { connection as signalR };

--
Gitblit v1.8.0