liusuyi
2026-01-16 05f799b8a5ce57b1f98dc5f8ab08308c32a6ec63
ard-vtdu/src/main/java/com/ard/vtdu/service/impl/ArdVtduServiceImpl.java
@@ -28,22 +28,14 @@
    @Resource
    private ArdVtduMapper ardVtduMapper;
    @Resource
    private IArdMediaService mediaService;
    private IArdMediaService ardMediaService;
    @PostConstruct
    public void initMediaMTX() {
        //清空mediamtx流媒体数据
        mediaService.clearAll();
    }
    @Scheduled(cron = "0/5 * * * * ?")
    public void syncMediamtx() {
        log.debug("定时同步MediaMTX任务");
        List<String> nameList = mediaService.getNameList();
        List<ArdVtdu> ardVtduList = selectArdVtduList(new ArdVtdu());
        asyncMediaMTX(ardVtduList, nameList);
        ardMediaService.clearAll();
    }
    /**
@@ -76,7 +68,8 @@
     */
    @Override
    public int insertArdVtdu(ArdVtdu ardVtdu) {
        ardVtdu = mediaService.addPath(ardVtdu);
        ardVtdu.setCreateTime(DateUtils.getNowDate());
        ardVtdu = ardMediaService.addPath(ardVtdu);
        return ardVtduMapper.insertArdVtdu(ardVtdu);
    }
@@ -88,7 +81,8 @@
     */
    @Override
    public int updateArdVtdu(ArdVtdu ardVtdu) {
        ardVtdu = mediaService.editPath(ardVtdu);
        ardVtdu.setUpdateTime(DateUtils.getNowDate());
        ardVtdu = ardMediaService.editPath(ardVtdu);
        ardVtdu.setUpdateTime(DateUtils.getNowDate());
        return ardVtduMapper.updateArdVtdu(ardVtdu);
    }
@@ -104,7 +98,7 @@
        for (String name : names) {
            log.debug("流媒体【" + name + "】通道删除");
        }
        mediaService.removePath(names);
        ardMediaService.removePath(names);
        return ardVtduMapper.deleteArdVtduByNames(names);
    }
@@ -116,7 +110,7 @@
     */
    @Override
    public int deleteArdVtduByName(String name) {
        mediaService.removePath(name);
        ardMediaService.removePath(name);
        log.debug("流媒体【" + name + "】通道删除");
        return ardVtduMapper.deleteArdVtduByName(name);
    }
@@ -183,7 +177,7 @@
    public void asyncMediaMTX(List<ArdVtdu> vtdus, List<String> names) {
        //需要更新的数据,参数顺序注意
        sameList(vtdus, names).forEach(vtdu -> {
            Conf conf = mediaService.getPathConfig(vtdu.getName());
            Conf conf = ardMediaService.getPathConfig(vtdu.getName());
            if (conf == null || conf.getSource() == null) {
                return;
            }
@@ -194,26 +188,32 @@
            boolean isRtspSourceChanged = !Objects.equals(confRtspSource, currentRtspSource);
            // 如果 RTSP 源发生变化,则更新路径
            if (isRtspSourceChanged) {
                mediaService.editPath(vtdu);
                ardMediaService.editPath(vtdu);
            }
        });
        //需要删除的数据
        diffListToDel(vtdus, names).forEach(name -> {
            mediaService.removePath(name);
            ardMediaService.removePath(name);
        });
        //需要新增的数据
        diffListToAdd(vtdus, names).forEach(vtdu -> {
            mediaService.addPath(vtdu);
            ardMediaService.addPath(vtdu);
        });
    }
    //匹配rtsp地址
    private String matchRtsp(String value) {
        Matcher matcher = Pattern.compile("rtsp://[^\\s\"]+").matcher(value);
        if (matcher.find()) {
            return matcher.group();
        } else {
            return "";
    /**
     * 同步mediamtx
     */
    @Scheduled(cron = "0/10 * * * * ?")
    public void syncMediamtx() {
        log.debug("定时同步MediaMTX任务");
        try {
            List<String> nameList = ardMediaService.getNameList();
            List<ArdVtdu> ardVtduList = this.selectArdVtduList(new ArdVtdu());
            asyncMediaMTX(ardVtduList, nameList);
        }
        catch (Exception e) {
            log.error("同步MediaMTX任务失败", e);
        }
    }
}