<?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.ruoyi.web.modules.trading.mapper.BizEntryIsolationAllocMapper">

    <resultMap type="com.ruoyi.web.modules.trading.domain.BizEntryIsolationAlloc" id="BizEntryIsolationAllocResult">
        <id     property="id"          column="id"/>
        <result property="entryId"     column="entry_id"/>
        <result property="penId"       column="pen_id"/>
        <result property="quantity"    column="quantity"/>
        <result property="earTags"     column="ear_tags"/>
        <result property="sortOrder"   column="sort_order"/>
        <result property="penCode"     column="pen_code"/>
    </resultMap>

    <select id="selectAllocListByEntryId" parameterType="long" resultMap="BizEntryIsolationAllocResult">
        select a.id, a.entry_id, a.pen_id, a.quantity, a.ear_tags, a.sort_order, p.pen_code
        from biz_entry_isolation_alloc a
        left join biz_isolation_pen p on a.pen_id = p.id
        where a.entry_id = #{entryId}
        order by a.sort_order asc, a.id asc
    </select>

    <delete id="deleteAllocByEntryId" parameterType="long">
        delete from biz_entry_isolation_alloc where entry_id = #{entryId}
    </delete>

    <insert id="batchInsertAlloc">
        insert into biz_entry_isolation_alloc (entry_id, pen_id, quantity, ear_tags, sort_order)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.entryId}, #{item.penId}, #{item.quantity}, #{item.earTags}, #{item.sortOrder})
        </foreach>
    </insert>
</mapper>
