<?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.ho.business.mapper.OneClickSequentialControlMapper">

    <sql id="Base_Column_List">
        id,col,col_name,max_value,min_value,station_id,src_id,set_value,sort,control_name,flag_id
    </sql>

    <select id="getListByParam" resultType="com.ho.business.entity.OneClickSequentialControl">
        select
        <include refid="Base_Column_List"/>
        from one_click_sequential_control
        <where>
            <if test="vo.controlName != null">
                and control_name = #{vo.controlName}
            </if>
            <if test="vo.stationId != null">
                and station_id = #{vo.stationId}
            </if>
            <if test="vo.srcId != null">
                and src_id = #{vo.srcId}
            </if>
            order by sort
        </where>
    </select>

    <select id="getListLikeParam" resultType="com.ho.business.entity.OneClickSequentialControl">
        select
        <include refid="Base_Column_List"/>
        from one_click_sequential_control
        <where>
            <if test="vo.controlName != null">
                and control_name LIKE concat('%',#{vo.controlName},'%')
            </if>
            <if test="vo.stationId != null">
                and station_id = #{vo.stationId}
            </if>
            <if test="vo.srcId != null">
                and src_id = #{vo.srcId}
            </if>
            order by sort
        </where>
    </select>

    <insert id="insertBatch">
        INSERT INTO one_click_sequential_control
        (col,col_name,max_value,min_value,station_id,src_id,set_value,sort,control_name,flag_id)
        VALUES
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.col},#{item.colName},#{item.maxValue},#{item.minValue},#{item.stationId},#{item.srcId}
            ,#{item.setValue} ,#{item.sort},#{item.controlName},#{item.flagId}
            )
        </foreach>

    </insert>

    <update id="updateBatch" keyColumn="id" keyProperty="id" parameterType="java.util.List" useGeneratedKeys="true">
        <foreach collection="list" item="item" index="index" separator=";">
            update one_click_sequential_control set
            col = #{item.col},col_name = #{item.colName},max_value = #{item.maxValue}, min_value = #{item.minValue}, station_id = #{item.stationId},
            src_id = #{item.srcId},set_value = #{item.setValue},sort = #{item.sort},control_name = #{item.controlName},flag_id = #{item.flagId}
            where id = #{item.id}
        </foreach>
    </update>

    <delete id="deleteByIds">
        delete
        from one_click_sequential_control
        <where>
            <if test="ids != null and ids.size() != 0">
                and id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>

    <delete id="deleteByControlName" >
        delete from one_click_sequential_control where control_name = #{controlName} and station_id = #{stationId}
    </delete>

</mapper>
