package com.sunyard.ssp.modules.monitor.log.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sunyard.ssp.modules.monitor.log.entity.SysLog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fyc
 * @since 2020-03-31
 */
@Repository
public interface SysLogMapper extends BaseMapper<SysLog> {

    @Select("<script>"+
            " SELECT *\n" +
            "        FROM SC_SYS_LOG\n" +
            "        <where>\n" +
            "            <if test=\"keyWord!='' and keyWord!=null\">\n" +
            "                and instr(FILE_NAME||LINE||THREAD||LOG_LEVEL||MESSAGE||CLAZZ||METHOD,#{keyWord},1,1)>0\n" +
            "            </if>\n" +
            "            <if test=\"startTime != null and endTime !=null\">\n" +
            "              and CREATE_TIME  between #{startTime} and #{endTime}\n" +
            "            </if>\n" +
            "        </where>\n" +
            "        order by CREATE_TIME desc"+
            "</script>")
    List<SysLog> queryList(IPage<SysLog> iPage,
                           @Param("keyWord") String keyWord,
                           @Param("startTime") LocalDate startTime,
                           @Param("endTime")LocalDate endTime);

    @Update("<script>"+
            "truncate table SC_SYS_LOG"+
            "</script>")
    Integer truncateTable();
}
