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

    <resultMap type="com.ruoyi.platform.domain.ModelDependency" id="ModelDependencyMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="currentModelId" column="current_model_id" jdbcType="INTEGER"/>
        <result property="expInsId" column="exp_ins_id" jdbcType="INTEGER"/>
        <result property="parentModels" column="parent_models" jdbcType="VARCHAR"/>
        <result property="refItem" column="ref_item" jdbcType="VARCHAR"/>
        <result property="trainTask" column="train_task" jdbcType="VARCHAR"/>
        <result property="trainDataset" column="train_dataset" jdbcType="VARCHAR"/>
        <result property="trainParams" column="train_params" jdbcType="VARCHAR"/>
        <result property="trainImage" column="train_image" jdbcType="VARCHAR"/>
        <result property="testDataset" column="test_dataset" jdbcType="VARCHAR"/>
        <result property="projectDependency" column="project_dependency" jdbcType="VARCHAR"/>
        <result property="version" column="version" 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="queryByIns" resultMap="ModelDependencyMap">
        select
        id,current_model_id,exp_ins_id,parent_models,ref_item,train_task,train_dataset,train_params,train_image,test_dataset,project_dependency,version,create_by,create_time,update_by,update_time,state
        from model_dependency
        <where>
            exp_ins_id = #{expInsId} and state = 1
        </where>
    </select>
    <select id="queryByInsAndTrainTaskId" resultMap="ModelDependencyMap">
        select
        id,current_model_id,exp_ins_id,parent_models,ref_item,train_task,train_dataset,train_params,train_image,test_dataset,project_dependency,version,create_by,create_time,update_by,update_time,state
        from model_dependency
        <where>
            exp_ins_id = #{expInsId} and train_task like concat('%', #{taskId}, '%') limit 1
        </where>
    </select>
    <select id="queryChildrenByVersionId" resultMap="ModelDependencyMap">
        select
        id,current_model_id,exp_ins_id,parent_models,ref_item,train_task,train_dataset,train_params,train_image,test_dataset,project_dependency,version,create_by,create_time,update_by,update_time,state
        from model_dependency
        <where>
            parent_models like concat('%', #{model_id}, '%') AND   parent_models like concat('%', #{version}, '%') and state = 1
        </where>
    </select>

    <select id="queryByModelDependency" resultMap="ModelDependencyMap">
        select
        id,current_model_id,exp_ins_id,parent_models,ref_item,train_task,train_dataset,train_params,train_image,test_dataset,project_dependency,version,create_by,create_time,update_by,update_time,state
        from model_dependency
        <where>
            <if test="modelDependency.id != null">
                and id = #{modelDependency.id}
            </if>
            <if test="modelDependency.currentModelId != null">
                and current_model_id = #{modelDependency.currentModelId}
            </if>
            <if test="modelDependency.expInsId != null">
                and exp_ins_id = #{modelDependency.expInsId}
            </if>
            <if test="modelDependency.parentModels != null">
                and parent_models = #{modelDependency.parentModels}
            </if>
            <if test="modelDependency.refItem != null and modelDependency.refItem != ''">
                and ref_item = #{modelDependency.refItem}
            </if>
            <if test="modelDependency.trainTask != null and modelDependency.trainTask != ''">
                and train_task = #{modelDependency.trainTask}
            </if>
            <if test="modelDependency.trainDataset != null and modelDependency.trainDataset != ''">
                and train_dataset = #{modelDependency.trainDataset}
            </if>
            <if test="modelDependency.trainParams != null and modelDependency.trainParams != ''">
                and train_params = #{modelDependency.trainParams}
            </if>
            <if test="modelDependency.trainImage != null and modelDependency.trainImage != ''">
                and train_image = #{modelDependency.trainImage}
            </if>
            <if test="modelDependency.testDataset != null and modelDependency.testDataset != ''">
                and test_dataset = #{modelDependency.testDataset}
            </if>
            <if test="modelDependency.projectDependency != null and modelDependency.projectDependency != ''">
                and project_dependency = #{modelDependency.projectDependency}
            </if>
            <if test="modelDependency.version != null and modelDependency.version != ''">
                and version = #{modelDependency.version}
            </if>
            <if test="modelDependency.createBy != null and modelDependency.createBy != ''">
                and create_by = #{modelDependency.createBy}
            </if>
            <if test="modelDependency.createTime != null">
                and create_time = #{modelDependency.createTime}
            </if>
            <if test="modelDependency.updateBy != null and modelDependency.updateBy != ''">
                and update_by = #{modelDependency.updateBy}
            </if>
            <if test="modelDependency.updateTime != null">
                and update_time = #{modelDependency.updateTime}
            </if>
            <if test="modelDependency.state != null">
                and state = #{modelDependency.state}
            </if>
        </where>
    </select>

    <!--查询单个-->
    <select id="queryById" resultMap="ModelDependencyMap">
        select
          id, current_model_id, exp_ins_id, parent_models, ref_item, train_task, train_dataset, train_params, train_image, test_dataset, project_dependency, version, create_by, create_time, update_by, update_time, state
        from model_dependency
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="ModelDependencyMap">
        select
        id, current_model_id, exp_ins_id, parent_models, ref_item, train_task, train_dataset, train_params, train_image,
        test_dataset, project_dependency, version, create_by, create_time, update_by, update_time, state
        from model_dependency
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="currentModelId != null">
                and current_model_id = #{currentModelId}
            </if>
            <if test="expInsId != null">
                and exp_ins_id = #{expInsId}
            </if>
            <if test="parentModels != null and parentModels != ''">
                and parent_models = #{parentModels}
            </if>
            <if test="refItem != null and refItem != ''">
                and ref_item = #{refItem}
            </if>
            <if test="trainTask != null and trainTask != ''">
                and train_task = #{trainTask}
            </if>
            <if test="trainDataset != null and trainDataset != ''">
                and train_dataset = #{trainDataset}
            </if>
            <if test="trainParams != null and trainParams != ''">
                and train_params = #{trainParams}
            </if>
            <if test="trainImage != null and trainImage != ''">
                and train_image = #{trainImage}
            </if>
            <if test="testDataset != null and testDataset != ''">
                and test_dataset = #{testDataset}
            </if>
            <if test="projectDependency != null and projectDependency != ''">
                and project_dependency = #{projectDependency}
            </if>
            <if test="version != null and version != ''">
                and version = #{version}
            </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>
            <if test="state != null">
                and state = #{state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from model_dependency
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="currentModelId != null">
                and current_model_id = #{currentModelId}
            </if>
            <if test="expInsId != null">
                and exp_ins_id = #{expInsId}
            </if>
            <if test="parentModels != null and parentModels != ''">
                and parent_models = #{parentModels}
            </if>
            <if test="refItem != null and refItem != ''">
                and ref_item = #{refItem}
            </if>
            <if test="trainTask != null and trainTask != ''">
                and train_task = #{trainTask}
            </if>
            <if test="trainDataset != null and trainDataset != ''">
                and train_dataset = #{trainDataset}
            </if>
            <if test="trainParams != null and trainParams != ''">
                and train_params = #{trainParams}
            </if>
            <if test="trainImage != null and trainImage != ''">
                and train_image = #{trainImage}
            </if>
            <if test="testDataset != null and testDataset != ''">
                and test_dataset = #{testDataset}
            </if>
            <if test="projectDependency != null and projectDependency != ''">
                and project_dependency = #{projectDependency}
            </if>
            <if test="version != null and version != ''">
                and version = #{version}
            </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>
            <if test="state != null">
                and state = #{state}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into model_dependency(current_model_id, exp_ins_id, parent_models, ref_item, train_task, train_dataset, train_params, train_image, test_dataset, project_dependency, version, create_by, create_time, update_by, update_time, state)
        values (#{currentModelId}, #{expInsId}, #{parentModels}, #{refItem}, #{trainTask}, #{trainDataset}, #{trainParams}, #{trainImage}, #{testDataset}, #{projectDependency}, #{version}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{state})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into model_dependency(current_model_id, exp_ins_id, parent_models, ref_item, train_task, train_dataset,
        train_params, train_image, test_dataset, project_dependency, version, create_by, create_time, update_by,
        update_time, state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.currentModelId}, #{entity.expInsId}, #{entity.parentModels}, #{entity.refItem},
            #{entity.trainTask}, #{entity.trainDataset}, #{entity.trainParams}, #{entity.trainImage},
            #{entity.testDataset}, #{entity.projectDependency}, #{entity.version}, #{entity.createBy},
            #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}, #{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into model_dependency(current_model_id, exp_ins_id, parent_models, ref_item, train_task, train_dataset,
        train_params, train_image, test_dataset, project_dependency, version, create_by, create_time, update_by,
        update_time, state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.currentModelId}, #{entity.expInsId}, #{entity.parentModels}, #{entity.refItem},
            #{entity.trainTask}, #{entity.trainDataset}, #{entity.trainParams}, #{entity.trainImage},
            #{entity.testDataset}, #{entity.projectDependency}, #{entity.version}, #{entity.createBy},
            #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}, #{entity.state})
        </foreach>
        on duplicate key update
        current_model_id = values(current_model_id),
        exp_ins_id = values(exp_ins_id),
        parent_models = values(parent_models),
        ref_item = values(ref_item),
        train_task = values(train_task),
        train_dataset = values(train_dataset),
        train_params = values(train_params),
        train_image = values(train_image),
        test_dataset = values(test_dataset),
        project_dependency = values(project_dependency),
        version = values(version),
        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 model_dependency
        <set>
            <if test="currentModelId != null">
                current_model_id = #{currentModelId},
            </if>
            <if test="expInsId != null">
                exp_ins_id = #{expInsId},
            </if>
            <if test="parentModels != null and parentModels != ''">
                parent_models = #{parentModels},
            </if>
            <if test="refItem != null and refItem != ''">
                ref_item = #{refItem},
            </if>
            <if test="trainTask != null and trainTask != ''">
                train_task = #{trainTask},
            </if>
            <if test="trainDataset != null and trainDataset != ''">
                train_dataset = #{trainDataset},
            </if>
            <if test="trainParams != null and trainParams != ''">
                train_params = #{trainParams},
            </if>
            <if test="trainImage != null and trainImage != ''">
                train_image = #{trainImage},
            </if>
            <if test="testDataset != null and testDataset != ''">
                test_dataset = #{testDataset},
            </if>
            <if test="projectDependency != null and projectDependency != ''">
                project_dependency = #{projectDependency},
            </if>
            <if test="version != null and version != ''">
                version = #{version},
            </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>
            <if test="state != null">
                state = #{state},
            </if>
        </set>
        where id = #{id}
    </update>

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

</mapper>

