فهرست منبع

接收mqtt消息新增告警管理

tjf 1 هفته پیش
والد
کامیت
4f833cb67c

+ 9 - 15
ruoyi-admin/src/main/java/com/ruoyi/web/controller/manage/WarnManageController.java

@@ -1,31 +1,25 @@
 package com.ruoyi.web.controller.manage;
 
-import java.util.List;
-import javax.servlet.http.HttpServletResponse;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.manage.domain.WarnManage;
 import com.ruoyi.manage.service.IWarnManageService;
-import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.common.core.page.TableDataInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 
 /**
  * 告警管理Controller
  *
  * @author boman
- * @date 2025-05-07
+ * @date 2025-06-19
  */
 @RestController
 @RequestMapping("/manage/warnManage")

+ 7 - 5
ruoyi-admin/src/main/resources/application.yml

@@ -76,12 +76,14 @@ xss:
 
 # MQTT配置
 mqtt:
-  server-uri: tcp://13.229.167.76:1883
-  #  server-uri: tcp://127.0.0.1:1883
+#  server-uri: tcp://13.229.167.76:1883
+  server-uri: tcp://60.171.161.56:20009
+#  server-uri: tcp://192.168.101.147:1883
+#  server-uri: tcp://127.0.0.1:1883
   client-id: JavaClient
-  username:
-  password:
-  default-topic: test/topic
+  username: admin
+  password: 9o0p(O)P
+  default-topic: toServer_leaveStat,toServer_playStat
   default-qos: 1
   timeout: 30
   keep-alive: 60

+ 54 - 37
ruoyi-system/src/main/java/com/ruoyi/manage/domain/ChannelNumber.java

@@ -7,28 +7,40 @@ import javax.validation.constraints.NotNull;
 
 /**
  * 通道管理对象 channel_number
- * 
+ *
  * @author boman
  * @date 2025-05-07
  */
-public class ChannelNumber extends BaseEntity
-{
+public class ChannelNumber extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** 通道ID */
+    /**
+     * 通道ID
+     */
     private Long channelId;
-
-    /** 设备ID */
+    /**
+     * 设备Ip
+     */
+    private String equipmentIp;
+    /**
+     * 设备ID
+     */
     @NotNull
     private Long equipmentId;
-    /** 设备编号 */
+    /**
+     * 设备编号
+     */
     @Excel(name = "设备编号")
     private String equipmentNum;
 
-    /** 设备名称 */
+    /**
+     * 设备名称
+     */
     @Excel(name = "设备名称")
     private String equipmentName;
-    /** 通道编号 */
+    /**
+     * 通道编号
+     */
     @Excel(name = "通道编号")
     @NotNull
     private String channelNum;
@@ -38,7 +50,9 @@ public class ChannelNumber extends BaseEntity
      */
     private String port;
 
-    /** 视频地址 */
+    /**
+     * 视频地址
+     */
     @Excel(name = "视频地址")
     private String videoAddress;
     /**
@@ -50,15 +64,21 @@ public class ChannelNumber extends BaseEntity
      */
     private String password;
 
-    /** 探测协议类型 */
+    /**
+     * 探测协议类型
+     */
     @Excel(name = "探测协议类型")
     private String protocolType;
 
-    /** 通道描述 */
+    /**
+     * 通道描述
+     */
     @Excel(name = "通道描述")
     private String channelDetails;
 
-    /** 删除标志(0代表存在 1代表删除) */
+    /**
+     * 删除标志(0代表存在 1代表删除)
+     */
     private String delFlag;
     /**
      * 是否设置过参数 N Y 不在数据库中
@@ -70,6 +90,14 @@ public class ChannelNumber extends BaseEntity
      */
     private ParameterSet parameterSet;
 
+    public String getEquipmentIp() {
+        return equipmentIp;
+    }
+
+    public void setEquipmentIp(String equipmentIp) {
+        this.equipmentIp = equipmentIp;
+    }
+
     public ParameterSet getParameterSet() {
         return parameterSet;
     }
@@ -134,63 +162,51 @@ public class ChannelNumber extends BaseEntity
         this.password = password;
     }
 
