<?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.zbf.system.mapper.TErrorLogMapper">

    <resultMap type="TErrorLog" id="TErrorLogResult">
            <result property="id"    column="id"    />
            <result property="errId"    column="err_id"    />
            <result property="errName"    column="err_name"    />
            <result property="errDate"    column="err_date"    />
            <result property="sts"    column="sts"    />
            <result property="errEndDate"    column="err_end_date"    />
            <result property="agvId"    column="agv_id"    />
            <result property="agvLoc"    column="agv_loc"    />
    </resultMap>

    <sql id="selectTErrorLogVo">
        select id, err_id, err_name, err_date, sts, err_end_date, agv_id, agv_loc from t_error_log
    </sql>

    <select id="selectTErrorLogList" parameterType="TErrorLog" resultMap="TErrorLogResult">
        <include refid="selectTErrorLogVo"/>
        <where>
                        <if test="errId != null  and errId != ''"> and err_id = #{errId}</if>
                        <if test="errName != null  and errName != ''"> and err_name like concat('%', #{errName}, '%')</if>
                        <if test="errDate != null "> and err_date = #{errDate}</if>
                        <if test="sts != null  and sts != ''"> and sts = #{sts}</if>
                        <if test="errEndDate != null "> and err_end_date = #{errEndDate}</if>
                        <if test="agvId != null  and agvId != ''"> and agv_id = #{agvId}</if>
                        <if test="agvLoc != null  and agvLoc != ''"> and agv_loc = #{agvLoc}</if>
        </where>
    </select>

    <select id="selectTErrorLogById" parameterType="Long" resultMap="TErrorLogResult">
            <include refid="selectTErrorLogVo"/>
            where id = #{id}
    </select>

    <insert id="insertTErrorLog" parameterType="TErrorLog">
        insert into t_error_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,</if>
                    <if test="errId != null and errId != ''">err_id,</if>
                    <if test="errName != null">err_name,</if>
                    <if test="errDate != null">err_date,</if>
                    <if test="sts != null">sts,</if>
                    <if test="errEndDate != null">err_end_date,</if>
                    <if test="agvId != null">agv_id,</if>
                    <if test="agvLoc != null">agv_loc,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},</if>
                    <if test="errId != null and errId != ''">#{errId},</if>
                    <if test="errName != null">#{errName},</if>
                    <if test="errDate != null">#{errDate},</if>
                    <if test="sts != null">#{sts},</if>
                    <if test="errEndDate != null">#{errEndDate},</if>
                    <if test="agvId != null">#{agvId},</if>
                    <if test="agvLoc != null">#{agvLoc},</if>
        </trim>
    </insert>

    <update id="updateTErrorLog" parameterType="TErrorLog">
        update t_error_log
        <trim prefix="SET" suffixOverrides=",">
                    <if test="errId != null and errId != ''">err_id = #{errId},</if>
                    <if test="errName != null">err_name = #{errName},</if>
                    <if test="errDate != null">err_date = #{errDate},</if>
                    <if test="sts != null">sts = #{sts},</if>
                    <if test="errEndDate != null">err_end_date = #{errEndDate},</if>
                    <if test="agvId != null">agv_id = #{agvId},</if>
                    <if test="agvLoc != null">agv_loc = #{agvLoc},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTErrorLogByIds" parameterType="String">
        update t_error_log set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTErrorLogByIds" parameterType="String">
        update t_error_log set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTErrorLogById" parameterType="Long">
        delete from t_error_log  where id = #{id}
    </delete>

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