<?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.TGasIllegalMapper">
    
    <resultMap type="TGasIllegal" id="TGasIllegalResult">
        <result property="illegalId"    column="illegal_id"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="illegalTitle"    column="illegal_title"    />
        <result property="content"    column="content"    />
        <result property="people"    column="people"    />
        <result property="illegalTime"    column="illegal_time"    />
        <result property="penalty"    column="penalty"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTGasIllegalVo">
        SELECT illegal_id, beyond_enterprise_id, illegal_title,
	(SELECT enterprise_name FROM t_enterprise_info WHERE  enterprise_id = beyond_enterprise_id) AS enterpriseName,
         content, people, illegal_time, penalty, file_url, create_time
         FROM t_gas_illegal
    </sql>

    <select id="selectTGasIllegalList" parameterType="TGasIllegal" resultMap="TGasIllegalResult">
        <include refid="selectTGasIllegalVo"/>
        <where>  
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="illegalTitle != null  and illegalTitle != ''"> and illegal_title like concat('%', #{illegalTitle},'%')</if>
            <if test="illegalTime != null "> and illegal_time = #{illegalTime}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTGasIllegalById" parameterType="Long" resultMap="TGasIllegalResult">
        <include refid="selectTGasIllegalVo"/>
        where illegal_id = #{illegalId}
    </select>
        
    <insert id="insertTGasIllegal" parameterType="TGasIllegal" useGeneratedKeys="true" keyProperty="illegalId">
        insert into t_gas_illegal
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="illegalTitle != null">illegal_title,</if>
            <if test="content != null">content,</if>
            <if test="people != null">people,</if>
            <if test="illegalTime != null">illegal_time,</if>
            <if test="penalty != null">penalty,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="illegalTitle != null">#{illegalTitle},</if>
            <if test="content != null">#{content},</if>
            <if test="people != null">#{people},</if>
            <if test="illegalTime != null">#{illegalTime},</if>
            <if test="penalty != null">#{penalty},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTGasIllegal" parameterType="TGasIllegal">
        update t_gas_illegal
        <trim prefix="SET" suffixOverrides=",">
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="illegalTitle != null">illegal_title = #{illegalTitle},</if>
            <if test="content != null">content = #{content},</if>
            <if test="people != null">people = #{people},</if>
            <if test="illegalTime != null">illegal_time = #{illegalTime},</if>
            <if test="penalty != null">penalty = #{penalty},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where illegal_id = #{illegalId}
    </update>

    <delete id="deleteTGasIllegalById" parameterType="Long">
        delete from t_gas_illegal where illegal_id = #{illegalId}
    </delete>

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