package com.yeejoin.amos.boot.module.jxiop.biz.tdmapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IndicatorData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IndicatorDataMapper extends BaseMapper<IndicatorData> {

    @Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and equipment_number = #{equipmentNumber} and  created_time >= #{startTime} and created_time <= #{endTime} and gateway_id =#{gatewayId}")
    List<IndicatorData> selectDataByequipmentIndexNameAndtimeAndEquipmentNumber(@Param("equipmentIndexName") String equipmentIndexName, @Param("equipmentNumber") String equipmentNumber, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId);

    @Select("select `value`, created_time, `value_f` as valueF, equipment_index_name from iot_data.indicator_data where equipment_index_name like '%路电流%' and equipment_number = #{equipmentNumber} and  created_time >= #{startTime} and created_time <= #{endTime} and gateway_id =#{gatewayId}")
    List<IndicatorData> selectDataByequipmentIndexNameAndtimeAndEquipmentNumberPv(@Param("equipmentNumber") String equipmentNumber, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId);

    @Select("select last(`value_f`) as `value_f`,created_time from  iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and gateway_id=#{gatewayId} ")
    IndicatorData selectLastDataOfPower(@Param("equipmentIndexName") String equipmentIndexName, @Param("gatewayId") String gatewayId);

    @Select("select last(`value_f`) as `value_f`,created_time from  iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and gateway_id=#{gatewayId} and created_time <= #{endTime} ")
    IndicatorData selectLastDataOfPower(@Param("equipmentIndexName") String equipmentIndexName, @Param("gatewayId") String gatewayId,@Param("endTime") String endTime);
    @Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName}  and  created_time >= #{startTime} and created_time <= #{endTime} and gateway_id =#{gatewayId}")
    List<IndicatorData> selectDataByequipmentIndexNameAndtime(@Param("equipmentIndexName") String equipmentIndexName, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId);
}
