liusuyi
2026-02-10 4ac9edd4c0030d2daafd712cd14ef9080b2f1e43
优化
1 files added
9 files modified
132 ■■■■■ changed files
ard-admin/src/main/java/com/ard/web/controller/monitor/CacheController.java 2 ●●●●● patch | view | raw | blame | history
ard-common/src/main/java/com/ard/common/constant/CacheConstants.java 4 ●●●●● patch | view | raw | blame | history
ard-device/src/main/java/com/ard/device/camera/config/AsyncConfiguration.java 42 ●●●●● patch | view | raw | blame | history
ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java 34 ●●●●● patch | view | raw | blame | history
ard-device/src/main/java/com/ard/device/channel/service/impl/ArdChannelServiceImpl.java 16 ●●●●● patch | view | raw | blame | history
ard-system/src/main/java/com/ard/system/service/impl/SysUserServiceImpl.java 10 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/work/component/websocket/handler/UavAllManager.java 4 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/work/component/websocket/handler/UavControlManager.java 16 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/work/service/control/UavControlService.java 2 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/work/service/impl/ArdFlightTaskServiceImpl.java 2 ●●●●● patch | view | raw | blame | history
ard-admin/src/main/java/com/ard/web/controller/monitor/CacheController.java
@@ -43,9 +43,7 @@
        caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
        caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
        caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
        caches.add(new SysCache(CacheConstants.CAMERA_LIST_KEY, "相机列表"));
        caches.add(new SysCache(CacheConstants.UAV_ONLINE_KEY, "在线无人机"));
        caches.add(new SysCache(CacheConstants.SYS_USER_KEY, "用户列表"));
    }
    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
ard-common/src/main/java/com/ard/common/constant/CacheConstants.java
@@ -55,7 +55,7 @@
    /**
     * 所有相机 redis key
     */
    public static final String CAMERA_LIST_KEY = "camera_list:";
    public static final String CAMERA_LIST = "camera:list";
    /**
     * 在线无人机 redis key
@@ -65,5 +65,5 @@
    /**
     * 用户列表 redis key
     */
    public static final String SYS_USER_KEY = "sys_user:";
    public static final String SYS_USER= "user:list";
}
ard-device/src/main/java/com/ard/device/camera/config/AsyncConfiguration.java
New file
@@ -0,0 +1,42 @@
package com.ard.device.camera.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
 * @ClassName: AsyncConfiguration
 * @Description: 异步线程配置类
 * @Author: Administrator
 * @Date: 2023年02月03日 11:25
 * @Version: 1.0
 **/
