<?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.TLpgTraceBackMapper">
    
    <resultMap type="TLpgTraceBack" id="TLpgTraceBackResult">
        <result property="traceId"    column="trace_id"    />
        <result property="traceType"    column="trace_type"    />
        <result property="relationId"    column="relation_id"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="bottleCode"    column="bottle_code"    />
        <result property="people"    column="people"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTLpgTraceBackVo">
        select trace_id, trace_type, relation_id, beyond_enterprise_id, station_name, bottle_code,
         (SELECT enterprise_name FROM t_enterprise_info WHERE  enterprise_id = beyond_enterprise_id) AS enterpriseName,
         people, create_time, remark from t_lpg_trace_back
    </sql>

    <select id="selectTLpgTraceBackList" parameterType="TLpgTraceBack" resultMap="TLpgTraceBackResult">
        <include refid="selectTLpgTraceBackVo"/>
        <where>  
            <if test="traceType != null  and traceType != ''"> and trace_type = #{traceType}</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="bottleCode != null  and bottleCode != ''"> and bottle_code = #{bottleCode}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTLpgTraceBackById" parameterType="Long" resultMap="TLpgTraceBackResult">
        <include refid="selectTLpgTraceBackVo"/>
        where trace_id = #{traceId}
    </select>
        
    <insert id="insertTLpgTraceBack" parameterType="TLpgTraceBack" useGeneratedKeys="true" keyProperty="traceId">
        insert into t_lpg_trace_back
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="traceType != null">trace_type,</if>
            <if test="relationId != null">relation_id,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="stationName != null">station_name,</if>
            <if test="bottleCode != null">bottle_code,</if>
            <if test="people != null">people,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="traceType != null">#{traceType},</if>
            <if test="relationId != null">#{relationId},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="bottleCode != null">#{bottleCode},</if>
            <if test="people != null">#{people},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTLpgTraceBack" parameterType="TLpgTraceBack">
        update t_lpg_trace_back
        <trim prefix="SET" suffixOverrides=",">
            <if test="traceType != null">trace_type = #{traceType},</if>
            <if test="relationId != null">relation_id = #{relationId},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="bottleCode != null">bottle_code = #{bottleCode},</if>
            <if test="people != null">people = #{people},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where trace_id = #{traceId}
    </update>

    <delete id="deleteTLpgTraceBackById" parameterType="Long">
        delete from t_lpg_trace_back where trace_id = #{traceId}
    </delete>

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