package com.yutou.nas.Services.impl;

import com.yutou.nas.Services.IBangumiService;
import com.yutou.nas.mybatis.dao.BangumiItemDao;
import com.yutou.nas.mybatis.model.BangumiItem;
import com.yutou.nas.mybatis.model.BangumiItemExample;
import com.yutou.nas.utils.BTDownloadManager;
import com.yutou.nas.utils.Log;
import com.yutou.nas.utils.RedisTools;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("BangumiService")
public class BangumiServiceImpl implements IBangumiService {
    @Resource
    BangumiItemDao itemDao;
    @Override
    public List<BangumiItem> getAllBangumi() {
        BangumiItemExample example=new BangumiItemExample();
        example.createCriteria().andEnableEqualTo(1);
        return itemDao.selectByExample(example);
    }

    @Override
    public void download(int id,boolean isDownloadNext, String url) {
        BangumiItem item = itemDao.selectByPrimaryKey(id);
        if(item!=null){
            BTDownloadManager.download(item.getTitle(),url);
            if(!isDownloadNext){
                Log.i("跳过下载","确定跳过："+item.getTitle()+"的下载，id = "+item.getId());
                RedisTools.set(item.getId()+"","next");
            }
        }
    }
}
