<?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.taais.biz.mapper.AlgorithmSubtaskMapper">
    <resultMap id="AlgorithmSubtaskResultMap" type="com.taais.biz.domain.AlgorithmSubtask">
        <id property="id" column="id" />
        <result property="taskId" column="task_id" />
        <result property="name" column="name" />
        <result property="type" column="type" />
        <result property="status" column="status" />
        <result property="parameters" column="parameters" />
        <result property="startTime" column="start_time" />
        <result property="endTime" column="end_time" />
        <result property="costSecond" column="cost_second" />
        <result property="log" column="log" />
        <result property="index" column="index" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="remarks" column="remarks" />
    </resultMap>

<select id="getFirstNeedProcessSubtask" parameterType="Long" resultMap="AlgorithmSubtaskResultMap">
    select * from algorithm_subtask t where t.task_id = #{id} and t.status = '0' order by t.index asc limit 1
</select>
<select id="getSubtaskByTaskId" parameterType="Long" resultMap="AlgorithmSubtaskResultMap">
    select * from algorithm_subtask t where t.task_id = #{taskId} order by index asc
</select>

    <select id="getTrainModelPath" parameterType="Long" resultType="String">
        SELECT
            abp.result_path
        FROM
            algorithm_biz_process abp
        WHERE
            abp.algorithm_id = (SELECT parent_id FROM algorithm_config ac WHERE ac.id = (SELECT abp2.algorithm_id FROM algorithm_biz_process abp2 WHERE abp2.id = #{bizId}))
        AND abp.sub_task_id = (
            SELECT
                ast.id
            FROM
                algorithm_subtask ast
            WHERE
                ast.type = '1' AND ast.task_id = (
                SELECT
                    ast2.task_id
                FROM
                    algorithm_subtask ast2
                WHERE
                    ast2.id = ( SELECT abp2.sub_task_id FROM algorithm_biz_process abp2 WHERE abp2.id = #{bizId} )
            )
        )
    </select>

</mapper>
