From 56062b177a71cf781f8e480c0ec6f5e8394e7a8e Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Thu, 16 Oct 2025 14:51:29 +0800
Subject: [PATCH] 1.修改服务器状态接口优化。 2.无人机盒子对象增加盒子别名字段。 3.动态修改服务状态。

---
 ard-work/src/main/java/com/ard/work/mapper/ArdServerInfoMapper.java              |    3 +
 ard-work/src/main/java/com/ard/work/domain/entity/ArdDroneInfo.java              |    7 +++
 ard-work/src/main/java/com/ard/work/service/impl/ArdDroneInfoServiceImpl.java    |   10 +----
 ard-work/src/main/resources/mapper/ArdServerInfoMapper.xml                       |    6 +-
 ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java      |    6 +++
 ard-work/src/main/java/com/ard/work/service/impl/ArdServerInfoServiceImpl.java   |    4 +-
 ard-admin/src/main/java/com/ard/web/controller/work/ArdServerInfoController.java |    6 +-
 ard-work/src/main/java/com/ard/work/domain/entity/ArdServerInfo.java             |    8 +++-
 ard-work/src/main/resources/mapper/ArdDroneInfoMapper.xml                        |   33 ++++++++++------
 ard-work/src/main/java/com/ard/work/service/IArdServerInfoService.java           |    2 
 10 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/ard-admin/src/main/java/com/ard/web/controller/work/ArdServerInfoController.java b/ard-admin/src/main/java/com/ard/web/controller/work/ArdServerInfoController.java
index 1f616a4..8a531ba 100644
--- a/ard-admin/src/main/java/com/ard/web/controller/work/ArdServerInfoController.java
+++ b/ard-admin/src/main/java/com/ard/web/controller/work/ArdServerInfoController.java
@@ -112,9 +112,9 @@
     @ApiOperation("修改服务器状态")
     @PreAuthorize("@ss.hasPermi('work:server:updateStatus')")
     @Log(title = "服务器管理", businessType = BusinessType.UPDATE)
-    @PutMapping("/{id}")
-    public AjaxResult updateServerStatus(@PathVariable("id") String id) {
-        return toAjax(ardServerInfoService.updateServerStatus(id));
+    @PutMapping("/{id}/{status}")
+    public AjaxResult updateServerStatus(@PathVariable("id") String id,@PathVariable("status") String status) {
+        return toAjax(ardServerInfoService.updateServerStatus(id,status));
     }
 
 }
diff --git a/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java b/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
index c3635c3..a52c955 100644
--- a/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
+++ b/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
@@ -81,9 +81,13 @@
                 Channel channel = f.channel();
                 channel.attr(AttributeKey.valueOf("serverId")).set(serverId);
                 TyTcpServerCache.putTcpServerCache(serverId, true);
+                // 断开服务器,修改状态为: 0 - 在线
+                ardServerService.updateServerStatus(serverId, "1");
             } else {
                 log.warn("❌ 服务器 [{}] 连接失败", serverId);
                 TyTcpServerCache.putTcpServerCache(serverId, false);
+                // 断开服务器,修改状态为: 0 - 离线
+                ardServerService.updateServerStatus(serverId, "0");
             }
         });
 
@@ -107,6 +111,8 @@
         if (session != null && session.getChannelFuture() != null) {
             session.getChannelFuture().channel().close();
             log.info("断开服务器 [{}] 连接", serverId);
+            // 断开服务器,修改状态为: 0 - 离线
+            ardServerService.updateServerStatus(serverId, "0");
         }
         TyTcpServerCache.removeTcpServerCache(serverId);
     }
diff --git a/ard-work/src/main/java/com/ard/work/domain/entity/ArdDroneInfo.java b/ard-work/src/main/java/com/ard/work/domain/entity/ArdDroneInfo.java
index 1d74cb6..81763ac 100644
--- a/ard-work/src/main/java/com/ard/work/domain/entity/ArdDroneInfo.java
+++ b/ard-work/src/main/java/com/ard/work/domain/entity/ArdDroneInfo.java
@@ -3,7 +3,7 @@
 import com.ard.common.annotation.Excel;
 import com.ard.common.core.domain.BaseEntity;
 import com.ard.work.domain.receiver.BoxInfoReceiver;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.*;
 
 import java.util.Date;
@@ -39,6 +39,7 @@
     private String boxVersion;
 
     /** 启动时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "启动时间")
     private Date startTime;
 
@@ -70,6 +71,10 @@
     @Excel(name = "服务器管理ID")
     private String serverId;
 
+    /** 盒子别名 */
+    @Excel(name = "盒子别名")
+    private String boxAliasName;
+
     /**
      * 服务器实体对象
      */
