TkVideoMapper.xml 5.51 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.TkVideoMapper">
    <resultMap type="org.thingsboard.server.common.data.yunteng.dto.TkVideoDTO" id="videoMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="avatar" column="avatar"/>
        <result property="videoUrl" column="video_url"/>
        <result property="brand" column="brand"/>
        <result property="deviceType" column="device_type" />
        <result property="sn" column="sn"/>
        <result property="tenantId" column="tenant_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="description" column="description"/>
        <result property="status" column="status"/>
        <result property="additionalJson" column="additional_json"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="organizationId" column="organization_id"/>
        <result property="organizationName" column="organization_name"/>
        <result property="accessMode" column="access_mode"/>
        <result property="videoPlatformId" column="video_platform_id"/>
        <result property="streamType" column="stream_type"/>
        <result property="playProtocol" column="play_protocol"/>
        <result property="params" column="params"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <association property="videoPlatformDTO" javaType="org.thingsboard.server.common.data.yunteng.dto.TkVideoPlatformDTO">
            <result property="host" column="host"/>
            <result property="appKey" column="app_key"/>
            <result property="appSecret" column="app_secret"/>
            <result property="ssl" column="ssl"/>
            <result property="protocolType" column="protocol_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
            <result property="remark" column="remark"/>
            <result property="type" column="type"/>
        </association>
    </resultMap>



    <sql id="basicColumns">
        base.id,base.sn,base.name,base.avatar,base.video_url,base.description,base.status,base.additional_json,
        base.device_type,base.organization_id,base.brand,base.access_mode,base.video_platform_id,base.stream_type,
        base.play_protocol,base.tenant_id,base.create_time,base.update_time,base.creator, base.updater,base.params
    </sql>

    <sql id="detailColumns">
        <include refid="basicColumns"/>
        ,org.name AS organization_name,ivp.host,ivp.app_key,ivp.app_secret,ivp.ssl,ivp.remark,ivp.protocol_type,
        ivp.type
    </sql>
    <select id="getVideoPage" resultMap="videoMap">
        SELECT
        <include refid="detailColumns"/>
        FROM tk_device_camera base
        LEFT JOIN tk_organization org ON org.id = base.organization_id
        LEFT JOIN tk_video_platform ivp ON ivp.id = base.video_platform_id
        <where>
            <if test="tenantId !=null and tenantId !=''">
                AND base.tenant_id = #{tenantId}
            </if>
            <if test="name !=null and name !=''">
                AND  base.name LIKE concat('%',#{name}::TEXT,'%')
            </if>
            <if test="status !=null">
                AND base.status = #{status}
            </if>
            <if test="organization !=null">
                AND base.organization_id IN
                <foreach collection="organization" item="organizationId" open="(" separator="," close=")">
                    #{organizationId}
                </foreach>
            </if>
        </where>
    </select>

    <select id="getVideoInfosByTenantIdOrAccessModeOrId" resultMap="videoMap">
        SELECT
        <include refid="detailColumns"/>
        FROM tk_device_camera base
        LEFT JOIN tk_organization org ON org.id = base.organization_id
        LEFT JOIN tk_video_platform ivp ON ivp.id = base.video_platform_id
        <where>
            <if test="tenantId !=null and tenantId !=''">
                AND base.tenant_id = #{tenantId}
            </if>
            <if test="id !=null and id !=''">
                AND base.id = #{id}
            </if>
            <if test="accessMode !=null">
                AND base.access_mode = #{accessMode}
            </if>
        </where>
    </select>

    <select id="getVideoInfosByOrganizationIds" resultMap="videoMap">
        SELECT
        <include refid="detailColumns"/>
        FROM tk_device_camera base
        LEFT JOIN tk_organization org ON org.id = base.organization_id
        LEFT JOIN tk_video_platform ivp ON ivp.id = base.video_platform_id
        <where>
            <if test="tenantId !=null and tenantId !=''">
                AND base.tenant_id = #{tenantId}
            </if>
            <if test="organizationIds !=null">
                AND base.organization_id IN
                <foreach collection="organizationIds" item="organizationId" open="(" separator="," close=")">
                    #{organizationId}
                </foreach>
            </if>
        </where>
    </select>
    <delete id="deleteVideosByDeviceIds">
        DELETE FROM tk_device_camera
        WHERE
            tenant_id = #{tenantId}
          AND POSITION ( #{deviceId} IN params ) >0
    </delete>
</mapper>