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);
|
}
|
|
}
|