IotDeviceMapper.xml 9.8 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="com.ruoyi.system.mapper.IotDeviceMapper">
    
    <resultMap type="IotDevice" id="IotDeviceResult">
        <result property="active_time"    column="active_time"    />
        <result property="client_id"    column="client_id"    />
        <result property="completion_auth"    column="completion_auth"    />
        <result property="create_by"    column="create_by"    />
        <result property="create_time"    column="create_time"    />
        <result property="del_flag"    column="del_flag"    />
        <result property="firmware_version"    column="firmware_version"    />
        <result property="img_url"    column="img_url"    />
        <result property="is_shadow"    column="is_shadow"    />
        <result property="latitude"    column="latitude"    />
        <result property="location_way"    column="location_way"    />
        <result property="longitude"    column="longitude"    />
        <result property="name"    column="name"    />
        <result property="network_address"    column="network_address"    />
        <result property="network_ip"    column="network_ip"    />
        <result property="remark"    column="remark"    />
        <result property="rssi"    column="rssi"    />
        <result property="status"    column="status"    />
        <result property="summary"    column="summary"    />
        <result property="things_model_value"    column="things_model_value"    />
        <result property="update_by"    column="update_by"    />
        <result property="update_time"    column="update_time"    />
        <result property="product_id"    column="product_id"    />
        <result property="mqtt_username"    column="mqtt_username"    />
        <result property="payload_type"    column="payload_type"    />
        <result property="things_model_config"    column="things_model_config"    />
        <result property="listen_service_ip"    column="listen_service_ip"    />
        <result property="device_life"    column="device_life"    />
        <result property="data_update_time"    column="data_update_time"    />

    </resultMap>

    <sql id="selectIotDeviceVo">
        select active_time, client_id, completion_auth, create_by, create_time, del_flag, firmware_version, img_url, is_shadow, latitude, location_way, longitude, `name`, network_address, network_ip, remark, rssi, status, summary, things_model_value, update_by, update_time, product_id,mqtt_username,payload_type,things_model_config,listen_service_ip,device_life,data_update_time from iot_device
    </sql>

    <select id="selectIotDeviceList" parameterType="IotDevice" resultMap="IotDeviceResult">
        <include refid="selectIotDeviceVo"/>
        <where>
            <if test="status !=null">
                and `status` = #{status}
            </if>
            <if test="product_id !=null and product_id != ''">
                and product_id = #{product_id}
            </if>
            <if test="mqtt_username !=null and mqtt_username != ''">
                and mqtt_username = #{mqtt_username}
            </if>
            <if test="client_id != null and client_id != ''">
                AND client_id like concat('%', #{client_id}, '%')
            </if>
        </where>
    </select>
    
    <select id="selectIotDeviceByClient_id" parameterType="String" resultMap="IotDeviceResult">
        <include refid="selectIotDeviceVo"/>
        where client_id = #{client_id}
    </select>
        
    <insert id="insertIotDevice" parameterType="IotDevice">
        insert into iot_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="active_time != null">active_time,</if>
            <if test="client_id != null and client_id != ''">client_id,</if>
            <if test="completion_auth != null">completion_auth,</if>
            <if test="create_by != null">create_by,</if>
            <if test="del_flag != null">del_flag,</if>
            <if test="firmware_version != null">firmware_version,</if>
            <if test="img_url != null">img_url,</if>
            <if test="is_shadow != null">is_shadow,</if>
            <if test="latitude != null">latitude,</if>
            <if test="location_way != null">location_way,</if>
            <if test="longitude != null">longitude,</if>
            <if test="name != null">`name`,</if>
            <if test="network_address != null">network_address,</if>
            <if test="network_ip != null">network_ip,</if>
            <if test="remark != null">remark,</if>
            <if test="rssi != null">rssi,</if>
            <if test="status != null">status,</if>
            <if test="summary != null">summary,</if>
            <if test="things_model_value != null">things_model_value,</if>
            <if test="update_by != null">update_by,</if>
            <if test="update_time != null">update_time,</if>
            <if test="product_id != null">product_id,</if>
            <if test="mqtt_username != null">mqtt_username,</if>
            <if test="payload_type != null">payload_type,</if>
            <if test="things_model_config != null">things_model_config,</if>
            <if test="device_life != null">device_life,</if>
            <if test="data_update_time != null">data_update_time,</if>
            create_time,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="active_time != null">#{active_time},</if>
            <if test="client_id != null and client_id != ''">#{client_id},</if>
            <if test="completion_auth != null">#{completion_auth},</if>
            <if test="create_by != null">#{create_by},</if>
            <if test="del_flag != null">#{del_flag},</if>
            <if test="firmware_version != null">#{firmware_version},</if>
            <if test="img_url != null">#{img_url},</if>
            <if test="is_shadow != null">#{is_shadow},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="location_way != null">#{location_way},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="name != null">#{name},</if>
            <if test="network_address != null">#{network_address},</if>
            <if test="network_ip != null">#{network_ip},</if>
            <if test="remark != null">#{remark},</if>
            <if test="rssi != null">#{rssi},</if>
            <if test="status != null">#{status},</if>
            <if test="summary != null">#{summary},</if>
            <if test="things_model_value != null">#{things_model_value},</if>
            <if test="update_by != null">#{update_by},</if>
            <if test="update_time != null">#{update_time},</if>
            <if test="product_id != null">#{product_id},</if>
            <if test="mqtt_username != null">#{mqtt_username},</if>
            <if test="payload_type != null">#{payload_type},</if>
            <if test="things_model_config != null">#{things_model_config},</if>
            <if test="device_life != null">#{device_life},</if>
            <if test="data_update_time != null">#{data_update_time},</if>
            UNIX_TIMESTAMP(NOW()),
         </trim>
    </insert>

    <update id="updateIotDevice" parameterType="IotDevice">
        update iot_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="active_time != null">active_time = #{active_time},</if>
            <if test="completion_auth != null">completion_auth = #{completion_auth},</if>
            <if test="create_by != null">create_by = #{create_by},</if>
            <if test="create_time != null">create_time = #{create_time},</if>
            <if test="del_flag != null">del_flag = #{del_flag},</if>
            <if test="firmware_version != null">firmware_version = #{firmware_version},</if>
            <if test="img_url != null">img_url = #{img_url},</if>
            <if test="is_shadow != null">is_shadow = #{is_shadow},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="location_way != null">location_way = #{location_way},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="name != null">`name` = #{name},</if>
            <if test="network_address != null">network_address = #{network_address},</if>
            <if test="network_ip != null">network_ip = #{network_ip},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="rssi != null">rssi = #{rssi},</if>
            <if test="status != null">status = #{status},</if>
            <if test="summary != null">summary = #{summary},</if>
            <if test="things_model_value != null">things_model_value = #{things_model_value},</if>
            <if test="update_by != null">update_by = #{update_by},</if>
            <if test="update_time != null">update_time = #{update_time},</if>
            <if test="product_id != null">product_id = #{product_id},</if>
            <if test="mqtt_username != null">mqtt_username = #{mqtt_username},</if>
            <if test="payload_type != null">payload_type = #{payload_type},</if>
            <if test="things_model_config != null">things_model_config = #{things_model_config},</if>
            <if test="device_life != null">device_life = #{device_life},</if>
            <if test="data_update_time != null">data_update_time = #{data_update_time},</if>
        </trim>
        where client_id = #{client_id}
    </update>

    <delete id="deleteIotDeviceByClient_id" parameterType="String">
        delete from iot_device where client_id = #{client_id}
    </delete>

    <delete id="deleteIotDeviceByClient_ids" parameterType="String">
        delete from iot_device where client_id in 
        <foreach item="client_id" collection="array" open="(" separator="," close=")">
            #{client_id}
        </foreach>
    </delete>
</mapper>