fix:修复更新所有人bookmarkUpdateTime不生效问题
This commit is contained in:
parent
f7b195a21e
commit
3b5f178ca7
@ -0,0 +1,30 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.consumer;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.fanxb.bookmark.business.user.dao.UserDao;
|
||||||
|
import com.fanxb.bookmark.common.annotation.MqConsumer;
|
||||||
|
import com.fanxb.bookmark.common.constant.RedisConstant;
|
||||||
|
import com.fanxb.bookmark.common.entity.redis.RedisConsumer;
|
||||||
|
import com.fanxb.bookmark.common.entity.redis.UserBookmarkUpdate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2020/1/26 上午11:54
|
||||||
|
*/
|
||||||
|
@MqConsumer(RedisConstant.BOOKMARK_UPDATE_TIME)
|
||||||
|
public class UserInfoUpdateConsumer implements RedisConsumer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deal(String message) {
|
||||||
|
UserBookmarkUpdate item = JSON.parseObject(message, UserBookmarkUpdate.class);
|
||||||
|
if (item.getUserId() == -1) {
|
||||||
|
userDao.updateAllBookmarkUpdateTime(item.getUpdateTime());
|
||||||
|
} else {
|
||||||
|
userDao.updateLastBookmarkUpdateTime(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -125,4 +125,14 @@ public interface UserDao {
|
|||||||
*/
|
*/
|
||||||
@Update("update user set bookmarkChangeTime=#{updateTime} where userId=#{userId}")
|
@Update("update user set bookmarkChangeTime=#{updateTime} where userId=#{userId}")
|
||||||
void updateLastBookmarkUpdateTime(UserBookmarkUpdate item);
|
void updateLastBookmarkUpdateTime(UserBookmarkUpdate item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能描述: 更新所有用户的更新时间
|
||||||
|
*
|
||||||
|
* @param time time
|
||||||
|
* @author 123
|
||||||
|
* @date 2020/3/29 18:18
|
||||||
|
*/
|
||||||
|
@Update("update user set bookmarkChangeTime=#{time}")
|
||||||
|
void updateAllBookmarkUpdateTime(long time);
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package com.fanxb.bookmark.business.user.schedule;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.fanxb.bookmark.business.user.dao.UserDao;
|
|
||||||
import com.fanxb.bookmark.common.constant.RedisConstant;
|
|
||||||
import com.fanxb.bookmark.common.entity.redis.UserBookmarkUpdate;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fanxb
|
|
||||||
* @date 2020/1/26 上午11:54
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class UserInfoUpdate {
|
|
||||||
/**
|
|
||||||
* 阻塞时间
|
|
||||||
*/
|
|
||||||
private static final int BLOCK_TIME = 15;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StringRedisTemplate redisTemplate;
|
|
||||||
@Autowired
|
|
||||||
private UserDao userDao;
|
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 100000)
|
|
||||||
public void userBookmarkUpdateTime() {
|
|
||||||
String value;
|
|
||||||
while ((value = redisTemplate.opsForList().rightPop(RedisConstant.BOOKMARK_UPDATE_TIME, BLOCK_TIME, TimeUnit.SECONDS)) != null) {
|
|
||||||
UserBookmarkUpdate item = JSON.parseObject(value, UserBookmarkUpdate.class);
|
|
||||||
userDao.updateLastBookmarkUpdateTime(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user