<?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.aucma.report.mapper.ProductOffLineMapper">

    <resultMap type="ProductOffLine" id="ProductOffLineResult">
        <result property="objId" column="obj_id"/>
        <result property="productFactoryCode" column="product_factory_code"/>
        <result property="productSncode" column="product_sncode"/>
        <result property="productOrderNo" column="product_order_no"/>
        <result property="productSaleNo" column="product_sale_no"/>
        <result property="productSaleLineNo" column="product_sale_line_no"/>
        <result property="productCode" column="product_code"/>
        <result property="productModel" column="product_model"/>
        <result property="productName" column="product_name"/>
        <result property="productType" column="product_type"/>
        <result property="productCheckInfo" column="product_check_info"/>
        <result property="productRemark" column="product_remark"/>
        <result property="productBarNo" column="product_bar_no"/>
        <result property="productMasterModel" column="product_master_model"/>
        <result property="productVersion" column="product_version"/>
        <result property="productUserinfo" column="product_userinfo"/>
        <result property="productCirculate" column="product_circulate"/>
        <result property="productCreatedate" column="product_createdate"/>
        <result property="productScantime" column="product_scantime"/>
        <result property="boxCode" column="box_code"/>
        <result property="productLineCode" column="product_line_code"/>
        <result property="productLineName" column="product_line_name"/>
        <result property="factoryName" column="factory_name"/>
    </resultMap>

    <sql id="selectProductOffLineVo">
        SELECT po.obj_id,
               po.product_factory_code,
               BF.FACTORY_NAME,
               po.product_sncode,
               substr(po.product_order_no,5) product_order_no,
               po.product_sale_no,
               po.product_sale_line_no,
               po.product_code,
               po.product_model,
               po.product_name,
               po.product_type,
               po.product_check_info,
               po.product_remark,
               po.product_bar_no,
               po.product_master_model,
               po.product_version,
               po.product_userinfo,
               po.product_circulate,
               po.product_createdate,
               po.product_scantime,
               po.box_code,
               po.product_line_code,
               PL.PRODUCT_LINE_NAME
        FROM VIEW_PRODUCT_OFFLINE po
                 LEFT JOIN BASE_FACTORY BF ON BF.FACTORY_CODE = po.product_factory_code
                 LEFT JOIN BASE_PRODUCTLINE PL ON PL.PRODUCT_LINE_CODE = po.product_line_code
    </sql>

    <select id="selectProductOffLineList" parameterType="ProductOffLine" resultMap="ProductOffLineResult">
        <include refid="selectProductOffLineVo"/>
        <where>
            <if test="productFactoryCode != null  and productFactoryCode != ''">and po.product_factory_code =
                #{productFactoryCode}
            </if>
            <if test="productSncode != null  and productSncode != ''">and po.product_sncode = #{productSncode}</if>
            <if test="productOrderNo != null  and productOrderNo != ''">and po.product_order_no like concat(concat('%',
                #{productOrderNo}), '%')</if>
            <if test="productSaleNo != null  and productSaleNo != ''">and po.product_sale_no = #{productSaleNo}</if>
            <if test="productSaleLineNo != null  and productSaleLineNo != ''">and po.product_sale_line_no =
                #{productSaleLineNo}
            </if>
            <if test="productCode != null  and productCode != ''">and po.product_code = #{productCode}</if>
            <if test="productModel != null  and productModel != ''">and po.product_model = #{productModel}</if>
            <if test="productName != null  and productName != ''">and po.product_name like concat(concat('%',
                #{productName}), '%')
            </if>
            <if test="productType != null  and productType != ''">and po.product_type = #{productType}</if>
            <if test="productCheckInfo != null  and productCheckInfo != ''">and po.product_check_info =
                #{productCheckInfo}
            </if>
            <if test="productRemark != null  and productRemark != ''">and po.product_remark = #{productRemark}</if>
            <if test="productBarNo != null  and productBarNo != ''">and po.product_bar_no = #{productBarNo}</if>
            <if test="productMasterModel != null  and productMasterModel != ''">and po.product_master_model =
                #{productMasterModel}
            </if>
            <if test="productVersion != null  and productVersion != ''">and po.product_version = #{productVersion}</if>
            <if test="productUserinfo != null  and productUserinfo != ''">and po.product_userinfo = #{productUserinfo}</if>
            <if test="productCirculate != null  and productCirculate != ''">and po.product_circulate =
                #{productCirculate}
            </if>
            <if test="productCreatedate != null ">and po.product_createdate = #{productCreatedate}</if>
            <if test="boxCode != null  and boxCode != ''">and po.box_code = #{boxCode}</if>
            <if test="productLineCode != null  and productLineCode != ''">and po.product_line_code = #{productLineCode}
            </if>
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(po.product_scantime, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
        </where>
        ORDER BY po.product_scantime
    </select>

</mapper>