<?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.yice.webadmin.app.dao.ModelVersionMapper">
    <resultMap id="BaseResultMap" type="com.yice.webadmin.app.model.ModelVersion">
        <id column="version_id" jdbcType="BIGINT" property="versionId"/>
        <result column="model_id" jdbcType="BIGINT" property="modelId"/>
        <result column="version_name" jdbcType="VARCHAR" property="versionName"/>
        <result column="version_describe" jdbcType="VARCHAR" property="versionDescribe"/>
        <result column="protocol" jdbcType="VARCHAR" property="protocol"/>
        <result column="protocol_url" jdbcType="VARCHAR" property="protocolUrl"/>
        <result column="io_mode" jdbcType="VARCHAR" property="ioMode"/>
        <result column="copyright" jdbcType="VARCHAR" property="copyright"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="model_version" jdbcType="TINYINT" property="modelVersion"/>
        <result column="status" jdbcType="TINYINT" property="status"/>
        <result column="version_source" jdbcType="VARCHAR" property="versionSource"/>
        <result column="base_model" jdbcType="VARCHAR" property="baseModel"/>
        <result column="business_label" jdbcType="VARCHAR" property="businessLabel"/>
        <result column="base_id" jdbcType="BIGINT" property="baseId"/>
        <result column="model_training_method" jdbcType="VARCHAR" property="modelTrainingMethod"/>
        <result column="run_name" jdbcType="VARCHAR" property="runName"/>
        <result column="training_task" jdbcType="VARCHAR" property="trainingTask"/>
        <result column="model_url" jdbcType="VARCHAR" property="modelUrl"/>
        <result column="is_compress" jdbcType="TINYINT" property="isCompress"/>
        <result column="task_id" jdbcType="BIGINT" property="taskId"/>
        <result column="run_id" jdbcType="BIGINT" property="runId"/>
        <result column="base_prompt_template" jdbcType="VARCHAR" property="basePromptTemplate"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO lmp_model_version
        (version_id,
        model_id,
        version_name,
        version_describe,
        protocol,
        protocol_url,
        io_mode,
        copyright,
        create_user_id,
        create_time,
        update_user_id,
        update_time,
        model_version,
        status,
        version_source,
        base_model,
        business_label,
        base_id,
        model_training_method,
        run_name,
        training_task,
        model_url,
        is_compress,
        task_id,
        run_id,
        base_prompt_template
        )
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.versionId},
            #{item.modelId},
            #{item.versionName},
            #{item.versionDescribe},
            #{item.protocol},
            #{item.protocolUrl},
            #{item.ioMode},
            #{item.copyright},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.modelVersion},
            #{item.status},
            #{item.versionSource},
            #{item.baseModel},
            #{item.businessLabel},
            #{item.baseId},
            #{item.modelTrainingMethod},
            #{item.runName},
            #{item.trainingTask},
            #{item.modelUrl},
            #{item.isCompress},
            #{item.taskId},
            #{item.runId},
            #{item.basePromptTemplate}
            )
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.yice.webadmin.app.dao.ModelVersionMapper.inputFilterRef"/>
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="modelVersionFilter != null">
            <if test="modelVersionFilter.modelId != null">
                AND lmp_model_version.model_id = #{modelVersionFilter.modelId}
            </if>
        </if>
    </sql>

    <select id="getModelVersionList" resultMap="BaseResultMap" parameterType="com.yice.webadmin.app.model.ModelVersion">
        SELECT * FROM lmp_model_version
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
