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

    <resultMap type="com.ruoyi.system.domain.TaskResult" id="TaskResultMap">
        <result property="resultId" column="result_id" jdbcType="INTEGER"/>
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="taskid" column="taskid" jdbcType="VARCHAR"/>
        <result property="starttime" column="starttime" jdbcType="TIMESTAMP"/>
        <result property="endtime" column="endtime" jdbcType="TIMESTAMP"/>
        <result property="width" column="width" jdbcType="NUMERIC"/>
        <result property="planid" column="planid" jdbcType="INTEGER"/>
        <result property="acreagesum" column="acreagesum" jdbcType="VARCHAR"/>
        <result property="flowsum" column="flowsum" jdbcType="NUMERIC"/>
        <result property="positions" column="positions" jdbcType="VARCHAR"/>
        <result property="elevations" column="elevations" jdbcType="VARCHAR"/>
        <result property="acreages" column="acreages" jdbcType="VARCHAR"/>
        <result property="waterlevels" column="waterlevels" jdbcType="VARCHAR"/>
        <result property="wspeeds" column="wspeeds" jdbcType="VARCHAR"/>
        <result property="flows" column="flows" jdbcType="VARCHAR"/>
        <result property="siteId" column="site_id" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="stopwspeeds" column="stopwspeeds" jdbcType="VARCHAR"/>
        <result property="partwspeeds" column="partwspeeds" jdbcType="VARCHAR"/>
        <result property="waterlevel" column="waterlevel" jdbcType="NUMERIC"/>
        <result property="berthingId" column="berthing_id" jdbcType="INTEGER"/>
        <result property="stopId" column="stop_id" jdbcType="INTEGER"/>
    </resultMap>

    <resultMap type="com.ruoyi.system.dto.TaskResultSortDTO" id="TaskResultSortDTOMap">
        <result property="resultId" column="result_id" jdbcType="INTEGER"/>
        <result property="flowsum" column="flowsum" jdbcType="NUMERIC"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="waterlevel" column="waterlevel" jdbcType="NUMERIC"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TaskResultMap">
        select
            result_id, id, type, taskid, starttime, endtime, width, planid, acreagesum, flowsum, positions, elevations, acreages, waterlevels, wspeeds, flows, site_id, create_time, status, stopwspeeds, partwspeeds, waterlevel, berthing_id, stop_id
        from task_result
        where result_id = #{resultId}
    </select>

    <!--查询单个-->
    <select id="queryByTaskid" resultMap="TaskResultMap">
        select
            result_id, id, type, taskid, starttime, endtime, width, planid, acreagesum, flowsum, positions, elevations, acreages, waterlevels, wspeeds, flows, site_id, create_time, status, stopwspeeds, partwspeeds, waterlevel, berthing_id, stop_id
        from task_result
        where taskid = #{taskid}
        limit 1
    </select>

    <!--查询单个-->
    <select id="queryBySiteIdOne" resultMap="TaskResultMap">
        select
            result_id, id, type, taskid, starttime, endtime, width, planid, acreagesum, flowsum, positions, elevations, acreages, waterlevels, wspeeds, flows, site_id, create_time, status, stopwspeeds, partwspeeds, waterlevel, berthing_id, stop_id
        from task_result
        where site_id = #{siteId} and (status in (0, 2, 3))
        order by create_time desc
        limit 1
    </select>

    <!--查询单个-->
    <select id="queryByTimeQuery" resultMap="TaskResultSortDTOMap">
        select
            result_id, site_id, taskid, flowsum, create_time, waterlevel
        from task_result
        where site_id = #{scattperPlotQuery.siteId} and waterlevel is not null
        <if test="scattperPlotQuery.startTime != null and scattperPlotQuery.endTime != null">
            and create_time between #{scattperPlotQuery.startTime} and #{scattperPlotQuery.endTime}
        </if>
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TaskResultMap">
        select
            result_id, id, type, taskid, starttime, endtime, width, planid, acreagesum, flowsum, positions, elevations, acreages, waterlevels, wspeeds, flows, site_id, create_time, status, stopwspeeds, partwspeeds, waterlevel, berthing_id, stop_id
        from task_result
        <where>
            <if test="achievementQuery.siteId != null">
                and site_id = #{achievementQuery.siteId}
            </if>
        </where>
        order by create_time desc
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from task_result
        <where>
            <if test="resultId != null">
                and result_id = #{resultId}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="taskid != null and taskid != ''">
                and taskid = #{taskid}
            </if>
            <if test="starttime != null">
                and starttime = #{starttime}
            </if>
            <if test="endtime != null">
                and endtime = #{endtime}
            </if>
            <if test="width != null">
                and width = #{width}
            </if>
            <if test="planid != null">
                and planid = #{planid}
            </if>
            <if test="acreagesum != null and acreagesum != ''">
                and acreagesum = #{acreagesum}
            </if>
            <if test="flowsum != null">
                and flowsum = #{flowsum}
            </if>
            <if test="positions != null and positions != ''">
                and positions = #{positions}
            </if>
            <if test="elevations != null and elevations != ''">
                and elevations = #{elevations}
            </if>
            <if test="acreages != null and acreages != ''">
                and acreages = #{acreages}
            </if>
            <if test="waterlevels != null and waterlevels != ''">
                and waterlevels = #{waterlevels}
            </if>
            <if test="wspeeds != null">
                and wspeeds = #{wspeeds}
            </if>
            <if test="flows != null and flows != ''">
                and flows = #{flows}
            </if>
            <if test="siteId != null">
                and site_id = #{siteId}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="stopwspeeds != null and stopwspeeds != ''">
                and stopwspeeds = #{stopwspeeds}
            </if>
            <if test="partwspeeds != null and partwspeeds != ''">
                and partwspeeds = #{partwspeeds}
            </if>
            <if test="waterlevel != null">
                and waterlevel = #{waterlevel}
            </if>
            <if test="berthingId != null">
                and berthing_id = #{berthingId}
            </if>
            <if test="stopId != null">
                and stop_id = #{stopId}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="resultId" useGeneratedKeys="true">
        insert into task_result(id, type, taskid, starttime, endtime, width, planid, acreagesum, flowsum, positions, elevations, acreages, waterlevels, wspeeds, flows, site_id, create_time, status, stopwspeeds, partwspeeds, waterlevel, berthing_id, stop_id)
        values (#{id}, #{type}, #{taskid}, #{starttime}, #{endtime}, #{width}, #{planid}, #{acreagesum}, #{flowsum}, #{positions}, #{elevations}, #{acreages}, #{waterlevels}, #{wspeeds}, #{flows}, #{siteId}, #{createTime}, #{status}, #{stopwspeeds}, #{partwspeeds}, #{waterlevel}, #{berthingId}, #{stopId})
    </insert>

    <insert id="insertBatch" keyProperty="resultId" useGeneratedKeys="true">
        insert into task_result(id, type, taskid, starttime, endtime, width, planid, acreagesum, flowsum, positions, elevations, acreages, waterlevels, wspeeds, flows, site_id, create_time, status, stopwspeeds, partwspeeds, waterlevel, berthing_id, stop_id)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.id}, #{entity.type}, #{entity.taskid}, #{entity.starttime}, #{entity.endtime}, #{entity.width}, #{entity.planid}, #{entity.acreagesum}, #{entity.flowsum}, #{entity.positions}, #{entity.elevations}, #{entity.acreages}, #{entity.waterlevels}, #{entity.wspeeds}, #{entity.flows}, #{entity.siteId}, #{entity.createTime}, #{entity.status}, #{entity.stopwspeeds}, #{entity.partwspeeds}, #{entity.waterlevel}, #{entity.berthingId}, #{entity.stopId})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="resultId" useGeneratedKeys="true">
        insert into task_result(id, type, taskid, starttime, endtime, width, planid, acreagesum, flowsum, positions, elevations, acreages, waterlevels, wspeeds, flows, site_id, create_time, status, stopwspeeds, partwspeeds, waterlevel, berthing_id, stop_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.type}, #{entity.taskid}, #{entity.starttime}, #{entity.endtime}, #{entity.width}, #{entity.planid}, #{entity.acreagesum}, #{entity.flowsum}, #{entity.positions}, #{entity.elevations}, #{entity.acreages}, #{entity.waterlevels}, #{entity.wspeeds}, #{entity.flows}, #{entity.siteId}, #{entity.createTime}, #{entity.status}, #{entity.stopwspeeds}, #{entity.partwspeeds}, #{entity.waterlevel}, #{entity.berthingId}, #{entity.stopId})
        </foreach>
        on duplicate key update
