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

    <resultMap type="com.ruoyi.platform.domain.DatasetTempStorage" id="DatasetTempStorageMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="version" column="version" jdbcType="VARCHAR"/>
        <result property="source" column="source" jdbcType="VARCHAR"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
        <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"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="DatasetTempStorageMap">
        select
            id, name, version, source, state, create_by, create_time, update_by, update_time
        from dataset_temp_storage
        where id = #{id}
    </select>

    <!--查询指定条件的数据-->
    <select id="queryByDatasetTempStorage" resultMap="DatasetTempStorageMap">
        select
        id, name, version, source, state, create_by, create_time, update_by, update_time
        from dataset_temp_storage
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="version != null and version != ''">
                and version = #{version}
            </if>
            <if test="source != null and source != ''">
                and source = #{source}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
        </where>
        limit 1
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="DatasetTempStorageMap">
        select
        id, name, version, source, state, create_by, create_time, update_by, update_time
        from dataset_temp_storage
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="version != null and version != ''">
                and version = #{version}
            </if>
            <if test="source != null and source != ''">
                and source = #{source}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from dataset_temp_storage
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="version != null and version != ''">
                and version = #{version}
            </if>
            <if test="source != null and source != ''">
                and source = #{source}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
        </where>
    </select>

    <select id="queryByInsId" resultType="com.ruoyi.platform.domain.DatasetTempStorage">
        select *
        from dataset_temp_storage
        where JSON_CONTAINS(source, #{insId})
        order by id desc limit 1
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into dataset_temp_storage(name, version, source, state, create_by, create_time, update_by, update_time)
        values (#{name}, #{version}, #{source}, #{state}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into dataset_temp_storage(name, version, source, state, create_by, create_time, update_by, update_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.version}, #{entity.source}, #{entity.state}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into dataset_temp_storage(name, version, source, state, create_by, create_time, update_by, update_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.version}, #{entity.source}, #{entity.state}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
        </foreach>
        on duplicate key update
        name = values(name),
        version = values(version),
        source = values(source),
        state = values(state),
        create_by = values(create_by),
        create_time = values(create_time),
        update_by = values(update_by),
        update_time = values(update_time)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update dataset_temp_storage
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="version != null and version != ''">
                version = #{version},
            </if>
            <if test="source != null and source != ''">
                source = #{source},
            </if>
            <if test="state != null">
                state = #{state},
            </if>
            <if test="createBy != null and createBy != ''">
                create_by = #{createBy},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateBy != null and updateBy != ''">
                update_by = #{updateBy},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where id = #{id}
    </update>

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

</mapper>
