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

import cn.com.ctop.crawler.modules.oceanengine.entity.HotMaterial;
import cn.com.ctop.crawler.modules.oceanengine.mapper.HotMaterialMapper;
import cn.com.ctop.crawler.modules.oceanengine.service.IHotMaterialService;
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.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Primary

public class HotMaterialServiceImpl extends ServiceImpl<HotMaterialMapper, HotMaterial> implements IHotMaterialService {
    @Override
    public IPage<HotMaterial> queryHotFeeds(String title,String userName, String start, String end, String orderByColumn, String orderByType, Integer pageNo, Integer pageSize) {
        QueryWrapper<HotMaterial> queryWrapper = new QueryWrapper<>();
        if (null != userName && !"".equals(userName)) {
            queryWrapper.like("author", userName);
        }
        if (null != title && !"".equals(title)) {
            queryWrapper.like("title", title);
        }
        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<HotMaterial> page = new Page<>(pageNo, pageSize);
        return this.page(page, queryWrapper);
    }

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