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

    <!-- 通用查询映射结果 -->
    <resultMap id="IcBatchCodeExt" type="com.hzs.common.domain.scm.ic.ext.IcBatchCodeExt">
        <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_CREATOR" property="pkCreator" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="PK_PRODUCT" property="pkProduct" />
        <result column="BIZ_DATE" property="bizDate" />
        <result column="PRODUCT_DATE" property="productDate" />
        <result column="EXPIRE_DATE" property="expireDate" />
        <result column="BATCH_CODE" property="batchCode" />
        <result column="VALID_PERIOD" property="validPeriod" />
    </resultMap>

    <select id="queryBatchCodeByProduct" resultType="java.lang.Long">
        <foreach collection="batchCodeParamList" item="item" open=" " separator=" union " close=" ">
            select pk_id from ic_batch_code
            where del_flag=0 and pk_product = #{item.pkProduct} and pk_id=#{item.pkBatchCode}
        </foreach>
    </select>
    <select id="queryBatchCodeByCondition" resultMap="IcBatchCodeExt">
        select ic.*,bp.product_code,bp.product_name from ic_batch_code ic
        inner join bd_product bp
        on ic.pk_product=bp.pk_id
        where ic.del_flag=0 and bp.del_flag=0
        and ic.pk_country = #{pkCountry}
        <if test="productCode != null and productCode !=''">
            and bp.product_code like '%' || #{productCode} || '%'
        </if>
        <if test="productName != null and productName != ''">
            and bp.product_name like '%' ||  #{productName} || '%'
        </if>
        <if test="batchCode != null and batchCode != ''">
            and ic.batch_code = #{batchCode}
        </if>
        <if test="pkProduct != null">
            and ic.pk_product = #{pkProduct}
        </if>
    </select>

</mapper>
