<?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.ruoyi.shipping.mapper.TTemporaryFileMapper">
    
    <resultMap type="TTemporaryFile" id="TTemporaryFileResult">
        <result property="fId"    column="f_id"    />
        <result property="fCntrno"    column="f_cntrno"    />
        <result property="fSealno"    column="f_sealno"    />
        <result property="fGoodsid"    column="f_goodsid"    />
        <result property="fPackageid"    column="f_packageid"    />
        <result property="fCntrid"    column="f_cntrid"    />
        <result property="fCntrweight"    column="f_cntrweight"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="packageName"    column="package_name"    />
        <result property="cntrName"    column="cntr_name"    />
        <result property="fileName"    column="file_name"    />
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectTTemporaryFileVo">
        select f_id, f_cntrno, f_sealno, f_goodsid, f_packageid, f_cntrid, f_cntrweight, goods_name, package_name, cntr_name, file_name, create_by, create_time, update_by, update_time, remark from t_temporary_file
    </sql>

    <select id="selectTTemporaryFileList" parameterType="TTemporaryFile" resultMap="TTemporaryFileResult">
        <include refid="selectTTemporaryFileVo"/>
        <where>  
            <if test="fCntrno != null  and fCntrno != ''"> and f_cntrno = #{fCntrno}</if>
            <if test="fSealno != null  and fSealno != ''"> and f_sealno = #{fSealno}</if>
            <if test="fGoodsid != null "> and f_goodsid = #{fGoodsid}</if>
            <if test="fPackageid != null  and fPackageid != ''"> and f_packageid = #{fPackageid}</if>
            <if test="fCntrid != null "> and f_cntrid = #{fCntrid}</if>
            <if test="fCntrweight != null "> and f_cntrweight = #{fCntrweight}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="packageName != null  and packageName != ''"> and package_name like concat('%', #{packageName}, '%')</if>
            <if test="cntrName != null  and cntrName != ''"> and cntr_name like concat('%', #{cntrName}, '%')</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
        </where>
    </select>
    
    <select id="selectTTemporaryFileById" parameterType="Long" resultMap="TTemporaryFileResult">
        <include refid="selectTTemporaryFileVo"/>
        where f_id = #{fId}
    </select>
        
    <insert id="insertTTemporaryFile" parameterType="TTemporaryFile" useGeneratedKeys="true" keyProperty="fId">
        insert into t_temporary_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fCntrno != null">f_cntrno,</if>
            <if test="fSealno != null">f_sealno,</if>
            <if test="fGoodsid != null">f_goodsid,</if>
            <if test="fPackageid != null">f_packageid,</if>
            <if test="fCntrid != null">f_cntrid,</if>
            <if test="fCntrweight != null">f_cntrweight,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="packageName != null">package_name,</if>
            <if test="cntrName != null">cntr_name,</if>
            <if test="fileName != null">file_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fCntrno != null">#{fCntrno},</if>
            <if test="fSealno != null">#{fSealno},</if>
            <if test="fGoodsid != null">#{fGoodsid},</if>
            <if test="fPackageid != null">#{fPackageid},</if>
            <if test="fCntrid != null">#{fCntrid},</if>
            <if test="fCntrweight != null">#{fCntrweight},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="packageName != null">#{packageName},</if>
            <if test="cntrName != null">#{cntrName},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTTemporaryFile" parameterType="TTemporaryFile">
        update t_temporary_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="fCntrno != null">f_cntrno = #{fCntrno},</if>
            <if test="fSealno != null">f_sealno = #{fSealno},</if>
            <if test="fGoodsid != null">f_goodsid = #{fGoodsid},</if>
            <if test="fPackageid != null">f_packageid = #{fPackageid},</if>
            <if test="fCntrid != null">f_cntrid = #{fCntrid},</if>
            <if test="fCntrweight != null">f_cntrweight = #{fCntrweight},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="packageName != null">package_name = #{packageName},</if>
            <if test="cntrName != null">cntr_name = #{cntrName},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTTemporaryFileById" parameterType="Long">
        delete from t_temporary_file where f_id = #{fId}
    </delete>
    <delete id="deleteTTemporaryFilefileName" parameterType="string">
        delete from t_temporary_file where file_name = #{fileName} and create_by = #{createBy}
    </delete>

    <delete id="deleteTTemporaryFileByIds" parameterType="String">
        delete from t_temporary_file where f_id in 
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>
    <select id="selectTTemporaryFileMessage" parameterType="TTemporaryFile" resultType="com.ruoyi.shipping.domain.TTemporaryFile">
        SELECT
        tf.f_id AS fId,
        tf.f_cntrno AS fCntrno,
        tf.f_sealno AS fSealno,
        IFNULL(tg.f_id,0) AS fGoodsid,
        sd.dict_value AS fPackageid,
        tc.f_id AS fCntrid,
        tf.f_cntrweight AS fCntrweight,
        tf.goods_name AS goodsName,
        tf.package_name AS packageName,
        tf.cntr_name AS cntrName,
        tf.file_name AS fileName,
        tf.create_by AS createBy,
        tf.create_time AS createTime,
        tf.update_by AS updateBy,
        tf.update_time AS updateTime,
        tf.remark AS remark
        FROM
        t_temporary_file tf
        LEFT JOIN t_goods tg ON tf.goods_name = tg.f_name
        LEFT JOIN sys_dict_data sd ON sd.dict_label = tf.package_name
        AND sd.dict_type = 'f_packageid'
        LEFT JOIN t_cntr tc ON tc.f_no = tf.cntr_name
        <where>
            <if test="fCntrno != null  and fCntrno != ''"> and tf.f_cntrno = #{fCntrno}</if>
            <if test="fSealno != null  and fSealno != ''"> and tf.f_sealno = #{fSealno}</if>
            <if test="fGoodsid != null "> and tf.f_goodsid = #{fGoodsid}</if>
            <if test="fPackageid != null  and fPackageid != ''"> and tf.f_packageid = #{fPackageid}</if>
            <if test="fCntrid != null "> and tf.f_cntrid = #{fCntrid}</if>
            <if test="fCntrweight != null "> and tf.f_cntrweight = #{fCntrweight}</if>
            <if test="goodsName != null  and goodsName != ''"> and tf.goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="packageName != null  and packageName != ''"> and tf.package_name like concat('%', #{packageName}, '%')</if>
            <if test="cntrName != null  and cntrName != ''"> and tf.cntr_name like concat('%', #{cntrName}, '%')</if>
            <if test="fileName != null  and fileName != ''"> and tf.file_name = #{fileName}</if>
            <if test="createBy != null  and createBy != ''">and tf.create_by = #{createBy}</if>
        </where>
        ORDER BY tf.f_cntrno
    </select>
    
</mapper>