<?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.base.plan.mapper.AlgSchemeStepWindowMapper">
    <update id="updateStepIdByParentId">
        update alg_scheme_step_window
        set scheme_step_id = #{schemeStepId}
        where parent_id = #{parentId}
    </update>

    <!--    <bind name="parentId" value="'%' + parentId + '%'"/>
        CONCAT(#{parentId},'%')
    -->

    <select id="getAlgSchemeStepWindowByParentIdSubstring"
            resultType="com.base.plan.model.entity.AlgSchemeStepWindow">
        <bind name="parentId" value="parentId + '%'" />
        SELECT
            assw.id ,
            assw.scheme_step_id,
            assw.start_time,
            assw.end_time,
            assw.satellite_id,
            assw.satellite_code,
            assw.access_time,
            assw.parent_id
        FROM
            alg_scheme_step_window assw
        WHERE
            assw.parent_id LIKE #{parentId}
            and assw.id in (
                select distinct(aswp.scheme_step_window_id) from alg_scheme_window_pass aswp where aswp.pass_type = 1
            )
            and assw.id in (
                select distinct(aswp.scheme_step_window_id) from alg_scheme_window_pass aswp where aswp.pass_type = 2
            )
        ORDER BY assw.access_time;
    </select>


    <select id="getAlgSchemeStepWindowByParentIds" resultType="com.base.plan.model.entity.AlgSchemeStepWindow">
        SELECT
            assw.id,
            assw.scheme_step_id,
            assw.start_time,
            assw.end_time,
            assw.satellite_id,
            assw.satellite_code,
            assw.access_time,
            assw.parent_id
        FROM
            alg_scheme_step_window assw
        WHERE
            assw.parent_id IN
            <foreach collection="parentIds" item="parentId" open="(" close=")" separator=",">
                #{parentId}
            </foreach>
            and assw.id in (
                select distinct(aswp.scheme_step_window_id) from alg_scheme_window_pass aswp where aswp.pass_type = 1
            )
            and assw.id in (
                select distinct(aswp.scheme_step_window_id) from alg_scheme_window_pass aswp where aswp.pass_type = 2
            )
        ORDER BY assw.access_time;
    </select>
</mapper>