From 209a57aecbf26911f6a3ae0692b51ed0289f5b1a Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期四, 14 九月 2023 17:04:56 +0800 Subject: [PATCH] 优化理片笼逻辑 --- springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java | 36 ++++++++++++++++++++---------------- 1 files changed, 20 insertions(+), 16 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java b/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java index 1597562..f45650a 100644 --- a/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java +++ b/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; @@ -20,9 +21,14 @@ } List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.DBx0.0", 40); - if (plclist == null) { - - } else { + // 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(); @@ -31,13 +37,15 @@ if (sendwServer != null) { sendwServer.sendMessage(jsonObject.toString()); } - // 将读取到的plclist转为数组 - 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); + + } + // 灏咺ntlist杞崲涓烘暟缁� + Integer[] shuzu1 = Intlist.toArray(new Integer[0]); String[] shuzu = { "D01 VFD error", @@ -82,15 +90,11 @@ "B02 OUT pos error", }; alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class); - for (short i = 0; i < shuzu1.length; i++) { - // 查询结束时间为null的个数 + for (short i = 0; i < shuzu.length; i++) { short result = alarmMapper.selectnullti(shuzu[i]); - // 读取PLC对应地址的值为1并且该地址没有结束时间为null的数据,添加一条新的报警信息 if (shuzu1[i] == 1 && result == 0) { alarmMapper.Insertalarm(shuzu[i]); - } - // 读取PLC对应地址的值为0并且该地址有结束时间为null的数据,修改该条数据的结束时间 - else if (shuzu1[i] == 0 && result > 0) { + } else if (shuzu1[i] == 0 && result > 0) { alarmMapper.updatealarm(shuzu[i]); } } -- Gitblit v1.8.0