From 03f241781205b4aaafa6cee66e7402a41ef97fc1 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期五, 24 五月 2024 15:27:40 +0800
Subject: [PATCH] 增加websocket 推送下片数据给前端

---
 UI-Project/src/views/UnLoadGlass/Landingindication.vue                                                                            |   42 ++++
 UI-Project/src/views/Returns/returns.vue                                                                                          |    7 
 UI-Project/src/utils/constants.js                                                                                                 |    1 
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java                                         |   68 +++++++
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/AppRunnerConfig.java                                      |    2 
 UI-Project/src/views/UnLoadGlass/loadmachinerack.vue                                                                              |  207 +++++-----------------
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownCacheGlassTask.java                               |   15 +
 UI-Project/src/views/UnLoadGlass/Landingindicationtwo.vue                                                                         |   42 ++++
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downworkstation/controller/DownWorkstationController.java |    2 
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketConfig.java                                |   16 +
 hangzhoumesParent/moduleService/UnLoadGlassModule/pom.xml                                                                         |    5 
 UI-Project/src/utils/WebSocketService.js                                                                                          |   39 ++++
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketServer.java                                |   50 +++--
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/resources/application.yml                                              |    2 
 14 files changed, 308 insertions(+), 190 deletions(-)

diff --git a/UI-Project/src/utils/WebSocketService.js b/UI-Project/src/utils/WebSocketService.js
new file mode 100644
index 0000000..432bd9c
--- /dev/null
+++ b/UI-Project/src/utils/WebSocketService.js
@@ -0,0 +1,39 @@
+// WebSocketService.js
+
+let socket = null;
+
+export const initializeWebSocket = (socketUrl, messageHandler) => {
+    if (typeof WebSocket === "undefined") {
+      console.log("Your browser does not support WebSocket");
+      return null;
+    }
+  
+    const socket = new WebSocket(socketUrl);
+  
+    socket.onopen = function () {
+      console.log("WebSocket is now open");
+    };
+  
+    socket.onmessage = (msg) => {
+      if (!msg.data) {
+        return;
+      }
+  
+      const obj = JSON.parse(msg.data);
+  
+      // 璋冪敤娑堟伅澶勭悊鍑芥暟锛屽皢鏁版嵁浼犻�掔粰 Vue 缁勪欢
+      if (messageHandler) {
+        messageHandler(obj);
+      }
+    };
+  
+    return socket;
+  };
+  
+
+  export const closeWebSocket = (socket) => {
+    if (socket && socket.readyState === WebSocket.OPEN) {
+        socket.close();
+        console.log("WebSocket connection closed");
+    }
+};
\ No newline at end of file
diff --git a/UI-Project/src/utils/constants.js b/UI-Project/src/utils/constants.js
new file mode 100644
index 0000000..8a665eb
--- /dev/null
+++ b/UI-Project/src/utils/constants.js
@@ -0,0 +1 @@
+export const WebSocketHost = "localhost";
\ No newline at end of file
diff --git a/UI-Project/src/views/Returns/returns.vue b/UI-Project/src/views/Returns/returns.vue
index 1bf0404..84188cb 100644
--- a/UI-Project/src/views/Returns/returns.vue
+++ b/UI-Project/src/views/Returns/returns.vue
@@ -400,9 +400,10 @@
       ElMessage.success(response.message);
       // window.location.reload() 
       blinda.value = false;