id = values(id),
type = values(type),
taskid = values(taskid),
starttime = values(starttime),
endtime = values(endtime),
width = values(width),
planid = values(planid),
acreagesum = values(acreagesum),
flowsum = values(flowsum),
positions = values(positions),
elevations = values(elevations),
acreages = values(acreages),
waterlevels = values(waterlevels),
wspeeds = values(wspeeds),
flows = values(flows),
site_id = values(site_id),
create_time = values(create_time),
status = values(status),
stopwspeeds = values(stopwspeeds),
partwspeeds = values(partwspeeds),
waterlevel = values(waterlevel),
berthing_id = values(berthing_id),
stop_id = values(stop_id)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update task_result
        <set>
            <if test="id != null and id != ''">
                id = #{id},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="taskid != null and taskid != ''">
                taskid = #{taskid},
            </if>
            <if test="starttime != null">
                starttime = #{starttime},
            </if>
            <if test="endtime != null">
                endtime = #{endtime},
            </if>
            <if test="width != null">
                width = #{width},
            </if>
            <if test="planid != null">
                planid = #{planid},
            </if>
            <if test="acreagesum != null and acreagesum != ''">
                acreagesum = #{acreagesum},
            </if>
            <if test="flowsum != null">
                flowsum = #{flowsum},
            </if>
            <if test="positions != null and positions != ''">
                positions = #{positions},
            </if>
            <if test="elevations != null and elevations != ''">
                elevations = #{elevations},
            </if>
            <if test="acreages != null and acreages != ''">
                acreages = #{acreages},
            </if>
            <if test="waterlevels != null and waterlevels != ''">
                waterlevels = #{waterlevels},
            </if>
            <if test="wspeeds != null">
                wspeeds = #{wspeeds},
            </if>
            <if test="flows != null and flows != ''">
                flows = #{flows},
            </if>
            <if test="siteId != null">
                site_id = #{siteId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="stopwspeeds != null and stopwspeeds != ''">
                stopwspeeds = #{stopwspeeds},
            </if>
            <if test="partwspeeds != null and partwspeeds != ''">
                partwspeeds = #{partwspeeds},
            </if>
            <if test="waterlevel != null">
                waterlevel = #{waterlevel},
            </if>
            <if test="berthingId != null">
                berthing_id = #{berthingId},
            </if>
            <if test="stopId != null">
                stop_id = #{stopId},
            </if>
        </set>
        where result_id = #{resultId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from task_result where result_id = #{resultId}
    </delete>

</mapper>

