package org.jeecg.modules.newWarning.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.newWarning.entity.NewWarnHistory;

import java.util.List;

/**
 * <p>
 * 报警历史数据表 Mapper 接口
 * </p>
 *
 * @author zrj
 * @since 2022-12-09
 */

public interface NewWarnHistoryMapper extends BaseMapper<NewWarnHistory> {

    @Select(" select * from \n" +
            " ( select t.*, row_number() over(partition by jh order by warn_time desc) as row_number from WARN_HISTORY t \n" +
            "  ${ew.customSqlSegment} \n" +
            " ) temp\n" +
            " where row_number='1'")
    Page<NewWarnHistory> groupSelct(@Param("ew")QueryWrapper<NewWarnHistory> wrapper, Page<NewWarnHistory> page);

    /**
     * 按照日期分组查询返回日期列表数据
     * @return
     */
    @Select("select to_char(warn_time,'yyyy-MM-dd') as warnDate from WARN_HISTORY group by to_char(warn_time,'yyyy-MM-dd') order by  to_char(warn_time,'yyyy-MM-dd') desc")
    List<String> groupData();

    @Select("select * from ( select *from WARN_HISTORY ${ew.customSqlSegment}) where rownum<2")
    NewWarnHistory selectOneOrcale(@Param("ew")QueryWrapper<NewWarnHistory> wrapper);


}
