wu
2023-09-13 b6901c795d8640776818e7d2be6a3396b4a2f535
springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java
@@ -1,66 +1,85 @@
package com.example.springboot.component;
import java.sql.SQLException;
import java.util.List;
import javax.websocket.Session;
import org.springframework.beans.factory.annotation.Autowired;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
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 {
  private AlarmMapper alarmMapper;
  @Autowired
  private JdbcConnections jdbcConnections;
  private SpianService spianService;
  @Override
  public void run() {
    while (this != null) {
      try {
        Thread.sleep(10000);
        Thread.sleep(500);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        //\\ TODO Auto-generated catch block
        e.printStackTrace();
      }
      List<Boolean> bitlist = S7control.getinstance().ReadBits("DB2.0.0", 100);
      spianService = WebSocketServer.applicationContext.getBean(SpianService.class);
      jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class);
      //根据玻璃id获取订单号
      try {
          Glass glass=jdbcConnections.selectGlass(112);
      List<Short> paramlist = S7control.getinstance().ReadWord("DB100.6", 1);
          //System.out.println(glass.getOrderId());
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      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);
        }
      }
        //System.out.println(exist);
      }
    }
      // 查询数据库
      // 推送到前端
      // Parameter
      JSONObject jsonObject = new JSONObject();
      jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, });
      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
      if (sendwServer != null) {
        sendwServer.sendMessage(jsonObject.toString());
      }
      // Action
      // JSONObject jsonObject2 = new JSONObject();
      // jsonObject2.append("acion",
      // new short[] { 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
      // 1, 1, 1, 0, 0, });
      // WebSocketServer sendwServer2 = WebSocketServer.sessionMap.get("Action");
      // if (sendwServer2 != null) {
      // sendwServer2.sendMessage(jsonObject2.toString());
      // }
      // Sign
      JSONObject jsonObject3 = new JSONObject();
      jsonObject3.append("sig",
          new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0,
              1, });
      WebSocketServer sendwServer3 = WebSocketServer.sessionMap.get("Sign");
      if (sendwServer3 != null) {
        sendwServer3.sendMessage(jsonObject3.toString());
      }
      // State
      JSONObject jsonObject4 = new JSONObject();
      jsonObject4.append("sta", new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, });
      WebSocketServer sendwServer4 = WebSocketServer.sessionMap.get("State");
      if (sendwServer4 != null) {
        sendwServer4.sendMessage(jsonObject4.toString());
      }
    }
  }
}