<?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.aidex.system.mapper.SysShipMapper">

    <sql id="sysShipColumns">
        a.ship_num as "shipNum",

        a.ship_nanme as "shipNanme",

        a.gps_device_num as "gpsDeviceNum",

        a.nuclear_load_num as "nuclearLoadNum",

        a.lat as "lat",

        a.lng as "lng",

        a.status as "status",

        a.remark as "remark",

        a.id as "id",

        a.create_by as "createBy",

        a.create_dept as "createDept",

        a.create_time as "createTime",

        a.update_by as "updateBy",

        a.update_time as "updateTime",

        a.update_ip as "updateIp",

        a.version as "version",

        a.del_flag as "delFlag"

    </sql>

    <sql id="sysShipJoins">
    </sql>

    <select id="get" resultType="SysShip">
        SELECT
            <include refid="sysShipColumns"/>
        FROM sys_ship a
        <include refid="sysShipJoins"/>
        WHERE a.id = #{id}
    </select>

    <select id="findList" resultType="SysShip">
        SELECT
            <include refid="sysShipColumns"/>
        FROM sys_ship a
        <include refid="sysShipJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="shipNum != null and shipNum != ''">
                and a.ship_num like concat('%', #{shipNum}, '%')
            </if>
            <if test="shipNanme != null and shipNanme != ''">
                and a.ship_nanme like concat('%', #{shipNanme}, '%')
            </if>
            <if test="gpsDeviceNum != null and gpsDeviceNum != ''">
                and a.gps_device_num like concat('%', #{gpsDeviceNum}, '%')
            </if>
            <if test="nuclearLoadNum != null ">
                AND a.nuclear_load_num = #{nuclearLoadNum}
            </if>
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
            </otherwise>
        </choose>
    </select>

    <select id="findListWithUnique" resultType="SysShip">
        SELECT
            a.id
        FROM sys_ship a
        <include refid="sysShipJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="notEqualId != null and notEqualId != ''">
                AND id != #{notEqualId}
            </if>
        </where>
    </select>


    <insert id="insert">
        INSERT INTO sys_ship(
            ship_num,

            ship_nanme,

            gps_device_num,

            nuclear_load_num,

            lat,

            lng,

            status,

            remark,

            id,

            create_by,

            create_dept,

            create_time,

            update_by,

            update_time,

            update_ip,

            version,

            del_flag

        ) VALUES (
            #{shipNum},

            #{shipNanme},

            #{gpsDeviceNum},

            #{nuclearLoadNum},

            #{lat},

            #{lng},

            #{status},

            #{remark},

            #{id},

            #{createBy},

            #{createDept},

            #{createTime},

            #{updateBy},

            #{updateTime},

            #{updateIp},

            #{version},

            #{delFlag}

        )
    </insert>

    <update id="update">
        UPDATE sys_ship SET
            ship_num = #{shipNum},
            ship_nanme = #{shipNanme},
            gps_device_num = #{gpsDeviceNum},
            nuclear_load_num = #{nuclearLoadNum},
            lat = #{lat},
            lng = #{lng},
            status = #{status},
            remark = #{remark},
            update_by = #{updateBy},
            update_time = #{updateTime},
            update_ip = #{updateIp},
            version = version + 1
        WHERE id = #{id} and version = #{version}
    </update>

    <update id="updateStatus">
        UPDATE sys_ship SET
            status = #{status},
            version = version + 1
        WHERE id = #{id}
    </update>

    <update id="delete">
        UPDATE sys_ship SET
            del_flag = #{DEL_FLAG_DELETE}
        WHERE id = #{id}
    </update>

    <delete id="deleteSysShipByIds">
        UPDATE sys_ship SET
            del_flag = #{DEL_FLAG_DELETE}
        WHERE id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
