package com.sky.ioc.mapper.notice;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.notice.Feedback;
import com.sky.ioc.entity.params.notice.FeedBackParam;
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 FeedBackMapper extends BaseMapper<Feedback> {

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


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

    @Select("<script>" +
            " update feedback 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 feedback 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);
}
