<?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.TVesselMapper">

    <resultMap type="TVessel" id="TVesselResult">
        <result property="fId" column="f_id"/>
        <result property="fNo" column="f_no"/>
        <result property="fName" column="f_name"/>
        <result property="fEname" column="f_ename"/>
        <result property="fImo" column="f_imo"/>
        <result property="fOwer" column="f_ower"/>
        <result property="fManage" column="f_manage"/>
        <result property="fNationality" column="f_nationality"/>
        <result property="fRegistry" column="f_registry"/>
        <result property="fDateofdelivery" column="f_dateofdelivery"/>
        <result property="fWeight" column="f_weight"/>
        <result property="fStatus" column="f_status"/>
        <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="selectTVesselVo">
        select f_id, f_no, f_name, f_ename, f_imo, f_ower, f_manage, f_nationality, f_registry, f_dateofdelivery, f_weight, case when f_status = 'T' then '正常' else '停用' end as f_status, create_by, create_time, update_by, update_time, remark from t_vessel
    </sql>

    <select id="selectTVesselList" parameterType="TVessel" resultMap="TVesselResult">
        <include refid="selectTVesselVo"/>
        <where>
            <if test="fNo != null  and fNo != ''">and f_no = #{fNo}</if>
            <if test="fName != null  and fName != ''">and f_name like concat('%', #{fName}, '%')</if>
            <if test="fEname != null  and fEname != ''">and f_ename like concat('%', #{fEname}, '%')</if>
            <if test="fImo != null  and fImo != ''">and f_imo = #{fImo}</if>
            <if test="fOwer != null  and fOwer != ''">and f_ower = #{fOwer}</if>
            <if test="fManage != null  and fManage != ''">and f_manage = #{fManage}</if>
            <if test="fNationality != null  and fNationality != ''">and f_nationality = #{fNationality}</if>
            <if test="fRegistry != null  and fRegistry != ''">and f_registry = #{fRegistry}</if>
            <if test="fDateofdelivery != null ">and f_dateofdelivery = #{fDateofdelivery}</if>
            <if test="fWeight != null ">and f_weight = #{fWeight}</if>
            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
            <if test="createBy != null  and createBy != ''">and create_by like concat('%', #{createBy}, '%')</if>
            <if test="remark != null  and remark != ''">and remark like concat('%', #{remark}, '%')</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="selectTVesselById" parameterType="Long" resultMap="TVesselResult">
        <include refid="selectTVesselVo"/>
        where f_id = #{fId}
    </select>

    <insert id="insertTVessel" parameterType="TVessel" useGeneratedKeys="true" keyProperty="fId">
        insert into t_vessel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fNo != null and fNo != ''">f_no,</if>
            <if test="fName != null and fName != ''">f_name,</if>
            <if test="fEname != null and fEname != ''">f_ename,</if>
            <if test="fImo != null and fImo != ''">f_imo,</if>
            <if test="fOwer != null">f_ower,</if>
            <if test="fManage != null">f_manage,</if>
            <if test="fNationality != null">f_nationality,</if>
            <if test="fRegistry != null">f_registry,</if>
            <if test="fDateofdelivery != null">f_dateofdelivery,</if>
            <if test="fWeight != null">f_weight,</if>
            <if test="fStatus != null">f_status,</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="fNo != null and fNo != ''">#{fNo},</if>
            <if test="fName != null and fName != ''">#{fName},</if>
            <if test="fEname != null and fEname != ''">#{fEname},</if>
            <if test="fImo != null and fImo != ''">#{fImo},</if>
            <if test="fOwer != null">#{fOwer},</if>
            <if test="fManage != null">#{fManage},</if>
            <if test="fNationality != null">#{fNationality},</if>
            <if test="fRegistry != null">#{fRegistry},</if>
            <if test="fDateofdelivery != null">#{fDateofdelivery},</if>
            <if test="fWeight != null">#{fWeight},</if>
            <if test="fStatus != null">#{fStatus},</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="updateTVessel" parameterType="TVessel">
        update t_vessel
        <trim prefix="SET" suffixOverrides=",">
            <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
            <if test="fName != null and fName != ''">f_name = #{fName},</if>
            <if test="fEname != null and fEname != ''">f_ename = #{fEname},</if>
            <if test="fImo != null and fImo != ''">f_imo = #{fImo},</if>
            <if test="fOwer != null">f_ower = #{fOwer},</if>
            <if test="fManage != null">f_manage = #{fManage},</if>
            <if test="fNationality != null">f_nationality = #{fNationality},</if>
            <if test="fRegistry != null">f_registry = #{fRegistry},</if>
            <if test="fDateofdelivery != null">f_dateofdelivery = #{fDateofdelivery},</if>
            <if test="fWeight != null">f_weight = #{fWeight},</if>
            <if test="fStatus != null">f_status = #{fStatus},</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="deleteTVesselById" parameterType="Long">
        delete from t_vessel where f_id = #{fId}
    </delete>

    <delete id="deleteTVesselByIds" parameterType="String">
        delete from t_vessel where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>
    <select id="selectTVesselfNo" parameterType="TVessel" resultMap="TVesselResult">
        SELECT
	        f_id,
	        f_no
        FROM
	        t_vessel
        WHERE
	        f_no = #{fNo}
    </select>
    <select id="selectTVesselfName" parameterType="TVessel" resultMap="TVesselResult">
        SELECT
	        f_id,
	        f_name
        FROM
	        t_vessel
        WHERE
	        f_name = #{fName}
    </select>
    <select id="selectTVesselfEname" parameterType="TVessel" resultMap="TVesselResult">
        SELECT
	        f_id,
	        f_ename
        FROM
	        t_vessel
        WHERE
	        f_ename = #{fEname}
    </select>
    <select id="selectTVesselfImo" parameterType="TVessel" resultMap="TVesselResult">
        SELECT
	        f_id,
	        f_imo
        FROM
	        t_vessel
        WHERE
	        f_imo = #{fImo}
    </select>
    <select id="selectTVesselfNumber"  resultType="map">
        SELECT
	        f_id fId,
	        f_name fName
        FROM
	        t_vessel
        WHERE
	        f_status = 'T'
            <if test="fName != null and fName != ''">
                and f_name like concat('%', #{fName}, '%')
            </if>
    </select>

</mapper>