<?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.xxfc.platform.vehicle.mapper.BookRecordAccItemMapper" >

    <insert id="batchAdd" parameterType="java.util.List">
        insert into book_record_acc_item(book_record_id,acc_item_id,amount) values
        <foreach collection="list" index="i" item="item" separator="," open="" close="">
            (#{item.bookRecordId},#{item.id},#{item.amount})
        </foreach>
    </insert>

    <insert id="batchAdd2Tb" parameterType="java.util.Map">
        insert into ${tbName}(id,book_record_id,acc_item_id,amount) values
        <foreach collection="list" index="i" item="item" separator="," open="" close="">
            (#{item.id},#{item.bookRecordId},#{item.accItemId},#{item.amount})
        </foreach>
    </insert>

    <select id="getByRecords" parameterType="java.util.List" resultType="com.xxfc.platform.vehicle.entity.BookRecordAccItem" >
        select id,book_record_id,acc_item_id,amount from  ${tbName} where book_record_id in
            <foreach collection="bookRecordIds" index="i" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>

    </select>

    <insert id="createTbIfNotExists" parameterType="java.lang.String">
        CREATE TABLE IF NOT EXISTS ${_parameter} (
                `id` bigint(20) NOT NULL AUTO_INCREMENT,
                `book_record_id` bigint(20) NOT NULL COMMENT '申请记录id',
                `acc_item_id` int(11) NOT NULL COMMENT '对应随行物品id',
                `amount` int(10) NULL DEFAULT NULL COMMENT '数量',
                PRIMARY KEY (`id`) USING BTREE,
                INDEX `i_book_record_id`(`book_record_id`) USING BTREE,
                INDEX `i_acc_item_id`(`acc_item_id`) USING BTREE
                ) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '汽车随行物品预定记录关系历史表，按年分表'  ROW_FORMAT = Dynamic;

    </insert>
</mapper>