feat:记录用户上次修改书签的时间

This commit is contained in:
fanxb 2020-01-26 16:25:19 +08:00
parent 05aba42335
commit cf22fd2997
7 changed files with 78 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package com.fanxb.bookmark.business.user.dao; package com.fanxb.bookmark.business.user.dao;
import com.fanxb.bookmark.common.entity.User; import com.fanxb.bookmark.common.entity.User;
import com.fanxb.bookmark.common.entity.redis.UserBookmarkUpdate;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -100,6 +101,7 @@ public interface UserDao {
/** /**
* 更新用户新邮箱 * 更新用户新邮箱
*
* @param userId userId * @param userId userId
* @param newPassword userId * @param newPassword userId
*/ */
@ -108,8 +110,19 @@ public interface UserDao {
/** /**
* 新邮箱校验成功更新邮箱 * 新邮箱校验成功更新邮箱
*
* @param userId userId * @param userId userId
*/ */
@Update("update user set email=newEmail,newEmail='' where userId=#{userId}") @Update("update user set email=newEmail,newEmail='' where userId=#{userId}")
void updateEmailByUserId(int userId); void updateEmailByUserId(int userId);
/**
* 功能描述: 更新用户上次更新书签时间
*
* @param item item
* @author fanxb
* @date 2020/1/26 下午3:47
*/
@Update("update user set bookmarkChangeTime=#{updateTime} where userId=#{userId}")
void updateLastBookmarkUpdateTime(UserBookmarkUpdate item);
} }

View File

@ -0,0 +1,35 @@
package com.fanxb.bookmark.business.user.schedule;
import com.alibaba.fastjson.JSON;
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;
@Scheduled(fixedDelay = 5000)
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);
}
}
}

View File

@ -100,9 +100,4 @@ public class BaseInfoService {
} }
userDao.updateEmailByUserId(userId); userDao.updateEmailByUserId(userId);
} }
@PostConstruct
public void updateBookmarkUpdateTime(){
}
} }

View File

@ -0,0 +1,25 @@
package com.fanxb.bookmark.common.configuration;
import com.fanxb.bookmark.common.factory.CustomThreadFactory;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
/**
* Created with IntelliJ IDEA
*
* @author fanxb
* @date 2020/1/26
*/
public class ScheduleConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
ScheduledExecutorService service = new ScheduledThreadPoolExecutor(5, new CustomThreadFactory("schedule"));
scheduledTaskRegistrar.setScheduler(service);
}
}

View File

@ -4,6 +4,7 @@ package com.fanxb.bookmark.web;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
/** /**
@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication(scanBasePackages = {"com.fanxb.bookmark"}) @SpringBootApplication(scanBasePackages = {"com.fanxb.bookmark"})
@MapperScan(basePackages = "com.fanxb.bookmark.**.dao") @MapperScan(basePackages = "com.fanxb.bookmark.**.dao")
@EnableTransactionManagement @EnableTransactionManagement
@EnableScheduling
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);

View File

@ -25,7 +25,7 @@ spring:
database: 0 database: 0
host: localhost host: localhost
password: password:
timeout: 500ms timeout: 20000ms
lettuce: lettuce:
pool: pool:
max-active: 20 max-active: 20

View File

@ -1,2 +1,2 @@
ALTER TABLE `psn`.`user` ALTER TABLE `user`
ADD COLUMN `bookmarkChangeTime` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 AFTER `lastLoginTime`; ADD COLUMN `bookmarkChangeTime` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 AFTER `lastLoginTime`;