派生自 projectDept/qhighschool

胡仁荣
2023-08-04 2174b22bbbb45284765a23b8189df59583c65d29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.qxueyou.scc.teach.live.dao;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import com.alibaba.druid.util.StringUtils;
import com.qxueyou.scc.base.service.impl.RedisCacheBean;
import com.qxueyou.scc.base.util.UUIDUtils;
 
@Repository
public class MediaLiveDAO {
    
    @Autowired
    RedisCacheBean cache;
 
    public void saveLiveClasses(String liveId,List<String> classIds) {
        
        List<String> origNoticeClasses = cache.lstAll("LiveClasses_"+liveId);
        for(String classId:origNoticeClasses) {
            cache.lstRemove("ClassLives_"+classId, liveId);
        }
        
        cache.lstTrim("LiveClasses_"+liveId, 1, 0);
        cache.lstRightPushAll("LiveClasses_"+liveId, classIds);
        
        for(String classId:classIds) {
            cache.lstRightPush("ClassLives_"+classId, liveId);
        }
    }
    
    public List<String> getLiveClasses(String liveId) {
        return cache.lstAll("LiveClasses_"+liveId);
    }
    
    public List<String> getClassLives(String classId) {
        return cache.lstAll("ClassLives_"+classId);
    }
    
    public String getChatRoomId(String liveId) {
        String chatRoomId = cache.get(liveId);
        
        if(StringUtils.isEmpty(chatRoomId)){
            chatRoomId = UUIDUtils.UUID();
            if(!cache.setIfAbsent(liveId,chatRoomId)){
                return this.getChatRoomId(liveId);
            }
        }
        
        return chatRoomId;
    }
    
}