<?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.system.config.mapper.BdBarCodeItemsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdBarCodeItems">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_BAR_CODE" property="pkBarCode"/>
        <result column="BAR_CODE" property="barCode"/>
        <result column="CODE_STATUS" property="codeStatus"/>
        <result column="PRINT_TIME" property="printTime"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG
        ,
        PK_COUNTRY,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PK_BAR_CODE, BAR_CODE, CODE_STATUS, PRINT_TIME
    </sql>

    <!--   查询条形码详情列表-->
    <select id="queryBarCodeItemsList" parameterType="com.hzs.common.domain.system.config.ext.BdBarCodeItemsExt"
            resultType="com.hzs.common.domain.system.config.ext.BdBarCodeItemsExt">
        SELECT
        a.PK_ID,
        a.PK_BAR_CODE,
        a.BAR_CODE,
        a.CODE_STATUS,
        a.PRINT_TIME,
        a.BATCH,
        a.CREATION_TIME,
        b.PK_PRODUCT,
        c.PRODUCT_CODE as productCode,
        c.PRODUCT_NAME as productName
        FROM
        bd_bar_code_items a
        INNER JOIN bd_bar_code b ON a.PK_BAR_CODE = b.pk_ID
        INNER JOIN bd_product c ON b.pk_product = c.pk_ID
        WHERE
        a.DEL_FLAG = 0
        AND b.DEL_FLAG =0
        and c.DEL_FLAG =0
        <if test="barCode != null and barCode !='' ">
            AND a.BAR_CODE like #{barCode} || '%'
        </if>
        <if test="pkBarCode != null ">
            AND a.PK_BAR_CODE = #{pkBarCode}
        </if>
        <if test="codeStatus != null ">
            AND a.CODE_STATUS = #{codeStatus}
        </if>

        <if test="batch != null ">
            AND a.BATCH = #{batch}
        </if>
        <if test="startDatePrint != null ">
            and a.PRINT_TIME &gt;= #{startDatePrint, jdbcType=DATE}
        </if>
        <if test="endDatePrint != null ">
            and a.PRINT_TIME &lt; #{endDatePrint, jdbcType=DATE}
        </if>
        <if test="startDate != null ">
            and a.CREATION_TIME &gt;= #{startDate, jdbcType=DATE}
        </if>
        <if test="endDate != null ">
            and a.CREATION_TIME &lt; #{endDate, jdbcType=DATE}
        </if>

        <if test="productCode != null and productCode !='' ">
            AND c.PRODUCT_CODE like #{productCode} || '%'
        </if>
        <if test="productName != null and productName !='' ">
            AND c.product_Name  like #{productName} || '%'
        </if>
        order by a.PK_ID desc
    </select>

    <!-- 查询条码 -->
    <select id="queryPrintBarCode" resultType="com.hzs.common.domain.system.config.ext.BdBarCodeItemsExt">
        select bbci.*, bbc.PK_PRODUCT
        from BD_BAR_CODE_ITEMS bbci
        inner join BD_BAR_CODE bbc
        on bbc.pk_id = bbci.pk_bar_code
        where bbci.del_flag = 0
        and bbci.pk_country = #{pkCountry}
        and bbci.bar_code in
        <foreach collection="barCodeList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

</mapper>
