wu
2023-12-08 31101f632c27c05d15f30ca3084e3ed3da2a29af
springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
@@ -28,7 +28,7 @@
    FileInputStream fileInputStream;
    try {
      // 从文件中读取字节数据存入 fileInputStream
      fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/Alarm.json");
      fileInputStream = new FileInputStream("src/main/resources/Alarm.json");
      // 读取 fileInputStream 中字节并将其解码为字符
      InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
      // 提高读取效率,在 BufferedReader 内包装 InputStreamReader
@@ -82,20 +82,21 @@
        e.printStackTrace();
      }
      this.readValue();
      String PlcAddress = this.name;
      Integer Plccount = this.count;
//      this.readValue();
//      String PlcAddress = this.name;
//      Integer Plccount = this.count;
      // 根据地址读取PCL数据
      // List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress,
      // Plccount);
      Boolean[] values = { false, 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));
      List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", 71);
//      List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress, Plccount);
      // System.out.println(plclist);
      // Boolean[] values = { false, 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();
@@ -113,22 +114,23 @@
        }
        // 将Intlist转换为数组
        // System.out.println(Intlist);
        Integer[] shuzu1 = Intlist.toArray(new Integer[0]);
        // 定义的报警内容数组,获取json返回的集合
        List<String> myCollection;
        myCollection = readValue();
        String[] array1 = myCollection.toArray(new String[myCollection.size()]);
        // System.out.println(myCollection);
      //  System.out.println(array1.length);
        alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class);
        for (short i = 0; i < array1.length; i++) {
          // 查询对应报警信息结束时间为null的条数
          short result = alarmMapper.selectnullti(array1[i]);
          // 读取到PLC的值为1并且对应报警信息结束时间为null的条数的条数为0
          // System.out.println(result);
          if (shuzu1[i] == 1 && result == 0) {
            // 填加一条报警信息,有开始时间
            alarmMapper.Insertalarm(array1[i]);
             alarmMapper.Insertalarm(array1[i]);
          } else if (shuzu1[i] == 0 && result > 0) {
            // 修改该条报警信息的结束时间
            alarmMapper.updatealarm(array1[i]);