TkDeviceProfileMapper.xml 5.78 KB
<?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="org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper">
    <resultMap type="org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity" id="detail">
        <result property="id" column="id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="creator" column="creator" />
        <result property="updater" column="updater" />
        <result property="name" column="name"/>
        <result property="image" column="image"/>
        <result property="description" column="description"/>
        <result property="tenantId" column="tenant_id" />
        <result property="transportType" column="transport_type"/>
        <result property="provisionType" column="provision_type"/>
        <result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
        <result property="tbProfileId" column="tb_profile_id" />
        <result property="profileData" column="profile_data"  typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="defaultQueueName" column="default_queue_name"/>
        <result property="defaultRuleChainId" column="default_rule_chain_id"/>
        <result property="default" column="is_default"/>
        <result property="type" column="type"/>
        <result property="categoryId" column="category_id"/>
        <result property="categoryName" column="categoryName"/>
        <result property="firmwareId" column="firmware_id" />
        <result property="softwareId" column="software_id" />
        <result property="isEdge" column="is_edge"/>
    </resultMap>


    <sql id="basicColumns">
            base.id,
            base.id AS tb_profile_id,
            base.name,
            base.image,
            base.description,
            base.tenant_id,
            base.transport_type,
            base.provision_type,
            base.profile_data,
            base.default_queue_name,
            base.default_rule_chain_id,
            base.is_default,
            base.type,
            base.script_id,
            base.device_type,
            base.created_time AS create_time,
            base.category_id
    </sql>

    <select id="getProfilePage" resultMap="detail">
        SELECT
        <include refid="basicColumns"/>,base.name as categoryName ,
        CASE
        WHEN re.to_id is not null THEN 1
        ELSE 0
        END AS is_edge
        FROM device_profile base
        LEFT JOIN relation re on re.to_id = base.id and from_type = 'EDGE'  and re.relation_type = 'ManagedByEdge'
        <where>
            <if test="tenantId !=null">
                AND base.tenant_id = #{tenantId}
            </if>
            <if test="profileName !=null and profileName !=''">
                AND base.name LIKE CONCAT('%',#{profileName},'%')
            </if>
            <if test="transportType !=null and transportType !=''">
                AND base.transport_type = #{transportType}
            </if>
            <if test="deviceProfileIds != null">
                AND base.id IN
                <foreach collection="deviceProfileIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>

        </where>
    </select>


    <select id="selectDetail" resultMap="detail">
        SELECT
        <include refid="basicColumns"/>,base.firmware_id,base.software_id
        FROM device_profile base
        <where>
            <if test="tenantId !=null">
                AND base.tenant_id = #{tenantId}
            </if>
            <if test="id !=null">
                AND (base.id = #{id} OR base.id = #{id})
            </if>
        </where>
    </select>
    <select id="profileByScriptId" resultMap="detail">
        SELECT
        <include refid="basicColumns"/>
        FROM device_profile base
        <if test="isSceneLinkage == true">
            LEFT JOIN relation re on re.to_id = base.id and from_type = 'EDGE'  and re.relation_type = 'ManagedByEdge'
        </if>
        <where>
             base.tenant_id = #{tenantId}
            <if test="isSceneLinkage == true">
            and re.to_id is null
            </if>
            <if test="scriptId !=null and scriptId !=''">
                AND base.script_id = #{scriptId}
            </if>
            <if test="deviceType !=null">
                AND base.device_type = #{deviceType}
            </if>
            <if test="transportType !=null">
                AND base.transport_type = #{transportType}
            </if>
            <if test="deviceProfileIds != null">
                AND base.id IN
                <foreach collection="deviceProfileIds" item="deviceProfile_id" open="(" separator="," close=")">
                    #{deviceProfile_id}
                </foreach>
            </if>

        </where>
    </select>

    <select id="profileByTransportAndIds" resultMap="detail">
        SELECT
        <include refid="basicColumns"/>
        FROM device_profile base
        <where>
            iot.tenant_id = #{tenantId}
            <if test="projectIds != null">
                AND base.id IN
                <foreach collection="projectIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="transportType !=null">
                AND base.transport_type = #{transportType}
            </if>
        </where>
    </select>

    <select id="getDeviceProfileIds" resultType="java.lang.String">
        SELECT base.id
        FROM device_profile base
        WHERE base.tenant_id = #{tenantId}
        AND base.transport_type = #{transportType}
    </select>
</mapper>