Merge pull request '支持多 platform 参数的 Redis 缓存' (#61) from baladiwei/gitlink-notification-system:master into master

This commit is contained in:
baladiwei 2021-09-13 14:29:16 +08:00
commit a024251f02
1 changed files with 9 additions and 10 deletions

View File

@ -1,6 +1,5 @@
package cn.org.gitlink.notification.model.service.notification.impl;
import cn.org.gitlink.notification.common.constant.NotificationSystemConstant;
import cn.org.gitlink.notification.common.utils.RedisUtil;
import cn.org.gitlink.notification.model.dao.entity.SysNotification;
import cn.org.gitlink.notification.model.dao.entity.vo.NewSysNotificationVo;
@ -19,7 +18,7 @@ import java.util.List;
@Service(value = "SysNotificationServiceImpl")
public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMapper, SysNotification> implements SysNotificationService {
private static final String CACHE_KEY_PREFFIX = "GITLINK-CACHE#R";
private static final String CACHE_KEY_PREFFIX = "GNSCache#";
@Autowired
@ -40,7 +39,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
for (String receiver : list) {
sysNotification.setReceiver(Integer.parseInt(receiver));
baseMapper.insertSelective(newSysNotificationVo.getPlatform(), sysNotification);
this.delUserCache(Integer.parseInt(receiver));
this.delUserCache(newSysNotificationVo.getPlatform(), Integer.parseInt(receiver));
}
return true;
}
@ -49,14 +48,14 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
public int markNotificationAs(String platform, Integer receiver, String notificationIds, Integer status) throws Exception {
int count = baseMapper.updateStatusByNotificationId(platform, receiver, notificationIds, status);
if (count > 0) {
this.delUserCache(receiver);
this.delUserCache(platform, receiver);
}
return count;
}
@Override
public int getUnreadNotificationCount(String platform, Integer receiver) throws Exception {
String KEY_ALL_COUNT = CACHE_KEY_PREFFIX + receiver + "#COUNT";
String KEY_ALL_COUNT = CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "#COUNT";
Object foundResult = this.redisUtil.get(KEY_ALL_COUNT);
if (foundResult != null) {
return (Integer) foundResult;
@ -68,7 +67,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
@Override
public List<SysNotification> getUnreadNotificationByType(String platform, Integer receiver, Integer size, Integer type) throws Exception {
String KEY_TYPE_LIST = CACHE_KEY_PREFFIX + receiver + "#T" + type + "#LIST";
String KEY_TYPE_LIST = CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "#T" + type + "#LIST";
Object foundResult = this.redisUtil.get(KEY_TYPE_LIST);
if (foundResult != null) {
return (List<SysNotification>) foundResult;
@ -80,7 +79,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
@Override
public int getUnreadNotificationByType(Integer type, String platform, Integer receiver) throws Exception {
String KEY_TYPE_COUNT = CACHE_KEY_PREFFIX + receiver + "#T" + type + "#COUNT";
String KEY_TYPE_COUNT = CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "#T" + type + "#COUNT";
Object foundResult = this.redisUtil.get(KEY_TYPE_COUNT);
if (foundResult != null) {
return (Integer) foundResult;
@ -92,7 +91,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
@Override
public Page<SysNotification> getNotification(int type, int page, int size, String orderBy, String platform, Integer receiver) throws Exception {
String KEY_PAGE_LIST = CACHE_KEY_PREFFIX + receiver + "P" + page + "S" + size + "T" + type + "#LIST";
String KEY_PAGE_LIST = CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "P" + page + "S" + size + "T" + type + "#LIST";
Object foundResult = this.redisUtil.get(KEY_PAGE_LIST);
if (foundResult != null) {
return (Page<SysNotification>) foundResult;
@ -109,7 +108,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
//////////////////////////////// 私有方法 ////////////////////////////////
private void delUserCache(Integer receiver) {
redisUtil.scanAndDel(CACHE_KEY_PREFFIX + receiver + "*");
private void delUserCache(String platform, Integer receiver) {
redisUtil.scanAndDel(CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "*");
}//end of method
}