From cdc594d12e46b7dd2e37c7a2071c133f8404f9be Mon Sep 17 00:00:00 2001 From: ZengTao <2773468879@qq.com> Date: 星期二, 12 九月 2023 18:25:55 +0800 Subject: [PATCH] 测试代码,部分代码进行优化 --- springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java | 95 ++++++++++++++++++++++++++++++++++------------- 1 files changed, 68 insertions(+), 27 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java b/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java index 6eae7f5..65b6d28 100644 --- a/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java +++ b/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java @@ -1,41 +1,82 @@ package com.example.springboot.component; +import java.sql.SQLException; import java.util.List; -import cn.hutool.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; + +import com.example.springboot.service.JdbcConnections; +import com.example.springboot.service.SpianService; +import com.example.springboot.entity.Glass; +import com.example.springboot.mapper.AlarmMapper; public class PlcHold extends Thread { - @Override - public void run() { - while (this != null) { - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - List<Boolean> bitlist = S7control.getinstance().ReadBits("DB2.0.0", 100); + private AlarmMapper alarmMapper; - List<Short> paramlist = S7control.getinstance().ReadWord("DB100.6", 1); + @Autowired + private JdbcConnections jdbcConnections; - //鏌ヨ鏁版嵁搴� - //鎺ㄩ�佸埌鍓嶇 - - JSONObject jsonObject = new JSONObject(); - jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5 }); - WebSocketServer sendwServer = WebSocketServer.sessionMap.get("talkvue"); - if (sendwServer != null) { - sendwServer.sendMessage(jsonObject.toString()); - } + private SpianService spianService; - JSONObject jsonObject2 = new JSONObject(); - jsonObject2.append("params", new short[] { 0, 3, 2, 3, 4, 5 }); - WebSocketServer sendwServer2 = WebSocketServer.sessionMap.get("action"); - if (sendwServer2 != null) { - sendwServer2.sendMessage(jsonObject2.toString()); - } + @Override + public void run() { + + while (this != null) { + try { + + Thread.sleep(500); + } catch (InterruptedException e) { + //\\ TODO Auto-generated catch block + e.printStackTrace(); + } + spianService = WebSocketServer.applicationContext.getBean(SpianService.class); + + jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class); + try { + Glass glass=jdbcConnections.selectGlass(112); + //System.out.println(glass.getOrderId()); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } + + //鍒ゆ柇杩涚墖璇锋眰 + List<Short> datas1List=S7control.getinstance().ReadWord("DB106.24", 1); + List<Short> datas1ListState=S7control.getinstance().ReadWord("DB106.8", 1); + if(datas1List!=null &&datas1ListState!=null){ + //鑾峰彇prc杩涚墖璇锋眰鏁版嵁 + boolean exist = datas1List.contains((short)1); + //鑾峰彇杩涚墖杞︾姸鎬� + boolean exist1 = datas1ListState.contains((short)0); + //杩涚墖璇锋眰涓�1鏃� + if(exist=true){ + //褰撹繘鐗囪溅绌洪棽鏃� + if(exist1=true){ + //鑾峰彇杩涚墖id + List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13); + //鑾峰彇鐜荤拑id + for(Short list1:datas1ListID){ + + spianService.selectAll((short)list1); + } + } + + + + + //System.out.println(exist); + } } + + + + + // 鏌ヨ鏁版嵁搴� + // 鎺ㄩ�佸埌鍓嶇 + + } + } + } -- Gitblit v1.8.0