<?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.filecenter.mapper.OtaupgradMapper">


    <sql id="Base_Column_List">
        id
        ,station_id,src_id,
        device_name,file_name,version,
        update_cause,update_name,create_time,update_time
    </sql>


    <insert id="insertBatch">
        INSERT INTO otaupgrad
        (station_id,src_id,
        device_name,file_name,version,
        update_cause,update_name,create_time,update_time)
        VALUES
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.stationId},#{item.srcId},
            #{item.deviceName},#{item.fileName},#{item.version} ,
            #{item.updateCause},#{item.updateName},#{item.createTime},#{item.updateTime}
            )
        </foreach>
    </insert>

    <select id="selectAll" resultType="com.ho.filecenter.entity.Otaupgrad">
        select
        <include refid="Base_Column_List"/>
        from otaupgrad
        <where>
            <if test="stationIdList != null and stationIdList.size !=0">
                and station_id in
                <foreach collection="stationIdList" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
            <if test="stationId != null">
                and station_id = #{stationId}
            </if>
            <if test="srcId != null">
                and src_id = #{srcId}
            </if>
            <if test="deviceName != null and deviceName != ''">
                and device_name LIKE concat('%',#{deviceName},'%')
            </if>

        </where>
        ORDER BY update_time DESC
    </select>

<!--    <select id="selectByStationIdAndSrcId" resultType="com.ho.filecenter.entity.Otaupgrad">
        select
        <include refid="Base_Column_List"/>
        from otaupgrad
        where
        station_id =#{stationId}
        and src_id = #{srcId}
        ORDER BY create_time DESC
        LIMIT 1
    </select>-->

</mapper>
