<?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.hdkj.lt.bf.mapper.FhzgPlanStrategyMapper">


    <select id="getStrategyconfigList" resultType="com.hdkj.lt.bf.entity.vo.FhzgStrategyConfigVO">
        select id,version_name,transfer_strategy,status,start_time,down_time,create_name
        from fhzg_plan_transfer_strategy_config
        <where>
            <if test="dto.transferStrategy != null ">
                and transfer_strategy = #{dto.transferStrategy}
            </if>
            <if test="dto.versionName != null and dto.versionName !=''">
                and version_name like concat('%',#{dto.versionName},'%')
            </if>
            <if test="dto.status != null">
                and status = #{dto.status}
            </if>
            <if test="dto.startBeginTime != null and dto.startEndTime != null">
                and start_time between #{dto.startBeginTime} and #{dto.startEndTime}
            </if>
            <if test="dto.downBeginTime != null and dto.downEndTime != null">
                and down_time between #{dto.downBeginTime} and #{dto.downEndTime}
            </if>
        </where>
        order by status asc, create_time desc
    </select>

    <select id="getVersionName" resultType="java.util.HashMap">
        select version_name,transfer_strategy
        from fhzg_plan_transfer_strategy_config
        where id = #{strategyId}
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
        insert into fhzg_plan_transfer_strategy_config
            (version_name,transfer_strategy,status,create_name,creator,create_time,last_editor,last_time)
        values
            (#{versionName},#{transferStrategy},#{status},#{createName},#{creator},#{createTime},#{lastEditor},#{lastTime})
    </insert>

    <update id="update">
        update fhzg_plan_transfer_strategy_config
        set
            version_name = #{dto.versionName},
            transfer_strategy = #{dto.transferStrategy},
            last_editor = #{dto.lastEditor},
            last_time = #{dto.lastTime}
        where
           id = #{dto.id}
    </update>

    <update id="updateDownStatus">
        update fhzg_plan_transfer_strategy_config
        set status = 2,
            down_time = #{dto.downTime},
            last_editor = #{dto.lastEditor},
            last_time = #{dto.lastTime}
        where status = 0
        and transfer_strategy = #{dto.transferStrategy}
    </update>

    <update id="updateStartStatus">
        update fhzg_plan_transfer_strategy_config
        set status = 0,
            start_time = #{dto.startTime},
            last_editor = #{dto.lastEditor},
            last_time = #{dto.lastTime}
        where id = #{dto.strategyId}
    </update>
</mapper>