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

    <resultMap type="com.ruoyi.system.domain.BerthingFloatConfig" id="BerthingFloatConfigMap">
        <result property="floatId" column="float_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="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="timespan" column="timespan" jdbcType="INTEGER"/>
        <result property="wlevelchange" column="wlevelchange" jdbcType="NUMERIC"/>
        <result property="siteName" column="site_name" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="BerthingFloatConfigMap">
        select
            float_id, id, site_id, planid, create_time, status, is_del, wlevel, timespan, wlevelchange, type
        from berthing_float_config
        where float_id = #{floatId} and is_del = 0
    </select>

    <!--查询单个-->
    <select id="queryByMaxPlanid" resultMap="BerthingFloatConfigMap">
        select
            float_id, id, site_id, planid, create_time, status, is_del, wlevel, timespan, wlevelchange, type
        from berthing_float_config
        where site_id = #{siteId} and is_del = 0
        order by planid desc
        limit 1
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BerthingFloatConfigMap">
        select
            a.float_id, a.id, a.site_id, a.planid, a.create_time, a.status, a.is_del, a.wlevel, a.timespan, a.wlevelchange, a.type, b.site_name
        from berthing_float_config as a
        join site_info as b on a.site_id = b.site_id
        <where>
            <if test="floatPointQuery.floatId != null">
                and a.float_id = #{floatPointQuery.floatId}
            </if>
            <if test="floatPointQuery.siteId != null">
                and a.site_id = #{floatPointQuery.siteId}
            </if>
        </where>
        and a.is_del = 0
        order by a.wlevel desc
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from berthing_float_config
        <where>
            <if test="floatId != null">
                and float_id = #{floatId}
            </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="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="timespan != null">
                and timespan = #{timespan}
            </if>
            <if test="wlevelchange != null">
                and wlevelchange = #{wlevelchange}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
                and is_del = 0
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="floatId" useGeneratedKeys="true">
        insert into berthing_float_config(id, site_id, planid, create_time, status, is_del, wlevel, timespan, wlevelchange, type)
        values (#{id}, #{siteId}, #{planid}, #{createTime}, #{status}, #{isDel}, #{wlevel}, #{timespan}, #{wlevelchange}, #{type})
    </insert>

    <insert id="insertBatch" keyProperty="floatId" useGeneratedKeys="true">
        insert into berthing_float_config(id, site_id, planid, create_time, status, is_del, wlevel, timespan, wlevelchange, type)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.id}, #{entity.siteId}, #{entity.planid}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.wlevel}, #{entity.timespan}, #{entity.wlevelchange}, #{entity.type})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="floatId" useGeneratedKeys="true">
        insert into berthing_float_config(id, site_id, planid, create_time, status, is_del, wlevel, timespan, wlevelchange, type)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.siteId}, #{entity.planid}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.wlevel}, #{entity.timespan}, #{entity.wlevelchange}, #{entity.type})
        </foreach>
        on duplicate key update
id = values(id),
site_id = values(site_id),
planid = values(planid),
create_time = values(create_time),
status = values(status),
is_del = values(is_del),
wlevel = values(wlevel),
timespan = values(timespan),
wlevelchange = values(wlevelchange),
type = values(type)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update berthing_float_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="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="timespan != null">
                timespan = #{timespan},
            </if>
            <if test="wlevelchange != null">
                wlevelchange = #{wlevelchange},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
        </set>
        where float_id = #{floatId}
    </update>

    <!--通过主键删除-->
    <update id="deleteById">
        update berthing_float_config set is_del = 1 where float_id = #{floatId}
    </update>

</mapper>