@Configuration
@EnableAsync(proxyTargetClass = true)
public class AsyncConfiguration {
    @Bean("globalExecutor")
    public ThreadPoolTaskExecutor globalExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //配置核心线程数
        executor.setCorePoolSize(18);
        //配置最大线程数
        executor.setMaxPoolSize(36);
        //配置队列大小
        executor.setQueueCapacity(100);
        //线程的名称前缀
        executor.setThreadNamePrefix("globalExecutor-");
        //线程活跃时间(秒)
        executor.setKeepAliveSeconds(3000);
        //等待所有任务结束后再关闭线程池
        executor.setWaitForTasksToCompleteOnShutdown(true);
        //设置拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        //执行初始化
        executor.initialize();
        return executor;
    }
}
ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java
@@ -28,6 +28,7 @@
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -59,6 +60,8 @@
    @Resource
    protected Validator validator;
    @Resource(name = "globalExecutor")
    private ThreadPoolTaskExecutor executorService;
    @Override
    public void run(ApplicationArguments args) {
@@ -67,23 +70,15 @@
    public void initCamera() {
        //清空相机缓存
        redisService.deleteObject(redisService.keys(getCacheKey("*")));
        redisService.deleteObject(CacheConstants.CAMERA_LIST);
        //重新加载相机到缓存
        ardCameraMapper.selectArdCameraList(new ArdCamera()).forEach(ardCamera -> {
            ardCameraMapper.resetCameraLoginId(ardCamera);
            redisService.setCacheObject(getCacheKey(ardCamera.getId()), ardCamera);
            cameraSDKService.login(ardCamera);
            redisService.setCacheMapValue(CacheConstants.CAMERA_LIST, ardCamera.getId(), ardCamera);
            // 提交到线程池异步执行
            executorService.submit(() -> {
                cameraSDKService.login(ardCamera);
            });
        });
    }
    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    private String getCacheKey(String configKey) {
        return CacheConstants.CAMERA_LIST_KEY + configKey;
    }
@@ -146,6 +141,7 @@
        ardCamera.setUserId(SecurityUtils.getUserId());
        int res = ardCameraMapper.insertArdCamera(ardCamera);
        if (res > 0) {
            redisService.setCacheMapValue(CacheConstants.CAMERA_LIST, ardCamera.getId(), ardCamera);
            cameraSDKService.login(ardCamera);//sdk登录获取通道信息
        }
        return res;
@@ -163,6 +159,7 @@
        ardCamera.setUpdateBy(SecurityUtils.getUsername());
        int res = ardCameraMapper.updateArdCamera(ardCamera);
        if (res > 0) {
            redisService.setCacheMapValue(CacheConstants.CAMERA_LIST, ardCamera.getId(), ardCamera);
            cameraSDKService.logout(ardCamera);//sdk注销
            cameraSDKService.login(ardCamera);//sdk登录获取通道信息
        }
@@ -182,7 +179,7 @@
            ArdCamera camera = ardCameraMapper.selectArdCameraById(id);
            if (camera != null) {
                //redis中删除
                redisService.deleteObject(getCacheKey(id));
                redisService.deleteCacheMapValue(CacheConstants.CAMERA_LIST, id);
                //删除当前相机的所有通道
                ardChannelService.deleteArdChannelByDeviceId(id);
                //sdk注销
@@ -203,7 +200,7 @@
        int i = ardCameraMapper.deleteArdCameraById(id);
        if (i > 0) {
            //redis中删除
            redisService.deleteObject(getCacheKey(id));
            redisService.deleteCacheMapValue(CacheConstants.CAMERA_LIST, id);
            //删除当前相机的所有通道
            ardChannelService.deleteArdChannelByDeviceId(id);
            //sdk注销
@@ -305,7 +302,7 @@
    @Override
    public ArdCamera checkAirportHasCamera(ArdCamera camera) {
        ArdCamera info = ardCameraMapper.checkAirportHasCamera(camera);
        if (StringUtils.isNotNull(info)&& !info.getId().equals(camera.getId())) {
        if (StringUtils.isNotNull(info) && !info.getId().equals(camera.getId())) {
            return info;
        }
        return null;
@@ -369,8 +366,6 @@
    public void LoginEventListener(LoginEvent loginEvent) {
        ArdCamera camera = loginEvent.getCamera();
        ardCameraMapper.updateArdCamera(camera);
        // SDK 登录成功后写入 Redis
        redisService.setCacheObject(getCacheKey(camera.getId()), camera);
    }
    /**
@@ -426,6 +421,7 @@
            log.error("同步相机在线状态异常:{}", ex.getMessage());
        }
    }
    /**
     * 同步相机通道
     */
ard-device/src/main/java/com/ard/device/channel/service/impl/ArdChannelServiceImpl.java
@@ -39,6 +39,7 @@
    private IArdVtduService ardVtduService;
    @Resource
    private MediamtxConfig mediamtxConfig;
    /**
     * 查询通道管理
     *
@@ -154,10 +155,10 @@
            ArdChannel ardChannel = new ArdChannel();
            ardChannel.setUseDataScope(false);
            List<ArdChannel> channels = this.selectArdChannelList(ardChannel);
            if (channels == null || channels.isEmpty()) {
                // log.warn("没有获取到通道数据,退出同步");
                return;
            }
//            if (channels == null || channels.isEmpty()) {
//                // log.warn("没有获取到通道数据,退出同步");
//                return;
//            }
            List<ArdVtdu> ardVtduList = ardVtduService.selectArdVtduList(new ArdVtdu());
            Set<String> validNames = channels.stream()
@@ -172,7 +173,8 @@
                        "rtsp://" + mediamtxConfig.getPlayHost() + ":" + mediamtxConfig.getRtspPort() + "/" + name;  //
                // 拼接 webrtcUrl
                String rtmpUrl =
                        "rtmp://" + mediamtxConfig.getPlayHost() + ":" + mediamtxConfig.getRtmpPort() + "/" + name;  // 拼接
                        "rtmp://" + mediamtxConfig.getPlayHost() + ":" + mediamtxConfig.getRtmpPort() + "/" + name;
                // 拼接
                // webrtcUrl
                String protocol = mediamtxConfig.isHttps() ? "https://" : "http://";
                String webrtcUrl =
@@ -225,7 +227,7 @@
                log.info("删除不再存在的媒体记录:{}", Arrays.toString(namesArray));
            }
        } catch (Exception e) {
          log.error("定时同步Vtdu任务异常:{}", e.getMessage());
            log.error("定时同步Vtdu任务异常:{}", e.getMessage());
        }
    }
@@ -233,7 +235,7 @@
    // 根据通道信息获取rtsp源地址
    private String getRtspSource(ArdChannel channel) {
        String rtspSource = "";
        ArdCamera ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + channel.getDeviceId());
        ArdCamera ardCamera = redisCache.getCacheMapValue(CacheConstants.CAMERA_LIST, channel.getDeviceId());
        if (ardCamera != null) {
            switch (ardCamera.getFactory()) {
                case "1":
ard-system/src/main/java/com/ard/system/service/impl/SysUserServiceImpl.java
@@ -83,7 +83,7 @@
        // 将用户列表存入 Redis,使用用户 ID 作为 Redis 键
        userList.forEach(user -> {
            redisCache.setCacheObject(CacheConstants.SYS_USER_KEY + user.getUserId(), user);
            redisCache.setCacheMapValue(CacheConstants.SYS_USER, user.getUserId().toString(), user);
        });
        log.info("用户信息已成功加载到 Redis!");
@@ -266,7 +266,7 @@
        // 新增用户信息
        int rows = userMapper.insertUser(user);
        // 同步到 Redis
        redisCache.setCacheObject(CacheConstants.SYS_USER_KEY + user.getUserId(), user);
        redisCache.setCacheMapValue(CacheConstants.SYS_USER, user.getUserId().toString(), user);
        // 新增用户岗位关联
        insertUserPost(user);
        // 新增用户与角色管理
@@ -306,7 +306,7 @@
        // 更新用户信息
        int result = userMapper.updateUser(user);
        // 同步到 Redis
        redisCache.setCacheObject(CacheConstants.SYS_USER_KEY + user.getUserId(), user);
        redisCache.setCacheMapValue(CacheConstants.SYS_USER, user.getUserId().toString(), user);
        return result;
    }
@@ -445,7 +445,7 @@
        // 删除用户信息
        int result = userMapper.deleteUserById(userId);
        // 从 Redis 删除用户信息
        redisCache.deleteObject(CacheConstants.SYS_USER_KEY + userId);
        redisCache.deleteCacheMapValue(CacheConstants.SYS_USER, userId.toString());
        return result;
    }
@@ -471,7 +471,7 @@
        // 批量删除 Redis 中的用户信息
        for (Long userId : userIds) {
            redisCache.deleteObject(CacheConstants.SYS_USER_KEY + userId);
            redisCache.deleteCacheMapValue(CacheConstants.SYS_USER, userId.toString());
        }
        return result;
    }
ard-work/src/main/java/com/ard/work/component/websocket/handler/UavAllManager.java
@@ -57,12 +57,12 @@
        map.put("signal", uavSignalInfo);
        // 获取当前控制飞行的用户ID
        Long flyUserId = uavControlService.getCurrentController(boxSn, "fly");
        SysUser flyUser = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + flyUserId);
        SysUser flyUser = redisCache.getCacheMapValue(CacheConstants.SYS_USER, flyUserId.toString());
        // 将飞行当前控制者用户ID添加到映射中
        map.put("flyController", flyUser);
        // 获取当前控制载荷的用户ID
        Long payloadUserId = uavControlService.getCurrentController(boxSn, "payload");
        SysUser payloadUser = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + payloadUserId);
        SysUser payloadUser = redisCache.getCacheMapValue(CacheConstants.SYS_USER, payloadUserId.toString());
        // 将载荷当前控制者用户ID添加到映射中
        map.put("payloadController", payloadUser);
        return map;
ard-work/src/main/java/com/ard/work/component/websocket/handler/UavControlManager.java
@@ -26,7 +26,7 @@
     */
    public void sendControlRequest(Long controllerId, String boxSn, String type, Long requesterId) {
        SysUser requester = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + requesterId);
        SysUser requester = redisCache.getCacheMapValue(CacheConstants.SYS_USER, requesterId.toString());
        UavControlMessage msg = new UavControlMessage();
        msg.setBoxSn(boxSn);
@@ -45,7 +45,7 @@
     */
    public void sendControlApproval(Long requesterId, String boxSn, String type, Long controllerId) {
        SysUser controller = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + controllerId);
        SysUser controller = redisCache.getCacheMapValue(CacheConstants.SYS_USER, controllerId.toString());
        UavControlMessage msg = new UavControlMessage();
        msg.setBoxSn(boxSn);
@@ -64,7 +64,7 @@
     */
    public void sendControlRejection(Long requesterId, String boxSn, String type, Long controllerId) {
        SysUser controller = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + controllerId);
        SysUser controller = redisCache.getCacheMapValue(CacheConstants.SYS_USER, controllerId.toString());
        UavControlMessage msg = new UavControlMessage();
        msg.setBoxSn(boxSn);
@@ -83,8 +83,8 @@
     */
    public void sendControlTakeover(Long oldControllerId, Long newControllerId, String boxSn, String type) {
        SysUser newController = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + newControllerId);
        SysUser oldController = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + oldControllerId);
        SysUser newController = redisCache.getCacheMapValue(CacheConstants.SYS_USER, newControllerId.toString());
        SysUser oldController = redisCache.getCacheMapValue(CacheConstants.SYS_USER, oldControllerId.toString());
        // 1️⃣ 通知原控制者:你被抢占了
        UavControlMessage msgOld = new UavControlMessage();
@@ -125,7 +125,7 @@
     * 控制权释放
     */
    public void sendControlRelease(String boxSn, String type, Long operatorId) {
        SysUser operator = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + operatorId);
        SysUser operator = redisCache.getCacheMapValue(CacheConstants.SYS_USER, operatorId.toString());
        UavControlMessage message = new UavControlMessage();
        message.setBoxSn(boxSn);
@@ -155,10 +155,10 @@
        Map<String, Object> map = new HashMap<>();
        map.put("boxSn", boxSn);
        // 将飞行当前控制者用户ID添加到映射中
        SysUser flyUser = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + flyUserId);
        SysUser flyUser = redisCache.getCacheMapValue(CacheConstants.SYS_USER, flyUserId.toString());
        map.put("flyController", flyUser);
        // 将载荷当前控制者用户ID添加到映射中
        SysUser payloadUser = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + payloadUserId);
        SysUser payloadUser = redisCache.getCacheMapValue(CacheConstants.SYS_USER, payloadUserId.toString());
        map.put("payloadController", payloadUser);
        // 返回包含当前控制者信息的映射
        return map;
ard-work/src/main/java/com/ard/work/service/control/UavControlService.java
@@ -141,7 +141,7 @@
            // 🚨 其他请求者自动拒绝(强烈建议)
            for (Long other : requesters) {
                if (!other.equals(requester)) {
                    requesters.remove(requester);
                    requesters.remove(other);
                    uavControlManager.sendControlRejection(other, boxSn, controlType.getType(), controller);
                }
            }
ard-work/src/main/java/com/ard/work/service/impl/ArdFlightTaskServiceImpl.java
@@ -132,7 +132,7 @@
            Long flyUserId = uavControlService.getCurrentController(flightTask.getBoxSn(), "fly");
            if (flyUserId != null) {
                SysUser flyUser = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + flyUserId);
                SysUser flyUser = redisCache.getCacheMapValue(CacheConstants.SYS_USER, flyUserId.toString());
                if (flyUser != null && flyUser.getNickName() != null) {
                    flightTask.setCreateBy(flyUser.getNickName());
                }