package com.usoftchina.bi.server.dao.common;

import com.usoftchina.bi.core.base.TestPage;
import com.usoftchina.bi.server.model.po.MessageLog;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MessageLogMapper {

    @Insert("INSERT INTO BI_MESSAGELOG(BML_MODULE,BML_ORDER,BML_ID,BML_DATE,BML_MAN,BML_CONTENT,BML_RESULT,BML_SEARCH) "
            + "VALUES(#{module,jdbcType=VARCHAR}, #{order,jdbcType=VARCHAR}, #{id,jdbcType=INTEGER}, SYSDATE, #{userName,jdbcType=VARCHAR},"
            + "#{content,jdbcType=VARCHAR}, #{result,jdbcType=VARCHAR}, #{search,jdbcType=VARCHAR})")
    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT BI_MESSAGELOG_SEQ.NEXTVAL FROM DUAL",keyColumn = "id")
    void insert(MessageLog messageLog);


    @Select("SELECT * FROM BI_MESSAGELOG ORDER BY BML_ID DESC")
    @Results(id = "BaseResultMap", value = {
            @Result(id = true, column = "BML_ID", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "BML_DATE", property = "date", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "BML_MAN", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "BML_CONTENT", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "BML_RESULT", property = "result", jdbcType = JdbcType.VARCHAR),
            @Result(column = "BML_SEARCH", property = "search", jdbcType = JdbcType.VARCHAR),
            @Result(column = "BML_MODULE", property = "module", jdbcType = JdbcType.VARCHAR),
            @Result(column = "BML_ORDER", property = "order", jdbcType = JdbcType.VARCHAR),
    })
    List<MessageLog> list(TestPage testPage);
}
