<?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.StepWindowRelationMapper">
    <update id="initConfirmStatus">
        <bind name="parentId" value="parentId + '%'" />
        update
            step_window_relation swr
        set
            swr.is_confirm = 1
        <where>
            swr.id in (
                select
                    *
                from
                (
                    select
                        swr.id
                    from
                        step_window_relation swr
                    left join alg_scheme_step_window assw on
                        swr.window_id = assw.id
                    and assw.parent_id like
                        #{parentId}
                    where
                        swr.is_confirm = 2
                ) t1
            )
        </where>
    </update>
    <update id="initConfirmStatusByList">
        update
            step_window_relation swr1
        set
            swr1.is_confirm = 1
        <where>
            swr1.id in (
                select
                    swr.id
                from
                    step_window_relation swr
                        left join alg_scheme_step_window assw on
                        swr.window_id = assw.id
                            and assw.parent_id in
                            <foreach collection="parentIds" item="parentId"  open="(" separator="," close=")">
                                #{parentId}
                            </foreach>
                where
                    swr.is_confirm = 2)
        </where>
    </update>
    <update id="batchUpdateConfirmStatus">
        update step_window_relation swr
        set swr.is_confirm = 2
        <where>
            swr.window_id in
            <foreach collection="windowIds" item="windowId" open="(" separator="," close=")">
                #{windowId}
            </foreach>
        </where>
    </update>

    <select id="selectIsUsedStepWindowDTOList" resultType="com.base.plan.model.dto.StepWindowDTO">
        SELECT
        step.id stepId,
        step.step_name,
        assw.id windowId,
        assw.satellite_id satelliteId,
        assw.start_time startTime,
        assw.end_time endTime,
        strip.cir_cle circle,
        strip.roll_angle rollAngle
        FROM
        alg_scheme_step step
        LEFT JOIN step_window_relation wr ON step.id = wr.step_id
        LEFT JOIN alg_scheme_step_window assw ON wr.window_id = assw.id
        <!-- 新增关联条带，获取侧摆和圈号 -->
        LEFT JOIN strip_info strip ON strip.window_id=assw.id
        <where>
            <if test="list!=null and list.size!=0">
                step.id in
                <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            and wr.is_confirm=2
        </where>
    </select>

    <insert id="batchInsert" parameterType="com.base.plan.model.entity.StepWindowRelation">
        insert into step_window_relation (id,window_id,step_id,create_time,update_time,is_confirm)
        values
        <foreach item="item" index="index" collection="list" separator=",">
            (
            #{item.id},
            #{item.windowId},
            #{item.stepId},
            #{item.createTime},
            #{item.updateTime},
            #{item.isConfirm}
            )
        </foreach>
    </insert>

</mapper>
