<?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.StepWindowDataPassRelationMapper">
    <update id="initSelected" parameterType="string">
        <bind name="parentId" value="parentId + '%'" />
        update
            step_window_data_pass_relation swdpr
        set
            swdpr.is_confirm = '1'
        <where>
            swdpr.window_id in (
                select
                    assw.id from alg_scheme_step_window  assw
                where assw.parent_id like #{parentId}
            )
            and
            swdpr.is_confirm = '2'
        </where>
    </update>
    <update id="initSelectedByList" parameterType="arraylist">
        update
            step_window_data_pass_relation swdpr
        set
            swdpr.is_confirm = '1'
        <where>
            swdpr.window_id in (
                select
                    assw.id from alg_scheme_step_window  assw
                where assw.parent_id in
                <foreach collection="parentIds" item="parentId" open="(" separator="," close=")">
                    #{parentId}
                </foreach>
            )
            and
            swdpr.is_confirm = '2'
        </where>
    </update>

    <update id="batchUpdateConfirmStatus">
        update
            step_window_data_pass_relation swdpr
        set
            swdpr.is_confirm = '2'
        <where>
            swdpr.data_station_window_id in
            <foreach collection="dataWindowIds" item="dataWindowId"  open="(" separator="," close=")">
                #{dataWindowId}
            </foreach>
        </where>
    </update>

    <select id="selectIsUsedStepStationWindowDTOList" resultType="com.base.plan.model.dto.StepWindowDTO">
        SELECT
            step.id stepId,
            step.step_name,
            aswp.satellite_id satelliteId,
            aswp.start_time startTime,
            aswp.end_time endTime,
            aswp.id stationWindowId,
            aswp.station_code stationCode,
            aswp.station_id stationId
        FROM
            alg_scheme_step step
            LEFT JOIN step_window_data_pass_relation swdpr ON step.id = swdpr.step_id
            LEFT JOIN alg_scheme_window_pass aswp ON aswp.id = swdpr.data_station_window_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 swdpr.is_confirm=#{isConfirm}
        </where>
    </select>


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

    
</mapper>
