<?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.prolog.cs.biz.inbound.dao.rcv.RcvRejectLinesMapper">
	<resultMap id="mainMap" type="com.prolog.cs.biz.inbound.dto.rcv.RcvRejectLinesDTO">
		<result column="in_reject_line_id" property="inRejectLineId"/>
		<result column="rcv_header_id" property="rcvHeaderId"/>
		<result column="rcv_line_id" property="rcvLineId"/>
		<result column="line_num" property="lineNum"/>
		<result column="warehouse_locator_id" property="warehouseLocatorId"/>
		<result column="item_id" property="itemId"/>
		<result column="piece_qty" property="pieceQty"/>
		<result column="uom" property="uom"/>
		<result column="uom_type" property="uomType"/>
		<result column="conversion_rate" property="conversionRate"/>
		<result column="odd_case_qty" property="oddCaseQty"/>
		<result column="odd_piece_qty" property="oddPieceQty"/>
		<result column="batch_id" property="batchId"/>
		<result column="batch_num" property="batchNum"/>
		<result column="batch_production_date" property="batchProductionDate"/>
		<result column="batch_expired_date" property="batchExpiredDate"/>
		<result column="vendor_batch_num" property="vendorBatchNum"/>
		<result column="manufacturer_lot_num" property="manufacturerLotNum"/>
		<result column="container_code" property="containerCode"/>
		<result column="goods_case_code" property="goodsCaseCode"/>
		<result column="comments" property="comments"/>
		<result column="result" property="result"/>
		<result column="reason" property="reason"/>
		<result column="executor_user" property="executorUser"/>
		<!-- <result column="segment1" property="segment1"/>
		<result column="segment2" property="segment2"/>
		<result column="segment3" property="segment3"/>
		<result column="segment4" property="segment4"/>
		<result column="segment5" property="segment5"/>
		<result column="attribute1" property="attribute1"/>
		<result column="attribute2" property="attribute2"/>
		<result column="attribute3" property="attribute3"/>
		<result column="attribute4" property="attribute4"/>
		<result column="attribute5" property="attribute5"/> -->
		<result column="task_id" property="taskId"/>
		<result column="mtl_owner_id" property="mtlOwnerId"/>
		<result column="warehouse_id" property="warehouseId"/>
		<result column="src_bill_type" property="srcBillType"/>
		<result column="src_header_id" property="srcHeaderId"/>
		<result column="src_line_id" property="srcLineId"/>
		<result column="asn_header_id" property="asnHeaderId"/>
		<result column="asn_line_id" property="asnLineId"/>
	</resultMap>
	<sql id="mainClomuns" >
		t1.in_reject_line_id,
		t1.rcv_header_id,
		t1.rcv_line_id,
		t1.line_num,
		t1.warehouse_locator_id,
		t1.item_id,
		t1.piece_qty,
		t1.uom,
		t1.uom_type,
		t1.conversion_rate,
		t1.odd_case_qty,
		t1.odd_piece_qty,
		t1.batch_id,
		t1.batch_num,
		t1.batch_production_date,
		t1.batch_expired_date,
		t1.vendor_batch_num,
		t1.manufacturer_lot_num,
		t1.container_code,
		t1.goods_case_code,
		t1.comments,
		t1.result,
		t1.reason,
		t1.executor_user,
		<!-- t1.segment1,
		t1.segment2,
		t1.segment3,
		t1.segment4,
		t1.segment5,
		t1.attribute1,
		t1.attribute2,
		t1.attribute3,
		t1.attribute4,
		t1.attribute5, -->
		t1.task_id,
		t1.mtl_owner_id,
		t1.warehouse_id,
		t1.src_bill_type,
		t1.src_header_id,
		t1.src_line_id,
		t1.asn_header_id,
		t1.asn_line_id,
		<!-- 
		t1.enterprise_id,
		t1.gmt_create,
		t1.creator,
		t1.creator_name,
		t1.modifier,
		t1.modifier_name, -->
		t1.gmt_modified,
	</sql>
	<select id="getReport" resultMap="mainMap">
		select
		distinct
		<include refid="mainClomuns"></include>
	    t3.ITEM_NUM as itemNum,
	   	t3.ITEM_NAME as itemName,
	   	t3.CATEGORY_NAME as categoryName,
	   	t3.specification as specification,
	   	t3.ITEM_HEALTH_LISTED_LICENSOR as itemHealthListedLicensor,
	   	t3.ITEM_HEALTH_PRODUCE_LICENSE as itemHealthProduceLicense,
	   	t3.ITEM_HEALTH_STORE_CATEGORY as itemHealthStoreCategory,
	   	t3.IS_INSTRUMENT as isInstrument,
	   	t3.ITEM_IS_IMPORTED as itemIsImported,
	   	t3.MANUFACTURER_NAME as manufacturerName,
	   	t3.ITEM_HEALTH_REGISTER_NBR as itemHealthRegisterNbr,
	   	t3.ITEM_HEALTH_COMMON_NAME as itemHealthCommonName,
	   	t3.RETURN_INFO as returnInfo,
	   	t3.RETURN_COLD_QUALITY as returnColdQuality,
	   	t3.RETURN_EXPLAIN as returnExplain,
	   	t3.IS_LOCK as isLock,
	   	t3.IS_HOSTED as isHosted,
	   	t3.ITEM_IS_SPECIAL as itemIsSpecial,
	   	t3.IS_BACTERIA as isBacteria,
	   	t3.SHELF_LIFE_DAYS as shelfLifeDays,
	   	t3.SHELF_LIFE_UNIT as shelfLifeUnit,
	   	t2.show_production_date as showProductionDate,	
	   	t2.show_expired_date as showExpiredDate,
	   	t2.item_zjm as itemZjm,
	   	t2.approval_number as approvalNumber,
	   	t2.production_place as productionPlace
			
		FROM
		WMS_IN_RCV_REJECT_LINES t1
		LEFT JOIN
		WMS_IN_RCV_LINES t2
		on t1.rcv_line_id = t2.RCV_LINE_ID
		LEFT JOIN
		WMS_IN_RCV_LINES_PROFILES t3
		on t1.rcv_line_id = t3.RCV_LINE_ID
		where
		1=1
		<if test="rcvHeaderId != null  and rcvHeaderId !=''">
			and t1.rcv_header_id = #{rcvHeaderId}
		</if>
		<if test="itemId != null  and itemId !=''">
			and t1.item_id = #{itemId}
		</if>
		<if test="itemCode != null  and itemCode !=''">
			and UPPER(t3.item_num) like concat(CONCAT('%',UPPER(#{itemCode})),'%')
		</if>
		<if test="itemName != null  and itemName !=''">
			and UPPER(t3.item_name) like concat(concat('%',UPPER(#{itemName})),'%')
		</if>
		<if test="itemZjm != null  and itemZjm !=''">
		    and UPPER(t2.ITEM_ZJM) like CONCAT(CONCAT('%',UPPER(#{itemZjm})),'%') 
		</if>
		<if test="manufacturerLotNum != null  and manufacturerLotNum !=''">
			and UPPER(t1.manufacturer_lot_num) like CONCAT(concat('%',UPPER(#{manufacturerLotNum})),,'%')
		</if>
		order by t1.gmt_modified
		desc
	</select>
</mapper>