diff --git a/ard-work/src/main/java/com/ard/work/domain/entity/ArdServerInfo.java b/ard-work/src/main/java/com/ard/work/domain/entity/ArdServerInfo.java
index e46879f..ce3d01d 100644
--- a/ard-work/src/main/java/com/ard/work/domain/entity/ArdServerInfo.java
+++ b/ard-work/src/main/java/com/ard/work/domain/entity/ArdServerInfo.java
@@ -52,8 +52,12 @@
     /** 部门ID */
     private Long deptId;
 
-    /** 服务器状态 */
-    private Long serverStatus;
+    /**
+     * 服务器状态
+     * 0:离线
+     * 1:在线
+     */
+    private String serverStatus;
 
     private List<ArdDroneInfo> ardDroneInfoList;
 
diff --git a/ard-work/src/main/java/com/ard/work/mapper/ArdServerInfoMapper.java b/ard-work/src/main/java/com/ard/work/mapper/ArdServerInfoMapper.java
index ebf01ee..3956cb8 100644
--- a/ard-work/src/main/java/com/ard/work/mapper/ArdServerInfoMapper.java
+++ b/ard-work/src/main/java/com/ard/work/mapper/ArdServerInfoMapper.java
@@ -1,5 +1,6 @@
 package com.ard.work.mapper;
 import com.ard.work.domain.entity.ArdServerInfo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -65,6 +66,6 @@
      * @param id 服务器管理主键
      * @return 结果
      */
-    public int updateServerStatus(String id);
+    public int updateServerStatus(@Param("id") String id, @Param("status") String status);
 
 }
diff --git a/ard-work/src/main/java/com/ard/work/service/IArdServerInfoService.java b/ard-work/src/main/java/com/ard/work/service/IArdServerInfoService.java
index 2dbb6cc..f6ab3d7 100644
--- a/ard-work/src/main/java/com/ard/work/service/IArdServerInfoService.java
+++ b/ard-work/src/main/java/com/ard/work/service/IArdServerInfoService.java
@@ -68,6 +68,6 @@
     /**
      * 修改服务器状态
      */
-    public int updateServerStatus(String id);
+    public int updateServerStatus(String id,String status);
 
 }
