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

    <resultMap type="com.ruoyi.system.domain.BerthingPointConfig" id="BerthingPointConfigMap">
        <result property="stopId" column="stop_id" jdbcType="INTEGER"/>
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="siteId" column="site_id" jdbcType="INTEGER"/>
        <result property="planid" column="planid" jdbcType="INTEGER"/>
        <result property="berthingId" column="berthing_id" jdbcType="INTEGER"/>
        <result property="positions" column="positions" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="isDel" column="is_del" jdbcType="INTEGER"/>
        <result property="wlevel" column="wlevel" jdbcType="NUMERIC"/>
        <result property="factors" column="factors" jdbcType="VARCHAR"/>
        <result property="siteName" column="site_name" jdbcType="VARBINARY"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="BerthingPointConfigMap">
        select
            stop_id, id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors
        from berthing_point_config
        where stop_id = #{stopId}
    </select>

    <!--查询单个-->
    <select id="queryByPlanid" resultMap="BerthingPointConfigMap">
        select
            stop_id, id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors
        from berthing_point_config
        where site_id = #{siteId} and planid = #{planid} and is_del = 0
    </select>


    <!--查询单个-->
    <select id="queryMaxPlanid" resultMap="BerthingPointConfigMap">
        select
            MAX(planid) as planid
        from berthing_point_config
        where site_id = #{siteId} and is_del = 0
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BerthingPointConfigMap">
        select
            a.stop_id, a.id, a.site_id, a.planid, a.berthing_id, a.positions, a.create_time, a.status, a.is_del, a.wlevel, a.factors, b.site_name
        from berthing_point_config as a
        join site_info as b on a.site_id = b.site_id
        <where>
            <if test="stopPointQuery.stopId != null">
                and a.stop_id = #{stopPointQuery.stopId}
            </if>
            <if test="stopPointQuery.siteId != null">
                and a.site_id = #{stopPointQuery.siteId}
            </if>
            and a.is_del = 0
        </where>
        order by a.wlevel desc
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from berthing_point_config
        <where>
            <if test="stopId != null">
                and stop_id = #{stopId}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="siteId != null">
                and site_id = #{siteId}
            </if>
            <if test="planid != null">
                and planid = #{planid}
            </if>
            <if test="berthingId != null">
                and berthing_id = #{berthingId}
            </if>
            <if test="positions != null and positions != ''">
                and positions = #{positions}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="isDel != null">
                and is_del = #{isDel}
            </if>
            <if test="wlevel != null">
                and wlevel = #{wlevel}
            </if>
            <if test="factors != null and factors != ''">
                and factors = #{factors}
            </if>
                and is_del = 0
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="stopId" useGeneratedKeys="true">
        insert into berthing_point_config (id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors)
        values (#{id}, #{siteId}, #{planid}, #{berthingId}, #{positions}, #{createTime}, #{status}, #{isDel}, #{wlevel}, #{factors})
    </insert>

    <insert id="insertBatch" keyProperty="stopId" useGeneratedKeys="true">
        insert into berthing_point_config(id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.id}, #{entity.siteId}, #{entity.planid}, #{entity.berthingId}, #{entity.positions}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.wlevel}, #{entity.factors})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="stopId" useGeneratedKeys="true">
        insert into berthing_point_config(id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.siteId}, #{entity.planid}, #{entity.berthingId}, #{entity.positions}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.wlevel}, #{entity.factors})
        </foreach>
        on duplicate key update
id = values(id),
site_id = values(site_id),
planid = values(planid),
berthing_id = values(berthing_id),
positions = values(positions),
create_time = values(create_time),
status = values(status),
is_del = values(is_del),
wlevel = values(wlevel),
factors = values(factors)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update berthing_point_config
        <set>
            <if test="id != null and id != ''">
                id = #{id},
            </if>
            <if test="siteId != null">
                site_id = #{siteId},
            </if>
            <if test="planid != null">
                planid = #{planid},
            </if>
            <if test="berthingId != null">
                berthing_id = #{berthingId},
            </if>
            <if test="positions != null and positions != ''">
                positions = #{positions},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="isDel != null">
                is_del = #{isDel},
            </if>
            <if test="wlevel != null">
                wlevel = #{wlevel},
            </if>
            <if test="factors != null and factors != ''">
                factors = #{factors},
            </if>
        </set>
        where stop_id = #{stopId}
    </update>

    <!--通过主键删除-->
    <update id="deleteById">
        update berthing_point_config set is_del = 1 where stop_id = #{stopId}
    </update>

</mapper>

