package com.community.huiju.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.community.huiju.model.TpEquipment;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

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

    /**
     * 根据小区获取 监控列表 HLS
     * @param communityId
     * @return
     */
    @ResultType(TpEquipment.class)
    @Select("select " +
            "tm.*, " +
            "(select `key` FROM tp_configuration WHERE id = tm.url_id) as monitoringUrl, " +
            "(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 monitoringAddress " +
            "FROM " +
            "tp_equipment tm " +
            "where tm.community_id = #{communityId} and tm.equipment_type = 1")
    IPage<TpEquipment> selectMonitoringByCommunityId(IPage<TpEquipment> page, @Param("communityId") Integer communityId);

    /**
     * 根据小区 和 单元号 查询所有设备
     * @param communityId
     * @param unitId
     * @return
     */
    @ResultType(TpEquipment.class)
    @Select("select " +
            "te.* " +
            "from tp_unit_equipment trne left join tp_equipment te " +
            "on trne.equipment_id = te.id " +
            "where trne.community_id=#{communityId} and trne.unit_id=#{unitId} and te.equipment_type=#{equipmentType}")
    List<TpEquipment> selectByCommunityIdAndUnitId(Integer communityId, Integer unitId, Integer equipmentType);
}
