<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.northking.cctp.device.db.dao.CdMobileDeviceDao">

    <resultMap id="DetailMap" type="net.northking.cctp.device.dto.device.CdMobileDeviceDetailDto">
        <!-- 主键id -->
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <!-- 平台类型 -->
        <result column="platform" jdbcType="VARCHAR" property="platform"/>
        <!-- 平台版本 -->
        <result column="platform_version" jdbcType="VARCHAR" property="platformVersion"/>
    </resultMap>

    <select id="queryPage" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceQueryDto">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cdp.expired_time AS projectExpiredTime,
        cdt.expired_time AS tenantExpiredTime,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdt.recycle_type AS tenantRecycleType,
        cdp.recycle_type AS proRecycleType
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status != '3'
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>

            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceStatus != null">
                AND cds.device_status = #{deviceStatus,jdbcType=VARCHAR}
            </if>
            <if test="usageStatus != null">
                AND cds.usage_status = #{usageStatus,jdbcType=VARCHAR}
            </if>
            <if test="tenantId != null">
                AND cdt.tenant_id = #{tenantId,jdbcType=VARCHAR}
            </if>
            <if test="projectId != null">
                AND cdp.project_id = #{projectId,jdbcType=VARCHAR}
            </if>
            <if test="projectExpiredTimeStart != null">
                AND cdp.expired_time >= #{projectExpiredTimeStart,jdbcType=TIMESTAMP}
            </if>
            <if test="projectExpiredTimeEnd != null">
                AND cdp.expired_time &lt;= #{projectExpiredTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="tenantExpiredTimeStart != null">
                AND cdt.expired_time >= #{tenantExpiredTimeStart,jdbcType=TIMESTAMP}
            </if>
            <if test="tenantExpiredTimeEnd != null">
                AND cdt.expired_time &lt;= #{tenantExpiredTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="proNull != null">
                AND cdp.project_id is null
            </if>
            <if test="tenantNull != null">
                AND cdt.tenant_id is null
            </if>
            <if test="proCheck != null">
                AND cdp.project_id is not null
            </if>
            <if test="tenantCheck != null">
                AND cdt.tenant_id is not null
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>

    <select id="queryDeviceByPro" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceScriptDto">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdm.model_img AS modelImg,
        cdm.ram_size AS ramSize,
        cdm.resolution AS resolution
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status = '1'
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null and productName != ''">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>
            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="usageStatus != null and usageStatus.size > 0">
                AND cds.usage_status in
                <foreach collection="usageStatus" item="status" open="(" separator="," close=")">
                    #{status,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="tenantId != null">
                AND cdt.tenant_id = #{tenantId,jdbcType=VARCHAR}
            </if>
            <if test="proCheck != null">
                AND cdp.project_id = #{projectId,jdbcType=VARCHAR}
            </if>
            <if test="proNull != null">
                AND cdp.project_id is null
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>


    <select id="queryAllMobDevice" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceScriptDto">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdm.model_img AS modelImg,
        cdm.ram_size AS ramSize,
        cdm.resolution AS resolution,
        token.user_by AS userBy,
        token.user_id AS userId
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        LEFT JOIN cd_device_token token ON token.id = cmd.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status = '1'
            and cds.usage_status != '3'
            and (cdt.tenant_id = #{tenantId,jdbcType=VARCHAR} or cdt.tenant_id is null)
            and (cdp.project_id = #{projectId,jdbcType=VARCHAR} or cdp.project_id is null)
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null and productName != ''">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>
            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="usageStatus != null and usageStatus.size > 0">
                AND cds.usage_status in
                <foreach collection="usageStatus" item="status" open="(" separator="," close=")">
                    #{status,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceList != null and deviceList.size > 0">
                AND cmd.id in
                <foreach collection="deviceList" item="deviceId" open="(" separator="," close=")">
                    #{deviceId,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>


    <select id="queryPublicMobDevice" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceScriptDto">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdm.model_img AS modelImg,
        cdm.ram_size AS ramSize,
        cdm.resolution AS resolution,
        token.user_by AS userBy,
        token.user_id AS userId
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        LEFT JOIN cd_device_token token ON token.id = cmd.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status = '1'
            and cds.usage_status != '3'
            and  cdp.project_id is null
            and (cdt.tenant_id = #{tenantId,jdbcType=VARCHAR} or cdt.tenant_id is null)
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null and productName != ''">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>
            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="usageStatus != null and usageStatus.size > 0">
                AND cds.usage_status in
                <foreach collection="usageStatus" item="status" open="(" separator="," close=")">
                    #{status,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceList != null and deviceList.size > 0">
                AND cmd.id in
                <foreach collection="deviceList" item="deviceId" open="(" separator="," close=")">
                    #{deviceId,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>

    <select id="queryPrivateMobDevice" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceScriptDto">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdm.model_img AS modelImg,
        cdm.ram_size AS ramSize,
        cdm.resolution AS resolution,
        token.user_by AS userBy,
        token.user_id AS userId
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        LEFT JOIN cd_device_token token ON token.id = cmd.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status = '1'
            and cds.usage_status != '3'
            and  cdp.project_id = #{projectId,jdbcType=VARCHAR}
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null and productName != ''">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>
            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="usageStatus != null and usageStatus.size > 0">
                AND cds.usage_status in
                <foreach collection="usageStatus" item="status" open="(" separator="," close=")">
                    #{status,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceList != null and deviceList.size > 0">
                AND cmd.id in
                <foreach collection="deviceList" item="deviceId" open="(" separator="," close=")">
                    #{deviceId,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>


    <select id="queryDeviceList" resultMap="BaseResultMap">
        select
        cmd.*
        from
        <include refid="Table_Name"/> cmd
        left join cd_device_status cds
        ON cmd.id = cds.id
        where
        cds.device_status = '1'
        and cmd.id in
        <foreach collection="list" item="idItem" open="(" separator="," close=")">
            #{idItem, jdbcType=VARCHAR}
        </foreach>
    </select>


    <select id="queryMobileList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from
        <include refid="Table_Name"/>
        where id in
        <foreach collection="list" item="idItem" open="(" separator="," close=")">
            #{idItem, jdbcType=VARCHAR}
        </foreach>
    </select>


    <select id="queryCtrlIds" resultType="string" parameterType="java.util.List">
        select
        DISTINCT
        ctrl_id
        from
        <include refid="Table_Name"/> cmd
        left join cd_device_status cds
        ON cmd.id = cds.id
        where
        cmd.id in
        <foreach collection="list" item="idItem" open="(" separator="," close=")">
            #{idItem, jdbcType=VARCHAR}
        </foreach>
    </select>

    <update id="updateDeviceCtrl">
        update
        <include refid="Table_Name"/>
        set
        ctrl_id=#{ctrlId}
        where id in
        <foreach collection="ids" item="idItem" open="(" separator="," close=")">
            #{idItem, jdbcType=VARCHAR}
        </foreach>
    </update>


    <select id="queryAllMobDevice2" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceScriptDto2">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdm.model_img AS modelImg,
        cdm.ram_size AS ramSize,
        cdm.resolution AS resolution,
        token.user_by AS userBy,
        token.user_id AS userId
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        LEFT JOIN cd_device_token token ON token.id = cmd.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status = '1'
            and cds.usage_status != '3'
            and (cdt.tenant_id = #{tenantId,jdbcType=VARCHAR} or cdt.tenant_id is null)
            and (cdp.project_id in
            <foreach collection="proIds" open="(" close=")" separator="," item="projectId">
                #{projectId}
            </foreach>
            or cdp.project_id is null)
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null and productName != ''">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>
            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="usageStatus != null and usageStatus.size > 0">
                AND cds.usage_status in
                <foreach collection="usageStatus" item="status" open="(" separator="," close=")">
                    #{status,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceList != null and deviceList.size > 0">
                AND cmd.id in
                <foreach collection="deviceList" item="deviceId" open="(" separator="," close=")">
                    #{deviceId,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceSelectQueryDto!=null">
                <if test="deviceSelectQueryDto.brandId != null and deviceSelectQueryDto.brandId !=''">
                    AND cdm.brand_id=#{deviceSelectQueryDto.brandId}
                </if>
                <if test="deviceSelectQueryDto.modelName != null and deviceSelectQueryDto.modelName !=''">
                    AND LOCATE(#{deviceSelectQueryDto.modelName,jdbcType=VARCHAR},cdm.model_name)>0
                </if>
                <if test="deviceSelectQueryDto.resolution != null and deviceSelectQueryDto.resolution !=''">
                    AND cdm.resolution=#{deviceSelectQueryDto.resolution}
                </if>
                <if test="deviceSelectQueryDto.versionCode != null and deviceSelectQueryDto.versionCode!=''">
                    AND cmd.platform_version=#{deviceSelectQueryDto.versionCode}
                </if>
                <if test="deviceSelectQueryDto.versionType != null and deviceSelectQueryDto.versionType !=''">
                    AND cmd.platform=#{deviceSelectQueryDto.versionType}
                </if>
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>


    <select id="queryPublicMobDevice2" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceScriptDto2">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdm.model_img AS modelImg,
        cdm.ram_size AS ramSize,
        cdm.resolution AS resolution,
        token.user_by AS userBy,
        token.user_id AS userId
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        LEFT JOIN cd_device_token token ON token.id = cmd.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status = '1'
            and cds.usage_status != '3'
            and  cdp.project_id is null
            and (cdt.tenant_id = #{tenantId,jdbcType=VARCHAR} or cdt.tenant_id is null)
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null and productName != ''">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>
            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="usageStatus != null and usageStatus.size > 0">
                AND cds.usage_status in
                <foreach collection="usageStatus" item="status" open="(" separator="," close=")">
                    #{status,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceList != null and deviceList.size > 0">
                AND cmd.id in
                <foreach collection="deviceList" item="deviceId" open="(" separator="," close=")">
                    #{deviceId,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceSelectQueryDto!=null">
                <if test="deviceSelectQueryDto.brandId != null and deviceSelectQueryDto.brandId !=''">
                    AND cdm.brand_id=#{deviceSelectQueryDto.brandId}
                </if>
                <if test="deviceSelectQueryDto.modelName != null and deviceSelectQueryDto.modelName !=''">
                    AND LOCATE(#{deviceSelectQueryDto.modelName,jdbcType=VARCHAR},cdm.model_name)>0
                </if>
                <if test="deviceSelectQueryDto.resolution != null and deviceSelectQueryDto.resolution !=''">
                    AND cdm.resolution=#{deviceSelectQueryDto.resolution}
                </if>
                <if test="deviceSelectQueryDto.versionCode != null and deviceSelectQueryDto.versionCode!=''">
                    AND cmd.platform_version=#{deviceSelectQueryDto.versionCode}
                </if>
                <if test="deviceSelectQueryDto.versionType != null and deviceSelectQueryDto.versionType !=''">
                    AND cmd.platform=#{deviceSelectQueryDto.versionType}
                </if>
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>

    <select id="queryPrivateMobDevice2" resultMap="DetailMap"
            parameterType="net.northking.cctp.device.dto.device.CdMobileDeviceScriptDto2">
        SELECT
        cmd.id,
        cmb.brand_name_cn AS brandNameCn,
        cdm.model_name AS modelName,
        cdm.product_name AS productName,
        cmd.platform,
        cmd.platform_version,
        cdc.ctrl_ip AS ctrlIp,
        cdc.ctrl_addr AS ctrlAddr,
        cdp.project_id AS projectId,
        cds.device_status AS deviceStatus,
        cds.usage_status AS usageStatus,
        cdt.tenant_id AS tenantId,
        cdm.model_img AS modelImg,
        cdm.ram_size AS ramSize,
        cdm.resolution AS resolution,
        token.user_by AS userBy,
        token.user_id AS userId
        FROM cd_mobile_device cmd
        LEFT JOIN cd_device_tenant cdt ON cmd.id = cdt.id
        LEFT JOIN cd_device_project cdp ON cmd.id = cdp.id
        LEFT JOIN cd_device_status cds ON cmd.id = cds.id
        LEFT JOIN cd_device_model cdm ON cmd.model_id = cdm.id
        LEFT JOIN cd_device_ctrl cdc ON cmd.ctrl_id = cdc.id
        LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
        LEFT JOIN cd_device_token token ON token.id = cmd.id
        <trim prefix="WHERE" prefixOverrides="AND">
            cds.device_status = '1'
            and cds.usage_status != '3'
            and cdp.project_id in
            <foreach collection="proIds" open="(" close=")" separator="," item="projectId">
                #{projectId}
            </foreach>
            <if test="brandNameCn != null">
                AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},cmb.brand_name_cn)>0
            </if>
            <if test="productName != null and productName != ''">
                AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name)>0
            </if>
            <if test="platform != null and platform.size > 0">
                AND cmd.platform in
                <foreach collection="platform" item="item" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="usageStatus != null and usageStatus.size > 0">
                AND cds.usage_status in
                <foreach collection="usageStatus" item="status" open="(" separator="," close=")">
                    #{status,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceList != null and deviceList.size > 0">
                AND cmd.id in
                <foreach collection="deviceList" item="deviceId" open="(" separator="," close=")">
                    #{deviceId,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deviceSelectQueryDto!=null">
                <if test="deviceSelectQueryDto.brandId != null and deviceSelectQueryDto.brandId !=''">
                    AND cdm.brand_id=#{deviceSelectQueryDto.brandId}
                </if>
                <if test="deviceSelectQueryDto.modelName != null and deviceSelectQueryDto.modelName !=''">
                    AND LOCATE(#{deviceSelectQueryDto.modelName,jdbcType=VARCHAR},cdm.model_name)>0
                </if>
                <if test="deviceSelectQueryDto.resolution != null and deviceSelectQueryDto.resolution !=''">
                    AND cdm.resolution=#{deviceSelectQueryDto.resolution}
                </if>
                <if test="deviceSelectQueryDto.versionCode != null and deviceSelectQueryDto.versionCode!=''">
                    AND cmd.platform_version=#{deviceSelectQueryDto.versionCode}
                </if>
                <if test="deviceSelectQueryDto.versionType != null and deviceSelectQueryDto.versionType !=''">
                    AND cmd.platform=#{deviceSelectQueryDto.versionType}
                </if>
            </if>
        </trim>
        ORDER BY cds.device_status,cmd.registed_time DESC
    </select>

</mapper>