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


    <insert id="saveStandardsRegulations" parameterType="api.common.pojo.po.scene.StandardsRegulationsPO">
        insert into simulation.scene_standards_regulations
        (regulations_id, scene_name, regulation_type, standard_type,
         create_user_id, create_time, modify_user_id, modify_time,
         is_deleted, share, video_preview, video_address, osgb_address, xml_address, xodr_address,
         json_address, max_time)
        values (#{regulationsId,jdbcType=VARCHAR}, #{sceneName,jdbcType=VARCHAR}, #{regulationType,jdbcType=VARCHAR},
                #{standardType,jdbcType=VARCHAR},
                #{createUserId,jdbcType=VARCHAR}, #{createTime}, #{modifyUserId,jdbcType=VARCHAR}, #{modifyTime},
                #{isDeleted,jdbcType=VARCHAR}, #{share,jdbcType=VARCHAR}, #{videoPreview,jdbcType=VARCHAR},
                #{videoAddress,jdbcType=VARCHAR}, #{osgbAddress,jdbcType=VARCHAR},
                #{xmlAddress,jdbcType=VARCHAR}, #{xodrAddress,jdbcType=VARCHAR}, #{jsonAddress,jdbcType=VARCHAR},
                #{maxTime,jdbcType=VARCHAR})
    </insert>

    <insert id="saveStandardsRegulationsList" parameterType="java.util.List">
        insert into simulation.scene_standards_regulations
        (regulations_id,scene_name,regulation_type,standard_type,
        create_user_id,create_time,modify_user_id,modify_time,
        is_deleted,share,video_preview,video_address,osgb_address,xml_address,xodr_address,
        json_address,max_time)
        values
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.regulationsId,jdbcType=VARCHAR},#{item.sceneName,jdbcType=VARCHAR},#{item.regulationType,jdbcType=VARCHAR},
            #{item.standardType,jdbcType=VARCHAR},

            #{item.createUserId,jdbcType=VARCHAR},#{item.createTime},#{item.modifyUserId,jdbcType=VARCHAR},#{item.modifyTime},
            #{item.isDeleted,jdbcType=VARCHAR},
            #{item.share,jdbcType=VARCHAR},#{item.videoPreview,jdbcType=VARCHAR},#{item.videoAddress,jdbcType=VARCHAR},#{item.osgbAddress,jdbcType=VARCHAR},
            #{item.xmlAddress,jdbcType=VARCHAR},
            #{item.xodrAddress,jdbcType=VARCHAR},#{item.jsonAddress,jdbcType=VARCHAR},#{item.maxTime,jdbcType=VARCHAR})
        </foreach>
    </insert>
    <update id="deleteBySceneNames">
        update scene_standards_regulations
        set is_deleted     = '1',
        modify_user_id = #{modifyUserId},
        modify_time = #{modifyTime}
        where is_deleted = '0'
        and scene_name in
        <foreach item="item" collection="sceneNames" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <select id="queryStandardsRegulationsList" parameterType="api.common.pojo.param.scene.StandardsRegulationsParam"
            resultType="api.common.pojo.po.scene.StandardsRegulationsPO">
        select
        regulations_id,scene_name,regulation_type,standard_type,
        create_user_id,create_time,modify_user_id,
        modify_time,is_deleted,share,video_address,osgb_address,
        xml_address,xodr_address,json_address,video_preview,max_time
        from simulation.scene_standards_regulations
        <where>
            is_deleted = '0'
            <if test="sceneName != null and sceneName != ''">
                and scene_name like CONCAT('%',#{sceneName,jdbcType=VARCHAR},'%')
            </if>
            <if test="regulationType != null and regulationType.size()>0">
                and regulation_type in
                <foreach collection="regulationType" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="standardType != null and standardType != ''">
                and standard_type like CONCAT('%',#{standardType,jdbcType=VARCHAR},'%')
            </if>
            <if test="ids != null and ids.length>0">
                and regulations_id in
                <foreach collection="ids" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="allSceneNames != null and allSceneNames.length>0">
                and scene_name in
                <foreach collection="allSceneNames" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="AllIds != null and AllIds.size()>0">
                and regulations_id in
                <foreach collection="AllIds" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="share != null and share==0">
                and share =#{share}
            </if>
            <if test="share != null and share==1">
                and share !='0'
            </if>
            <if test="userId != null and userId != ''">
                and create_user_id =#{userId}
            </if>
        </where>
        order by create_time,scene_name desc

    </select>

    <select id="queryStandardsRegulationsListByBq" parameterType="api.common.pojo.param.scene.StandardsRegulationsParam"
            resultType="api.common.pojo.po.scene.StandardsRegulationsPO">
        select
        regulations_id,scene_name,regulation_type,standard_type,
        create_user_id,create_time,modify_user_id,
        modify_time,is_deleted,share,video_address,osgb_address,
        xml_address,xodr_address,json_address,video_preview,max_time
        from simulation.scene_standards_regulations
        <where>
            is_deleted = '0'
            <if test="AllIds != null and AllIds.size()>0">
                and regulations_id in
                <foreach collection="AllIds" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>

            <if test="label != null and label.size()>0">
                and regulation_type in
                <foreach collection="label" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by modify_time desc

    </select>
    <update id="deleteStandardsRegulations" parameterType="api.common.pojo.po.scene.StandardsRegulationsPO">
        update simulation.scene_standards_regulations
        <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 regulations_id = #{regulationsId,jdbcType=VARCHAR}
    </update>

    <select id="queryStandardsRegulationsByName" parameterType="api.common.pojo.po.scene.StandardsRegulationsPO"
            resultType="api.common.pojo.po.scene.StandardsRegulationsPO">
        select regulations_id, scene_name, regulation_type, standard_type,
        create_user_id, create_time, modify_user_id, modify_time,
        is_deleted, share, video_preview, video_address, osgb_address, xml_address, xodr_address,
        json_address, max_time
        from simulation.scene_standards_regulations
        where is_deleted = '0'
        <if test="sceneName != null and sceneName!=''">
            and scene_name = #{sceneName,jdbcType=VARCHAR}
        </if>
        <if test="share != null and share==0">
            and share =#{share}
        </if>
        <if test="share != null and share!= '' and share!=0">
            and share !='0'
        </if>
    </select>

    <select id="selectAllByName" parameterType="api.common.pojo.po.scene.StandardsRegulationsPO"
            resultType="api.common.pojo.po.scene.StandardsRegulationsPO">
        select regulations_id,
               scene_name,
               regulation_type,
               standard_type,
               create_user_id,
               create_time,
               modify_user_id,
               modify_time,
               is_deleted,
               share,
               video_preview,
               video_address,
               osgb_address,
               xml_address,
               xodr_address,
               json_address,
               max_time
        from simulation.scene_standards_regulations
        where is_deleted = '0'
          and scene_name = #{sceneName,jdbcType=VARCHAR}
    </select>

    <update id="updateStandardsRegulations" parameterType="api.common.pojo.po.scene.StandardsRegulationsPO">
        update simulation.scene_standards_regulations
        set scene_name=#{sceneName},
            regulation_type=#{regulationType},
            standard_type=#{standardType},
            modify_user_id=#{modifyUserId},
            modify_time=#{modifyTime},
            video_address=#{videoAddress},
            osgb_address=#{osgbAddress},
            xml_address=#{xmlAddress},
            xodr_address=#{xodrAddress},
            json_address=#{jsonAddress},
            max_time=#{maxTime}
        where regulations_id = #{regulationsId,jdbcType=VARCHAR}
    </update>
    <update id="updateStandardsRegulationsList" parameterType="java.util.List">
        <foreach collection="list" index="index" item="item" separator=";">
            update simulation.scene_standards_regulations
            set scene_name=#{item.sceneName},regulation_type=#{item.regulationType},
            standard_type=#{item.standardType},modify_user_id=#{item.modifyUserId},
            modify_time=#{item.modifyTime},video_address=#{item.videoAddress},
            osgb_address=#{item.osgbAddress},xml_address=#{item.xmlAddress},
            xodr_address=#{item.xodrAddress},json_address=#{item.jsonAddress},max_time=#{item.maxTime}
            where regulations_id = #{item.regulationsId,jdbcType=VARCHAR}
        </foreach>
    </update>

    <select id="queryStandardsRegulationsListByQx" parameterType="api.common.pojo.param.scene.StandardsRegulationsParam"
            resultType="api.common.pojo.po.scene.StandardsRegulationsPO">
        select
        regulations_id,scene_name,regulation_type,standard_type,
        create_user_id,create_time,modify_user_id,
        modify_time,is_deleted,share,video_address,osgb_address,
        xml_address,xodr_address,json_address,video_preview,max_time
        from (select bz.* from( select s.scene_name
        FROM system_scene_package p
        JOIN system_user_scene u on p.id = u.package_id and u.is_deleted = '0' and p.is_deleted = '0'
        JOIN system_scene_package_sublist s on p.id = s.scene_and_package
        where scene_type='2' and s.is_deleted = '0' and user_id=#{userId} group by s.scene_name)qx join
        scene_standards_regulations bz on qx.scene_name=bz.scene_name and bz.share='2' union select jtNew.* from scene_standards_regulations jtNew where jtNew.share='1' and is_deleted='0') dd
        <where>
            is_deleted = '0'
            <if test="sceneName != null and sceneName != ''">
                and scene_name like CONCAT('%',#{sceneName,jdbcType=VARCHAR},'%')
            </if>
            <if test="regulationType != null and regulationType.size()>0">
                and regulation_type in
                <foreach collection="regulationType" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="standardType != null and standardType != ''">
                and standard_type like CONCAT('%',#{standardType,jdbcType=VARCHAR},'%')
            </if>
            <if test="ids != null and ids.length>0">
                and regulations_id in
                <foreach collection="ids" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="allSceneNames != null and allSceneNames.length>0">
                and scene_name in
                <foreach collection="allSceneNames" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="AllIds != null and AllIds.size()>0">
                and regulations_id in
                <foreach collection="AllIds" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="share != null and share==0">
                and share =#{share}
            </if>
            <if test="share != null and share!= '' and share!=0">
                and share !='0'
            </if>
        </where>
        order by create_time,scene_name desc

    </select>

    <select id="queryStandardsRegulationsListByBqAndQx"
            parameterType="api.common.pojo.param.scene.StandardsRegulationsParam"
            resultType="api.common.pojo.po.scene.StandardsRegulationsPO">
        select
        regulations_id,scene_name,regulation_type,standard_type,
        create_user_id,create_time,modify_user_id,
        modify_time,is_deleted,share,video_address,osgb_address,
        xml_address,xodr_address,json_address,video_preview,max_time
        from (select bz.* from( select s.scene_name
        FROM system_scene_package p
        JOIN system_user_scene u on p.id = u.package_id and u.is_deleted = '0' and p.is_deleted = '0'
        JOIN system_scene_package_sublist s on p.id = s.scene_and_package
        where scene_type='2' and s.is_deleted = '0' and user_id=#{userId} group by s.scene_name)qx join
        scene_standards_regulations bz on qx.scene_name=bz.scene_name) dd
        <where>
            is_deleted = '0'
            <if test="AllIds != null and AllIds.size()>0">
                and regulations_id in
                <foreach collection="AllIds" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>

            <if test="label != null and label.size()>0">
                and regulation_type in
                <foreach collection="label" item="item" index="index"
                         separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by modify_time desc

    </select>

    <select id="queryStandardsRegulationsById" parameterType="java.lang.String"
            resultType="api.common.pojo.po.scene.StandardsRegulationsPO">
        select regulations_id, scene_name, regulation_type, standard_type,
         create_user_id, create_time, modify_user_id, modify_time,
         is_deleted, share, video_preview, video_address, osgb_address, xml_address, xodr_address,
         json_address, max_time
        from simulation.scene_standards_regulations
     where regulations_id=#{id}
    </select>
    <select id="queryRegulationType" resultType="java.lang.String"></select>
    <select id="selectIdsByNames" resultType="java.lang.String">
        select regulations_id
        from scene_standards_regulations
        where is_deleted = '0'
        and scene_name in
        <foreach item="item" collection="list" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>
</mapper>
