IotProductMapper.xml 4.7 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.IotProductMapper">
    
    <resultMap type="IotProduct" id="IotProductResult">
        <result property="create_time"    column="create_time"    />
        <result property="encryption_type"    column="encryption_type"    />
        <result property="id"    column="id"    />
        <result property="open_encryption"    column="open_encryption"    />
        <result property="mqtt_password"    column="mqtt_password"    />
        <result property="role_id"    column="role_id"    />
        <result property="mqtt_salt"    column="mqtt_salt"    />
        <result property="used"    column="used"    />
        <result property="mqtt_username"    column="mqtt_username"    />
        <result property="product_name"    column="product_name"    />

    </resultMap>

    <sql id="selectIotProductVo">
        select `id`,`mqtt_username`,`mqtt_password`,`product_name`,`mqtt_salt`,`create_time`,`encryption_type`,`open_encryption`,`used`,`role_id` from iot_product
    </sql>

    <select id="selectIotProductList" parameterType="IotProduct" resultMap="IotProductResult">
        <include refid="selectIotProductVo"/>
        <where>
            <if test="product_name != null and product_name != ''">
                AND `product_name` like concat('%', #{product_name}, '%')
            </if>
            <if test="role_id !=null and role_id != ''">
                and role_id = #{role_id}
            </if>
            <if test="mqtt_username != null and mqtt_username != ''">
                AND `mqtt_username` like concat('%', #{mqtt_username}, '%')
            </if>
        </where>
    </select>
    
    <select id="selectIotProductById" parameterType="Integer" resultMap="IotProductResult">
        <include refid="selectIotProductVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertIotProduct" parameterType="IotProduct" useGeneratedKeys="true" keyProperty="id">
        insert into iot_product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="encryption_type != null">encryption_type,</if>
            <if test="open_encryption != null">open_encryption,</if>
            <if test="mqtt_password != null and mqtt_password != ''">mqtt_password,</if>
            <if test="role_id != null">role_id,</if>
            <if test="mqtt_salt != null">mqtt_salt,</if>
            <if test="used != null">used,</if>
            <if test="mqtt_username != null and mqtt_username != ''">mqtt_username,</if>
            <if test="product_name != null and product_name != ''">product_name,</if>
            create_time,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">

            <if test="encryption_type != null">#{encryption_type},</if>
            <if test="open_encryption != null">#{open_encryption},</if>
            <if test="mqtt_password != null and mqtt_password != ''">#{mqtt_password},</if>
            <if test="role_id != null">#{role_id},</if>
            <if test="mqtt_salt != null">#{mqtt_salt},</if>
            <if test="used != null">#{used},</if>
            <if test="mqtt_username != null and mqtt_username != ''">#{mqtt_username},</if>
            <if test="product_name != null and product_name != ''">#{product_name},</if>
            UNIX_TIMESTAMP(NOW()),
         </trim>
    </insert>

    <update id="updateIotProduct" parameterType="IotProduct">
        update iot_product
        <trim prefix="SET" suffixOverrides=",">
            <if test="create_time != null">create_time = #{create_time},</if>
            <if test="encryption_type != null">encryption_type = #{encryption_type},</if>
            <if test="open_encryption != null">open_encryption = #{open_encryption},</if>
            <if test="mqtt_password != null and mqtt_password != ''">mqtt_password = #{mqtt_password},</if>
            <if test="role_id != null">role_id = #{role_id},</if>
            <if test="mqtt_salt != null">mqtt_salt = #{mqtt_salt},</if>
            <if test="used != null">used = #{used},</if>
            <if test="mqtt_username != null and mqtt_username != ''">mqtt_username = #{mqtt_username},</if>
            <if test="product_name != null and product_name != ''">product_name = #{product_name},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIotProductById" parameterType="Integer">
        delete from iot_product where id = #{id}
    </delete>

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