<?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.quotation.mapper.TSeapriceQueryLogMapper">

    <resultMap type="TSeapriceQueryLog" id="TSeapriceQueryLogResult">
        <result property="fId" column="f_id"/>
        <result property="fPortOriginId" column="f_port_origin_id"/>
        <result property="fPortDestinationId" column="f_port_destination_id"/>
        <result property="fPortTransitId" column="f_port_transit_id"/>
        <result property="fPortOriginName" column="f_port_origin_name"/>
        <result property="fPortDestinationName" column="f_port_destination_name"/>
        <result property="fPortTransitName" column="f_port_transit_name"/>
        <result property="fValiddateBegin" column="f_validdate_begin"/>
        <result property="fValiddateEnd" column="f_validdate_end"/>
        <result property="fUserId" column="f_user_id"/>
        <result property="fQueryDatetime" column="f_query_datetime"/>
        <result property="fDelFlag" column="f_del_flag"/>
    </resultMap>

    <sql id="selectTSeapriceQueryLogVo">
        select s.f_id,
               s.f_port_origin_id,
               s.f_port_destination_id,
               s.f_port_transit_id,
               de.f_name  as f_port_destination_name,
               ori.f_name as f_port_origin_name,
               tr.f_name  as f_port_transit_name,
               s.f_validdate_begin,
               s.f_validdate_end,
               s.f_user_id,
               s.f_query_datetime,
               s.f_del_flag
        from t_seaprice_query_log s
                 left join t_address de on de.f_id = s.f_port_destination_id
                 left join t_address ori on ori.f_id = s.f_port_origin_id
                 left join t_address tr on tr.f_id = s.f_port_transit_id
    </sql>

    <select id="selectTSeapriceQueryLogList" parameterType="TSeapriceQueryLog" resultMap="TSeapriceQueryLogResult">
        <include refid="selectTSeapriceQueryLogVo"/>
        <where>
            <if test="fPortOriginId != null ">and s.f_port_origin_id = #{fPortOriginId}</if>
            <if test="fPortDestinationId != null ">and s.f_port_destination_id = #{fPortDestinationId}</if>
            <if test="fPortTransitId != null ">and s.f_port_transit_id = #{fPortTransitId}</if>
            <if test="fValiddateBegin != null ">and s.f_validdate_begin = #{fValiddateBegin}</if>
            <if test="fValiddateEnd != null ">and s.f_validdate_end = #{fValiddateEnd}</if>
            <if test="fUserId != null ">and s.f_user_id = #{fUserId}</if>
            <if test="fQueryDatetime != null ">and s.f_query_datetime = #{fQueryDatetime}</if>
            <if test="fDelFlag != null  and fDelFlag != ''">and s.f_del_flag = #{fDelFlag}</if>
        </where>
            order by s.f_id desc
    </select>

    <select id="selectTSeapriceQueryLogById" parameterType="Long" resultMap="TSeapriceQueryLogResult">
        <include refid="selectTSeapriceQueryLogVo"/>
        where s.f_id = #{fId}
    </select>

    <insert id="insertTSeapriceQueryLog" parameterType="TSeapriceQueryLog">
        insert into t_seaprice_query_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fId != null">f_id,</if>
            <if test="fPortOriginId != null">f_port_origin_id,</if>
            <if test="fPortDestinationId != null">f_port_destination_id,</if>
            <if test="fPortTransitId != null">f_port_transit_id,</if>
            <if test="fValiddateBegin != null">f_validdate_begin,</if>
            <if test="fValiddateEnd != null">f_validdate_end,</if>
            <if test="fUserId != null">f_user_id,</if>
            <if test="fQueryDatetime != null">f_query_datetime,</if>
            <if test="fDelFlag != null">f_del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fId != null">#{fId},</if>
            <if test="fPortOriginId != null">#{fPortOriginId},</if>
            <if test="fPortDestinationId != null">#{fPortDestinationId},</if>
            <if test="fPortTransitId != null">#{fPortTransitId},</if>
            <if test="fValiddateBegin != null">#{fValiddateBegin},</if>
            <if test="fValiddateEnd != null">#{fValiddateEnd},</if>
            <if test="fUserId != null">#{fUserId},</if>
            <if test="fQueryDatetime != null">#{fQueryDatetime},</if>
            <if test="fDelFlag != null">#{fDelFlag},</if>
        </trim>
    </insert>

    <update id="updateTSeapriceQueryLog" parameterType="TSeapriceQueryLog">
        update t_seaprice_query_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="fPortOriginId != null">f_port_origin_id = #{fPortOriginId},</if>
            <if test="fPortDestinationId != null">f_port_destination_id = #{fPortDestinationId},</if>
            <if test="fPortTransitId != null">f_port_transit_id = #{fPortTransitId},</if>
            <if test="fValiddateBegin != null">f_validdate_begin = #{fValiddateBegin},</if>
            <if test="fValiddateEnd != null">f_validdate_end = #{fValiddateEnd},</if>
            <if test="fUserId != null">f_user_id = #{fUserId},</if>
            <if test="fQueryDatetime != null">f_query_datetime = #{fQueryDatetime},</if>
            <if test="fDelFlag != null">f_del_flag = #{fDelFlag},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTSeapriceQueryLogById" parameterType="Long">
        delete
        from t_seaprice_query_log
        where f_id = #{fId}
    </delete>

    <delete id="deleteTSeapriceQueryLogByIds" parameterType="String">
        delete from t_seaprice_query_log where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>

</mapper>