SmartUserDeviceMapper.xml 3.25 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="cn.com.glsx.smart.modules.mapper.SmartUserDeviceMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.smart.modules.entity.SmartUserDevice">
        <!--@mbg.generated generated on Fri Apr 23 15:24:29 CST 2021.-->
        <!--@Table smart_user_device-->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="device_id" jdbcType="VARCHAR" property="deviceId"/>
        <result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
        <result column="type" jdbcType="TINYINT" property="type"/>
        <result column="channel" jdbcType="TINYINT" property="channel"/>
        <result column="parent_id" jdbcType="VARCHAR" property="parentId"/>
        <result column="platform_product_id" jdbcType="VARCHAR" property="platformProductId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="type_id" jdbcType="VARCHAR" property="typeId"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated generated on Fri Apr 23 15:24:29 CST 2021.-->
        id, user_id, device_id, device_name, type, channel, parent_id, platform_product_id,
        create_time, update_time
    </sql>

    <select id="getList" resultMap="BaseResultMap">
        select id, user_id, device_id, device_name, type, channel, parent_id, platform_product_id,
            create_time, update_time
        from smart_user_device
        <where>
            <if test="userId != null">
                and user_id = #{userId,jdbcType=BIGINT}
            </if>
            <if test="type != null">
                and type = #{type,jdbcType=TINYINT}
            </if>
        </where>
    </select>

    <select id="getByDeviceId" resultMap="BaseResultMap">
        select ud.id, ud.user_id, ud.device_id, ud.device_name, ud.type, ud.channel, ud.parent_id,
            ud.platform_product_id, ud.create_time, ud.update_time,
            sf.url icon
        from smart_user_device ud
        left join smart_product p on p.platform_product_id = ud.platform_product_id
        left join smart_sys_file sf on sf.id = p.icon
        <where>
            <if test="deviceId != null and deviceId != ''">
                and ud.device_id = #{deviceId,jdbcType=VARCHAR}
            </if>
        </where>
        limit 1
    </select>
    <select id="findByParentId" resultMap="BaseResultMap">
        select s1.device_name,s1.device_id,s2.type_id as type_id from smart_user_device s1
         left join smart_product s2 on s1.platform_product_id= s2.platform_product_id
         where type=2 and
        parent_id=#{infrared_id}
    </select>

    <delete id="deleteDevice">
        delete from smart_user_device
        <where>
            <if test="deviceId != null and deviceId != ''">
                and device_id = #{deviceId,jdbcType=VARCHAR}
            </if>
            <if test="channel != null">
                and channel = #{channel,jdbcType=TINYINT}
            </if>
        </where>
    </delete>
</mapper>