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

    <resultMap type="com.ruoyi.web.modules.trading.domain.BizMarketEntryEarTag" id="BizMarketEntryEarTagResult">
        <id     property="id"          column="id"/>
        <result property="entryId"     column="entry_id"/>
        <result property="supplierId"  column="supplier_id"/>
        <result property="earTag"      column="ear_tag"/>
    </resultMap>

    <select id="selectEarTagListByEntryId" parameterType="long" resultMap="BizMarketEntryEarTagResult">
        select id, entry_id, supplier_id, ear_tag
        from biz_market_entry_ear_tag
        where entry_id = #{entryId}
        order by id asc
    </select>

    <select id="selectOccupiedEarTags" resultType="string">
        select t.ear_tag
        from biz_market_entry_ear_tag t
        inner join biz_market_entry e on e.id = t.entry_id and e.del_flag = '0'
        <if test="excludeEntryId != null">
            where e.id != #{excludeEntryId}
        </if>
    </select>

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

    <insert id="batchInsertEarTag">
        insert into biz_market_entry_ear_tag (entry_id, supplier_id, ear_tag)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.entryId}, #{item.supplierId}, #{item.earTag})
        </foreach>
    </insert>

    <select id="selectDistinctEarTagsBySupplierId" resultType="string">
        select distinct t.ear_tag
        from biz_market_entry_ear_tag t
        inner join biz_market_entry e on e.id = t.entry_id and e.del_flag = '0'
        where e.supplier_id = #{supplierId}
        order by t.ear_tag asc
    </select>

    <select id="selectEarTagsBySupplierIdOnly" resultType="string">
        select distinct ear_tag
        from biz_market_entry_ear_tag
        where supplier_id = #{supplierId}
        order by ear_tag asc
    </select>

    <delete id="deleteBySupplierIdAndEarTag">
        delete from biz_market_entry_ear_tag
        where supplier_id = #{supplierId}
          and ear_tag = #{earTag}
    </delete>

</mapper>
