package com.gyee.alarm.mapper.auto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.alarm.model.auto.ProBasicDevice;
import com.gyee.alarm.model.auto.ProBasicDeviceMetrics;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 设备指标 Mapper 接口
 * </p>
 *
 * @author shilin
 * @since 2023-08-01
 */
public interface ProBasicDeviceMetricsMapper extends BaseMapper<ProBasicDeviceMetrics> {


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

            "</script>"})
    ProBasicDeviceMetrics getDeviceMetricsByCode(@Param("deviceId")String deviceId,
                                         @Param("metricCode")String metricCode);
    @Select({"<script>",
            "select * from pro_basic_device_metrics a",
            "<where>",
            "<if test='deviceId !=null' >",
            "and a.device_id=#{deviceId}",
            "</if>",
            "</where>",
            "order by metric_code ",
            "</script>"})
    List<ProBasicDeviceMetrics> getDeviceMetricsByDeviceId(@Param("deviceId")String deviceId);
    @Select({"<script>",
            "select * from pro_basic_device_metrics 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<ProBasicDeviceMetrics> getDeviceMetricsByStructureCode(@Param("deviceId")String deviceId,
                                                        @Param("structureCode")String structureCode);
    @Select({"<script>",
            "select * from pro_basic_device_metrics a ",
            "<where>",
            "<if test='deviceId !=null' >",
            "and a.device_id=#{deviceId}",
            "</if>",
            "<if test='structureCode !=null '>",
            "and a.structure_code=#{structureCode}",
            "</if>",
            "</where>",
            "order by metric_code ",
            "</script>"})

    IPage<ProBasicDeviceMetrics> pageQueryAll(Page page, @Param("deviceId")String deviceId, @Param("structureCode")String structureCode);
    @Select({"<script>",
            "select * from pro_basic_device_metrics a ",
            "<where>",
            "<if test='metricCode !=null '>",
            "and a.metric_code=#{metricCode}",
            "</if>",
            "</where>",

            "</script>"})
    ProBasicDeviceMetrics selectByMetriccode(@Param("metriccode")String metriccode);

}
