<?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.songhua.system.mapper.BasicCruiseShipMapper">
    
    <resultMap type="BasicCruiseShip" id="BasicCruiseShipResult">
        <result property="id"    column="id"    />
        <result property="shipName"    column="ship_name"    />
        <result property="shipType"    column="ship_type"    />
        <result property="lengthOverall"    column="length_overall"    />
        <result property="registrationNumber"    column="registration_number"    />
        <result property="quantity"    column="quantity"    />
        <result property="propulsion"    column="propulsion"    />
        <result property="safetyEquipment"    column="safety_equipment"    />
        <result property="passengerCapacity"    column="passenger_capacity"    />
    </resultMap>

    <sql id="selectBasicCruiseShipVo">
        select id, ship_name, ship_type, length_overall, registration_number, quantity, propulsion,safety_equipment,passenger_capacity from basic_cruise_ship
    </sql>

    <select id="selectBasicCruiseShipList" parameterType="BasicCruiseShip" resultMap="BasicCruiseShipResult">
        <include refid="selectBasicCruiseShipVo"/>
        <where>  
            <if test="shipName != null  and shipName != ''"> and ship_name like concat('%', #{shipName}, '%')</if>
        </where>
    </select>
    
    <select id="selectBasicCruiseShipById" parameterType="Long" resultMap="BasicCruiseShipResult">
        <include refid="selectBasicCruiseShipVo"/>
        where id = #{id}
    </select>

    <insert id="insertBasicCruiseShip" parameterType="BasicCruiseShip" useGeneratedKeys="true" keyProperty="id">
        insert into basic_cruise_ship
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shipName != null">ship_name,</if>
            <if test="shipType != null">ship_type,</if>
            <if test="lengthOverall != null">length_overall,</if>
            <if test="registrationNumber != null">registration_number,</if>
            <if test="quantity != null">quantity,</if>
            <if test="propulsion != null">propulsion,</if>
            <if test="passengerCapacity != null">passenger_capacity,</if>
            <if test="safetyEquipment != null">safety_equipment,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shipName != null">#{shipName},</if>
            <if test="shipType != null">#{shipType},</if>
            <if test="lengthOverall != null">#{lengthOverall},</if>
            <if test="propulsion != null">#{propulsion},</if>
            <if test="registrationNumber != null">#{registrationNumber},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="passengerCapacity != null">#{passengerCapacity},</if>
            <if test="safetyEquipment != null">#{safetyEquipment},</if>
         </trim>
    </insert>

    <update id="updateBasicCruiseShip" parameterType="BasicCruiseShip">
        update basic_cruise_ship
        <trim prefix="SET" suffixOverrides=",">
            <if test="shipName != null">ship_name = #{shipName},</if>
            <if test="shipType != null">ship_type = #{shipType},</if>
            <if test="lengthOverall != null">length_overall = #{lengthOverall},</if>
            <if test="registrationNumber != null">registration_number = #{registrationNumber},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="propulsion != null">propulsion = #{propulsion},</if>
            <if test="passengerCapacity != null">passenger_capacity = #{passengerCapacity},</if>
            <if test="safetyEquipment != null">safety_equipment = #{safetyEquipment},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBasicCruiseShipById" parameterType="Long">
        delete from basic_cruise_ship where id = #{id}
    </delete>

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