<?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.fastbee.deviceModel.mapper.DeviceModelMapper">

    <resultMap type="DeviceModel" id="DeviceModelResult">
        <result property="modelId"    column="model_id"    />
        <result property="model"    column="model"    />
        <result property="image"    column="image"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectDeviceModelVo">
        select model_id, model, image, del_flag, create_time, create_by, update_time, update_by from iot_device_model
    </sql>

    <select id="selectDeviceModelList" parameterType="DeviceModel" resultMap="DeviceModelResult">
        <include refid="selectDeviceModelVo"/>
        <where>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
        </where>
    </select>

    <select id="selectDeviceModelByModelId" parameterType="Long" resultMap="DeviceModelResult">
        <include refid="selectDeviceModelVo"/>
        where model_id = #{modelId}
    </select>

    <insert id="insertDeviceModel" parameterType="DeviceModel" useGeneratedKeys="true" keyProperty="modelId">
        insert into iot_device_model
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="model != null">model,</if>
            <if test="image != null">image,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="model != null">#{model},</if>
            <if test="image != null">#{image},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateDeviceModel" parameterType="DeviceModel">
        update iot_device_model
        <trim prefix="SET" suffixOverrides=",">
            <if test="model != null">model = #{model},</if>
            <if test="image != null">image = #{image},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where model_id = #{modelId}
    </update>

    <delete id="deleteDeviceModelByModelId" parameterType="Long">
        delete from iot_device_model where model_id = #{modelId}
    </delete>

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