<?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.zehong.system.mapper.TGasAbnormalityMapper">
    
    <resultMap type="TGasAbnormality" id="TGasAbnormalityResult">
        <result property="abnormalityId"    column="abnormality_id"    />
        <result property="abnormalityType"    column="abnormality_type"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="bottleCode"    column="bottle_code"    />
        <result property="message"    column="message"    />
        <result property="status"    column="status"    />
        <result property="content"    column="content"    />
        <result property="people"    column="people"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTGasAbnormalityVo">
        select abnormality_id, abnormality_type, beyond_enterprise_id, bottle_code, message,
        (SELECT enterprise_name FROM t_enterprise_info WHERE  enterprise_id = beyond_enterprise_id) AS enterpriseName,
        status, content, people, create_time from t_gas_abnormality
    </sql>

    <select id="selectTGasAbnormalityList" parameterType="TGasAbnormality" resultMap="TGasAbnormalityResult">
        <include refid="selectTGasAbnormalityVo"/>
        <where>  
            <if test="abnormalityType != null  and abnormalityType != ''"> and abnormality_type = #{abnormalityType}</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="bottleCode != null  and bottleCode != ''"> and bottle_code = #{bottleCode}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTGasAbnormalityById" parameterType="Long" resultMap="TGasAbnormalityResult">
        <include refid="selectTGasAbnormalityVo"/>
        where abnormality_id = #{abnormalityId}
    </select>
        
    <insert id="insertTGasAbnormality" parameterType="TGasAbnormality" useGeneratedKeys="true" keyProperty="abnormalityId">
        insert into t_gas_abnormality
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="abnormalityType != null">abnormality_type,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="bottleCode != null">bottle_code,</if>
            <if test="message != null">message,</if>
            <if test="status != null">status,</if>
            <if test="content != null">content,</if>
            <if test="people != null">people,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="abnormalityType != null">#{abnormalityType},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="bottleCode != null">#{bottleCode},</if>
            <if test="message != null">#{message},</if>
            <if test="status != null">#{status},</if>
            <if test="content != null">#{content},</if>
            <if test="people != null">#{people},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTGasAbnormality" parameterType="TGasAbnormality">
        update t_gas_abnormality
        <trim prefix="SET" suffixOverrides=",">
            <if test="abnormalityType != null">abnormality_type = #{abnormalityType},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="bottleCode != null">bottle_code = #{bottleCode},</if>
            <if test="message != null">message = #{message},</if>
            <if test="status != null">status = #{status},</if>
            <if test="content != null">content = #{content},</if>
            <if test="people != null">people = #{people},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where abnormality_id = #{abnormalityId}
    </update>

    <delete id="deleteTGasAbnormalityById" parameterType="Long">
        delete from t_gas_abnormality where abnormality_id = #{abnormalityId}
    </delete>

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