zhangyong
2023-09-15 70d4832d2d0f3d484dce6769beac3b4806e783a7
springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
@@ -3,6 +3,7 @@
import cn.hutool.json.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.example.springboot.mapper.AlarmMapper;
@@ -14,77 +15,88 @@
  public void run() {
    while (this != null) {
      try {
        Thread.sleep(10000);
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.DBx0.0", 40);
      List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", 40);
      // Boolean[] values = { true, false, true, false, true, false, true, false,
      // true, false, true, false, true, false,
      // true, false, true, false, true, false, true, false, true, false, true, false,
      // true, false, true, false, true,
      // false, true, false, true, false,
      // true, false, true, false };
      // List<Boolean> plclist = new ArrayList<>(Arrays.asList(values));
      if (plclist != null) {
      JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject = new JSONObject();
      jsonObject.append("params", plclist);
      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("alarm");
      if (sendwServer != null) {
        sendwServer.sendMessage(jsonObject.toString());
      }
        jsonObject.append("params", plclist);
        WebSocketServer sendwServer = WebSocketServer.sessionMap.get("alarm");
        if (sendwServer != null) {
          sendwServer.sendMessage(jsonObject.toString());
        }
      Short[] shuzu1 = plclist.toArray(new Short[0]);
      // Short[] shuzu1 = {
      // 0, 1, 0, 1, 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, 0, 1, 0, 1, 0, 1, 0, 1,
      // };
        // 将获取的布尔类型转换为整数类型
        List<Integer> Intlist = new ArrayList<>();
        for (Boolean value : plclist) {
          Intlist.add(value == true ? 1 : 0);
      String[] shuzu = {
          "D01 VFD error",
          "D02 VFD error",
          "D03 VFD error",
          "D04 VFD error",
          "D05 VFD error",
          "D06 VFD error",
          "B01 VFD error",
          "B02 VFD error",
          "A01 VFD error",
          "A02 VFD error",
          "A01 servo turn error",
          "A02 servo turn error",
          "A01 servo travel error",
          "A02 servo travel error",
          "B01 servo travel error",
          "B02 servo travel error",
          "D01 DEC error",
          "D01 pos error",
          "D02 DEC error",
          "D02 pos error",
          "D03 DEC error",
          "D03 pos error",
          "D04 DEC error",
          "D04 pos error",
          "D05 DEC error",
          "D05 pos error",
          "D06 DEC error",
          "D06 pos error",
          "A01 DEC error",
          "A01 pos error",
          "A02 DEC error",
          "A02 pos error",
          "B01 IN DEC error",
          "B01 IN pos error",
          "B01 OUT DEC error",
          "B01 OUT pos error",
          "B02 IN DEC error",
          "B02 IN pos error",
          "B02 OUT DEC error",
          "B02 OUT pos error",
      };
      alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class);
      for (short i = 0; i < shuzu1.length; i++) {
        short result = alarmMapper.selectnullti(shuzu[i]);
        if (shuzu1[i] == 1 && result == 0) {
          // alarmMapper.Insertalarm(shuzu[i]);
        } else if (shuzu1[i] == 0 && result > 0) {
          alarmMapper.updatealarm(shuzu[i]);
        }
        // 将Intlist转换为数组
        Integer[] shuzu1 = Intlist.toArray(new Integer[0]);
        String[] shuzu = {
            "D01 VFD error",
            "D02 VFD error",
            "D03 VFD error",
            "D04 VFD error",
            "D05 VFD error",
            "D06 VFD error",
            "B01 VFD error",
            "B02 VFD error",
            "A01 VFD error",
            "A02 VFD error",
            "A01 servo turn error",
            "A02 servo turn error",
            "A01 servo travel error",
            "A02 servo travel error",
            "B01 servo travel error",
            "B02 servo travel error",
            "D01 DEC error",
            "D01 pos error",
            "D02 DEC error",
            "D02 pos error",
            "D03 DEC error",
            "D03 pos error",
            "D04 DEC error",
            "D04 pos error",
            "D05 DEC error",
            "D05 pos error",
            "D06 DEC error",
            "D06 pos error",
            "A01 DEC error",
            "A01 pos error",
            "A02 DEC error",
            "A02 pos error",
            "B01 IN DEC error",
            "B01 IN pos error",
            "B01 OUT DEC error",
            "B01 OUT pos error",
            "B02 IN DEC error",
            "B02 IN pos error",
            "B02 OUT DEC error",
            "B02 OUT pos error",
        };
        alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class);
        for (short i = 0; i < shuzu.length; i++) {
          short result = alarmMapper.selectnullti(shuzu[i]);
          if (shuzu1[i] == 1 && result == 0) {
            alarmMapper.Insertalarm(shuzu[i]);
          } else if (shuzu1[i] == 0 && result > 0) {
            alarmMapper.updatealarm(shuzu[i]);
          }
        }
      }
    }