package com.gyee.runeconomy.mapper.auto;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gyee.runeconomy.model.auto.ProEconAlarmType;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 自定义类型 Mapper 接口
 * </p>
 *
 * @author wang
 * @since 2023-12-06
 */
public interface ProEconAlarmTypeMapper extends BaseMapper<ProEconAlarmType> {

    @Select("SELECT pro_econ_alarm_type.name, COUNT(pro_econ_shutdown_event.warning_id) AS num_of_warnings " +
            "FROM pro_econ_alarm_type " +
            "LEFT JOIN pro_econ_alarm_configuration ON pro_econ_alarm_type.nem_code = pro_econ_alarm_configuration.components " +
            "LEFT JOIN pro_econ_shutdown_event ON pro_econ_alarm_configuration.id = pro_econ_shutdown_event.warning_id " +
            "WHERE pro_econ_shutdown_event.stop_time::date = current_date " +
            "GROUP BY pro_econ_alarm_type.name")
    List<Map<String, Object>> getAlarmTypeCounts();

    @Select("SELECT pro_econ_alarm_type.name, COUNT(pro_econ_shutdown_event.warning_id) AS num_of_warnings " +
            "FROM pro_econ_alarm_type " + "LEFT JOIN pro_econ_alarm_configuration ON pro_econ_alarm_type.nem_code = pro_econ_alarm_configuration.components " +
            "LEFT JOIN pro_econ_shutdown_event ON pro_econ_alarm_configuration.id = pro_econ_shutdown_event.warning_id " +
            "WHERE EXTRACT(MONTH FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(MONTH FROM current_date) " +
            "GROUP BY pro_econ_alarm_type.name")
    List<Map<String, Object>> getAlarmTypeCountsmonth();


    @Select("SELECT pro_econ_alarm_type.name, COUNT(pro_econ_shutdown_event.warning_id) AS num_of_warnings "
            + "FROM pro_econ_alarm_type " + "LEFT JOIN pro_econ_alarm_configuration ON pro_econ_alarm_type.nem_code = pro_econ_alarm_configuration.components " +
            "LEFT JOIN pro_econ_shutdown_event ON pro_econ_alarm_configuration.id = pro_econ_shutdown_event.warning_id " +
            "WHERE EXTRACT(YEAR FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(YEAR FROM current_date) " +
            "GROUP BY pro_econ_alarm_type.name")
    List<Map<String, Object>> getAlarmTypeCountsyear();


    @Select("SELECT pro_econ_alarm_type.name, COUNT(pro_econ_shutdown_event.warning_id) AS num_of_warnings " +
            "FROM pro_econ_alarm_type " +
            "LEFT JOIN pro_econ_alarm_configuration ON pro_econ_alarm_type.nem_code = pro_econ_alarm_configuration.components " +
            "LEFT JOIN pro_econ_shutdown_event ON pro_econ_alarm_configuration.id = pro_econ_shutdown_event.warning_id " +
            "WHERE pro_econ_shutdown_event.stop_time::date = current_date " +
            "AND pro_econ_shutdown_event.windpowerstation_id = #{wpId} " +
            "GROUP BY pro_econ_alarm_type.name")
    List<Map<String, Object>> getAlarmTypeCountscz(@Param("wpId") String wpId);

    @Select("SELECT pro_econ_alarm_type.name, COUNT(pro_econ_shutdown_event.warning_id) AS num_of_warnings " +
            "FROM pro_econ_alarm_type " +
            "LEFT JOIN pro_econ_alarm_configuration ON pro_econ_alarm_type.nem_code = pro_econ_alarm_configuration.components " +
            "LEFT JOIN pro_econ_shutdown_event ON pro_econ_alarm_configuration.id = pro_econ_shutdown_event.warning_id " +
            "WHERE EXTRACT(MONTH FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(MONTH FROM current_date) " +
            "AND pro_econ_shutdown_event.windpowerstation_id = #{wpId} " +
            "GROUP BY pro_econ_alarm_type.name")
    List<Map<String, Object>> getAlarmTypeCountsmonthcz(@Param("wpId") String wpId);

    @Select("SELECT pro_econ_alarm_type.name, COUNT(pro_econ_shutdown_event.warning_id) AS num_of_warnings " +
            "FROM pro_econ_alarm_type " + "LEFT JOIN pro_econ_alarm_configuration ON pro_econ_alarm_type.nem_code = pro_econ_alarm_configuration.components " +
            "LEFT JOIN pro_econ_shutdown_event ON pro_econ_alarm_configuration.id = pro_econ_shutdown_event.warning_id " +
            "WHERE EXTRACT(YEAR FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(YEAR FROM current_date) " +
            "AND pro_econ_shutdown_event.windpowerstation_id = #{wpId} " +
            "GROUP BY pro_econ_alarm_type.name")
    List<Map<String, Object>> getAlarmTypeCountsyearcz(@Param("wpId") String wpId);


