package com.hdkj.lt.bf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hdkj.lt.bf.entity.AlarmEvent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

/**
 * 告警事件 Mapper
 */
@Mapper
public interface AlarmEventMapper extends BaseMapper<AlarmEvent> {

    /**
     * 按日期查询告警列表，联表 t_psr 获取馈线名称
     *
     * @param alarmDate 告警日期
     * @return 告警列表（含馈线名称）
     */
    @Select("SELECT a.*, p.name AS feeder_name, rm.before_health_score AS healthScore " +
            "FROM t_alarm_event a " +
            "LEFT JOIN dwd_shb_ds_feeder_base p ON a.feeder_id = p.psr_id " +
            "LEFT JOIN fhzg_recon_result rr ON rr.event_id = a.id " +
            "LEFT JOIN fhzg_recon_metrics rm ON rm.result_id = rr.id " +
            "WHERE a.alarm_date = #{alarmDate} " +
            "ORDER BY a.last_alarm_time DESC")
    List<AlarmEvent> selectAlarmListWithFeederName(@Param("alarmDate") LocalDate alarmDate);
}
