package com.fzm.mall.server.front.user.mapper;

import com.fzm.mall.server.front.user.model.Notice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.user.model.vo.NoticeVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 消息中心-公告 Mapper 接口
 * </p>
 *
 * @author fzm
 * @since 2021-06-02
 */
public interface NoticeMapper extends BaseMapper<Notice> {

    @Select("select * from notice where start_time<= #{time} and end_time >= #{time}  order by create_time desc limit #{start},#{size}")
    List<NoticeVo> getWithOutUid(@Param("start") int start, @Param("size") Integer size,@Param("time")long time);

    @Select("select count(*) from user_notice where uid = #{uid} and notice_id = #{n}")
    int getCountUidN(@Param("uid") String uid, @Param("n") String n);

    @Select("select count(*) from notice where start_time<= #{time} and end_time >= #{time}")
    Integer getCountTime(@Param("time")long time);

    @Select("select count(*) from user_notice where uid = #{uid} and notice_id = #{noticeId} ")
    int check(@Param("uid") String uid, @Param("noticeId") String noticeId);

    @Insert("insert into user_notice values(#{uid},#{noticeId},#{time},#{time})")
    void add(@Param("uid") String uid, @Param("noticeId") String noticeId, @Param("time") long currentTimeMillis);
}
