package com.fzm.mall.server.front.user.service.impl;

import com.fzm.mall.server.front.goods.model.vo.PageVo;
import com.fzm.mall.server.front.user.model.Notice;
import com.fzm.mall.server.front.user.mapper.NoticeMapper;
import com.fzm.mall.server.front.user.model.vo.NoticeVo;
import com.fzm.mall.server.front.user.service.INoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 消息中心-公告 服务实现类
 * </p>
 *
 * @author fzm
 * @since 2021-06-02
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {


    @Autowired
    private NoticeMapper noticeMapper;
    @Override
    public List<NoticeVo> getWithOutUid(PageVo pageVo) {
        int start = (pageVo.getPage()-1)*pageVo.getSize();
        return noticeMapper.getWithOutUid(start,pageVo.getSize(),System.currentTimeMillis());
    }

    @Override
    public boolean isRead(String uid,String n) {
        int i = noticeMapper.getCountUidN(uid,n);
        if(i != 0){
            return  true;
        }else{
            return  false;
        }
    }

    @Override
    public Integer getCount() {
        return noticeMapper.getCountTime(System.currentTimeMillis());
    }

    @Override
    public void addNotice(String uid, String noticeId) {
        int i = noticeMapper.check(uid,noticeId);
        if(i == 0){
            noticeMapper.add(uid,noticeId,System.currentTimeMillis());
        }
    }
}
