<?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.hzs.scm.ic.mapper.IcAvailableSpecsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="IcAvailableSpecs" type="com.hzs.common.domain.scm.ic.IcAvailableSpecs">
        <id column="PK_ID" property="pkId" />
        <result column="CREATION_TIME" property="creationTime" />
        <result column="MODIFIED_TIME" property="modifiedTime" />
        <result column="DEL_FLAG" property="delFlag" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="PK_CREATOR" property="pkCreator" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="PK_AVAILABLE_NUM" property="pkAvailableNum" />
        <result column="PK_SPECS_TYPE" property="pkSpecsType" />
        <result column="PK_SPECS" property="pkSpecs" />
        <result column="SPECS_NAME" property="specsName" />
    </resultMap>
    <update id="mergeIcAvailableSpecsByList">
        merge into IC_AVAILABLE_SPECS ip
        using (
        <foreach item="item" index="index" collection="availableSpecsList" separator=" union ">
            select #{item.pkAvailableNum} pk_available_num,#{item.pkSpecsType} PK_SPECS_TYPE,#{item.pkSpecs} PK_SPECS,
            #{item.specsName, jdbcType=VARCHAR} SPECS_NAME,#{item.pkCountry} pk_country,#{item.pkCreator} pk_creator from dual
        </foreach>
        ) b
        on (ip.pk_available_num=b.pk_available_num and ip.pk_specs=b.pk_specs)
        WHEN NOT MATCHED THEN
        insert (PK_ID, PK_AVAILABLE_NUM, PK_SPECS_TYPE, PK_SPECS, SPECS_NAME,PK_COUNTRY, PK_CREATOR)
        values (
        IC_AVAILABLE_SPECS_SEQ.Nextval,b.pk_available_num,b.PK_SPECS_TYPE,b.PK_SPECS,
        b.SPECS_NAME,b.pk_country,b.pk_creator)
    </update>
    <select id="queryAvailableSpecs" resultType="com.hzs.common.domain.scm.pub.ScmItemSpecs">
        select pk_id pk_specs,pk_specs_type,specs_name from bd_specs where
        del_flag=0 and pk_id in
        <foreach item="item" collection="specsIsArr" open="(" separator="," close=")">
            #{item}
        </foreach>
        order by pk_id
    </select>

</mapper>
