<?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.platform.mapper.DatasetDao">

    <resultMap type="com.ruoyi.platform.domain.Dataset" id="DatasetMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="description" column="description" jdbcType="VARCHAR"/>
        <result property="availableRange" column="available_range" jdbcType="INTEGER"/>
        <result property="dataType" column="data_type" jdbcType="VARCHAR"/>
        <result property="dataTag" column="data_tag" jdbcType="VARCHAR"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="DatasetMap">
        select
            id,name,description,available_range,data_type,data_tag,create_by,create_time,update_by,update_time,state
        from dataset
        where id = #{id} and state = 1
    </select>

    <!--查询单个-->
    <select id="findByName" resultMap="DatasetMap">
        select
            id,name,description,available_range,data_type,data_tag,create_by,create_time,update_by,update_time,state
        from dataset
        where name = #{name} and state = 1 limit 1
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="DatasetMap">
        select
        id,name,description,available_range,data_type,data_tag,create_by,create_time,update_by,update_time,state
        from dataset
        <where>
            state = 1
            <if test="dataset.id != null">
                and id = #{dataset.id}
            </if>
            <if test="dataset.name != null and dataset.name != ''">
                and name like "%"#{dataset.name}"%"
            </if>
            <if test="dataset.description != null and dataset.description != ''">
                and description = #{dataset.description}
            </if>
            <if test="dataset.availableRange != null">
                and available_range = #{dataset.availableRange}
            </if>
            <if test="dataset.dataType != null">
                and data_type = #{dataset.dataType}
            </if>
            <if test="dataset.dataTag != null">
                and data_tag = #{dataset.dataTag}
            </if>
            <if test="dataset.createBy != null and dataset.createBy != ''">
                and create_by = #{dataset.createBy}
            </if>
            <if test="dataset.createTime != null">
                and create_time = #{dataset.createTime}
            </if>
            <if test="dataset.updateBy != null and dataset.updateBy != ''">
                and update_by = #{dataset.updateBy}
            </if>
            <if test="dataset.updateTime != null">
                and update_time = #{dataset.updateTime}
            </if>
            <if test="dataset.state != null">
                and state = #{dataset.state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from dataset
        <where>
            state = 1
            <if test="dataset.id != null">
                and id = #{dataset.id}
            </if>
            <if test="dataset.name != null and dataset.name != ''">
                and name like "%"#{dataset.name}"%"
            </if>
            <if test="dataset.description != null and dataset.description != ''">
                and description = #{dataset.description}
            </if>
            <if test="dataset.availableRange != null">
                and available_range = #{dataset.availableRange}
            </if>
            <if test="dataset.dataType != null">
                and data_type = #{dataset.dataType}
            </if>
            <if test="dataset.dataTag != null">
                and data_tag = #{dataset.dataTag}
            </if>
            <if test="dataset.createBy != null and dataset.createBy != ''">
                and create_by = #{dataset.createBy}
            </if>
            <if test="dataset.createTime != null">
                and create_time = #{dataset.createTime}
            </if>
            <if test="dataset.updateBy != null and dataset.updateBy != ''">
                and update_by = #{dataset.updateBy}
            </if>
            <if test="dataset.updateTime != null">
                and update_time = #{dataset.updateTime}
            </if>
            <if test="dataset.state != null">
                and state = #{dataset.state}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into dataset(name,description,available_range,data_type,data_tag,create_by,create_time,update_by,update_time,state)
        values (#{dataset.name},#{dataset.description},#{dataset.availableRange},#{dataset.dataType},#{dataset.dataTag},#{dataset.createBy},#{dataset.createTime},#{dataset.updateBy},#{dataset.updateTime},#{dataset.state})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into dataset(name,description,available_range,data_type,data_tag,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}#{entity.description}#{entity.availableRange}#{entity.dataType}#{entity.dataTag}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into dataset(name,description,available_range,data_type,data_tag,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}#{entity.description}#{entity.availableRange#{entity.dataType}#{entity.dataTag}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state})
        </foreach>
        on duplicate key update
        name = values(name)description = values(description)available_range = values(available_range)data_type = values(data_type)data_tag = values(data_tag)create_by = values(create_by)create_time = values(create_time)update_by = values(update_by)update_time = values(update_time)state = values(state)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update dataset
        <set>
            <if test="dataset.name != null and dataset.name != ''">
                name = #{dataset.name},
            </if>
            <if test="dataset.description != null and dataset.description != ''">
                description = #{dataset.description},
            </if>
            <if test="dataset.availableRange != null and dataset.availableRange != ''">
                available_range = #{dataset.availableRange},
            </if>
            <if test="dataset.dataType != null">
                data_type = #{dataset.dataType},
            </if>
            <if test="dataset.dataTag != null">
                data_tag = #{dataset.dataTag},
            </if>
            <if test="dataset.createBy != null and dataset.createBy != ''">
                create_by = #{dataset.createBy},
            </if>
            <if test="dataset.createTime != null">
                create_time = #{dataset.createTime},
            </if>
            <if test="dataset.updateBy != null and dataset.updateBy != ''">
                update_by = #{dataset.updateBy},
            </if>
            <if test="dataset.updateTime != null">
                update_time = #{dataset.updateTime},
            </if>
            <if test="dataset.state != null">
                state = #{dataset.state}
            </if>
        </set>
        where id = #{dataset.id}
    </update>


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

</mapper>
