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

    <select id="checkName" parameterType="api.common.pojo.po.system.SceneImportPO" resultType="api.common.pojo.po.system.SceneImportPO">
        select
        id
        from scene_import_task
        where is_deleted = '0'
        and name = #{name,jdbcType=VARCHAR}
        and id &lt;&gt; #{id,jdbcType=VARCHAR}
    </select>
    <select id="querySceneImportByTaskId" parameterType="java.lang.String" resultType="api.common.pojo.po.system.SceneImportPO">
        select id,
            scene_type,
               scene_names
        from scene_import_task
        where id = #{id}
    </select>

    <insert id="insert" parameterType="api.common.pojo.po.system.SceneImportPO">
        INSERT INTO scene_import_task (
           id,
           name,
           data_directory,
           scene_type,
           status,
           create_user_id,
           create_time,
           modify_user_id,
           modify_time,
           evaluation_status,
           is_deleted
        )VALUES(
          #{id,jdbcType=VARCHAR},
          #{name,jdbcType=VARCHAR},
          #{dataDirectory,jdbcType=VARCHAR},
          #{sceneType,jdbcType=VARCHAR},
          #{status,jdbcType=VARCHAR},
          #{createUserId,jdbcType=VARCHAR},
          #{createTime,jdbcType=TIMESTAMP},
          #{modifyUserId,jdbcType=VARCHAR},
          #{modifyTime,jdbcType=TIMESTAMP},
          #{evaluationStatus,jdbcType=VARCHAR},
          #{isDeleted,jdbcType=VARCHAR}
        )
    </insert>

    <update id="update" parameterType="api.common.pojo.po.system.SceneImportPO">
        update scene_import_task set
          name = #{name,jdbcType=VARCHAR},
          data_directory = #{dataDirectory,jdbcType=VARCHAR},
          scene_type = #{sceneType,jdbcType=VARCHAR},
          create_time = #{createTime,jdbcType=TIMESTAMP},
          modify_time = #{modifyTime,jdbcType=TIMESTAMP},
          evaluation_status = #{evaluationStatus,jdbcType=VARCHAR},
          modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <update id="updateStatus" parameterType="api.common.pojo.po.system.SceneImportPO">
        update scene_import_task set
          status = #{status,jdbcType=VARCHAR},
          error_message = #{errorMessage},
          modify_time = #{modifyTime,jdbcType=TIMESTAMP},
          modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <update id="updateInfo" parameterType="api.common.pojo.po.system.SceneImportPO">
        update simulation.scene_import_task
        set status         = #{status,jdbcType=VARCHAR},
            false_num      = #{falseNum},
            success_num    = #{successNum},
            error_message  = #{errorMessage},
            modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
            modify_time    = #{modifyTime},
            scene_names    = #{sceneNames},
            total_time     = TIMESTAMPDIFF(SECOND,create_time, modify_time)
        where id = #{id,jdbcType=VARCHAR}
    </update>


    <select id="getSceneImporPagetList" parameterType="api.common.pojo.param.system.SceneImportPageParam" resultType="api.common.pojo.po.system.SceneImportPO">
        select
          id,
          name,
          scene_type,
          status,
          success_num,
          false_num,
          error_message,
          total_time,
          create_time,
          is_deleted,
          evaluation_status,
          evaluation_error_msg,
          start_evaluation_time,
          end_evaluation_time
        from simulation.scene_import_task
        where
        is_deleted = '0'
        <if test="name != null and name != ''">
            and name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
        </if>
        <if test="timeBegin != null and timeBegin != ''">
            and  DATE(create_time) &gt;= #{timeBegin}
        </if>
        <if test="timeEnd != null and timeEnd != ''">
            and  DATE(create_time) &lt;= #{timeEnd}
        </if>
        order by create_time desc
    </select>


    <update id="deleteImportTask" parameterType="api.common.pojo.po.system.SceneImportPO">
        update scene_import_task
        set is_deleted     = '1',
            modify_time    = #{modifyTime},
            modify_user_id = #{modifyUserId}
        where id = #{id,jdbcType=VARCHAR}
    </update>
</mapper>