package com.huiju.estateagents.property.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huiju.estateagents.property.model.TpEquipment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 设备表 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-04-15
 */
@Mapper
public interface TpEquipmentMapper extends BaseMapper<TpEquipment> {

    /**
     * 根据小区id 和 类型查询
     * @param communityId
     * @param equipmentType
     * @return
     */
    @ResultType(TpEquipment.class)
    @Select("select " +
            "tm.*, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.url_id) as url, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.security_guard_tel_id) as securityGuardTel, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.security_room_tel_id) as securityRoomTel, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.address_id) as address, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.uuid_id)as uuid " +
            "FROM " +
            "tp_equipment tm " +
            "where tm.community_id = #{communityId} and tm.equipment_type = #{equipmentType}")
    List<TpEquipment> selectAllByCommunityAndEquipmentType(@Param("communityId") Integer communityId, @Param("equipmentType") Integer equipmentType);


    /**
     * 根据小区id 和 类型查询 和 设备id
     * @param communityId
     * @param equipmentType
     * @return
     */
    @ResultType(TpEquipment.class)
    @Select("select " +
            "tm.*, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.url_id) as url, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.security_guard_tel_id) as securityGuardTel, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.security_room_tel_id) as securityRoomTel, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.address_id) as address, " +
            "(select configuration_value FROM tp_configuration WHERE id = tm.uuid_id)as uuid " +
            "FROM " +
            "tp_equipment tm " +
            "where tm.community_id = #{communityId} and tm.equipment_type = #{equipmentType} and tm.id = #{monitoringId}")
    TpEquipment getMonitoringById(@Param("communityId") Integer communityId, @Param("equipmentType") Integer equipmentType, @Param("monitoringId") Integer monitoringId);


}
