Parcourir la source

日志增加设备类型筛选

yangxiaokun il y a 2 ans
Parent
commit
c04267dae3

+ 2 - 0
src/main/java/com/zy/bms/common/Constant.java

@@ -9,7 +9,9 @@ package com.zy.bms.common;
 public class Constant {
 
     public static class DEVICE_TYPE {
+        //路牌
         public static final String LP = "lupai";
+        //普适型
         public static final String UBI = "gnss";
     }
 

+ 4 - 2
src/main/java/com/zy/bms/controller/LogsController.java

@@ -1,6 +1,8 @@
 package com.zy.bms.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.bms.common.ServerResponse;
+import com.zy.bms.entity.Instructions;
 import com.zy.bms.pojo.io.LogsIO;
 import com.zy.bms.service.IInstructionsService;
 import com.zy.bms.service.ILogsService;
@@ -35,7 +37,7 @@ public class LogsController {
      * 获取全部的指令
      */
     @GetMapping("instruction.do")
-    public ServerResponse getAllInstruction() {
-        return ServerResponse.success(instructionsService.list());
+    public ServerResponse getAllInstruction(String deviceType) {
+        return ServerResponse.success(instructionsService.list(new QueryWrapper<Instructions>().eq("device_type", deviceType)));
     }
 }

+ 8 - 2
src/main/java/com/zy/bms/entity/Instructions.java

@@ -2,11 +2,12 @@ package com.zy.bms.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
-import java.time.LocalDateTime;
-import java.io.Serializable;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.time.LocalDateTime;
+import java.io.Serializable;
+
 /**
  * 指令表
  *
@@ -32,6 +33,11 @@ public class Instructions implements Serializable {
      */
     private String remark;
 
+    /**
+     * 设备类型
+     */
+    private String deviceType;
+
     /**
      * 创建时间
      */

+ 5 - 0
src/main/java/com/zy/bms/entity/Logs.java

@@ -47,6 +47,11 @@ public class Logs {
      */
     private String m;
 
+    /**
+     * 设备类型￿
+     */
+    private String deviceType;
+
     /**
      * 创建时间
      */

+ 6 - 0
src/main/java/com/zy/bms/pojo/io/LogsIO.java

@@ -20,6 +20,12 @@ public class LogsIO extends PageIO {
      */
     private String openNum;
 
+
+    /**
+     * 设备类型
+     */
+    private String deviceType;
+
     /**
      * 指令
      */

+ 5 - 0
src/main/java/com/zy/bms/pojo/vo/LogsVo.java

@@ -42,6 +42,11 @@ public class LogsVo {
      */
     private String remark;
 
+    /**
+     * 设备类型
+     */
+    private String deviceType;
+
     /**
      * 创建时间
      */

+ 2 - 1
src/main/java/com/zy/bms/sender/CommonSender.java

@@ -24,7 +24,8 @@ public class CommonSender extends BaseSender {
         mqttDTO.put("regnum", device.getOpenNum())
                 .put("password", device.getPassword())
                 .put("group", device.getGroupId())
-                .put("sn", device.getSn());
+                .put("sn", device.getSn())
+                .put("type", device.getType());
         send(Constant.TOPIC.REGISTER_CLIENT, mqttDTO.json());
     }
 }

+ 0 - 1
src/main/java/com/zy/bms/service/ILogsService.java

@@ -3,7 +3,6 @@ package com.zy.bms.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zy.bms.entity.Logs;
-import com.zy.bms.pojo.dto.MqttDTO;
 import com.zy.bms.pojo.io.LogsIO;
 import com.zy.bms.pojo.vo.LogsVo;
 

+ 12 - 0
src/main/java/com/zy/bms/service/impl/LogsService.java

@@ -13,6 +13,8 @@ import com.zy.bms.service.ILogsService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.util.*;
+
 /**
  * MQTT 收发日志 Service
  *
@@ -23,6 +25,9 @@ import org.springframework.stereotype.Service;
 @Service
 public class LogsService extends ServiceImpl<LogsMapper, Logs> implements ILogsService {
 
+    private static final Set<String> UBI_SET = new HashSet<>(Arrays.asList("21", "23", "26", "27", "28", "29", "30", "80"));
+    private static final Set<String> LP_SET = new HashSet<>(Arrays.asList("70", "71", "72"));
+
     @Override
     public void saveReceive(String topic, String payload) {
         saveCommon(topic, payload, 0);
@@ -50,6 +55,13 @@ public class LogsService extends ServiceImpl<LogsMapper, Logs> implements ILogsS
         MqttDTO tmp = MqttDTO.parse(content);
         //创建日志对象
         Logs entity = Logs.builder().topic(topic).type(type).m(tmp.getM()).content(content).build();
+        if (UBI_SET.contains(tmp.getM())) {
+            entity.setDeviceType(Constant.DEVICE_TYPE.UBI);
+        } else if (LP_SET.contains(tmp.getM())) {
+            entity.setDeviceType(Constant.DEVICE_TYPE.LP);
+        } else {
+            entity.setDeviceType(tmp.getString("type"));
+        }
         String openNum = Constant.splitOpenNum(topic);
         entity.setOpenNum(openNum == null ? tmp.getString("regnum") : openNum);
         baseMapper.insert(entity);

+ 4 - 0
src/main/resources/mapper/LogsMapping.xml

@@ -8,6 +8,7 @@
             t1.type,
             t1.open_num,
             t1.content,
+            t1.device_type,
             t1.m,
             t1.create_time,
             t2.remark
@@ -21,6 +22,9 @@
             <if test="io.type != null and io.type > -1">
                 AND t1.type = #{io.type}
             </if>
+            <if test="io.deviceType != null and io.deviceType !=''">
+                AND t1.device_type = #{io.deviceType}
+            </if>
             <if test="io.m != null and io.m !=''">
                 AND t1.m = #{io.m}
             </if>