package com.ruoyi.framework.tesk;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.recovery.domain.RecContent;
import com.ruoyi.framework.recovery.service.IRecContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("ThumbsTask")
public class ThumbsTask {
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IRecContentService recContentService;

    public void ThumbsTaskSaveMysql() {
        List<RecContent> contents = recContentService.selectRecContentList(new RecContent());
        for (RecContent content : contents) {
            Object value = redisCache.getCacheMapValue(Constants.THUMBS_UP + content.getId(), "like");
            if (value != null) {
                content.setThumbs(Long.parseLong(value.toString()));
                recContentService.updateRecContent(content);
            }
        }
    }
}