    @Select("SELECT pro_econ_equipmentmodel.name, COUNT(pro_econ_shutdown_event.windturbine_id) AS num_of_events " +
            "FROM pro_econ_equipmentmodel " +
            "JOIN pro_basic_equipment ON pro_econ_equipmentmodel.id = pro_basic_equipment.model_id " +
            "JOIN pro_econ_shutdown_event ON pro_basic_equipment.id = pro_econ_shutdown_event.windturbine_id " +
            "WHERE pro_econ_shutdown_event.stop_time::date = current_date " +
            "GROUP BY pro_econ_equipmentmodel.name")
    List<Map<String, Object>> getResults();

    @Select("SELECT pro_econ_equipmentmodel.name, COUNT(pro_econ_shutdown_event.windturbine_id) AS num_of_events " +
            "FROM pro_econ_equipmentmodel " +
            "JOIN pro_basic_equipment ON pro_econ_equipmentmodel.id = pro_basic_equipment.model_id " +
            "JOIN pro_econ_shutdown_event ON pro_basic_equipment.id = pro_econ_shutdown_event.windturbine_id " +
            "WHERE EXTRACT(MONTH FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(MONTH FROM current_date) " +
            "GROUP BY pro_econ_equipmentmodel.name")
    List<Map<String, Object>> getResultsmonth();

    @Select("SELECT pro_econ_equipmentmodel.name, COUNT(pro_econ_shutdown_event.windturbine_id) AS num_of_events " +
            "FROM pro_econ_equipmentmodel " +
            "JOIN pro_basic_equipment ON pro_econ_equipmentmodel.id = pro_basic_equipment.model_id " +
            "JOIN pro_econ_shutdown_event ON pro_basic_equipment.id = pro_econ_shutdown_event.windturbine_id " +
            "WHERE EXTRACT(YEAR FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(YEAR FROM current_date) " +
            "GROUP BY pro_econ_equipmentmodel.name")
    List<Map<String, Object>> getResultsyear();

    @Select("SELECT pro_econ_equipmentmodel.name, COUNT(pro_econ_shutdown_event.windturbine_id) AS num_of_events " +
            "FROM pro_econ_equipmentmodel " +
            "JOIN pro_basic_equipment ON pro_econ_equipmentmodel.id = pro_basic_equipment.model_id " +
            "JOIN pro_econ_shutdown_event ON pro_basic_equipment.id = pro_econ_shutdown_event.windturbine_id " +
            "WHERE pro_econ_shutdown_event.stop_time::date = current_date " +
            "AND pro_econ_shutdown_event.windpowerstation_id = #{wpId} " +
            "GROUP BY pro_econ_equipmentmodel.name")
    List<Map<String, Object>> getResultscz(@Param("wpId") String wpId);

    @Select("SELECT pro_econ_equipmentmodel.name, COUNT(pro_econ_shutdown_event.windturbine_id) AS num_of_events " +
            "FROM pro_econ_equipmentmodel " +
            "JOIN pro_basic_equipment ON pro_econ_equipmentmodel.id = pro_basic_equipment.model_id " +
            "JOIN pro_econ_shutdown_event ON pro_basic_equipment.id = pro_econ_shutdown_event.windturbine_id " +
            "WHERE EXTRACT(MONTH FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(MONTH FROM current_date) " +
            "AND pro_econ_shutdown_event.windpowerstation_id = #{wpId} " +
            "GROUP BY pro_econ_equipmentmodel.name")
    List<Map<String, Object>> getResultsmonthcz(@Param("wpId") String wpId);

    @Select("SELECT pro_econ_equipmentmodel.name, COUNT(pro_econ_shutdown_event.windturbine_id) AS num_of_events " +
            "FROM pro_econ_equipmentmodel " +
            "JOIN pro_basic_equipment ON pro_econ_equipmentmodel.id = pro_basic_equipment.model_id " +
            "JOIN pro_econ_shutdown_event ON pro_basic_equipment.id = pro_econ_shutdown_event.windturbine_id " +
            "WHERE EXTRACT(YEAR FROM pro_econ_shutdown_event.stop_time::date) = EXTRACT(YEAR FROM current_date) " +
            "AND pro_econ_shutdown_event.windpowerstation_id = #{wpId} " +
            "GROUP BY pro_econ_equipmentmodel.name")
    List<Map<String, Object>> getResultsyearcz(@Param("wpId") String wpId);

}
