<?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.TShipDealMapper">
    
    <resultMap type="TShipDeal" id="TShipDealResult">
        <result property="fId"    column="f_id"    />
        <result property="fName"    column="f_name"    />
        <result property="fTypes"    column="f_types"    />
        <result property="fLoadportId"    column="f_loadport_id"    />
        <result property="fDestportId"    column="f_destport_id"    />
        <result property="fLoadportName"    column="f_loadport_name"    />
        <result property="fDestportName"    column="f_destport_name"    />
        <result property="fLoadportMode"    column="f_loadport_mode"    />
        <result property="fDestportMode"    column="f_destport_mode"    />
        <result property="fPeriodStart"    column="f_period_start"    />
        <result property="fPeriodEnd"    column="f_period_end"    />
        <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="selectTShipDealVo">
        select f_id, f_name, f_types, f_loadport_id, f_destport_id, f_loadport_name, f_destport_name, f_loadport_mode, f_destport_mode, f_period_start, f_period_end, create_by, create_time, update_by, update_time, remark from t_ship_deal
    </sql>

    <select id="selectTShipDealList" parameterType="TShipDeal" resultMap="TShipDealResult">
        <include refid="selectTShipDealVo"/>
        <where>  
            <if test="fName != null  and fName != ''"> and f_name like concat('%', #{fName}, '%')</if>
            <if test="fTypes != null  and fTypes != ''"> and f_types = #{fTypes}</if>
            <if test="fLoadportId != null "> and f_loadport_id = #{fLoadportId}</if>
            <if test="fDestportId != null "> and f_destport_id = #{fDestportId}</if>
            <if test="fLoadportName != null  and fLoadportName != ''"> and f_loadport_name like concat('%', #{fLoadportName}, '%')</if>
            <if test="fDestportName != null  and fDestportName != ''"> and f_destport_name like concat('%', #{fDestportName}, '%')</if>
            <if test="fLoadportMode != null  and fLoadportMode != ''"> and f_loadport_mode like concat('%', #{fLoadportMode}, '%')</if>
            <if test="fDestportMode != null  and fDestportMode != ''"> and f_destport_mode like concat('%', #{fDestportMode}, '%')</if>
            <if test="fPeriodStart != null "> and f_period_start &lt;= #{fPeriodStart}</if>
            <if test="fPeriodEnd != null "> and f_period_end &gt;= #{fPeriodEnd}</if>
            <if test='cLoadDate != null and cLoadDate[0] != null and cLoadDate[0]!= ""'>
                and create_time &gt;= #{cLoadDate[0]}
            </if>
            <if test='cLoadDate != null and cLoadDate[1] != null and cLoadDate[1]!= ""'>
                and create_time &lt;= #{cLoadDate[1]}
            </if>
        </where>
    </select>
    
    <select id="selectTShipDealById" parameterType="Long" resultMap="TShipDealResult">
        <include refid="selectTShipDealVo"/>
        where f_id = #{fId}
    </select>
        
    <insert id="insertTShipDeal" parameterType="TShipDeal" useGeneratedKeys="true" keyProperty="fId">
        insert into t_ship_deal
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fName != null">f_name,</if>
            <if test="fTypes != null and fTypes != ''">f_types,</if>
            <if test="fLoadportId != null">f_loadport_id,</if>
            <if test="fDestportId != null">f_destport_id,</if>
            <if test="fLoadportName != null">f_loadport_name,</if>
            <if test="fDestportName != null">f_destport_name,</if>
            <if test="fLoadportMode != null">f_loadport_mode,</if>
            <if test="fDestportMode != null">f_destport_mode,</if>
            <if test="fPeriodStart != null">f_period_start,</if>
            <if test="fPeriodEnd != null">f_period_end,</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="fName != null">#{fName},</if>
            <if test="fTypes != null and fTypes != ''">#{fTypes},</if>
            <if test="fLoadportId != null">#{fLoadportId},</if>
            <if test="fDestportId != null">#{fDestportId},</if>
            <if test="fLoadportName != null">#{fLoadportName},</if>
            <if test="fDestportName != null">#{fDestportName},</if>
            <if test="fLoadportMode != null">#{fLoadportMode},</if>
            <if test="fDestportMode != null">#{fDestportMode},</if>
            <if test="fPeriodStart != null">#{fPeriodStart},</if>
            <if test="fPeriodEnd != null">#{fPeriodEnd},</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="updateTShipDeal" parameterType="TShipDeal">
        update t_ship_deal
        <trim prefix="SET" suffixOverrides=",">
            <if test="fName != null">f_name = #{fName},</if>
            <if test="fTypes != null and fTypes != ''">f_types = #{fTypes},</if>
            <if test="fLoadportId != null">f_loadport_id = #{fLoadportId},</if>
            <if test="fDestportId != null">f_destport_id = #{fDestportId},</if>
            <if test="fLoadportName != null">f_loadport_name = #{fLoadportName},</if>
            <if test="fDestportName != null">f_destport_name = #{fDestportName},</if>
            <if test="fLoadportMode != null">f_loadport_mode = #{fLoadportMode},</if>
            <if test="fDestportMode != null">f_destport_mode = #{fDestportMode},</if>
            <if test="fPeriodStart != null">f_period_start = #{fPeriodStart},</if>
            <if test="fPeriodEnd != null">f_period_end = #{fPeriodEnd},</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="deleteTShipDealById" parameterType="Long">
        delete from t_ship_deal where f_id = #{fId}
    </delete>

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