| | |
| | | @Resource |
| | | private ArdVtduMapper ardVtduMapper; |
| | | @Resource |
| | | private IArdMediaService mediaService; |
| | | private IArdMediaService ardMediaService; |
| | | |
| | | |
| | | |
| | | @PostConstruct |
| | | public void initMediaMTX() { |
| | | //清空mediamtx流媒体数据 |
| | | mediaService.clearAll(); |
| | | ardMediaService.clearAll(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public int insertArdVtdu(ArdVtdu ardVtdu) { |
| | | ardVtdu.setCreateTime(DateUtils.getNowDate()); |
| | | ardVtdu = mediaService.addPath(ardVtdu); |
| | | ardVtdu = ardMediaService.addPath(ardVtdu); |
| | | return ardVtduMapper.insertArdVtdu(ardVtdu); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public int updateArdVtdu(ArdVtdu ardVtdu) { |
| | | ardVtdu.setUpdateTime(DateUtils.getNowDate()); |
| | | ardVtdu = mediaService.editPath(ardVtdu); |
| | | ardVtdu = ardMediaService.editPath(ardVtdu); |
| | | ardVtdu.setUpdateTime(DateUtils.getNowDate()); |
| | | return ardVtduMapper.updateArdVtdu(ardVtdu); |
| | | } |
| | |
| | | for (String name : names) { |
| | | log.debug("流媒体【" + name + "】通道删除"); |
| | | } |
| | | mediaService.removePath(names); |
| | | ardMediaService.removePath(names); |
| | | return ardVtduMapper.deleteArdVtduByNames(names); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public int deleteArdVtduByName(String name) { |
| | | mediaService.removePath(name); |
| | | ardMediaService.removePath(name); |
| | | log.debug("流媒体【" + name + "】通道删除"); |
| | | return ardVtduMapper.deleteArdVtduByName(name); |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 同步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); |
| | | } |
| | | } |
| | | } |