-      // tableData.value = response.data
-      // tableData.value = [];
-      state.updateKey ++
+      tableData.splice([]);
+    console.log(response)
+    console.log(tableData)
+      // state.updateKey ++
     } else {
       // 璇锋眰澶辫触锛屾樉绀洪敊璇秷鎭�
       ElMessage.error(response.msg);
diff --git a/UI-Project/src/views/UnLoadGlass/Landingindication.vue b/UI-Project/src/views/UnLoadGlass/Landingindication.vue
index bf305e6..a55acb0 100644
--- a/UI-Project/src/views/UnLoadGlass/Landingindication.vue
+++ b/UI-Project/src/views/UnLoadGlass/Landingindication.vue
@@ -32,9 +32,12 @@
 </template>
 
 <script  setup>
-import { ref, watchEffect } from 'vue';
+import { ref, watchEffect ,onMounted} from 'vue';
+
 import Swal from 'sweetalert2'
 import request from "@/utils/request";
+import { initializeWebSocket } from '@/utils/WebSocketService';
+ import { WebSocketHost } from '@/utils/constants';
 const racks = ref([
   { x: 50, y: 100, height: 100, width: 60, fillColor: '#6a6da9', item: { height: 90, width: 10, fillColor: 'yellow', content: 'NG123456' } },
  
@@ -110,9 +113,40 @@
   }
 };
 
-fetchFlowCardId()
-// setTimeout(fetchFlowCardId(),1000);
-//setInterval(fetchFlowCardId, 2000)
+const socketUrl = `ws://${WebSocketHost}:8085/api/talk/unloadglass2`;
+// 瀹氫箟娑堟伅澶勭悊鍑芥暟锛屾洿鏂� receivedData 鍙橀噺
+const handleMessage = (data) => {
+
+  // 鏇存柊 tableData 鐨勬暟鎹�
+
+  data.glassinfo[0].forEach((itemData, index) => {
+  if (index < racks.value.length) {
+    const rack = racks.value[index];
+    const newItem = {
+      content: itemData.item.content,
+      fillColor: itemData.item.fillColor,
+      width: itemData.item.width === 0 ? "" : 10,
+      height: itemData.item.height === 0 ? "" : 90
+    };
+
+    if (index === 2 && itemData.item.width > 0) {
+      newItem.width = 100;
+      newItem.height = 20;
+    }
+
+    rack.item = newItem;
+
+   // console.log("鏄剧ず鍥�1",racks.value); // 鎵撳嵃鏇存柊鍚庣殑 racks 鍊�
+  }
+});
+};
+
+// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
+
+onMounted(() => {
+  fetchFlowCardId(); // 鑾峰彇鏁版嵁
+  initializeWebSocket(socketUrl, handleMessage);
+});
 
 
 const showCustomAlert = (content) => {
diff --git a/UI-Project/src/views/UnLoadGlass/Landingindicationtwo.vue b/UI-Project/src/views/UnLoadGlass/Landingindicationtwo.vue
index e5f562f..cf75a2e 100644
--- a/UI-Project/src/views/UnLoadGlass/Landingindicationtwo.vue
+++ b/UI-Project/src/views/UnLoadGlass/Landingindicationtwo.vue
@@ -32,10 +32,12 @@
 </template>
 
 <script setup>
-import { ref, watchEffect } from 'vue';
+import { ref, watchEffect ,onMounted} from 'vue';
+
 import Swal from 'sweetalert2'
 import request from "@/utils/request";
-
+import { initializeWebSocket } from '@/utils/WebSocketService';
+ import { WebSocketHost } from '@/utils/constants';
 const racks = ref([
   { x: 50, y: 100, height: 100, width: 60, fillColor: '#6a6da9', item: { height: 90, width: 10, fillColor: 'yellow', content: 'NG123456' } },
  
@@ -110,7 +112,41 @@
   }
 };
 
-fetchFlowCardId()
+const socketUrl = `ws://${WebSocketHost}:8085/api/talk/unloadglass3`;
+// 瀹氫箟娑堟伅澶勭悊鍑芥暟锛屾洿鏂� receivedData 鍙橀噺
+const handleMessage = (data) => {
+
+  // 鏇存柊 tableData 鐨勬暟鎹�
+
+  data.glassinfo2[0].forEach((itemData, index) => {
+  if (index < racks.value.length) {
+    const rack = racks.value[index];
+    const newItem = {
+      content: itemData.item.content,
+      fillColor: itemData.item.fillColor,
+      width: itemData.item.width === 0 ? "" : 10,
+      height: itemData.item.height === 0 ? "" : 90
+    };
+
+    if (index === 2 && itemData.item.width > 0) {
+      newItem.width = 100;
+      newItem.height = 20;
+    }
+
+    rack.item = newItem;
+
+    //console.log("鏄剧ず鍥�2",racks.value); // 鎵撳嵃鏇存柊鍚庣殑 racks 鍊�
+  }
+});
+};
+
+// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
+
+onMounted(() => {
+  fetchFlowCardId(); // 鑾峰彇鏁版嵁
+  initializeWebSocket(socketUrl, handleMessage);
+});
+
 
 // const showCustomAlert = (content) => {
 //   var str="鏋跺彿   :      111\n" +
diff --git a/UI-Project/src/views/UnLoadGlass/loadmachinerack.vue b/UI-Project/src/views/UnLoadGlass/loadmachinerack.vue
index d4a17c1..d53fe3c 100644
--- a/UI-Project/src/views/UnLoadGlass/loadmachinerack.vue
+++ b/UI-Project/src/views/UnLoadGlass/loadmachinerack.vue
@@ -1,6 +1,7 @@
 <script setup>
 import {Search} from "@element-plus/icons-vue";
-import {reactive,  onMounted} from "vue";
+import {reactive, onMounted, onBeforeUnmount} from "vue";
+
 import {useRouter} from "vue-router"
 const router = useRouter()
 
@@ -9,75 +10,24 @@
 import Landingindication from "./Landingindication.vue";
 import Landingindicationtwo from "./Landingindicationtwo.vue";
 import request from "@/utils/request";
+import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
+ import { WebSocketHost } from '@/utils/constants';
+
 
 const dialogFormVisiblea = ref(false)
 
-
-
 const dialogFormVisiblea2 = ref(false)
-
-
-
-
-
-let socket;
-
-
-const initWebSocket = (token) =>{ //鍒濆鍖杦e
-
-let viewname = "unloadglass";
-
-if (typeof WebSocket === "undefined") {
-  console.log("鎮ㄧ殑娴忚鍣ㄤ笉鏀寔WebSocket");
-} else {
-  let socketUrl = "ws://" + "localhost"+":88" + "/api/talk/" + viewname;
-  if (socket != null) {
-    socket.close();
-    socket = null;
-  }
-
-  // 寮�鍚竴涓獁ebsocket鏈嶅姟
-  socket = new WebSocket(socketUrl);
-
-  // 鎵撳紑浜嬩欢
-  socket.onopen = function () {
-    console.log("websocket宸叉墦寮�");
-  };
-
-
-
-socket.onmessage = (msg) => {
-if (!msg.data) {
-return; // 濡傛灉鏀跺埌绌烘暟鎹紝鍒欑洿鎺ヨ繑鍥烇紝涓嶆墽琛屽悗缁�昏緫
-}
-
-    let obj = JSON.parse(msg.data);
-
-    
-      console.log('鏀跺埌娑堟伅锛�', obj.data);
- 
-  }
-
-  }
-  }
-
-
-
 
 // 鏁版嵁
 const loading = ref(false);
 
-
 // 寮规鏄剧ず鎺у埗
-
 const dialogFormVisible = ref(false);
-
 // 琛ㄥ崟鏁版嵁
 const workstationId = ref('');
 const flowCardId = ref('');
 const flowCardOptions = ref([]);
 const tableData = reactive([]);
-
 // 鏂规硶
 const handleSelectionChange = () => {
   // 澶勭悊琛ㄦ牸琛岄�夋嫨浜嬩欢
@@ -85,15 +35,10 @@
 
 const handleBindRack = (row) => {
   workstationId.value = row.workstationId; // 鍋囪rackNumber鏄灦鍙峰瓧娈电殑灞炴�у悕
-
   // 鍙戣捣鎺ュ彛璇锋眰鑾峰彇娴佺▼鍗″彿
     fetchFlowCardId(); 
-
-
   dialogFormVisiblea.value = true; // 鎵撳紑缁戝畾鏋跺瓙瀵硅瘽妗�
 };
-
-
 
 //鑾峰彇娴佺▼鍗″彿
 const fetchFlowCardId = async () => {
@@ -101,9 +46,12 @@
     const response = await request.get('unLoadGlass/downWorkStation/getflowCardId');
     console.log(response)
     if (response.code === 200) {
-      flowCardOptions.value = response.data.map(item => ({ flowcard_id: item.flow_card_Id }));
-      console.log(flowCardOptions.value)
-    } else {
+  flowCardOptions.value = response.data
+    .filter(item => item !== null)
+    .map(item => ({ flowcard_id: item.flow_card_Id }));
+  console.log(flowCardOptions.value);
+}
+ else {
       ElMessage.error(response.msg);
     }
   } catch (error) {
@@ -141,19 +89,12 @@
   // 鍋囪浣犵殑椤甸潰涓婃湁涓�涓悕涓� tableData 鐨� Vue 缁勪欢
   // 浣犲彲浠ョ洿鎺ユ洿鏂� tableData 鐨勬暟鎹�
   fetchTableData()
-
   // 浣跨敤 $forceUpdate() 寮哄埗鏇存柊缁勪欢
- 
+
 };
-
-
 
 const handleBindRack2 = (row) => {
   workstationId.value = row.workstationId; // 鍋囪rackNumber鏄灦鍙峰瓧娈电殑灞炴�у悕
-
-
-
-
   dialogFormVisiblea2.value = true; // 鎵撳紑缁戝畾鏋跺瓙瀵硅瘽妗�
 };
 //娓呴櫎鍐呭
@@ -185,9 +126,6 @@
 };
 
 
-
-
-
 // 鍙戦�佽幏鍙栬〃鏍兼暟鎹殑璇锋眰
 const fetchTableData = async () => {
   try {
@@ -210,89 +148,36 @@
 };
 
 
+const socketUrl = `ws://${WebSocketHost}:8085/api/talk/unloadglass`;
+// 瀹氫箟娑堟伅澶勭悊鍑芥暟锛屾洿鏂� receivedData 鍙橀噺
+const handleMessage = (data) => {
+
+  // 鏇存柊 tableData 鐨勬暟鎹�
+
+  tableData.splice(0, tableData.length, ...data.params[0]);
+ // console.log("鏇存柊鍚庢暟鎹�", tableData);
+
+};
+
+// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
+
+onMounted(() => {
+  fetchFlowCardId();
+  fetchTableData(); // 鑾峰彇鏁版嵁
+  initializeWebSocket(socketUrl, handleMessage);
+});
+
+onBeforeUnmount(() => {
+  console.log("鍏抽棴浜�")
+  closeWebSocket();
+});
+
+// beforeUnmount(() => {
+//   closeWebSocket();
+// });
 
 
-// initWebSocket();
-onMounted(fetchTableData);
 // setInterval(fetchTableData, 2000)
-
-const open = () => {
-  ElMessageBox.confirm(
-    '鏄惁鍒犻櫎璇ユ潯淇℃伅?',
-    '鎻愮ず',
-    {
-      confirmButtonText: '鏄�',
-      cancelButtonText: '鍙栨秷',
-      type: 'warning',
-    }
-  )
-    .then(() => {
-      ElMessage({
-        type: 'success',
-        message: '鍒犻櫎鎴愬姛锛�',
-      })
-    })
-    .catch(() => {
-      ElMessage({
-        type: 'info',
-        message: '鍒犻櫎澶辫触',
-      })
-    })
-}
-const getTableRow = (row,type) =>{
-  switch (type) {
-    case 'edit' :{
-      //alert('鎴戞帴鏀跺埌瀛愮粍浠朵紶閫佺殑缂栬緫淇℃伅')
-      router.push({path: '/main/returns/createReturns', query: { ReturnID: 'TH24010101' }})
-      break
-    }
-    case 'delete':{
-      alert('鎴戞帴鏀跺埌瀛愮粍浠朵紶閫佺殑鍒犻櫎淇℃伅')
-      break
-    }
-  }
-}
-
-const gridOptions = reactive({
-  border:  "full",//琛ㄦ牸鍔犺竟妗�
-  keepSource: true,//淇濇寔婧愭暟鎹�
-  align: 'center',//鏂囧瓧灞呬腑
-  stripe:true,//鏂戦┈绾�
-  rowConfig: {isCurrent: true, isHover: true,height: 50},//榧犳爣绉诲姩鎴栭�夋嫨楂樹寒
-  id: 'OrderList',
-  showFooter: true,//鏄剧ず鑴�
-  printConfig: {},
-  importConfig: {},
-  exportConfig: {},
-  scrollY:{ enabled: true },//寮�鍚櫄鎷熸粴鍔�
-  showOverflow:true,
-  columnConfig: {
-    resizable: true,
-    useKey: true
-  },
-  filterConfig: {   //绛涢�夐厤缃」
-    remote: true
-  },
-  customConfig: {
-    storage: true
-  },
-  editConfig: {
-    trigger: 'click',
-    mode: 'row',
-    showStatus: true
-  },
-  data:  [
-    {
-      'id': '1',
-      'long': '5',
-      'wide': '1005',
-      'thick': '183.6',
-    }
-  ],
-})
-
-
-
 
 
 </script>
@@ -311,7 +196,19 @@
           <el-table-column prop="racksnumber" align="center" label="宸茶惤鏋舵暟閲�" min-width="120" />
           <el-table-column prop="work_state" align="center" label="鐘舵��" min-width="120" />
           <el-table-column prop="deviceId" align="center" label="璁惧鍙�" min-width="120" />
-          <el-table-column prop="enableState" align="center" label="鍚敤鐘舵��" min-width="120" />
+         
+
+
+          <el-table-column
+            align="center"
+            label="鍚敤鐘舵��"
+            min-width="80"
+            prop="enableState"
+          >
+          <template #default="scope">
+            <el-tag type="success" >{{ scope.row.enableState==1?"鍚敤":"鏈惎鐢�"  }}</el-tag>
+          </template>
+          </el-table-column>
           <el-table-column fixed="right" label="鎿嶄綔" align="center" width="200">
             <template #default="scope">
             <el-button size="mini" type="text" plain v-show="scope.row.enableState !== '宸插惎鐢�' " @click="handleBindRack(scope.row)">缁戝畾鏋跺瓙</el-button>
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/pom.xml b/hangzhoumesParent/moduleService/UnLoadGlassModule/pom.xml
index f447221..fcf1a62 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/pom.xml
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/pom.xml
@@ -31,6 +31,11 @@
             <version>4.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+        </dependency>
+
     </dependencies>
 
     <properties>
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/AppRunnerConfig.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/AppRunnerConfig.java
index ddac7f5..252ad6f 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/AppRunnerConfig.java
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/AppRunnerConfig.java
@@ -20,7 +20,7 @@
     @Override
     public void run(ApplicationArguments args) throws Exception {
         log.info("鍚姩瀹屾垚");
-        S7object.getinstance().start();
+        //S7object.getinstance().start();
 
     }
 }
\ No newline at end of file
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downworkstation/controller/DownWorkstationController.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downworkstation/controller/DownWorkstationController.java
index d6f8f74..40f9793 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downworkstation/controller/DownWorkstationController.java
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downworkstation/controller/DownWorkstationController.java
@@ -149,7 +149,7 @@
         }
     }
 
