12.1 BitMap功能演示

Field Type Collation Null Key Default Extra Comment
id bigint unsigned (NULL) NO PRI (NULL) auto_increment 主键
user_id bigint unsigned (NULL) NO (NULL) 用户id
year year (NULL) NO (NULL) 签到的年
month tinyint (NULL) NO (NULL) 签到的月
date date (NULL) NO (NULL) 签到的日期
is_backup tinyint unsigned (NULL) YES (NULL) 是否补签

12.2 实现签到功能

说明
请求方式 Post
请求路径 /user/sign
请求参数
返回值
@PostMapping("/sign")
public Result sign(){
    return userService.sign();
}
@Override
public Result sign() {
    //1. 获取当前用户
    Long userId = UserHolder.getUser().getId();
    //2. 获取日期
    LocalDateTime now = LocalDateTime.now();
    //3. 拼接key
    String keySuffix = now.format(DateTimeFormatter.ofPattern(":yyyyMM"));
    String key = USER_SIGN_KEY + userId + keySuffix;
    //4. 获取今天是当月第几天(1~31)
    int dayOfMonth = now.getDayOfMonth();
    //5. 写入Redis  BITSET key offset 1
    stringRedisTemplate.opsForValue().setBit(key, dayOfMonth - 1, true);
    return Result.ok();
}

12.3 签到统计