<?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.breakdown.mapper.DeviceBreakdownMapper">

    <resultMap type="DeviceBreakdown" id="DeviceBreakdownResult">
        <result property="id"    column="id"    />
        <result property="type"    column="Type"    />
        <result property="faultName"    column="fault_name"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDeviceBreakdownVo">
        select id, Type, fault_name, update_by, del_flag, create_time, create_by, update_time from iot_device_breakdown
    </sql>

    <select id="selectDeviceBreakdownList" parameterType="DeviceBreakdown" resultMap="DeviceBreakdownResult">
        <include refid="selectDeviceBreakdownVo"/>
        <where>
            <if test="type != null  and type != ''"> and Type = #{type}</if>
            <if test="faultName != null  and faultName != ''"> and fault_name like concat('%', #{faultName}, '%')</if>
        </where>
    </select>

    <select id="selectDeviceBreakdownById" parameterType="Long" resultMap="DeviceBreakdownResult">
        <include refid="selectDeviceBreakdownVo"/>
        where id = #{id}
    </select>

    <insert id="insertDeviceBreakdown" parameterType="DeviceBreakdown" useGeneratedKeys="true" keyProperty="id">
        insert into iot_device_breakdown
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">Type,</if>
            <if test="faultName != null">fault_name,</if>
            <if test="updateBy != null">update_by,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="faultName != null">#{faultName},</if>
            <if test="updateBy != null">#{updateBy},</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>
        </trim>
    </insert>

    <update id="updateDeviceBreakdown" parameterType="DeviceBreakdown">
        update iot_device_breakdown
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">Type = #{type},</if>
            <if test="faultName != null">fault_name = #{faultName},</if>
            <if test="updateBy != null">update_by = #{updateBy},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeviceBreakdownById" parameterType="Long">
        delete from iot_device_breakdown where id = #{id}
    </delete>

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