package tech.glinfo.enbao.modules.sh.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import tech.glinfo.enbao.modules.sh.entity.ShDlinkEntity;

import java.util.List;
import java.util.Map;

/**
 * @author lyt
 * @date 2021/9/18 17:16
 */
@Mapper
public interface OtherShDlinkDao extends BaseMapper<ShDlinkEntity> {



    @Select("<script>" +
            "  SELECT * FROM sh_dlink a WHERE a.device_id = ${deviceId} AND #{time} between a.`start` and a.`end` AND a.status = 1 LIMIT 1"
            +
            " </script>")
    ShDlinkEntity checkTime(String time, Integer deviceId);

    @Select("<script>" +
            "   SELECT b.id, b.name, b.numbering, b.numbering_flag numberingFlag FROM sh_dlink_device a, sh_device b WHERE a.device_id = b.id AND a.dlink_id = ${id}"
            +
            " </script>")
    List<Map<String, Object>> dlinkDeviceList(Integer id);

    @Select("<script>" +
            "   SELECT id,status_o,create_time,start,end,title,device_id,user_id,status_t,status, (select count(1) from sh_dlink_device b where a.id=b.dlink_id) cnt FROM sh_dlink a WHERE user_id = ${uid} ORDER BY id DESC"
            +
            " </script>")
    List<Map<String, Object>> list(Integer uid);
}