-    public void setChannelId(Long channelId)
-    {
+    public void setChannelId(Long channelId) {
         this.channelId = channelId;
     }
 
-    public Long getChannelId() 
-    {
+    public Long getChannelId() {
         return channelId;
     }
 
-    public void setChannelNum(String channelNum) 
-    {
+    public void setChannelNum(String channelNum) {
         this.channelNum = channelNum;
     }
 
-    public String getChannelNum() 
-    {
+    public String getChannelNum() {
         return channelNum;
     }
 
-    public void setVideoAddress(String videoAddress) 
-    {
+    public void setVideoAddress(String videoAddress) {
         this.videoAddress = videoAddress;
     }
 
-    public String getVideoAddress() 
-    {
+    public String getVideoAddress() {
         return videoAddress;
     }
 
-    public void setProtocolType(String protocolType) 
-    {
+    public void setProtocolType(String protocolType) {
         this.protocolType = protocolType;
     }
 
-    public String getProtocolType() 
-    {
+    public String getProtocolType() {
         return protocolType;
     }
 
-    public void setChannelDetails(String channelDetails) 
-    {
+    public void setChannelDetails(String channelDetails) {
         this.channelDetails = channelDetails;
     }
 
-    public String getChannelDetails() 
-    {
+    public String getChannelDetails() {
         return channelDetails;
     }
 
-    public void setDelFlag(String delFlag) 
-    {
+    public void setDelFlag(String delFlag) {
         this.delFlag = delFlag;
     }
 
-    public String getDelFlag() 
-    {
+    public String getDelFlag() {
         return delFlag;
     }
 
@@ -198,6 +214,7 @@ public class ChannelNumber extends BaseEntity
     public String toString() {
         return "ChannelNumber{" +
                 "channelId=" + channelId +
+                ", equipmentIp='" + equipmentIp + '\'' +
                 ", equipmentId=" + equipmentId +
                 ", equipmentNum='" + equipmentNum + '\'' +
                 ", equipmentName='" + equipmentName + '\'' +

+ 24 - 20
ruoyi-system/src/main/java/com/ruoyi/manage/domain/EquipmentManage.java

@@ -3,8 +3,6 @@ package com.ruoyi.manage.domain;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 
 import javax.validation.constraints.NotNull;
 import java.util.Date;
@@ -21,6 +19,8 @@ public class EquipmentManage extends BaseEntity
 
     /** 设备ID */
     private Long equipmentId;
+    /** 设备Ip */
+    private String equipmentIp;
 
     /** 设备编号 */
     @Excel(name = "设备编号")
@@ -59,7 +59,15 @@ public class EquipmentManage extends BaseEntity
     /** 删除标志(0代表存在 1代表删除) */
     private String delFlag;
 
-    public void setEquipmentId(Long equipmentId) 
+    public String getEquipmentIp() {
+        return equipmentIp;
+    }
+
+    public void setEquipmentIp(String equipmentIp) {
+        this.equipmentIp = equipmentIp;
+    }
+
+    public void setEquipmentId(Long equipmentId)
     {
         this.equipmentId = equipmentId;
     }
@@ -161,22 +169,18 @@ public class EquipmentManage extends BaseEntity
 
     @Override
     public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("equipmentId", getEquipmentId())
-            .append("equipmentNum", getEquipmentNum())
-            .append("equipmentName", getEquipmentName())
-            .append("equipmentType", getEquipmentType())
-            .append("equipmentAddress", getEquipmentAddress())
-            .append("equipmentRegion", getEquipmentRegion())
-            .append("equipmentTime", getEquipmentTime())
-            .append("equipmentImage", getEquipmentImage())
-            .append("runState", getRunState())
-            .append("delFlag", getDelFlag())
-            .append("createBy", getCreateBy())
-            .append("createTime", getCreateTime())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
-            .append("remark", getRemark())
-            .toString();
+        return "EquipmentManage{" +
+                "equipmentId=" + equipmentId +
+                ", equipmentIp='" + equipmentIp + '\'' +
+                ", equipmentNum='" + equipmentNum + '\'' +
+                ", equipmentName='" + equipmentName + '\'' +
+                ", equipmentType='" + equipmentType + '\'' +
+                ", equipmentAddress='" + equipmentAddress + '\'' +
+                ", equipmentRegion='" + equipmentRegion + '\'' +
+                ", equipmentTime=" + equipmentTime +
+                ", equipmentImage='" + equipmentImage + '\'' +
+                ", runState='" + runState + '\'' +
+                ", delFlag='" + delFlag + '\'' +
+                '}';
     }
 }

+ 74 - 44
ruoyi-system/src/main/java/com/ruoyi/manage/domain/WarnManage.java

@@ -12,7 +12,7 @@ import java.util.Date;
  * 告警管理对象 warn_manage
  * 
  * @author boman
- * @date 2025-05-07
+ * @date 2025-06-19
  */
 public class WarnManage extends BaseEntity
 {
@@ -21,28 +21,40 @@ public class WarnManage extends BaseEntity
     /** 告警ID */
     private Long warnId;
 
-    /** 告警类别 */
-    @Excel(name = "告警类别")
-    private String warnType;
+    /** 设备ip */
+    @Excel(name = "设备ip")
+    private String equipmentIp;
 
-    /** 告警标识 */
-    @Excel(name = "告警标识")
-    private String warnSign;
+    /** 设备名称 */
+    @Excel(name = "设备名称")
+    private String equipmentName;
 
     /** 通道ID */
     @Excel(name = "通道ID")
     private Long channelId;
 
-    /** 视频地址 */
-    @Excel(name = "视频地址")
+    /** 通道编号 */
+    @Excel(name = "通道编号")
+    private String channelNum;
+
+    /** 算法类型 0:离岗 1:玩手机 */
+    @Excel(name = "算法类型 0:离岗 1:玩手机")
+    private String algorithmType;
+
+    /** 算法参数设置的值 */
+    @Excel(name = "算法参数设置的值")
+    private String parameterSet;
+
+    /** 告警视频地址 */
+    @Excel(name = "告警视频地址")
     private String videoAddress;
 
-    /** 上报地址 */
-    @Excel(name = "上报地址")
-    private String reportAddress;
+    /** 告警预览图片 */
+    @Excel(name = "告警预览图片")
+    private String warnImage;
 
-    /** 上报状态 */
-    @Excel(name = "上报状态")
+    /** 上报状态 0:成功 1:失败 */
+    @Excel(name = "上报状态 0:成功 1:失败")
     private String reportStatus;
 
     /** 告警时间 */
@@ -50,10 +62,6 @@ public class WarnManage extends BaseEntity
     @Excel(name = "告警时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date warnTime;
 
-    /** 告警预览图片 */
-    @Excel(name = "告警预览图片")
-    private String warnImage;
-
     /** 删除标志(0代表存在 1代表删除) */
     private String delFlag;
 
@@ -67,24 +75,24 @@ public class WarnManage extends BaseEntity
         return warnId;
     }
 
-    public void setWarnType(String warnType) 
+    public void setEquipmentIp(String equipmentIp) 
     {
-        this.warnType = warnType;
+        this.equipmentIp = equipmentIp;
     }
 
-    public String getWarnType() 
+    public String getEquipmentIp() 
     {
-        return warnType;
+        return equipmentIp;
     }
 
-    public void setWarnSign(String warnSign) 
+    public void setEquipmentName(String equipmentName) 
     {
-        this.warnSign = warnSign;
+        this.equipmentName = equipmentName;
     }
 
-    public String getWarnSign() 
+    public String getEquipmentName() 
     {
-        return warnSign;
+        return equipmentName;
     }
 
     public void setChannelId(Long channelId) 
@@ -97,6 +105,36 @@ public class WarnManage extends BaseEntity
         return channelId;
     }
 
+    public void setChannelNum(String channelNum) 
+    {
+        this.channelNum = channelNum;
+    }
+
+    public String getChannelNum() 
+    {
+        return channelNum;
+    }
+
+    public void setAlgorithmType(String algorithmType) 
+    {
+        this.algorithmType = algorithmType;
+    }
+
+    public String getAlgorithmType() 
+    {
+        return algorithmType;
+    }
+
+    public void setParameterSet(String parameterSet) 
+    {
+        this.parameterSet = parameterSet;
+    }
+
+    public String getParameterSet() 
+    {
+        return parameterSet;
+    }
+
     public void setVideoAddress(String videoAddress) 
     {
         this.videoAddress = videoAddress;
@@ -107,14 +145,14 @@ public class WarnManage extends BaseEntity
         return videoAddress;
     }
 
-    public void setReportAddress(String reportAddress) 
+    public void setWarnImage(String warnImage) 
     {
-        this.reportAddress = reportAddress;
+        this.warnImage = warnImage;
     }
 
-    public String getReportAddress() 
+    public String getWarnImage() 
     {
-        return reportAddress;
+        return warnImage;
     }
 
     public void setReportStatus(String reportStatus) 
@@ -137,16 +175,6 @@ public class WarnManage extends BaseEntity
         return warnTime;
     }
 
-    public void setWarnImage(String warnImage) 
-    {
-        this.warnImage = warnImage;
-    }
-
-    public String getWarnImage() 
-    {
-        return warnImage;
-    }
-
     public void setDelFlag(String delFlag) 
     {
         this.delFlag = delFlag;
@@ -161,14 +189,16 @@ public class WarnManage extends BaseEntity
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
             .append("warnId", getWarnId())
-            .append("warnType", getWarnType())
-            .append("warnSign", getWarnSign())
+            .append("equipmentIp", getEquipmentIp())
+            .append("equipmentName", getEquipmentName())
             .append("channelId", getChannelId())
+            .append("channelNum", getChannelNum())
+            .append("algorithmType", getAlgorithmType())
+            .append("parameterSet", getParameterSet())
             .append("videoAddress", getVideoAddress())
-            .append("reportAddress", getReportAddress())
+            .append("warnImage", getWarnImage())
             .append("reportStatus", getReportStatus())
             .append("warnTime", getWarnTime())
-            .append("warnImage", getWarnImage())
             .append("delFlag", getDelFlag())
             .append("createBy", getCreateBy())
             .append("createTime", getCreateTime())

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/manage/mapper/WarnManageMapper.java

@@ -8,7 +8,7 @@ import java.util.List;
  * 告警管理Mapper接口
  * 
  * @author boman
- * @date 2025-05-07
+ * @date 2025-06-19
  */
 public interface WarnManageMapper 
 {

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/manage/service/IWarnManageService.java

@@ -8,7 +8,7 @@ import java.util.List;
  * 告警管理Service接口
  * 
  * @author boman
- * @date 2025-05-07
+ * @date 2025-06-19
  */
 public interface IWarnManageService 
 {

+ 15 - 4
ruoyi-system/src/main/java/com/ruoyi/manage/service/impl/ChannelNumberServiceImpl.java

@@ -4,8 +4,10 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.manage.domain.ChannelNumber;
+import com.ruoyi.manage.domain.EquipmentManage;
 import com.ruoyi.manage.domain.ParameterSet;
 import com.ruoyi.manage.mapper.ChannelNumberMapper;
+import com.ruoyi.manage.mapper.EquipmentManageMapper;
 import com.ruoyi.manage.mapper.ParameterSetMapper;
 import com.ruoyi.manage.service.IChannelNumberService;
 import com.ruoyi.mqtt.service.MqttService;
@@ -34,6 +36,8 @@ public class ChannelNumberServiceImpl implements IChannelNumberService {
 
     @Autowired
     private ParameterSetMapper parameterSetMapper;
+    @Autowired
+    private EquipmentManageMapper equipmentManageMapper;
 
     @Autowired
     private MqttService mqttService;
@@ -54,6 +58,11 @@ public class ChannelNumberServiceImpl implements IChannelNumberService {
             channelNumber.setIsChannel(Y);
             channelNumber.setParameterSet(parameterSet);
         }
+        Long equipmentId = channelNumber.getEquipmentId();
+        EquipmentManage equipmentManage = equipmentManageMapper.selectEquipmentManageByEquipmentId(equipmentId);
+        if (equipmentManage != null) {
+            channelNumber.setEquipmentIp(equipmentManage.getEquipmentIp());
+        }
         return channelNumber;
     }
 
@@ -80,17 +89,18 @@ public class ChannelNumberServiceImpl implements IChannelNumberService {
         if (channelNumberOld != null) {
             return AjaxResult.error("设备已存在当前通道编号");
         }
+        channelNumber.setCreateTime(DateUtils.getNowDate());
+        channelNumberMapper.insertChannelNumber(channelNumber);
+        Long channelId = channelNumber.getChannelId();
         String videoAddress = channelNumber.getVideoAddress();
         if (StringUtils.isNotEmpty(videoAddress)) {
             try {
-                CompletableFuture<Void> future = mqttService.publish(DETECTION_RTSP, videoAddress);
+                CompletableFuture<Void> future = mqttService.publish(DETECTION_RTSP, channelId + "_" + videoAddress);
                 future.get(10, TimeUnit.SECONDS);
             } catch (InterruptedException | ExecutionException | TimeoutException e) {
                 return AjaxResult.error("发布消息失败:" + DETECTION_RTSP);
             }
         }
-        channelNumber.setCreateTime(DateUtils.getNowDate());
-        channelNumberMapper.insertChannelNumber(channelNumber);
         return AjaxResult.success();
     }
 
@@ -102,6 +112,7 @@ public class ChannelNumberServiceImpl implements IChannelNumberService {
      */
     @Override
     public AjaxResult updateChannelNumber(ChannelNumber channelNumber) {
+        Long channelId = channelNumber.getChannelId();
         ChannelNumber channelNumberOld = channelNumberMapper.selectChannelNumberByChannelNum(channelNumber);
         if (channelNumberOld != null && !channelNumber.getChannelId().equals(channelNumberOld.getChannelId())) {
             return AjaxResult.error("设备已存在当前通道编号");
@@ -109,7 +120,7 @@ public class ChannelNumberServiceImpl implements IChannelNumberService {
         String videoAddress = channelNumber.getVideoAddress();
         if (StringUtils.isNotEmpty(videoAddress)) {
             try {
-                CompletableFuture<Void> future = mqttService.publish(DETECTION_RTSP, videoAddress);
+                CompletableFuture<Void> future = mqttService.publish(DETECTION_RTSP, channelId + "_" + videoAddress);
                 future.get(10, TimeUnit.SECONDS);
             } catch (InterruptedException | ExecutionException | TimeoutException e) {
                 return AjaxResult.error("发布消息失败:" + DETECTION_RTSP);

+ 6 - 5
ruoyi-system/src/main/java/com/ruoyi/manage/service/impl/ParameterSetServiceImpl.java

@@ -77,6 +77,7 @@ public class ParameterSetServiceImpl implements IParameterSetService {
 
     //校验是否需要下发参数
     public AjaxResult checkParameter(ParameterSet parameterSet) {
+        Long channelId = parameterSet.getChannelId();
         //下发指令
         String channelRange = parameterSet.getChannelRange();
         String leaveTime = parameterSet.getLeaveTime();
@@ -85,35 +86,35 @@ public class ParameterSetServiceImpl implements IParameterSetService {
         String playRate = parameterSet.getPlayRate();
         if (StringUtils.isNotEmpty(channelRange)) {
             try {
-                CompletableFuture<Void> future = mqttService.publish(DETECTION_RECT, channelRange);
+                CompletableFuture<Void> future = mqttService.publish(DETECTION_RECT, channelId+"_"+channelRange);
                 future.get(10, TimeUnit.SECONDS);
             } catch (InterruptedException | ExecutionException | TimeoutException e) {
                 return AjaxResult.error("发布消息失败:" + DETECTION_RECT);
             }
         } else if (StringUtils.isNotEmpty(leaveTime)) {
             try {
-                CompletableFuture<Void> future = mqttService.publish(DETECTION_LEAVETIME, leaveTime);
+                CompletableFuture<Void> future = mqttService.publish(DETECTION_LEAVETIME, channelId+"_"+leaveTime);
                 future.get(10, TimeUnit.SECONDS);
             } catch (InterruptedException | ExecutionException | TimeoutException e) {
                 return AjaxResult.error("发布消息失败:" + DETECTION_LEAVETIME);
             }
         } else if (StringUtils.isNotEmpty(playTime)) {
             try {
-                CompletableFuture<Void> future = mqttService.publish(DETECTION_PLAYTIME, playTime);
+                CompletableFuture<Void> future = mqttService.publish(DETECTION_PLAYTIME, channelId+"_"+playTime);
                 future.get(10, TimeUnit.SECONDS);
             } catch (InterruptedException | ExecutionException | TimeoutException e) {
                 return AjaxResult.error("发布消息失败:" + DETECTION_PLAYTIME);
             }
         } else if (StringUtils.isNotEmpty(leaveRate)) {
             try {
-                CompletableFuture<Void> future = mqttService.publish(DETECTION_LEAVERATE, leaveRate);
+                CompletableFuture<Void> future = mqttService.publish(DETECTION_LEAVERATE, channelId+"_"+leaveRate);
                 future.get(10, TimeUnit.SECONDS);
             } catch (InterruptedException | ExecutionException | TimeoutException e) {
                 return AjaxResult.error("发布消息失败:" + DETECTION_LEAVERATE);
             }
         } else if (StringUtils.isNotEmpty(playRate)) {
             try {
-                CompletableFuture<Void> future = mqttService.publish(DETECTION_PLAYRATE, playRate);
+                CompletableFuture<Void> future = mqttService.publish(DETECTION_PLAYRATE, channelId+"_"+playRate);
                 future.get(10, TimeUnit.SECONDS);
             } catch (InterruptedException | ExecutionException | TimeoutException e) {
                 return AjaxResult.error("发布消息失败:" + DETECTION_PLAYRATE);

+ 29 - 1
ruoyi-system/src/main/java/com/ruoyi/manage/service/impl/WarnManageServiceImpl.java

@@ -1,5 +1,7 @@
 package com.ruoyi.manage.service.impl;
 
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.model.MqttMessage;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.manage.domain.WarnManage;
 import com.ruoyi.manage.mapper.WarnManageMapper;
@@ -13,7 +15,7 @@ import java.util.List;
  * 告警管理Service业务层处理
  * 
  * @author boman
- * @date 2025-05-07
+ * @date 2025-06-19
  */
 @Service
 public class WarnManageServiceImpl implements IWarnManageService 
@@ -94,4 +96,30 @@ public class WarnManageServiceImpl implements IWarnManageService
     {
         return warnManageMapper.deleteWarnManageByWarnId(warnId);
     }
+
+    /**
+     * 算法回调新增告警信息
+     * @param message
+     */
+    public void addWarnManage(MqttMessage message,String algorithmType){
+        String payload = message.getPayload();
+        JSONObject jsonObject = JSONObject.parseObject(payload);
+        String equipmentIp = jsonObject.getString("equipmentIp");
+        Long channelId = jsonObject.getLong("channelId");
+        String parameterSet = jsonObject.getString("parameterSet");
+        String algorithmResult = jsonObject.getString("algorithmResult");
+        String photoUrl = jsonObject.getString("photoUrl");
+        String videoUrl = jsonObject.getString("videoUrl");
+        WarnManage warnManage = new WarnManage();
+        warnManage.setEquipmentIp(equipmentIp);
+        warnManage.setChannelId(channelId);
+        warnManage.setParameterSet(parameterSet);
+        warnManage.setAlgorithmType(algorithmType);
+        warnManage.setReportStatus(algorithmResult);
+        warnManage.setVideoAddress(videoUrl);
+        warnManage.setWarnImage(photoUrl);
+        warnManage.setCreateTime(DateUtils.getNowDate());
+        warnManage.setWarnTime(DateUtils.getNowDate());
+        warnManageMapper.insertWarnManage(warnManage);
+    }
 }

+ 31 - 3
ruoyi-system/src/main/java/com/ruoyi/mqtt/service/MqttMessageListener.java

@@ -1,7 +1,9 @@
 package com.ruoyi.mqtt.service;
 
 import com.ruoyi.common.model.MqttMessage;
+import com.ruoyi.manage.service.impl.WarnManageServiceImpl;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.event.EventListener;
 import org.springframework.stereotype.Component;
 
@@ -19,6 +21,10 @@ import org.springframework.stereotype.Component;
 @Component
 public class MqttMessageListener {
 
+    @Autowired
+    private WarnManageServiceImpl warnManageService;
+
+
     /**
      * 处理接收到的MQTT消息
      *
@@ -27,18 +33,40 @@ public class MqttMessageListener {
     @EventListener
     public void handleMqttMessage(MqttMessage message) {
         log.info("收到MQTT消息事件: 主题={}, 消息内容={}", message.getTopic(), message.getPayload());
-
         // TODO: 添加自定义的业务逻辑来处理消息
+        /**
+         * 返回值为
+         {
+         "equipmentIp":"设备ip",
+        "channelId":"通道ID",
+          "parameterSet":"当前参数设置的值",
+         "algorithmType":"算法类型",
+         "algorithmResult":"算法结果  是否离岗(手机)0:正常 1:异常",
+          "photoUrl":"算法截图URL",
+          "videoUrl":"违规视频URL"
+         }
+         */
+        if(message.getTopic().equals("toServer_leaveStat")){
+            //插入告警信息
+            warnManageService.addWarnManage(message,"0");
+        }
+        else if(message.getTopic().equals("toServer_playStat")){
+            //插入告警信息
+            warnManageService.addWarnManage(message,"1");
+        }
+
         // 例如:解析JSON消息内容,更新数据库,触发其他操作等
 
-        // 可以根据主题进行不同的处理
+/*        // 可以根据主题进行不同的处理
         if (message.getTopic().startsWith("device/")) {
             handleDeviceMessage(message);
         } else if (message.getTopic().startsWith("alert/")) {
             handleAlertMessage(message);
-        }
+        }*/
     }
 
+
+
     /**
      * 处理设备相关消息
      *

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/mqtt/service/MqttService.java

@@ -42,7 +42,8 @@ public class MqttService {
         // 如果配置了默认主题,则自动订阅
         if (mqttProperties.getDefaultTopic() != null && !mqttProperties.getDefaultTopic().isEmpty()) {
             try {
-                subscribe(mqttProperties.getDefaultTopic());
+                List<String> topics = Arrays.asList(mqttProperties.getDefaultTopic().split(","));
+                subscribe(topics);
                 log.info("已自动订阅默认主题: {}", mqttProperties.getDefaultTopic());
             } catch (MqttException e) {
                 log.error("自动订阅默认主题失败: {}", e.getMessage(), e);

+ 22 - 1
ruoyi-system/src/main/resources/mapper/manage/EquipmentManageMapper.xml

@@ -6,6 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     
     <resultMap type="EquipmentManage" id="EquipmentManageResult">
         <result property="equipmentId"    column="equipment_id"    />
+        <result property="equipmentIp"    column="equipment_ip"    />
         <result property="equipmentNum"    column="equipment_num"    />
         <result property="equipmentName"    column="equipment_name"    />
         <result property="equipmentType"    column="equipment_type"    />
@@ -23,13 +24,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectEquipmentManageVo">
-        select equipment_id, equipment_num, equipment_name, equipment_type, equipment_address, equipment_region, equipment_time, equipment_image, run_state, del_flag, create_by, create_time, update_by, update_time, remark from equipment_manage
+        select equipment_id,
+               equipment_ip,
+               equipment_num,
+               equipment_name,
+               equipment_type,
+               equipment_address,
+               equipment_region,
+               equipment_time,
+               equipment_image,
+               run_state,
+               del_flag,
+               create_by,
+               create_time,
+               update_by,
+               update_time,
+               remark
+        from equipment_manage
     </sql>
 
     <select id="selectEquipmentManageList" parameterType="EquipmentManage" resultMap="EquipmentManageResult">
         <include refid="selectEquipmentManageVo"/>
         <where>  
             <if test="equipmentNum != null  and equipmentNum != ''"> and equipment_num  like concat('%', #{equipmentNum}, '%')</if>
+            <if test="equipmentIp != null  and equipmentIp != ''"> and equipment_id  like concat('%', #{equipmentIp}, '%')</if>
             <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
             <if test="equipmentType != null  and equipmentType != ''"> and equipment_type = #{equipmentType}</if>
             <if test="equipmentAddress != null  and equipmentAddress != ''"> and equipment_address = #{equipmentAddress}</if>
@@ -54,6 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <insert id="insertEquipmentManage" parameterType="EquipmentManage" useGeneratedKeys="true" keyProperty="equipmentId">
         insert into equipment_manage
         <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="equipmentIp != null">equipment_ip,</if>
             <if test="equipmentNum != null">equipment_num,</if>
             <if test="equipmentName != null">equipment_name,</if>
             <if test="equipmentType != null">equipment_type,</if>
@@ -70,6 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="remark != null">remark,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="equipmentIp != null">#{equipmentIp},</if>
             <if test="equipmentNum != null">#{equipmentNum},</if>
             <if test="equipmentName != null">#{equipmentName},</if>
             <if test="equipmentType != null">#{equipmentType},</if>
@@ -90,6 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <update id="updateEquipmentManage" parameterType="EquipmentManage">
         update equipment_manage
         <trim prefix="SET" suffixOverrides=",">
+            <if test="equipmentIp != null">equipment_ip = #{equipmentIp},</if>
             <if test="equipmentNum != null">equipment_num = #{equipmentNum},</if>
             <if test="equipmentName != null">equipment_name = #{equipmentName},</if>
             <if test="equipmentType != null">equipment_type = #{equipmentType},</if>

+ 31 - 21
ruoyi-system/src/main/resources/mapper/manage/WarnManageMapper.xml

@@ -6,14 +6,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     
     <resultMap type="WarnManage" id="WarnManageResult">
         <result property="warnId"    column="warn_id"    />
-        <result property="warnType"    column="warn_type"    />
-        <result property="warnSign"    column="warn_sign"    />
+        <result property="equipmentIp"    column="equipment_ip"    />
+        <result property="equipmentName"    column="equipment_name"    />
         <result property="channelId"    column="channel_id"    />
+        <result property="channelNum"    column="channel_num"    />
+        <result property="algorithmType"    column="algorithm_type"    />
+        <result property="parameterSet"    column="parameter_set"    />
         <result property="videoAddress"    column="video_address"    />
-        <result property="reportAddress"    column="report_address"    />
+        <result property="warnImage"    column="warn_image"    />
         <result property="reportStatus"    column="report_status"    />
         <result property="warnTime"    column="warn_time"    />
-        <result property="warnImage"    column="warn_image"    />
         <result property="delFlag"    column="del_flag"    />
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
@@ -23,20 +25,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectWarnManageVo">
-        select warn_id, warn_type, warn_sign, channel_id, video_address, report_address, report_status, warn_time, warn_image, del_flag, create_by, create_time, update_by, update_time, remark from warn_manage
+        select warn_id, equipment_ip, equipment_name, channel_id, channel_num, algorithm_type, parameter_set, video_address, warn_image, report_status, warn_time, del_flag, create_by, create_time, update_by, update_time, remark from warn_manage
     </sql>
 
     <select id="selectWarnManageList" parameterType="WarnManage" resultMap="WarnManageResult">
         <include refid="selectWarnManageVo"/>
         <where>  
-            <if test="warnType != null  and warnType != ''"> and warn_type = #{warnType}</if>
-            <if test="warnSign != null  and warnSign != ''"> and warn_sign = #{warnSign}</if>
+            <if test="equipmentIp != null  and equipmentIp != ''"> and equipment_ip = #{equipmentIp}</if>
+            <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
             <if test="channelId != null "> and channel_id = #{channelId}</if>
+            <if test="channelNum != null  and channelNum != ''"> and channel_num = #{channelNum}</if>
+            <if test="algorithmType != null  and algorithmType != ''"> and algorithm_type = #{algorithmType}</if>
+            <if test="parameterSet != null  and parameterSet != ''"> and parameter_set = #{parameterSet}</if>
             <if test="videoAddress != null  and videoAddress != ''"> and video_address = #{videoAddress}</if>
-            <if test="reportAddress != null  and reportAddress != ''"> and report_address = #{reportAddress}</if>
+            <if test="warnImage != null  and warnImage != ''"> and warn_image = #{warnImage}</if>
             <if test="reportStatus != null  and reportStatus != ''"> and report_status = #{reportStatus}</if>
             <if test="warnTime != null "> and warn_time = #{warnTime}</if>
-            <if test="warnImage != null  and warnImage != ''"> and warn_image = #{warnImage}</if>
         </where>
     </select>
     
@@ -48,14 +52,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <insert id="insertWarnManage" parameterType="WarnManage" useGeneratedKeys="true" keyProperty="warnId">
         insert into warn_manage
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="warnType != null">warn_type,</if>
-            <if test="warnSign != null">warn_sign,</if>
+            <if test="equipmentIp != null and equipmentIp != ''">equipment_ip,</if>
+            <if test="equipmentName != null and equipmentName != ''">equipment_name,</if>
             <if test="channelId != null">channel_id,</if>
+            <if test="channelNum != null and channelNum != ''">channel_num,</if>
+            <if test="algorithmType != null and algorithmType != ''">algorithm_type,</if>
+            <if test="parameterSet != null and parameterSet != ''">parameter_set,</if>
             <if test="videoAddress != null">video_address,</if>
-            <if test="reportAddress != null">report_address,</if>
+            <if test="warnImage != null">warn_image,</if>
             <if test="reportStatus != null">report_status,</if>
             <if test="warnTime != null">warn_time,</if>
-            <if test="warnImage != null">warn_image,</if>
             <if test="delFlag != null">del_flag,</if>
             <if test="createBy != null">create_by,</if>
             <if test="createTime != null">create_time,</if>
@@ -64,14 +70,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="remark != null">remark,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="warnType != null">#{warnType},</if>
-            <if test="warnSign != null">#{warnSign},</if>
+            <if test="equipmentIp != null and equipmentIp != ''">#{equipmentIp},</if>
+            <if test="equipmentName != null and equipmentName != ''">#{equipmentName},</if>
             <if test="channelId != null">#{channelId},</if>
+            <if test="channelNum != null and channelNum != ''">#{channelNum},</if>
+            <if test="algorithmType != null and algorithmType != ''">#{algorithmType},</if>
+            <if test="parameterSet != null and parameterSet != ''">#{parameterSet},</if>
             <if test="videoAddress != null">#{videoAddress},</if>
-            <if test="reportAddress != null">#{reportAddress},</if>
+            <if test="warnImage != null">#{warnImage},</if>
             <if test="reportStatus != null">#{reportStatus},</if>
             <if test="warnTime != null">#{warnTime},</if>
-            <if test="warnImage != null">#{warnImage},</if>
             <if test="delFlag != null">#{delFlag},</if>
             <if test="createBy != null">#{createBy},</if>
             <if test="createTime != null">#{createTime},</if>
@@ -84,14 +92,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <update id="updateWarnManage" parameterType="WarnManage">
         update warn_manage
         <trim prefix="SET" suffixOverrides=",">
-            <if test="warnType != null">warn_type = #{warnType},</if>
-            <if test="warnSign != null">warn_sign = #{warnSign},</if>
+            <if test="equipmentIp != null and equipmentIp != ''">equipment_ip = #{equipmentIp},</if>
+            <if test="equipmentName != null and equipmentName != ''">equipment_name = #{equipmentName},</if>
             <if test="channelId != null">channel_id = #{channelId},</if>
+            <if test="channelNum != null and channelNum != ''">channel_num = #{channelNum},</if>
+            <if test="algorithmType != null and algorithmType != ''">algorithm_type = #{algorithmType},</if>
+            <if test="parameterSet != null and parameterSet != ''">parameter_set = #{parameterSet},</if>
             <if test="videoAddress != null">video_address = #{videoAddress},</if>
-            <if test="reportAddress != null">report_address = #{reportAddress},</if>
+            <if test="warnImage != null">warn_image = #{warnImage},</if>
             <if test="reportStatus != null">report_status = #{reportStatus},</if>
             <if test="warnTime != null">warn_time = #{warnTime},</if>
-            <if test="warnImage != null">warn_image = #{warnImage},</if>
             <if test="delFlag != null">del_flag = #{delFlag},</if>
             <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>