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

    <insert id="saveSystemScenePackageSublist" parameterType="java.util.List">
        insert into simulation.system_scene_package_sublist
        (sublist_id,scene_type,scene_name,scene_and_package,
       create_user_id,create_time,modify_user_id,modify_time, is_deleted)
        values
         <foreach collection="list" index="index" item="item" separator=",">
        (#{item.sublistId,jdbcType=VARCHAR},#{item.sceneType,jdbcType=VARCHAR},#{item.sceneName,jdbcType=VARCHAR}, #{item.sceneAndPackage,jdbcType=VARCHAR},
        #{item.createUserId,jdbcType=VARCHAR},#{item.createTime},#{item.modifyUserId,jdbcType=VARCHAR},#{item.modifyTime},#{item.isDeleted,jdbcType=VARCHAR})
    </foreach>
    </insert>
    <update id="deleteBySceneNames">
        update system_scene_package_sublist
        set is_deleted  = '1',
            modify_time = #{modifyTime},
            modify_user_id = #{modifyUserId}
        where scene_name in
        <foreach item="item" collection="sceneNames" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>


    <select id="querySceneNaturalList" parameterType="api.common.pojo.po.scene.SystemScenePackageSublistPO"
            resultType="java.lang.String">
        select  DISTINCT(a.scene_name) scene_name
        FROM system_scene_package_sublist a join  scene_natural s on a.scene_name=s.natural_name where
            a.is_deleted='0' and s.is_deleted='0' and a.scene_and_package =#{sceneAndPackage} and a.scene_type =#{sceneType}
    </select>
    <select id="querySceneStandardsRegulationsList" parameterType="api.common.pojo.po.scene.SystemScenePackageSublistPO"
            resultType="java.lang.String">
        select  DISTINCT(a.scene_name) scene_name
        FROM system_scene_package_sublist a join  scene_standards_regulations s on a.scene_name=s.scene_name where
            a.is_deleted='0' and s.is_deleted='0' and a.scene_and_package =#{sceneAndPackage} and a.scene_type =#{sceneType}
    </select>

    <select id="querySceneAccidentList" parameterType="api.common.pojo.po.scene.SystemScenePackageSublistPO"
            resultType="java.lang.String">
        select  DISTINCT(a.scene_name) scene_name
        FROM system_scene_package_sublist a join  scene_accident s on a.scene_name=s.scene_name where
            a.is_deleted='0' and s.is_deleted='0' and a.scene_and_package =#{sceneAndPackage} and a.scene_type =#{sceneType}
    </select>

    <select id="querySceneGeneralTemplateList" parameterType="api.common.pojo.po.scene.SystemScenePackageSublistPO"
            resultType="java.lang.String">
        select  DISTINCT(a.scene_name) scene_name
        FROM system_scene_package_sublist a join  scene_general_template s on a.scene_name=s.scene_id where
            a.is_deleted='0' and s.is_deleted='0' and a.scene_and_package =#{sceneAndPackage} and a.scene_type =#{sceneType}
    </select>

    <update id="deleteSystemScenePackageSublist" parameterType="api.common.pojo.po.scene.SystemScenePackageSublistPO">
        update simulation.system_scene_package_sublist
        <set>
            <if test="isDeleted != null and isDeleted!=''">
                is_deleted = #{isDeleted,jdbcType=VARCHAR},
            </if>
            <if test="modifyUserId != null and modifyUserId!=''">
                modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
            </if>
            <if test="modifyTime != null">
                modify_time = #{modifyTime},
            </if>
        </set>
        where
        is_deleted='0'
        <if test="sublistId != null and sublistId != ''">
            and sublist_id=#{sublistId}
        </if>
        <if test="sceneAndPackage != null and sceneAndPackage != ''">
            and scene_and_package=#{sceneAndPackage}
        </if>
        <if test="sceneName != null and sceneName != ''">
            and scene_name=#{sceneName}
        </if>
    </update>


    <update id="deleteSystemScenePackageSublistBySC" parameterType="api.common.pojo.po.scene.SystemScenePackageSublistPO">
        update simulation.system_scene_package_sublist
        set is_deleted = #{isDeleted,jdbcType=VARCHAR},
         modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
         modify_time = #{modifyTime}
        where is_deleted='0' and scene_name=#{sceneName}
    </update>

</mapper>
