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

    <sql id="sysWharfColumns">
        a.wharf_order as "wharfOrder",

        a.wharf_nanme as "wharfNanme",

        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="sysWharfJoins">
    </sql>

    <select id="get" resultType="SysWharf">
        SELECT
            <include refid="sysWharfColumns"/>
        FROM sys_wharf a
        <include refid="sysWharfJoins"/>
        WHERE a.id = #{id}
    </select>

    <select id="findList" resultType="SysWharf">
        SELECT
            <include refid="sysWharfColumns"/>
        FROM sys_wharf a
        <include refid="sysWharfJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="wharfOrder != null ">
                AND a.wharf_order = #{wharfOrder}
            </if>
            <if test="wharfNanme != null and wharfNanme != ''">
                and a.wharf_nanme like concat('%', #{wharfNanme}, '%')
            </if>
            <if test="lat != null and lat != ''">
                and a.lat like concat('%', #{lat}, '%')
            </if>
            <if test="lng != null and lng != ''">
                and a.lng like concat('%', #{lng}, '%')
            </if>
            <if test="status != null and status != ''">
                and a.status = #{status}
            </if>
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
                ORDER BY a.wharf_order
            </otherwise>
        </choose>
    </select>

    <select id="findListWithUnique" resultType="SysWharf">
        SELECT
            a.id
        FROM sys_wharf a
        <include refid="sysWharfJoins"/>
        <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_wharf(
            wharf_order,

            wharf_nanme,

            lat,

            lng,

            status,

            remark,

            id,

            create_by,

            create_dept,

            create_time,

            update_by,

            update_time,

            update_ip,

            version,

            del_flag

        ) VALUES (
            #{wharfOrder},

            #{wharfNanme},

            #{lat},

            #{lng},

            #{status},

            #{remark},

            #{id},

            #{createBy},

            #{createDept},

            #{createTime},

            #{updateBy},

            #{updateTime},

            #{updateIp},

            #{version},

            #{delFlag}

        )
    </insert>

    <update id="update">
        UPDATE sys_wharf SET
            wharf_order = #{wharfOrder},
            wharf_nanme = #{wharfNanme},
            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_wharf SET
            status = #{status},
            version = version + 1
        WHERE id = #{id}
    </update>

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

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

</mapper>
