From 79f33da4df32fc139c3855a8ecca6545723e0815 Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期二, 19 九月 2023 08:08:17 +0800 Subject: [PATCH] 删除不需要的代码,玻璃信息放入其他数据库 方便测试显示数据库连接的信息 --- springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java | 179 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 138 insertions(+), 41 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 f45e84f..feaec32 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,14 +1,17 @@ package com.example.springboot.component; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; +import org.apache.ibatis.javassist.compiler.ast.Symbol; 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; +import com.example.springboot.mapper.SpianMapper; public class PlcHold extends Thread { @@ -16,71 +19,165 @@ @Autowired private JdbcConnections jdbcConnections; - + private SpianMapper spianMapper; private SpianService spianService; - @Override public void run() { - + boolean inglassbegin=false; + boolean outglassbegin=false; while (this != null) { try { - Thread.sleep(500); + Thread.sleep(1000); } catch (InterruptedException e) { - //\\ TODO Auto-generated catch block + // \\ TODO Auto-generated catch block e.printStackTrace(); } spianService = WebSocketServer.applicationContext.getBean(SpianService.class); + spianMapper = WebSocketServer.applicationContext.getBean(SpianMapper.class); jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class); - - //鏍规嵁鐜荤拑id鑾峰彇璁㈠崟鍙� - try { - Glass glass=jdbcConnections.selectGlass(112); - //System.out.println(glass.getOrderId()); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + // 鏍规嵁鐜荤拑id鑾峰彇璁㈠崟鍙�,鍗曠嫭鏁版嵁婧� + // try { + + // Glass glass = jdbcConnections.selectGlass(112); + + // // System.out.println(glass.getOrderId()); + // } catch (SQLException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // spianService.selectAll((short)257); + //鍒ゆ柇杩涚墖璇锋眰 + List<Short> datas1List = S7control.getinstance().ReadWord("DB106.24", 1);// 鑾峰彇prc杩涚墖璇锋眰鏁版嵁 + List<Short> datas1ListState = S7control.getinstance().ReadWord("DB106.8", 1);// 鑾峰彇杩涚墖杞︾姸鎬� + List<Short> datas1ListState2 = S7control.getinstance().ReadWord("DB105.12", 1);// 鑾峰彇杩涚墖杞︿换鍔℃槸鍚﹀惎鍔� + + if (datas1List != null && datas1ListState != null) { + + // 鑾峰彇prc杩涚墖璇锋眰鏁版嵁 + boolean exist = datas1List.contains((short) 1); + // 鑾峰彇杩涚墖杞︾姸鎬� + boolean exist1 = datas1ListState.contains((short) 0); + //鍒ゆ柇杩涚墖杞︿换鍔℃槸鍚﹀惎鍔� + boolean exist2 = datas1ListState2.contains((short) 1); + + String glassid=""; + StringBuilder strId=new StringBuilder(); + StringBuilder writedstrId=new StringBuilder(); + + if(!inglassbegin&!exist1) + { + inglassbegin=true; + } + if(inglassbegin&exist1) + { + inglassbegin=false; + spianMapper.UpdataAddCageState(1,2); + } + // 杩涚墖璇锋眰涓�1鏃� + if (exist == true) { + // 褰撹繘鐗囪溅绌洪棽鏃� + if (exist1 == true) { + //鑾峰彇宸蹭笅鍙戠殑杩涚墖id 涓巔lc璇锋眰鐨刬d浣滄瘮杈� + byte[] writedglassidbytes = S7control.getinstance().ReadByte("DB105.16", 1); + if (writedglassidbytes != null) { + // 鑾峰彇鐜荤拑id + for (byte iditem : writedglassidbytes) { + writedstrId.append(iditem); + } + } + // 鑾峰彇杩涚墖id + byte[] datas1ListID = S7control.getinstance().ReadByte("DB106.26", 1); + if (datas1ListID != null) { + // 鑾峰彇鐜荤拑id + for (byte list1 : datas1ListID) { + strId.append(list1); + + } + if(!writedstrId.toString().equals(strId.toString())) //宸茬粡涓嬪彂鐨刬d涓巔lc璇锋眰鐨刬d涓嶄竴鏍锋椂锛岃涓轰笉鏄噸澶嶇殑浠诲姟锛屾墠鎵ц涓嬪彂浠诲姟鎸囦护 + { + spianService.selectAll(strId.toString()); + S7control.getinstance().WriteByte("DB105.16",datas1ListID);//娲惧彂杩涚墖id + + } + //spianService.selectAll(Short.parseShort(strId.toString())); + } + + } + // System.out.println(exist); } - - spianService.selectout("11"); - //鍒ゆ柇杩涚墖璇锋眰 - 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); + if(exist1==false){//涓嬪彂浠诲姟鍚庡皢浠诲姟鍚姩鏀逛负0 + if(exist2==true) { + S7control.getinstance().WriteWord("DB105.12",(short)0);//杩涚墖浠诲姟鍚姩鏀逛负0 + } } } + + //spianService.selectAll((short) 111); + + List<Short> outlist = S7control.getinstance().ReadWord("DB106.20", 1); // 鍑虹墖杞︾姸鎬� + List<Short> outlist1 = S7control.getinstance().ReadWord("DB105.14", 1); // 鍑虹墖浠诲姟鏄惁鍚姩 + StringBuilder writedstrIdOut=new StringBuilder(); + //鑾峰彇宸蹭笅鍙戠殑鍑虹墖id + byte[] writedglassidbytesOut = S7control.getinstance().ReadByte("DB105.30", 1); + if (writedglassidbytesOut != null) { + // 鑾峰彇鐜荤拑id + for (byte iditem : writedglassidbytesOut) { + writedstrIdOut.append(iditem); + } + } + boolean outstate=false;//鍑虹墖杞︾┖闂插垽鏂� + boolean outstate1=false;//鍑虹墖杞︿换鍔℃槸鍚﹀惎鍔� + if (outlist != null&&outlist1!=null) { + // 鍒ゆ柇鎸夎鍗曞嚭鐗� + outstate = outlist.contains((short) 0);//鍑虹墖杞︾┖闂插垽鏂� + outstate1 = outlist1.contains((short) 1);//鍑虹墖杞︿换鍔℃槸鍚﹀惎鍔� + + Glass glass=spianMapper.SelectDBOut();//鍒ゆ柇鏄惁鏈夎皟鎷ㄥ悗鐨勫嚭鐗囦换鍔℃湭瀹屾垚 + if(!outglassbegin&!outstate)//褰撲换鍔¤繕鏈紑濮嬶紝涓斿嚭鐗囪溅涓嶇┖闂叉椂,浠诲姟鐘舵�佹敼涓哄紑濮� + { + outglassbegin=true; + } + if(outglassbegin&outstate)//褰撲换鍔″紑濮嬩笖鍑虹墖杞︾┖闂叉椂 + { + outglassbegin=false; + spianMapper.UpdataAddCageState(0,3); + } + + if(outstate== true &glass.getGlassId()!=null){ //褰撳嚭鐗囪溅绌洪棽涓旀湁鍑虹墖浠诲姟寰呭畬鎴愭椂 + if(glass.getId()==2&!writedstrIdOut.toString().equals(glass.getGlassId().toString())){ + spianService.selectout2(glass.getGlassId().toString()); + } + } + if(outstate==false){//涓嬪彂浠诲姟鍚庡皢浠诲姟鍚姩鏀逛负0//鍑虹墖杞︾┖闂插垽鏂� + if(outstate1==true){ + S7control.getinstance().WriteWord("DB105.14",(short)0);//鍑虹墖浠诲姟鍚姩鏀逛负0 + } + } + } - - - //System.out.println(exist); - } - } - - + + + + if (outstate == true) { // 鍑虹墖杞︾姸鎬佺┖闂叉椂 + Integer state=spianMapper.Selectoutstate(); + String orderid = spianMapper.SelectOrderout(); + + if (orderid != null &&state==0) { + spianService.selectout(orderid); + } + } + // 鏌ヨ鏁版嵁搴� // 鎺ㄩ�佸埌鍓嶇 } } - + } -- Gitblit v1.8.0