package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.template.model.pojo.SmartNotification;
import com.template.mapper.SmartNotificationMapper;
import com.template.model.result.PageUtils;
import com.template.services.SmartNotificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-01-30
 */
@Service
public class SmartNotificationServiceImpl extends ServiceImpl<SmartNotificationMapper, SmartNotification> implements SmartNotificationService {

    @Override
    public PageUtils<SmartNotification> pageRemindingList(Integer id, int currentPage, int pageCount, String type) {

        LambdaQueryWrapper<SmartNotification> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SmartNotification::getUserId,id)
                .eq(ObjectUtils.isNotEmpty(type),SmartNotification::getType,type)
                .orderByDesc(SmartNotification::getDateTime);

        IPage<SmartNotification> page = this.page(new Page<>(currentPage, pageCount), wrapper);

        return new PageUtils<>(page);
    }
}
