<?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.StandingBookMapper">

    <resultMap id="BaseResultMap" type="com.ho.filecenter.entity.StandingBook">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="stationId" column="station_id" jdbcType="INTEGER"/>
        <result property="deviceType" column="device_type" jdbcType="VARCHAR"/>
        <result property="deviceModel" column="device_model" jdbcType="VARCHAR"/>
        <result property="modelCode" column="model_code" jdbcType="VARCHAR"/>
        <result property="deviceNum" column="device_num" jdbcType="VARCHAR"/>
        <result property="factory" column="factory" jdbcType="VARCHAR"/>
        <result property="manufacturer" column="manufacturer" jdbcType="VARCHAR"/>
        <result property="warrantyPeriod" column="warranty_period" jdbcType="VARCHAR"/>
        <result property="notes" column="notes" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,station_id,device_type,device_model,
        model_code,device_num,factory,
        manufacturer,warranty_period,notes,
        create_time,update_time
    </sql>


    <insert id="addBatch" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into standing_book (<include refid="Base_Column_List"/>)
        values
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.id}
            ,#{item.stationId},#{item.deviceType},#{item.deviceModel},
            #{item.modelCode},#{item.deviceNum},#{item.factory},
            #{item.manufacturer},#{item.warrantyPeriod},#{item.notes},
            #{item.createTime},#{item.updateTime}
            )
        </foreach>
    </insert>


    <delete id="deleteById">
        delete
        from standing_book
        where id = #{id}
    </delete>
    <delete id="deleteByStationId">
        delete
        from standing_book
        where station_id = #{stationId}
    </delete>

    <select id="selectAll" resultType="com.ho.filecenter.entity.StandingBook">
        select
        <include refid="Base_Column_List"/>
        from standing_book
        where station_id = #{id}
    </select>

    <update id="updateByPrimaryKeySelective">
        update standing_book
        <set>
            <if test="stationId != null">
                station_id = #{stationId},
            </if>
            <if test="deviceType != null">
                device_type = #{deviceType},
            </if>
            <if test="deviceModel != null">
                device_model = #{deviceModel},
            </if>
            <if test="modelCode != null">
                model_code = #{modelCode},
            </if>
            <if test="deviceNum != null">
                device_num = #{deviceNum},
            </if>
            <if test="factory != null">
                factory = #{factory},
            </if>
            <if test="manufacturer != null">
                manufacturer = #{manufacturer},
            </if>
            <if test="warrantyPeriod != null">
                warranty_period = #{warrantyPeriod},
            </if>
            <if test="notes != null">
                notes = #{notes},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where id = #{id}
    </update>
</mapper>
