package com.sky.ioc.mapper.notice;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.notice.Notice;
import com.sky.ioc.entity.params.notice.NoticeParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface NoticeMapper extends BaseMapper<Notice> {

    @Select("<script>" +
            "select id,title,content,address,type,time,status from notice where is_del=0 " +
            "<if test='noticeParam!=null and noticeParam.startTime != null '>" +
            "<![CDATA[ and time >= #{noticeParam.startTime} AND time <= #{noticeParam.endTime} ]]> " +
            "</if>" +
            "<if test='noticeParam!=null and noticeParam.type != null '>" +
            " and type=#{noticeParam.type} " +
            "</if>"+
            "<if test='noticeParam!=null and noticeParam.status != null '>" +
            " and status=#{noticeParam.status} " +
            "</if>"+
            " order by time desc " +
            "<if test='noticeParam!=null and noticeParam.pageSize != null and noticeParam.pageStart != null '>" +
            " limit #{noticeParam.pageSize} offset #{noticeParam.pageStart} " +
            "</if>"+
            "</script>")
    List<Map<String,Object>> listPage(@Param("noticeParam")NoticeParam noticeParam);


    @Select("<script>" +
            "select count(1) from notice where is_del=0 " +
            "<if test='noticeParam!=null and noticeParam.startTime != null '>" +
            "<![CDATA[ and time >= #{noticeParam.startTime} AND time <= #{noticeParam.endTime} ]]> " +
            "</if>" +
            "<if test='noticeParam!=null and noticeParam.type != null '>" +
            " and type=#{noticeParam.type} " +
            "</if>"+
            "<if test='noticeParam!=null and noticeParam.status != null '>" +
            " and status=#{noticeParam.status} " +
            "</if>"+
            "</script>")
    long  countPage(@Param("noticeParam")NoticeParam noticeParam);

    @Select("<script>" +
            " update notice set status = 1,update_time = now()  " +
            " where id in (<foreach collection='ids' item='id' index='no' separator=','>#{id}</foreach>) "
            + "</script>")
    Integer updateStatusByIds(@Param("ids") List<Integer> ids);

    @Select("<script>" +
            " update notice set is_del = 1, update_time = now()  " +
            " where id in (<foreach collection='ids' item='id' index='no' separator=','>#{id}</foreach>) "
            + "</script>")
    Integer delByIds(@Param("ids") List<Integer> ids);

}
