Browse Source

相机树开发

gao.qiang 2 months ago
parent
commit
628f23d510

+ 4 - 0
business-service/src/main/java/com/ozs/service/entity/BaseDeviceDynamicManagement.java

@@ -74,5 +74,9 @@ public class BaseDeviceDynamicManagement extends BaseEntity implements Serializa
      * 相机状态(1在线2离线)
      */
     private Integer isDisable;
+    /**
+     * 最后一次心跳时间
+     */
+    private Date heartTime;
 
 }

+ 4 - 2
business-service/src/main/java/com/ozs/service/entity/vo/DeviceStateResp.java

@@ -41,11 +41,13 @@ public class DeviceStateResp extends PageVo implements Serializable {
     @Excel(name = "序列号")
     private String cameraSn;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
-    private Date updateTime;
+    @Excel(name = "最新的心跳时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date heartTime;
     @Excel(name = "线路类型",readConverterExp = "1=高铁,2=普铁")
     private Integer railwayType;
     private String railwayCode;
     private String deptId;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
 
 }

+ 19 - 2
business-service/src/main/java/com/ozs/service/service/impl/MqLogServiceImpl.java

@@ -1,11 +1,18 @@
 package com.ozs.service.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.ozs.service.entity.BaseDeviceDynamicManagement;
 import com.ozs.service.entity.MqLog;
+import com.ozs.service.mapper.BaseDeviceDynamicManagementMapper;
 import com.ozs.service.mapper.MqLogMapper;
 import com.ozs.service.service.MqLogService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
 
 /**
  * <p>
@@ -18,12 +25,22 @@ import org.springframework.stereotype.Service;
 @Service
 public class MqLogServiceImpl extends ServiceImpl<MqLogMapper, MqLog> implements MqLogService {
     @Autowired
-    MqLogMapper mqLogMapper;
+    private MqLogMapper mqLogMapper;
+    @Autowired
+    private BaseDeviceDynamicManagementMapper baseDeviceDynamicManagementMapper;
 
     @Override
+    @Transactional
     public void insetHeartLog(String cameraCode) {
         MqLog mqLog = new MqLog();
         mqLog.setCameraCode(cameraCode);
-        mqLogMapper.insert(mqLog);
+        int insert = mqLogMapper.insert(mqLog);
+        if (insert > 0) {
+            // 使用 LambdaUpdateWrapper进行更新
+            LambdaUpdateWrapper<BaseDeviceDynamicManagement> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.eq(BaseDeviceDynamicManagement::getCameraCode, cameraCode)
+                    .set(BaseDeviceDynamicManagement::getHeartTime, new Date());
+            baseDeviceDynamicManagementMapper.update(null, updateWrapper);
+        }
     }
 }

+ 3 - 2
business-service/src/main/resources/mapper/service/BaseCameraManagementMapper.xml

@@ -150,7 +150,8 @@
         man.electricity,
         ca.camera_code AS cameraCode,
         ca.camera_sn AS cameraSn,
-        man.update_time AS updateTime
+        man.update_time AS updateTime,
+        man.heart_time AS heartTime
         FROM
         base_camera_management AS ca
         LEFT JOIN base_railway_management AS ra ON ca.railway_code = ra.railway_code
@@ -194,7 +195,7 @@
             </if>
         </where>
         ORDER BY man.is_disable DESC,
-        man.update_time DESC
+        man.heart_time DESC
     </select>
     <select id="alarmCountSort" resultType="com.ozs.service.entity.vo.AlarmCountSortVo">
         SELECT COUNT(m.camera_code) AS cameraCount,c.camera_code AS cameraCode,c.measure_point_name AS measurePointName