Bladeren bron

继电器代码优化

qidingqiang 5 maanden geleden
bovenliggende
commit
b5236f5bee

+ 36 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/utils/ATCommandValidator.java

@@ -10,6 +10,7 @@ public class ATCommandValidator {
             Pattern.CASE_INSENSITIVE | Pattern.DOTALL  // 忽略大小写,允许 . 匹配换行符
     );
 
+
     /**
      * 判断命令是否匹配 AT+STACH...=1OK 格式
      * @param command 待验证的命令字符串
@@ -24,12 +25,22 @@ public class ATCommandValidator {
 
 
 
+
+
+
+
     // 正则表达式模式(匹配 AT+STACH4 和 OK 之间的任意字符串)
      static final Pattern COMMAND_PATTERN_ALL = Pattern.compile(
             "AT\\+STACH.*?OK",
             Pattern.DOTALL  // 允许 . 匹配换行符
     );
 
+
+
+
+    private static final String STACH0_COMMAND = "AT+STACH0=?";
+    private static final String STACH1_PREFIX = "+STACH1:";
+
     //匹配返回命令  判断是否有返回值
      static boolean isCommandValid(String command) {
         Matcher matcher = COMMAND_PATTERN_ALL.matcher(command);
@@ -64,4 +75,29 @@ public class ATCommandValidator {
     }
 
 
+
+    /**
+     * 检查输入是否包含需要跳过处理的AT命令
+     * @param input 输入字符串
+     * @return 如果包含特定命令则返回true,否则返回false
+     */
+    public static boolean shouldSkipProcessing(String input) {
+        if (input == null || input.isEmpty()) {
+            return true;
+        }
+
+        // 查找AT命令起始位置
+        int commandStartIndex = input.indexOf("AT+");
+        if (commandStartIndex == -1) {
+            return false;
+        }
+
+        // 提取命令部分
+        String commandPart = input.substring(commandStartIndex);
+
+        // 检查是否包含需要跳过的命令
+        return commandPart.contains(STACH0_COMMAND);
+    }
+
+
 }

+ 7 - 2
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/utils/RelayUtils.java

@@ -58,7 +58,7 @@ public class RelayUtils {
                 labRelayStatus.setHardwareOperate(HardwareOperate.CLOSE);
             }
             log.info("relayOpenClose继电器1{}操作: 设备编号={}, 操作位={},command={}", data, relayCode, bit,  labRelayStatus.getHardwareOperate());
-
+            
             //抛出继电器开关切换事件
             LabRelayNrStatusEvent relayNrStatusEvent = new LabRelayNrStatusEvent(labRelayStatus);
             SpringUtils.getApplicationContext().publishEvent(relayNrStatusEvent);
@@ -111,6 +111,10 @@ public class RelayUtils {
         LabRelayRegisterEvent labRelayRegisterEvent = new LabRelayRegisterEvent(labRelay);
         SpringUtils.getApplicationContext().publishEvent(labRelayRegisterEvent);
         if (data.contains(RelayConstants.AT_STACH_ALL_STR)) {
+//            if (ATCommandValidator.shouldSkipProcessing(data)){
+//                log.info("relayRefreshStatus继电器设备状态{}",data);
+//                return;
+//            }
             log.info("【继电器状态刷新】数据信息: {} ", data);
             String disposeCommand = data.replace(codeStr + RelayConstants.AT_STACH_ALL_STR, "");
             disposeCommand = disposeCommand.replace(RelayConstants.PLUS_STACH, "");
@@ -123,10 +127,11 @@ public class RelayUtils {
                 String status[] = split.split(",")[0].split(":");
                 if (status.length > 1) {
                     String bitStr = status[0].replace(RelayConstants.PLUS_STACH, "");
+                    String operate = status[1];
                     log.info("bit:" + bitStr + "继电器设备状态 status[]:" + Arrays.toString(status));
                     labRelayStatus.setNum(relayCode);
                     labRelayStatus.setBit(Integer.parseInt(bitStr));
-                    HardwareOperate hardwareOperate = bitStr.equals("1") ? HardwareOperate.OPEN : HardwareOperate.CLOSE;
+                    HardwareOperate hardwareOperate = operate.equals("1") ? HardwareOperate.OPEN : HardwareOperate.CLOSE;
                     labRelayStatus.setHardwareOperate(hardwareOperate);
                     LabRelayNrStatusEvent relayNrStatusEvent = new LabRelayNrStatusEvent(labRelayStatus);
                     SpringUtils.getApplicationContext().publishEvent(relayNrStatusEvent);

+ 41 - 19
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabViolationMapper.xml

@@ -496,25 +496,47 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="pageList" parameterType="com.zd.laboratory.domain.vo.LabViolationVO" resultMap="LabViolationVOResult">
         SELECT
-            v.id,
-            u.user_id join_user_id,
-            u.nick_name user_name,
-            u.user_name AS stuNo,
-            v.create_time AS createTime,
-            d.dept_name AS deptName,
-            v.status,
-            (select count(1) from lab_negativelist_history he where he.user_id = u.`user_id`) violation_num,
-            v.negative_list_num,
-            IFNULL((SELECT COUNT(1) FROM lab_blackdetail b inner join lab_blacklist t on b.black_id = t.id WHERE t.`join_user_id` = u.user_id GROUP BY b.black_id),0) black_list_num,
-            r.`credit_score` AS credit_score,
-            v.is_negative,
-            v.is_black_list,
-            (SELECT r.id FROM lab_negative_list_records r WHERE r.user_id = u.`user_id`) negative_id
-        FROM
-            sys_user u
-                INNER JOIN lab_violation v ON u.user_id = v.user_id
-                INNER JOIN sys_dept d ON u.dept_id = d.dept_id
-                INNER JOIN el_points_record r ON r.`join_user_id`=u.`user_id`
+        v.id,
+        u.user_id            AS join_user_id,
+        u.nick_name          AS user_name,
+        u.user_name          AS stuNo,
+        v.create_time        AS createTime,
+        d.dept_name          AS deptName,
+        v.status,
+
+        IFNULL(h.violation_num, 0)    AS violation_num,
+        v.negative_list_num,
+        IFNULL(b.black_list_num, 0)   AS black_list_num,
+
+        r.credit_score,
+        v.is_negative,
+        v.is_black_list,
+
+        n.id AS negative_id
+        FROM sys_user u
+        JOIN lab_violation      v ON v.user_id = u.user_id
+        JOIN sys_dept           d ON d.dept_id = u.dept_id
+        JOIN el_points_record   r ON r.join_user_id = u.user_id
+
+        /* 1. 违规次数一次聚合 */
+        LEFT JOIN (
+        SELECT user_id, COUNT(*) AS violation_num
+        FROM lab_negativelist_history
+        GROUP BY user_id
+        ) h ON h.user_id = u.user_id
+
+        /* 2. 黑名单次数一次聚合 */
+        LEFT JOIN (
+        SELECT t.join_user_id, COUNT(DISTINCT b.black_id) AS black_list_num
+        FROM lab_blackdetail b
+        JOIN lab_blacklist t ON t.id = b.black_id
+        WHERE t.blacklist_status = 1
+        GROUP BY t.join_user_id
+        ) b ON b.join_user_id = u.user_id
+
+        /* 3. 负面名单 id(只取一条即可) */
+        LEFT JOIN lab_negative_list_records n
+        ON n.user_id = u.user_id;
         where true
            <!--<if test="userId!=null"> and join_user_id=#{userId}</if>-->
            <if test="creact_id!=null"> and creact_id=#{creact_id}</if>