-    @ApiOperation("鑾峰彇宸ヤ綅鏄剧ず鍥�1")
+    @ApiOperation("鑾峰彇宸ヤ綅鏄剧ず鍥�2")
     @GetMapping("/getwo2")
     public ResponseEntity<Map<String, Object>> getw2o() {
         Map<String, Object> responseData = new HashMap<>();
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownCacheGlassTask.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownCacheGlassTask.java
index fdbbfc1..d8361e1 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownCacheGlassTask.java
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownCacheGlassTask.java
@@ -2,6 +2,7 @@
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.lang.Assert;
+import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.mes.common.S7object;
 import com.mes.common.config.Const;
@@ -21,6 +22,7 @@
 import com.mes.glassinfo.service.GlassInfoService;
 import com.mes.downglassinfo.entity.DownGlassTask;
 import com.mes.downglassinfo.service.DownGlassTaskService;
+import com.mes.tools.WebSocketServer;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +30,7 @@
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -63,7 +66,7 @@
 //    @Value("${mes.threshold}")
     private int threshold;
 
-    //@Scheduled(fixedDelay = 1000)
+  // @Scheduled(fixedDelay = 1000)
     public void plcdownGlassTask() {
    //   PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
 //        String taskRequestTypeValue = plcParameterObject.getPlcParameter("A06_request_word").getValue();
@@ -74,14 +77,14 @@
       // String G06RobotTaskRequestWord = plcParameterObject.getPlcParameter("G06RobotTaskRequestWord").getAddress();
 
 
-                String taskRequestTypeValue ="3";
+                String taskRequestTypeValue ="0";
         String glassIdeValue ="NG24041101C002-2-6-1-6";
         String confirmationWrodValue ="1";
         String outGlassstate="1";
         String confirmationWrodAddress="1";
-        String G11RobotTaskRequestWord ="1";
-        String G06RobotTaskRequestWord ="1";
-        String G13RobotTaskRequestWord ="1";
+        String G11RobotTaskRequestWord ="0";
+        String G06RobotTaskRequestWord ="0";
+        String G13RobotTaskRequestWord ="0";
 
                 log.info("1銆佽幏鍙栧埌鐨勮姹傚瓧涓猴細{}锛岃幏鍙栧埌鐨勬壂鎻廔D涓猴細{}锛岃幏鍙栧埌鐨勭‘璁ゅ瓧涓猴細{}锛岃幏鍙栧埌鐨勫嚭鐗囩姸鎬佷负锛歿}",
                 taskRequestTypeValue, glassIdeValue, confirmationWrodValue, outGlassstate);
@@ -127,6 +130,8 @@
 
 
 
+
+
     }
 
     /**
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java
new file mode 100644
index 0000000..308599c
--- /dev/null
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java
@@ -0,0 +1,68 @@
+package com.mes.job;
+
+import cn.hutool.json.JSONObject;
+import com.mes.downworkstation.entity.DownWorkstation;
+import com.mes.downworkstation.service.DownWorkstationService;
+import com.mes.tools.WebSocketServer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Component
+public class Downpush {
+
+
+    @Autowired
+    private DownWorkstationService downWorkstationService;
+    @Scheduled(fixedDelay = 1000)
+    public void Downpush() {
+
+
+        JSONObject jsonObject = new JSONObject();
+        JSONObject jsonObject2 = new JSONObject();
+        JSONObject jsonObject3 = new JSONObject();
+
+        List<DownWorkstation> data = downWorkstationService.getoneDownWorkstations(1,6);
+        List<Map<String, Object>> glassinfodata = downWorkstationService.getTotalGlassDimensionsByWorkstation(1,3);
+        List<Map<String, Object>> glassinfodata2 = downWorkstationService.getTotalGlassDimensionsByWorkstation(4,6);
+        jsonObject.append("params",data);
+        jsonObject2.append("glassinfo",glassinfodata);
+        jsonObject3.append("glassinfo2",glassinfodata2);
+        log.info(jsonObject.toString());
+        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("unloadglass");
+        ArrayList<WebSocketServer> sendwServer2 = WebSocketServer.sessionMap.get("unloadglass2");
+        ArrayList<WebSocketServer> sendwServer3 = WebSocketServer.sessionMap.get("unloadglass3");
+        //  log.info(sendwServer.toString());
+        if (sendwServer != null) {
+            for (WebSocketServer webserver : sendwServer) {
+
+                if (webserver != null&&webserver.session.isOpen()) {
+                    webserver.sendMessage(jsonObject.toString());
+                }
+            }
+        }
+        if (sendwServer2 != null) {
+            for (WebSocketServer webserver : sendwServer2) {
+
+                if (webserver != null&&webserver.session.isOpen()) {
+                    webserver.sendMessage(jsonObject2.toString());
+                }
+            }
+        }
+        if (sendwServer3 != null) {
+            for (WebSocketServer webserver : sendwServer3) {
+
+                if (webserver != null&&webserver.session.isOpen()) {
+                    webserver.sendMessage(jsonObject3.toString());
+                }
+            }
+        }
+
+    }
+}
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketConfig.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketConfig.java
new file mode 100644
index 0000000..56fb341
--- /dev/null
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketConfig.java
@@ -0,0 +1,16 @@
+package com.mes.tools;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+@Configuration
+public class WebSocketConfig {
+    
+
+     @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
+
+}
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketServer.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketServer.java
index fcd2a10..b10efb4 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketServer.java
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/WebSocketServer.java
@@ -1,28 +1,35 @@
 package com.mes.tools;
 
-import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.stereotype.Component;
-
-import javax.websocket.*;
-import javax.websocket.server.PathParam;
-import javax.websocket.server.ServerEndpoint;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.websocket.OnClose;
+import javax.websocket.OnError;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.stereotype.Component;
+
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+
 @ServerEndpoint(value = "/api/talk/{username}")
-@Component("webSocketServer")
+@Component
 public class WebSocketServer {
 
     // @Autowired
     // HomeMapper homeMapper;
 
-    public static ConfigurableApplicationContext applicationContext;
+    static ConfigurableApplicationContext applicationContext;
 
     // 瑙e喅鏃犳硶娉ㄥ叆mapper闂 //浣跨敤鏂规硶
     // homeMapper=WebSocketServer.applicationContext.getBean(HomeMapper.class);
@@ -38,7 +45,7 @@
     public static final Map<String, ArrayList<WebSocketServer>> sessionMap = new ConcurrentHashMap<>();
 
     String username;
-    Session session;
+    public Session session;
 
     public WebSocketServer() {
         this.messages = new ArrayList<>();
@@ -58,6 +65,15 @@
             sessionMap.put(username, arrayListwebserver);
         } else {
             webSocketServers.add(this);
+            // Short i=0;
+            // for (WebSocketServer webSocketServer : webSocketServers) {
+            //     if(webSocketServer==this){
+            //         i++;
+            //     }
+            // }
+            // if(i==0){
+            //     webSocketServers.add(this);
+            // }
         }
 
         log.info("鏈夋柊鐢ㄦ埛鍔犲叆锛寀sername={}, 褰撳墠鍦ㄧ嚎浜烘暟涓猴細{}", username, sessionMap.get(username).size());
@@ -81,15 +97,15 @@
     public void onClose(Session session, @PathParam("username") String username) {
         List<WebSocketServer> webSocketServers = sessionMap.get(username);
         ArrayList<WebSocketServer> arrayListwebserver = new ArrayList<WebSocketServer>();
-        if (webSocketServers.size() > 1) {
+        if (webSocketServers.size()>1) {
             for (WebSocketServer webSocketServer : webSocketServers) {
-                if (webSocketServer != this) {
+                if(webSocketServer!=this){
                     arrayListwebserver.add(webSocketServer);
                 }
             }
             sessionMap.put(username, arrayListwebserver);
             log.info("绉婚櫎username={}涓�鍚嶇敤鎴穝ession, {}鐨勫綋鍓嶅湪绾夸汉鏁颁负锛歿}", username, username, sessionMap.get(username).size());
-        } else {
+        }else{
             sessionMap.remove(username);
             log.info("绉婚櫎username={}涓�鍚嶇敤鎴穝ession, {}杩炴帴鍏抽棴, 褰撳墠杩炴帴鏁颁负锛歿}", username, username, sessionMap.size());
         }
@@ -157,6 +173,4 @@
     public void clearMessages() {
         messages.clear();
     }
-
-
 }
diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/resources/application.yml b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/resources/application.yml
index 90f92f5..5d44c2f 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/resources/application.yml
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/resources/application.yml
@@ -6,6 +6,8 @@
     active: prod
   application:
     name: unLoadGlass
+
+
 mybatis-plus:
   mapper-locations: classpath*:mapper/*.xml
   configuration:

--
Gitblit v1.8.0