package com.dji.sample.manage.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dji.sample.manage.model.dto.UpstreamDeviceDetailDTO;
import com.dji.sample.manage.model.entity.DeviceEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 * @author sean.zhou
 * @date 2021/11/10
 * @version 0.1
 */
public interface IDeviceMapper extends BaseMapper<DeviceEntity> {


    @Select("<script> " +
            "SELECT md.device_sn deviceSn " +
            " ,md.workspace_id workspaceId "+
            " ,mw.workspace_name workspaceName "+
            " ,md.nickname "+
            " ,md.device_name deviceName "+
            "   from manage_device md " +
            " left join manage_workspace mw on md.workspace_id = mw.workspace_id " +
            " where 1 = 1 " +
            "<if test='workspaceName != null'> " +
            " and worksapce_name LIKE CONCAT('%', #{workspaceName},'%')" +
            " </if> "+
            "<if test='workspaceId != null'> " +
            " and md.workspace_id = #{workspaceId} " +
            " </if> "+
            "</script>")
    List<UpstreamDeviceDetailDTO> selUpstreamDeviceList(@Param("workspaceName") String workspaceName,@Param("workspaceId") String workspaceId);

}