| | |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.security.authentication.event.AuthenticationSuccessEvent; |
| | | import com.ard.common.core.domain.model.LoginUser; |
| | | import org.springframework.security.authentication.event.LogoutSuccessEvent; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | |
| | | public void clearAllArdVtdu() { |
| | | ardVtduMapper.clearAllArdVtdu(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //需要更新的(流媒体和vtdu相同) |
| | | @Override |
| | |
| | | if (principal instanceof LoginUser) { |
| | | LoginUser loginUser = (LoginUser) principal; // 传统强制类型转换 |
| | | Long userId = loginUser.getUser().getUserId(); |
| | | String username = loginUser.getUsername(); |
| | | String name="user_" + userId; |
| | | // 1️⃣ 判断数据库是否已存在 |
| | | ArdVtdu existing = ardVtduMapper.selectArdVtduByName(name); |
| | | if (existing != null) { |
| | | log.info("流媒体【{}】已存在,跳过插入", name); |
| | | return; |
| | | } |
| | | ArdVtdu ardVtdu = ArdVtdu.builder() |
| | | .name("user_" + userId) // 用 userId 作为流名称 |
| | | .name(name) // 用 userId 作为流名称 |
| | | .rtspSource("publisher") // 或 "publisher",按业务区分 |
| | | .build(); |
| | | // 本地库插入 |
| | | insertArdVtdu(ardVtdu); |
| | | log.info("用户【{}】登录,立即加入流媒体", username); |
| | | } else { |
| | | log.warn("登录事件 principal 不是 LoginUser,无法获取 userId"); |
| | | log.info("用户【{}】登录,立即加入流媒体", name); |
| | | } |
| | | } |
| | | @EventListener |
| | | public void handleLogout(LogoutSuccessEvent event) { |
| | | Object principal = event.getAuthentication().getPrincipal(); |
| | | if (principal instanceof LoginUser) { |
| | | LoginUser loginUser = (LoginUser) principal; // 传统强制类型转换 |
| | | Long userId = loginUser.getUser().getUserId(); |
| | | String name="user_" + userId; |
| | | deleteArdVtduByName(name); |
| | | log.info("用户【{}】注销,立即移除流媒体", name); |
| | | } |
| | | } |
| | | } |