<?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.css.simulation.resource.server.infra.db.mysql.mapper.SimulationAutomaticSubprojectMapper" >



    <!--查询最新项目id-->
    <select id="selectLastProjectId" parameterType="string" resultType="api.common.pojo.po.project.SimulationAutomaticSubProjectPO">
        select project_date, project_num, project_id, parent_project_id
        from simulation_automatic_subproject
        where parent_id=#{id,jdbcType=VARCHAR} and is_deleted = '0'
        order by project_num desc
        limit 1
    </select>

    <!--添加自动运行子项目-->
    <insert id="addAutomaticSubProject" parameterType="api.common.pojo.po.project.SimulationAutomaticSubProjectPO">
        insert into simulation_automatic_subproject
        (
        id,
        parent_id,
        parent_project_id,
        project_num,
        project_id,
        project_name,
        now_run_state,
        evaluation_level,
        start_time,
        finish_time,
        create_time,
        create_user_id,
        modify_time,
        modify_user_id,
        is_deleted
        )
        values
        (
        #{id,jdbcType=VARCHAR},
        #{parentId,jdbcType=VARCHAR},
        #{parentProjectId,jdbcType=VARCHAR},
        #{projectNum,jdbcType=INTEGER},
        #{projectId,jdbcType=VARCHAR},
        #{projectName,jdbcType=VARCHAR},
        #{nowRunState,jdbcType=VARCHAR},
        #{evaluationLevel,jdbcType=VARCHAR},
        #{startTime,jdbcType=VARCHAR},
        #{finishTime,jdbcType=VARCHAR},
        #{createTime,jdbcType=TIMESTAMP},
        #{createUserId,jdbcType=VARCHAR},
        #{modifyTime,jdbcType=TIMESTAMP},
        #{modifyUserId,jdbcType=VARCHAR},
        #{isDeleted,jdbcType=VARCHAR}
        )
    </insert>

    <!--查询项目状态-->
    <select id="selectProjectNowRunState" resultType="api.common.pojo.po.project.SimulationAutomaticSubProjectPO">
        select now_run_state
        from simulation_automatic_subproject
        where
        is_deleted='0' and
        id in
        <foreach collection="array" open="(" separator="," close=")" item="id">
            #{id,jdbcType=VARCHAR}
        </foreach>
    </select>

    <!--删除-->
    <update id="deleteProject">
        update simulation_automatic_subproject
        set is_deleted='1'
        where id in
        <foreach collection="array" open="(" separator="," close=")" item="id">
            #{id,jdbcType=VARCHAR}
        </foreach>

    </update>
    <!--修改任务运行状态-->
    <update id="updateNowRunState" parameterType="api.common.pojo.param.project.SimulationManualProjectParam">
        update simulation_automatic_subproject
        set now_run_state = #{nowRunState,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <!--查询列表-->
    <select id="selectList" parameterType="api.common.pojo.param.project.SimulationManualProjectParam" resultType="api.common.pojo.vo.project.SimulationManualProjectVO" >
        select id,
               parent_id,
               parent_project_id,
               project_date,
               project_num,
               project_id,
               project_name,
               now_run_state,
               evaluation_level,
               start_time,
               start_time start_time_fmt,
               finish_time,
               finish_time finish_time_fmt,
               algorithm_score,
               task_number,
               task_completed,
               create_time,
               create_time create_time_fmt,
               create_user_id,
               modify_time,
               modify_user_id,
               is_deleted
        from simulation_automatic_subproject
        where is_deleted = '0'
          and parent_id = #{parentId}
        order by project_num desc
    </select>

    <!--根据id查询-->
    <select id="selectById" parameterType="api.common.pojo.param.project.SimulationManualProjectParam" resultType="api.common.pojo.po.project.SimulationAutomaticSubProjectPO">
        select * from simulation_automatic_subproject where id = #{id,jdbcType=VARCHAR} and is_deleted='0'
    </select>

    <!--关联主表查询-->
    <select id="selectProjectInfo" parameterType="api.common.pojo.param.project.SimulationManualProjectParam" resultType="api.common.pojo.vo.project.SimulationManualProjectVO">
        select s.id,
               p.scene,
               s.project_id,
               p.project_name,
               p.algorithm,
               p.algorithm_type,
               p.vehicle,
               p.project_describe,
               s.start_time,
               s.finish_time,
               s.now_run_state,
               p.parallelism,
               p.max_simulation_time,
               p.is_choice_gpu,
               s.evaluation_level,
               s.details
        from simulation_automatic_subproject s
                 left join simulation_automatic_project p on s.parent_id = p.id
        where s.id = #{id}
    </select>
    <select id="selectReportById" resultType="java.lang.String">
        select report from simulation_automatic_subproject where id = #{id}
    </select>
    <select id="selectParentIdById" resultType="java.lang.String">
        select parent_id from simulation_automatic_subproject where id = #{id}
    </select>


</mapper>
