派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.qxueyou.scc.admin.notice.dao;
 
import com.qxueyou.scc.base.service.ICacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import java.util.List;
 
@Repository
public class NoticeDAO {
 
    @Autowired
    ICacheService cache;
 
    public void saveNoticeClasses(String noticeId, List<String> classIds) {
 
        List<String> origNoticeClasses = cache.lstAll("NoticeClasses_" + noticeId);
        for (String classId : origNoticeClasses) {
            cache.lstRemove("ClassNotices_" + classId, noticeId);
        }
 
        cache.lstTrim("NoticeClasses_" + noticeId, 1, 0);//clear
        cache.lstRightPushAll("NoticeClasses_" + noticeId, classIds);
 
        for (String classId : classIds) {
            cache.lstRightPush("ClassNotices_" + classId, noticeId);
        }
 
    }
 
    public List<String> getLiveClasses(String noticeId) {
        return cache.lstAll("NoticeClasses_" + noticeId);
    }
 
    public List<String> getClassNotices(String classId) {
        return cache.lstAll("ClassNotices_" + classId);
    }
 
    public void view(String noticeId, String userId) {
        cache.set("NoticeView_" + noticeId + userId, Boolean.TRUE);
        cache.incr("NoticeViewCount_" + noticeId);
    }
 
    public boolean isView(String noticeId, String userId) {
        Boolean view = cache.get("NoticeView_" + noticeId + userId);
        return view == null ? Boolean.FALSE : view;
    }
 
    /**
     * 记录已读的学员
     *
     * @param noticeId
     * @param userId
     */
    public void addReadCount(String noticeId, String userId) {
        cache.lstRemove("noticeReadCount" + noticeId, userId);//删除用户之前查看的记录,避免重复记录;
        cache.lstRightPush("noticeReadCount" + noticeId, userId);
    }
 
    /**
     * 获取已读的学员人数
     */
    public int getReadCount(String noticeId) {
        List<Object> lstAll = cache.lstAll("noticeReadCount" + noticeId);
        return lstAll.size();
    }
 
    /**
     * 删除cache的key
     */
    public void deleteNoticeForCache(String noticeId) {
        cache.delete("noticeReadCount" + noticeId);
    }
 
}