<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.community.elevator.elevatoralarmsetting.mapper.AlarmSettingMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="alarmSettingResultMap" type="org.springblade.community.elevator.elevatoralarmsetting.entity.AlarmSetting">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="alarm_type" property="alarmType"/>
        <result column="alarm_name" property="alarmName"/>
        <result column="is_notice" property="isNotice"/>
        <result column="is_generate_job" property="isGenerateJob"/>
        <result column="level" property="level"/>
        <result column="residential_id" property="residentialId"/>
        <result column="residential_name" property="residentialName"/>
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="alarmTypeResultMap" type="org.springblade.modules.system.entity.DictBiz">
        <result column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="code" property="code"/>
        <result column="dict_key" property="dictKey"/>
        <result column="dict_value" property="dictValue"/>
        <result column="sort" property="sort"/>
        <result column="remark" property="remark"/>
        <result column="is_sealed" property="isSealed"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>

    <select id="selectAlarmSettingPage" resultMap="alarmSettingResultMap">
        SELECT dict.dict_key AS alarm_type, dict.dict_value AS alarm_name, setting.id, setting.is_notice, setting.tenant_id FROM `blade_dict_biz` dict
        LEFT JOIN yt_alarm_setting setting ON setting.alarm_type = dict.dict_key
        WHERE dict.`code` = 'yt_alarm_type'
        AND dict.dict_key != -1
        AND dict.is_deleted = 0
    </select>

    <select id="getNoUseAlarmSetting" resultMap="alarmTypeResultMap">
        SELECT * FROM blade_dict_biz
        WHERE code = 'yt_alarm_type'
        and dict_key != -1
        and dict_key NOT IN (SELECT alarm_type FROM `yt_alarm_setting` WHERE `level` = 2 and is_deleted = 0 and residential_id = #{residential})
    </select>

</mapper>
