package com.gyee.alarm.mapper.auto;

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

import java.util.List;

/**
 * <p>
 * 设备故障模型 Mapper 接口
 * </p>
 *
 * @author shilin
 * @since 2023-08-01
 */
public interface ProBasicDeviceFaultModeMapper extends BaseMapper<ProBasicDeviceFaultMode> {

    @Select({"<script>",
            "select * from pro_basic_device_fault_mode a ",
            "<where>",
            "<if test='code !=null' >",
            "and a.code=#{code}",
            "</if>",
            "</where>",

            "</script>"})
    ProBasicDeviceFaultMode getDeviceFaultModeByCode(@Param("code")String code);

    @Select({"<script>",
            "select * from pro_basic_device_fault_mode a ",
            "<where>",
            "<if test='deviceId !=null' >",
            "and a.device_id=#{deviceId}",
            "</if>",
            "</where>",

            "</script>"})
    List<ProBasicDeviceFaultMode> getDeviceFaultModeByDeviceId(@Param("deviceId")String deviceId);

    @Select({"<script>",
            "select * from pro_basic_device_fault_mode a ",
            "<where>",
            "<if test='deviceId !=null' >",
            "and a.device_id=#{deviceId}",
            "</if>",
            "<if test='structureCode !=null' >",
            "and   a.structure_code like '${structureCode}%'",
            "</if>",
            "</where>",

            "</script>"})
    List<ProBasicDeviceFaultMode> getDeviceFaultModeByStructureCode(@Param("deviceId")String deviceId,
                                                            @Param("structureCode")String structureCode);

    @Select({"<script>",
            "select * from pro_basic_device_fault_mode a ",
            "<where>",
            "<if test='deviceId !=null' >",
            "and a.device_id=#{deviceId}",
            "</if>",
            "<if test='nodeCode !=null' >",
            "and a.code=#{nodeCode}",
            "</if>",
            "</where>",

            "</script>"})
    ProBasicDeviceFaultMode getDeviceFaultModeTree(@Param("deviceId")String deviceId,
                                           @Param("nodeCode")String nodeCode);
}