diff --git a/ard-work/src/main/java/com/ard/work/service/impl/ArdDroneInfoServiceImpl.java b/ard-work/src/main/java/com/ard/work/service/impl/ArdDroneInfoServiceImpl.java
index ed3a12e..9128c2a 100644
--- a/ard-work/src/main/java/com/ard/work/service/impl/ArdDroneInfoServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/work/service/impl/ArdDroneInfoServiceImpl.java
@@ -138,9 +138,6 @@
             throw new IllegalArgumentException("部门ID不能为空");
         }
         try {
-
-            //utilMethod.authorizationVerification(boxSn.length);
-
             // 1. 检查已存在的无人机盒子
             List<ArdDroneInfo> existingDrones = getExistingDrones(boxSn);
             // 2. 授权数量验证
@@ -212,6 +209,7 @@
         drone.setId(IdUtils.simpleUUID());
         drone.setBoxSn(box.getBoxSn());
         drone.setBoxName(box.getBoxName());
+        drone.setBoxAliasName(box.getBoxName());
         drone.setStartTime(new Date());
         drone.setOnLine(box.getOnLine());
         drone.setVideoServer(box.getVideoServer());
@@ -239,13 +237,9 @@
      */
     private int batchInsertDrones(List<ArdDroneInfo> drones) {
         if (drones.isEmpty()) {
-            log.info("没有需要插入的无人机信息");
             return 0;
         }
-
-        int result = ArdDroneInfoMapper.insertArdDroneLs(drones);
-        log.info("成功插入 {} 条无人机记录", result);
-        return result;
+        return ArdDroneInfoMapper.insertArdDroneLs(drones);
     }
 
     /**
diff --git a/ard-work/src/main/java/com/ard/work/service/impl/ArdServerInfoServiceImpl.java b/ard-work/src/main/java/com/ard/work/service/impl/ArdServerInfoServiceImpl.java
index 247b335..636696e 100644
--- a/ard-work/src/main/java/com/ard/work/service/impl/ArdServerInfoServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/work/service/impl/ArdServerInfoServiceImpl.java
@@ -144,8 +144,8 @@
      * 修改服务器状态
      */
     @Override
-    public int updateServerStatus(String id) {
-        return ardServerInfoMapper.updateServerStatus(id);
+    public int updateServerStatus(String id,String status) {
+        return ardServerInfoMapper.updateServerStatus(id,status);
     }
 
     private String getEncryptStr(ArdServerInfo serverInfo, long timeStamp) {
diff --git a/ard-work/src/main/resources/mapper/ArdDroneInfoMapper.xml b/ard-work/src/main/resources/mapper/ArdDroneInfoMapper.xml
index cfab1bc..dafd26d 100644
--- a/ard-work/src/main/resources/mapper/ArdDroneInfoMapper.xml
+++ b/ard-work/src/main/resources/mapper/ArdDroneInfoMapper.xml
@@ -16,6 +16,7 @@
         <result property="lastTaskId"    column="last_task_id"    />
         <result property="userId"    column="user_id"    />
         <result property="deptId"    column="dept_id"    />
+        <result property="boxAliasName"    column="box_alias_name"    />
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
         <result property="updateBy"    column="update_by"    />
@@ -37,24 +38,25 @@
 
     <sql id="selectArdDroneVo">
         select id,
-            box_sn,
-            box_name,
-            box_version,
-            start_time,
-            on_line,
-            video_server,
-            video_port,
-            last_task_id,
-            server_id,
-            user_id,
-            dept_id
+               box_sn,
+               box_name,
+               box_version,
+               start_time,
+               on_line,
+               video_server,
+               video_port,
+               last_task_id,
+               server_id,
+               user_id,
+               dept_id,
+               box_alias_name
         from ard_drone_info
     </sql>
 
     <select id="selectArdDroneList" parameterType="ArdDroneInfo" resultMap="ArdDroneInfoResult">
         <include refid="selectArdDroneVo"/>
-        <where>  
-            <if test="boxSn != null  and boxSn != ''"> and box_sn = #{boxSn}</if>
+        <where>
+            <if test="boxSn != null  and boxSn != ''"> and box_sn like concat('%', #{boxSn}, '%')</if>
             <if test="boxName != null  and boxName != ''"> and box_name like concat('%', #{boxName}, '%')</if>
             <if test="boxVersion != null  and boxVersion != ''"> and box_version = #{boxVersion}</if>
             <if test="onLine != null "> and onLine = #{onLine}</if>
@@ -87,6 +89,7 @@
             <if test="serverId != null">server_id,</if>
             <if test="userId != null">user_id,</if>
             <if test="deptId != null">dept_id,</if>
+            <if test="boxAliasName != null">box_alias_name,</if>
             <if test="createBy != null">create_by,</if>
             <if test="createTime != null">create_time,</if>
             <if test="updateBy != null">update_by,</if>
@@ -106,6 +109,7 @@
             <if test="serverId != null">#{serverId},</if>
             <if test="userId != null">#{userId},</if>
             <if test="deptId != null">#{deptId},</if>
+            <if test="boxAliasName != null">#{boxAliasName},</if>
             <if test="createBy != null">#{createBy},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="updateBy != null">#{updateBy},</if>
@@ -128,6 +132,7 @@
             <if test="serverId != null">server_id = #{serverId},</if>
             <if test="userId != null">user_id = #{userId},</if>
             <if test="deptId != null">dept_id = #{deptId},</if>
+            <if test="boxAliasName != null">box_alias_name = #{boxAliasName},</if>
             <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
@@ -162,6 +167,7 @@
             server_id,
             user_id,
             dept_id,
+            box_alias_name,
             create_by,
             create_time,
             update_by,
@@ -181,6 +187,7 @@
             #{item.serverId},
             #{item.userId},
             #{item.deptId},
+            #{item.boxAliasName},
             #{item.createBy},
             #{item.createTime},
             #{item.updateBy},
diff --git a/ard-work/src/main/resources/mapper/ArdServerInfoMapper.xml b/ard-work/src/main/resources/mapper/ArdServerInfoMapper.xml
index 6029346..0e1c927 100644
--- a/ard-work/src/main/resources/mapper/ArdServerInfoMapper.xml
+++ b/ard-work/src/main/resources/mapper/ArdServerInfoMapper.xml
@@ -43,7 +43,7 @@
         <include refid="selectArdServerInfoVo"/>
         <where>
             <if test="id != null and id != ''"> and c.id = #{id}</if>
-            <if test="serverName != null and serverName != ''"> and server_name like c.concat('%', #{serverName}, '%')</if>
+            <if test="serverName != null and serverName != ''"> and c.server_name like c.concat('%', #{serverName}, '%')</if>
             <if test="accessKeyId != null and accessKeyId != ''"> and c.access_key_id = #{accessKeyId}</if>
             <if test="accessKeySecret != null and accessKeySecret != ''"> and c.access_key_secret = #{accessKeySecret}</if>
             <if test="serverStatus != null and serverStatus != ''"> and c.server_status = #{serverStatus}</if>
@@ -113,10 +113,10 @@
         where id = #{id}
     </update>
 
-    <update id="updateServerStatus" parameterType="String">
+    <update id="updateServerStatus">
         update ard_server_info
         <trim prefix="SET" suffixOverrides=",">
-            <if test="serverStatus != null">server_status = #{serverStatus},</if>
+            <if test="status != null">server_status = #{status},</if>
         </trim>
         where id = #{id}
     </update>

--
Gitblit v1.9.3