TkDeviceProfileMapper.xml 4.18 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.common.data.yunteng.dto.DeviceProfileDTO" 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="scriptId" column="script_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"/>
    </resultMap>


    <sql id="basicColumns">
        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
        ,iot.id,iot.script_id,iot.device_type,iot.create_time,iot.update_time,iot.creator,iot.updater,iot.tb_profile_id
    </sql>

    <select id="getProfilePage" resultMap="detail">
        SELECT
        <include refid="basicColumns"/>
        FROM device_profile base
        LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
        <where>
            <if test="tenantId !=null and tenantId !=''">
                AND iot.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::TEXT IN
                <foreach collection="deviceProfileIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>

        </where>
    </select>


    <select id="selectDetail" resultMap="detail">
        SELECT
        <include refid="basicColumns"/>
        FROM device_profile base
        LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
        <where>
            <if test="tenantId !=null and tenantId !=''">
                AND iot.tenant_id = #{tenantId}
            </if>
            <if test="id !=null and id !=''">
                AND (iot.id = #{id} OR iot.tb_profile_id = #{id})
            </if>
        </where>
    </select>
    <select id="profileByScriptId" resultMap="detail">
        SELECT
        <include refid="basicColumns"/>
        FROM device_profile base
        LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
        <where>
             iot.tenant_id = #{tenantId}
            <if test="scriptId !=null and scriptId !=''">
                AND iot.script_id = #{scriptId}
            </if>
            <if test="deviceType !=null">
                AND iot.device_type = #{deviceType}
            </if>
        </where>
    </select>

    <select id="getDeviceProfileIds" resultType="java.lang.String">
        SELECT iot.id
        FROM device_profile base
        LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
        WHERE iot.tenant_id = #{tenantId}
        AND base.transport_type = #{transportType}
    </select>
</mapper>