package cn.com.ctop.crawler.modules.oceanengine.service.impl;

import cn.com.ctop.crawler.modules.oceanengine.entity.DouyinHot;
import cn.com.ctop.crawler.modules.oceanengine.mapper.DouyinHotMapper;
import cn.com.ctop.crawler.modules.oceanengine.service.IDouyinHotService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DouyinHotServiceImpl extends ServiceImpl<DouyinHotMapper, DouyinHot> implements IDouyinHotService {
    @Autowired
    private DouyinHotMapper douyinHotMapper;

    @Override
    public void replaceBatch(List<DouyinHot> list){
        douyinHotMapper.replaceBatch(list);
    }

    @Override
    public IPage<DouyinHot> queryHotFeeds(String userName, String start, String end, String orderByColumn, String orderByType, Integer pageNo, Integer pageSize) {
        QueryWrapper<DouyinHot> queryWrapper = new QueryWrapper<>();
        if (null != userName && !"".equals(userName)) {
            queryWrapper.like("user_name", "%" + userName + "%");
        }
        if (null != start && !"".equals(start) && null != end && !"".equals(end)) {
            queryWrapper.between("create_time", start, end);
        }
        if (null != orderByType && "desc".equals(orderByType)) {
            queryWrapper.orderByDesc(orderByColumn);
        } else {
            queryWrapper.orderByAsc(orderByColumn);
        }
        Page<DouyinHot> page = new Page<>(pageNo, pageSize);
        return this.page(page, queryWrapper);
    }

    @Override
    public List<DouyinHot> getId() {
        QueryWrapper<DouyinHot> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id").orderByDesc("create_time");
        return this.list(queryWrapper);

    }
}
