<?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.scm.contract.dao.purchase.TagPurchaseDetailDao">

    <sql id="columns">
		a.`id` AS "id",
		a.`tag_purchase_id` AS "tagPurchaseId",
		a.`tag_type_id` AS "tagTypeId",
		a.`number` AS "number",
		a.`unit_price` AS "unitPrice"
    </sql>

    <sql id="joins">
    </sql>

    <insert id="saveList">
        INSERT INTO
        tag_purchase_detail
        (
        `id`,
        `tag_purchase_id`,
        `tag_type_id`,
        `number`,
        `unit_price`
        )
        VALUES
        <foreach item="data" index="index" collection="details" separator=",">
            (
            #{data.id},
            #{data.tagPurchaseId},
            #{data.tagTypeId},
            #{data.number},
            #{data.unitPrice}
            )
        </foreach>
    </insert>

    <delete id="deleteListByTagPurchaseId">
        DELETE FROM tag_purchase_detail WHERE `tag_purchase_id` = #{tagPurchaseId};
    </delete>


    <select id="getListByTagPurchaseId" resultType="com.scm.contract.model.purchase.TagPurchaseDetail">
        SELECT
        <include refid="columns"/>
        FROM tag_purchase_detail a
        <include refid="joins"/>
        WHERE a.`tag_purchase_id` = #{tagPurchaseId}
    </select>

    <select id="getListByTagPurchaseIds" resultType="com.scm.contract.model.purchase.TagPurchaseDetail">
        SELECT
        <include refid="columns"/>
        FROM tag_purchase_detail a
        <include refid="joins"/>
        WHERE a.`tag_purchase_id` IN
        <foreach item="id" index="index" collection="tagPurchaseIds" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
</mapper>
