<?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.pwt.web.mapper.PwtRobotFaultMapper">
    
    <resultMap type="PwtRobotFault" id="PwtRobotFaultResult">
        <result property="id"    column="id"    />
        <result property="subscript"    column="subscript"    />
        <result property="fault"    column="fault"    />
        <result property="faultLevel"    column="fault_level"    />
        <result property="enabled"    column="enabled"    />
        <result property="code"    column="code"    />
        <result property="sourceDeviceType"    column="source_device_type"    />
    </resultMap>

    <sql id="selectPwtRobotFaultVo">
        select id, subscript, fault, fault_level, enabled, code, source_device_type from pwt_robot_fault
    </sql>

    <select id="selectPwtRobotFaultList" parameterType="PwtRobotFault" resultMap="PwtRobotFaultResult">
        <include refid="selectPwtRobotFaultVo"/>
        <where>
            source_device_type = 2
        </where>
        order by subscript asc
    </select>
    
    <select id="selectPwtRobotFaultById" parameterType="Long" resultMap="PwtRobotFaultResult">
        <include refid="selectPwtRobotFaultVo"/>
        where id = #{id}
    </select>

    <select id="selectRobotFaultBySubscript" parameterType="Long" resultMap="PwtRobotFaultResult">
        <include refid="selectPwtRobotFaultVo"/>
        where subscript = #{subscript}
    </select>

    <insert id="insertPwtRobotFault" parameterType="PwtRobotFault" useGeneratedKeys="true" keyProperty="id">
        insert into pwt_robot_fault
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="subscript != null">subscript,</if>
            <if test="fault != null">fault,</if>
            <if test="faultLevel != null">fault_level,</if>
            <if test="enabled != null">enabled,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="subscript != null">#{subscript},</if>
            <if test="fault != null">#{fault},</if>
            <if test="faultLevel != null">#{faultLevel},</if>
            <if test="enabled != null">#{enabled},</if>
         </trim>
    </insert>

    <update id="updatePwtRobotFault" parameterType="PwtRobotFault">
        update pwt_robot_fault
        <trim prefix="SET" suffixOverrides=",">
            <if test="subscript != null">subscript = #{subscript},</if>
            <if test="fault != null">fault = #{fault},</if>
            <if test="faultLevel != null">fault_level = #{faultLevel},</if>
            <if test="enabled != null">enabled = #{enabled},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePwtRobotFaultById" parameterType="Long">
        delete from pwt_robot_fault where id = #{id}
    </delete>

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