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

    <resultMap type="com.ruoyi.platform.domain.DatasetVersion" id="DatasetVersionMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="datasetId" column="dataset_id" jdbcType="INTEGER"/>
        <result property="version" column="version" jdbcType="VARCHAR"/>
        <result property="url" column="url" jdbcType="VARCHAR"/>
        <result property="fileName" column="file_name" jdbcType="VARCHAR"/>
        <result property="fileSize" column="file_size" jdbcType="VARCHAR"/>
        <result property="availableCluster" column="available_cluster" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="description" column="description" 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="DatasetVersionMap">
        select
        id,dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state
        from dataset_version
        where id = #{id} and state = 1
    </select>
    <!--查询单个-->
    <select id="queryByDatasetId" resultMap="DatasetVersionMap">
        select
        id,dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state
        from dataset_version
        where dataset_id = #{datasetId} and state = 1
        order by create_time desc
    </select>

    <select id="queryByDatasetVersion" resultMap="DatasetVersionMap">
        select
        id,dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state
        from dataset_version
        <where>
            state = 1
            <if test="datasetVersion.datasetId != null">
                and dataset_id = #{datasetVersion.datasetId}
            </if>
            <if test="datasetVersion.version != null and datasetVersion.version != ''">
                and version = #{datasetVersion.version}
            </if>
        </where>
        limit 1
    </select>

    <select id="queryAllByDatasetVersion" resultMap="DatasetVersionMap">
        select
        id,dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state
        from dataset_version
        <where>
            state = 1
            <if test="datasetId != null">
                and dataset_id = #{datasetId}
            </if>
            <if test="version != null and version != ''">
                and version = #{version}
            </if>
        </where>
    </select>



    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="DatasetVersionMap">
        select
        id,dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state
        from dataset_version
        <where>
            state = 1
            <if test="datasetVersion.id != null">
                and id = #{datasetVersion.id}
            </if>
            <if test="datasetVersion.datasetId != null">
                and dataset_id = #{datasetVersion.datasetId}
            </if>
            <if test="datasetVersion.version != null and datasetVersion.version != ''">
                and version = #{datasetVersion.version}
            </if>
            <if test="datasetVersion.url != null and datasetVersion.url != ''">
                and url = #{datasetVersion.url}
            </if>
            <if test="datasetVersion.fileName != null and datasetVersion.fileName != ''">
                and file_name = #{datasetVersion.fileName}
            </if>
            <if test="datasetVersion.fileSize != null and datasetVersion.fileSize != ''">
                and file_size = #{datasetVersion.fileSize}
            </if>
            <if test="datasetVersion.availableCluster != null and datasetVersion.availableCluster != ''">
                and available_cluster = #{datasetVersion.availableCluster}
            </if>
            <if test="datasetVersion.status != null">
                and status = #{datasetVersion.status}
            </if>
            <if test="datasetVersion.description != null and datasetVersion.description != ''">
                and description = #{datasetVersion.description}
            </if>
            <if test="datasetVersion.createBy != null and datasetVersion.createBy != ''">
                and create_by = #{datasetVersion.createBy}
            </if>
            <if test="datasetVersion.createTime != null">
                and create_time = #{datasetVersion.createTime}
            </if>
            <if test="datasetVersion.updateBy != null and datasetVersion.updateBy != ''">
                and update_by = #{datasetVersion.updateBy}
            </if>
            <if test="datasetVersion.updateTime != null">
                and update_time = #{datasetVersion.updateTime}
            </if>
            <if test="datasetVersion.state != null">
                and state = #{datasetVersion.state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from dataset_version
        <where>
            state = 1
            <if test="datasetVersion.id != null">
                and id = #{datasetVersion.id}
            </if>
            <if test="datasetVersion.datasetId != null">
                and dataset_id = #{datasetVersion.datasetId}
            </if>
            <if test="datasetVersion.version != null and datasetVersion.version != ''">
                and version = #{datasetVersion.version}
            </if>
            <if test="datasetVersion.url != null and datasetVersion.url != ''">
                and url = #{datasetVersion.url}
            </if>
            <if test="datasetVersion.fileName != null and datasetVersion.fileName != ''">
                and file_name = #{datasetVersion.fileName}
            </if>
            <if test="datasetVersion.fileSize != null and datasetVersion.fileSize != ''">
                and file_size = #{datasetVersion.fileSize}
            </if>
            <if test="datasetVersion.availableCluster != null and datasetVersion.availableCluster != ''">
                and available_cluster = #{datasetVersion.availableCluster}
            </if>
            <if test="datasetVersion.status != null">
                and status = #{datasetVersion.status}
            </if>
            <if test="datasetVersion.description != null and datasetVersion.description != ''">
                and description = #{datasetVersion.description}
            </if>
            <if test="datasetVersion.createBy != null and datasetVersion.createBy != ''">
                and create_by = #{datasetVersion.createBy}
            </if>
            <if test="datasetVersion.createTime != null">
                and create_time = #{datasetVersion.createTime}
            </if>
            <if test="datasetVersion.updateBy != null and datasetVersion.updateBy != ''">
                and update_by = #{datasetVersion.updateBy}
            </if>
            <if test="datasetVersion.updateTime != null">
                and update_time = #{datasetVersion.updateTime}
            </if>
            <if test="datasetVersion.state != null">
                and state = #{datasetVersion.state}
            </if>
        </where>

    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into dataset_version(dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state)
        values (#{datasetVersion.datasetId},#{datasetVersion.version},#{datasetVersion.url},#{datasetVersion.fileName},#{datasetVersion.fileSize},#{datasetVersion.availableCluster},#{datasetVersion.status},#{datasetVersion.description},#{datasetVersion.createBy},#{datasetVersion.createTime},#{datasetVersion.updateBy},#{datasetVersion.updateTime},#{datasetVersion.state})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into dataset_version(dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.datasetId},#{entity.version},#{entity.url},#{entity.fileName},#{entity.fileSize},#{entity.availableCluster},#{entity.status},#{entity.description},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into dataset_version(dataset_id,version,url,file_name,file_size,available_cluster,status, description,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.datasetId},#{entity.version},#{entity.url},#{entity.fileName},#{entity.fileSize},#{entity.availableCluster},#{entity.status},#{entity.description},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state})
        </foreach>
        on duplicate key update
dataset_id = values(dataset_id)version = values(version)url = values(url)file_name = values(file_name)file_size = values(file_size)available_cluster = values(available_cluster)status = values(status)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_version
        <set>
            <if test="datasetVersion.id != null">
                 id = #{datasetVersion.id},
            </if>
            <if test="datasetVersion.datasetId != null">
                 dataset_id = #{datasetVersion.datasetId},
            </if>
            <if test="datasetVersion.version != null and datasetVersion.version != ''">
                 version = #{datasetVersion.version},
            </if>
            <if test="datasetVersion.url != null and datasetVersion.url != ''">
                 url = #{datasetVersion.url},
            </if>
            <if test="datasetVersion.fileName != null and datasetVersion.fileName != ''">
                 file_name = #{datasetVersion.fileName},
            </if>
            <if test="datasetVersion.fileSize != null and datasetVersion.fileSize != ''">
                 file_size = #{datasetVersion.fileSize},
            </if>
            <if test="datasetVersion.availableCluster != null and datasetVersion.availableCluster != ''">
                 available_cluster = #{datasetVersion.availableCluster},
            </if>
            <if test="datasetVersion.status != null">
                 status = #{datasetVersion.status},
            </if>
            <if test="datasetVersion.description != null and datasetVersion.description != ''">
                 description = #{datasetVersion.description},
            </if>
            <if test="datasetVersion.createBy != null and datasetVersion.createBy != ''">
                 create_by = #{datasetVersion.createBy},
            </if>
            <if test="datasetVersion.createTime != null">
                 create_time = #{datasetVersion.createTime},
            </if>
            <if test="datasetVersion.updateBy != null and datasetVersion.updateBy != ''">
                 update_by = #{datasetVersion.updateBy},
            </if>
            <if test="datasetVersion.updateTime != null">
                 update_time = #{datasetVersion.updateTime},
            </if>
            <if test="datasetVersion.state != null">
                 state = #{datasetVersion.state}
            </if>
        </set>
        where id = #{datasetVersion.id}
    </update>

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

</mapper>

