<?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.RcvLinesMapper">
<resultMap id="mainMap" type="com.prolog.cs.biz.inbound.dto.rcv.RcvLinesDTO">
	<result column="rcv_line_id" property="rcvLineId"/>
	<result column="rcv_header_id" property="rcvHeaderId"/>
	<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"/>
	<result column="item_id" property="itemId"/>
	<result column="uom" property="uom"/>
	<result column="line_num" property="lineNum"/>
	<result column="uom_type" property="uomType"/>
	<result column="qty" property="qty"/>
	<result column="conversion_rate" property="conversionRate"/>
	<result column="piece_qty" property="pieceQty"/>
	<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="stock_status" property="stockStatus"/>
	<result column="rcv_reason1" property="rcvReason1"/>
	<result column="rcv_reason2" property="rcvReason2"/>
	<result column="rcv_reason3" property="rcvReason3"/>
	<result column="rcv_rt_reason" property="rcvRtReason"/>
	<result column="warehouse_area" property="warehouseArea"/>
	<result column="warehouse_locator" property="warehouseLocator"/>
	<result column="executor_user" property="executorUser"/>
	<result column="comments" property="comments"/>
	<result column="wms_piece_qty" property="wmsPieceQty"/>
	<result column="src_bill_type" property="srcBillType"/>
	<result column="mtl_owner_id" property="mtlOwnerId"/>
	<result column="warehouse_id" property="warehouseId"/>
	<result column="item_health_is_double" property="itemHealthIsDouble"/>
	<result column="free_qty" property="freeQty"/>
	<result column="item_weight" property="itemWeight"/>
	<result column="item_volume" property="itemVolume"/>
	<result column="approval_number" property="approvalNumber"/>
	<result column="production_place " property="productionPlace"/>
	<result column="erp_batch_num" property="erpBatchNum"/>
	<result column="data_version" property="dataVersion"/>
	<!-- profile字段 -->
	<result column="ITEM_NUM" property="itemNum" />
	<result column="ITEM_NAME" property="itemName" />
	<result column="CATEGORY_NAME" property="categoryName" />
	<result column="ITEM_BARCODE" property="itemBarcode" />
	
	<!-- <result column="status_as" property="statusAs"/>
	<result column="enterprise_id" property="enterpriseId"/>
	<result column="gmt_create" property="gmtCreate"/>
	<result column="creator" property="creator"/>
	<result column="creator_name" property="creatorName"/>
	<result column="gmt_modified" property="gmtModified"/>
	<result column="modifier" property="modifier"/>
	<result column="created_name" property="createdName"/>
	
	<result column="last_updated_name" property="lastUpdatedName"/>
	<result column="modifier_name" property="modifierName"/>
	 -->
</resultMap>
<sql id="mainClomuns">
		t1.rcv_line_id,
			t1.rcv_header_id,
			t1.src_header_id,
			t1.src_line_id,
			t1.asn_header_id,
			t1.asn_line_id,
			t1.item_id,
			t1.uom,
			t1.line_num,
			t1.uom_type,
			t1.qty,
			t1.conversion_rate,
			t1.piece_qty,
			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.erp_batch_num,
			t1.container_code,
			t1.goods_case_code,
			t1.stock_status,
			t1.rcv_reason1,
			t1.rcv_reason2,
			t1.rcv_reason3,
			t1.rcv_rt_reason,
			t1.warehouse_area,
			t1.warehouse_locator,
			t1.executor_user,
			<!-- t1.segment1,
			t1.segment2,
			t1.segment3,
			t1.segment4,
			t1.segment5,
			t1.attribute1,
			t1.attribute2,
			t1.attribute3,
			t1.attribute4,
			t1.attribute5,
			t1.status_as,
			 -->
			t1.comments,
			t1.created_name,
			t1.last_updated_name,
			t1.wms_piece_qty,
			t1.src_bill_type,
			t1.mtl_owner_id,
			t1.item_health_is_double,
			t1.free_qty,
			t1.item_weight,
			t1.item_volume,
			t1.approval_number,
			t1.production_place,
			t1.warehouse_id,
			t1.warehouse_name as warehouseName,
			t1.warehouse_area_id as warehouseAreaId,
			t1.warehouse_area_name as warehouseAreaName,
			t1.mtl_owner_name as mtlOwnerName,
			t1.item_health_twovoteflag as itemHealthTwovoteflag,
			t1.ENTERPRISE_ID,
			t1.GMT_CREATE,
			t1.CREATOR,
			t1.CREATOR_NAME,
			t1.GMT_MODIFIED,
			t1.MODIFIER,
			t1.MODIFIER_NAME,
			t1.data_version,
	</sql>
	<select id="findList" resultMap="mainMap">
		select
		distinct
		<include refid="mainClomuns"></include>
		t1.WAREHOUSE_AREA_CODES as warehouseAreaCodes,
		t1.ITEM_IS_PIECE_OR_CASE as itemIsPieceOrCase,
		t1.WAREHOUSE_AREA_CATEGORYS as warehouseArea_categorys,
		t2.ITEM_NUM,
		t2.ITEM_NAME,
		t2.CATEGORY_NAME,
		t2.ITEM_BARCODE,
		t2.specification as specification,
		t2.ITEM_HEALTH_LISTED_LICENSOR as itemHealthListedLicensor,
		t2.ITEM_HEALTH_PRODUCE_LICENSE as itemHealthProduceLicense,
		t2.ITEM_HEALTH_STORE_CATEGORY as itemHealthStoreCategory,
		t2.ITEM_IS_RECHECK as itemIsRecheck,
		t2.IS_INSTRUMENT as isInstrument,
		t2.ITEM_IS_IMPORTED as itemIsImported,
		
		t2.MANUFACTURER_ID as manufacturerId,
		t2.MANUFACTURER_CODE as manufacturerCode,
		t2.MANUFACTURER_NAME as manufacturerName,
		t2.ITEM_HEALTH_REGISTER_NBR as itemHealthRegisterNbr,
		t2.ITEM_HEALTH_COMMON_NAME as itemHealthCommonName,
		t2.RETURN_INFO as returnInfo,
		t2.RETURN_COLD_QUALITY as returnColdQuality,
		t2.RETURN_EXPLAIN as returnExplain,
		t2.IS_LOCK as isLock,
		t2.IS_HOSTED as isHosted,
		t2.ITEM_IS_SPECIAL as itemIsSpecial,
		t2.IS_BACTERIA as isBacteria,
		t2.SHELF_LIFE_DAYS as shelfLifeDays,
		t2.SHELF_LIFE_UNIT as shelfLifeUnit
			
		FROM
			wms_in_rcv_lines t1,
			WMS_IN_RCV_LINES_PROFILES t2
		WHERE
		t1.RCV_LINE_ID = t2.RCV_LINE_ID
		<if test="enterpriseId != null  and enterpriseId !=''">
			and t1.enterprise_id = #{enterpriseId}
		</if>
		<if test="warehouseId != null  and warehouseId !=''">
			and t1.warehouse_id = #{warehouseId}
		</if>
		<if test="mtlOwnerId != null  and mtlOwnerId !=''">
			and t1.mtl_owner_id = #{mtlOwnerId}
		</if>
		<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="batchNum != null  and batchNum !=''">
			and t1.batch_num = #{batchNum}
		</if>
		<if test="rcvStockStatus != null  and rcvStockStatus !=''">
			and t1.stock_status = #{rcvStockStatus}
		</if>
		<if test="includeIds != null and includeIds.size() >0 ">
            and t1.rcv_line_id in
            <foreach collection="includeIds" item="item" open="("
                     separator="," close=")">
                #{item}
            </foreach>
        </if>
		<if test="excludeIds != null and excludeIds.size() >0 ">
            and t1.rcv_line_id not in
            <foreach collection="excludeIds" item="item" open="("
                     separator="," close=")">
                #{item}
            </foreach>
        </if>
		order by t1.gmt_modified
		desc
	</select>
	
	<select id="findByPkId" resultMap="mainMap" parameterType="String">
		select
		distinct
		<include refid="mainClomuns"></include>
		t1.WAREHOUSE_AREA_CODES as warehouseAreaCodes,
		t1.ITEM_IS_PIECE_OR_CASE as itemIsPieceOrCase,
		t1.WAREHOUSE_AREA_CATEGORYS as warehouseArea_categorys,
		t2.ITEM_NUM,
		t2.ITEM_NAME,
		t2.CATEGORY_NAME,
		t2.ITEM_BARCODE,
		t2.specification as specification,
		t2.ITEM_HEALTH_LISTED_LICENSOR as itemHealthListedLicensor,
		t2.ITEM_HEALTH_PRODUCE_LICENSE as itemHealthProduceLicense,
		t2.ITEM_HEALTH_STORE_CATEGORY as itemHealthStoreCategory,
		t2.ITEM_IS_RECHECK as itemIsRecheck,
		t2.IS_INSTRUMENT as isInstrument,
		t2.ITEM_IS_IMPORTED as itemIsImported,
		
		t2.MANUFACTURER_ID as manufacturerId,
		t2.MANUFACTURER_CODE as manufacturerCode,
		t2.MANUFACTURER_NAME as manufacturerName,
		t2.ITEM_HEALTH_REGISTER_NBR as itemHealthRegisterNbr,
		t2.ITEM_HEALTH_COMMON_NAME as itemHealthCommonName,
		t2.RETURN_INFO as returnInfo,
		t2.RETURN_COLD_QUALITY as returnColdQuality,
		t2.RETURN_EXPLAIN as returnExplain,
		t2.IS_LOCK as isLock,
		t2.IS_HOSTED as isHosted,
		t2.ITEM_IS_SPECIAL as itemIsSpecial,
		t2.IS_BACTERIA as isBacteria,
		t2.SHELF_LIFE_DAYS as shelfLifeDays,
		t2.SHELF_LIFE_UNIT as shelfLifeUnit
		
		FROM
			wms_in_rcv_lines t1,
			WMS_IN_RCV_LINES_PROFILES t2
		WHERE
		t1.RCV_LINE_ID = t2.RCV_LINE_ID and t1.RCV_LINE_ID  = #{pkId}
	</select>
	
	<select id="findRemainQty" parameterType="String" resultType="java.math.BigDecimal">
		SELECT
			(
				nvl( t1.ITEM_QTY, 0 ) + nvl( t1.FREE_QTY, 0 )
				- nvl( ( SELECT SUM( NVL( PIECE_QTY, 0 ) ) FROM WMS_IN_RCV_LINES t2 WHERE t2.ASN_LINE_ID = #{asnLineId} and t2.src_line_id is null  ), 0 )
		        - nvl( ( SELECT SUM( NVL( t3.affirmed_qty, 0 ) ) FROM IN_RECEIVING_ABNORMAL_D t3 WHERE t3.attr_str1 = #{asnLineId} ), 0 )
			) AS qty 
		FROM
			OMS_ASN_BILL_D t1 
		WHERE
			t1.LINEID = #{asnLineId}
			<!-- AND t1.P_ENTERPRISEID = #{enterpriseId} -->
	</select>
	<!-- <select id="findRemainQty" parameterType="String" resultType="java.math.BigDecimal">
		SELECT
			(nvl(t1.ITEM_QTY,0) + nvl(t1.FREE_QTY,0) - nvl(t2.PIECE_QTY,0) - nvl(t3.PIECE_QTY,0)) as qty
		FROM
			OMS_ASN_BILL_D t1
			LEFT JOIN WMS_IN_RCV_LINES t2 ON t1.LINEID = t2.ASN_LINE_ID 
			LEFT JOIN WMS_IN_TASK_REJECTED_DETAIL t3 ON t1.LINEID = t3.ASN_LINE_ID 
		WHERE
			t1.LINEID = #{asnLineId} 
			AND t1.P_ENTERPRISEID = #{enterpriseId}
            AND ROWNUM &lt;= 1
	</select> -->
	<select id="getRcvPreItemLotNum" resultType="com.prolog.cs.biz.inbound.vo.RcvLineLotInfo">
		select
		distinct
		t1.manufacturer_lot_num as "manufacturerLotNum",
		t1.SHOW_PRODUCTION_DATE as "showProductionDate",
		t1.SHOW_EXPIRED_DATE as "showExpiredDate",
		t1.BATCH_PRODUCTION_DATE as "batchProductionDate",
		t1.BATCH_EXPIRED_DATE as "batchExpiredDate"
		FROM
			wms_in_rcv_lines t1
		WHERE 1=1
		<if test="enterpriseId != null  and enterpriseId !=''">
			and t1.enterprise_id = #{enterpriseId}
		</if>
		<if test="manufacturerLotNum != null  and manufacturerLotNum !=''">
			and t1.manufacturer_lot_num like concat(concat('%',#{manufacturerLotNum}),'%')
		</if>
		<if test="warehouseId != null  and warehouseId !=''">
			and t1.warehouse_id = #{warehouseId}
		</if>
		<if test="mtlOwnerId != null  and mtlOwnerId !=''">
			and t1.mtl_owner_id = #{mtlOwnerId}
		</if>
		<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>
	</select>
	<insert id="saveWithVaildate" parameterType="rcvLines">
		INSERT INTO wms_in_rcv_lines (
			rcv_line_id,
			rcv_header_id,
			src_header_id,
			src_line_id,
			asn_header_id,
			asn_line_id,
			item_id,
			uom,
			line_num,
			uom_type,
			qty,
			conversion_rate,
			piece_qty,
			odd_case_qty,
			odd_piece_qty,
			batch_id,
			batch_num,
			batch_production_date,
			batch_expired_date,
			vendor_batch_num,
			manufacturer_lot_num,
			erp_batch_num,
			container_code,
			goods_case_code,
			stock_status,
			rcv_reason1,
			rcv_reason2,
			rcv_reason3,
			rcv_rt_reason,
			warehouse_area,
			warehouse_locator,
			executor_user,
			<!-- segment1,
			segment2,
			segment3,
			segment4,
			segment5,
			attribute1,
			attribute2,
			attribute3,
			attribute4,
			attribute5,
			status_as,
			 -->
			comments,
			created_name,
			last_updated_name,
			wms_piece_qty,
			src_bill_type,
			mtl_owner_id,
			item_health_is_double,
			free_qty,
			item_weight,
			item_volume,
			approval_number,
			production_place,
			warehouse_id,
			warehouse_name,
			warehouse_area_id,
			warehouse_area_name,
			mtl_owner_name,
			item_health_twovoteflag,
			ENTERPRISE_ID,
			GMT_CREATE,
			CREATOR,
			CREATOR_NAME,
			GMT_MODIFIED,
			MODIFIER,
			MODIFIER_NAME,
			data_version,
			
			item_is_piece_or_case,
			warehouse_area_categorys,
			warehouse_area_code,
			bldg_id,
			bldg_name,
			bldg_code,
			rcv_type,
			rcv_date,
			delegation_party_id,
			delegation_party_name,
			show_production_date,
			show_expired_date,
			warehouse_room_codes,
			piece_conversion_rate,
			asn_line_remark,
			item_zjm,
			is_delegate,
			is_retrospect,
			rqc_report_no,
			wh_locator_id,
			wh_locator_code,
			wh_area_code,
			wh_area_category_code,
			inventory_op_type,
			host_locator_id
			
			
			) 
		SELECT
			rcv_line_id,
			rcv_header_id,
			src_header_id,
			src_line_id,
			asn_header_id,
			asn_line_id,
			item_id,
			uom,
			line_num,
			uom_type,
			qty,
			conversion_rate,
			piece_qty,
			odd_case_qty,
			odd_piece_qty,
			batch_id,
			batch_num,
			batch_production_date,
			batch_expired_date,
			vendor_batch_num,
			manufacturer_lot_num,
			erp_batch_num,
			container_code,
			goods_case_code,
			stock_status,
			rcv_reason1,
			rcv_reason2,
			rcv_reason3,
			rcv_rt_reason,
			warehouse_area,
			warehouse_locator,
			executor_user,
			<!-- segment1,
			segment2,
			segment3,
			segment4,
			segment5,
			attribute1,
			attribute2,
			attribute3,
			attribute4,
			attribute5,
			status_as,
			 -->
			comments,
			created_name,
			last_updated_name,
			wms_piece_qty,
			src_bill_type,
			mtl_owner_id,
			item_health_is_double,
			free_qty,
			item_weight,
			item_volume,
			approval_number,
			production_place,
			warehouse_id,
			warehouse_name,
			warehouse_area_id,
			warehouse_area_name,
			mtl_owner_name,
			item_health_twovoteflag,
			ENTERPRISE_ID,
			GMT_CREATE,
			CREATOR,
			CREATOR_NAME,
			GMT_MODIFIED,
			MODIFIER,
			MODIFIER_NAME,
			data_version,
			
			item_is_piece_or_case,
			warehouse_area_categorys,
			warehouse_area_code,
			bldg_id,
			bldg_name,
			bldg_code,
			rcv_type,
			rcv_date,
			delegation_party_id,
			delegation_party_name,
			show_production_date,
			show_expired_date,
			warehouse_room_codes,
			piece_conversion_rate,
			asn_line_remark,
			item_zjm,
			is_delegate,
			is_retrospect,
			rqc_report_no,
			wh_locator_id,
			wh_locator_code,
			wh_area_code,
			wh_area_category_code,
			inventory_op_type,
			host_locator_id
			
		from 
		(
		select
			#{rcvLineId} as rcv_line_id,
			#{rcvHeaderId} as rcv_header_id,
			#{srcHeaderId} as src_header_id,
			#{srcLineId} as src_line_id,
			#{asnHeaderId} as asn_header_id,
			#{asnLineId} as asn_line_id,
			#{itemId} as item_id,
			#{uom} as uom,
			#{lineNum} as line_num,
			#{uomType} as uom_type,
			#{qty} as qty,
			#{conversionRate} as conversion_rate,
			#{pieceQty} as piece_qty,
			#{oddCaseQty} as odd_case_qty,
			#{oddPieceQty} as odd_piece_qty,
			#{batchId} as batch_id,
			#{batchNum} as batch_num,
			#{batchProductionDate} as batch_production_date,
			#{batchExpiredDate} as batch_expired_date,
			#{vendorBatchNum} as vendor_batch_num,
			#{manufacturerLotNum} as manufacturer_lot_num,
			#{erpBatchNum} as erp_batch_num,
			#{containerCode} as container_code,
			#{goodsCaseCode} as goods_case_code,
			#{stockStatus} as stock_status,
			#{rcvReason1} as rcv_reason1,
			#{rcvReason2} as rcv_reason2,
			#{rcvReason3} as rcv_reason3,
			#{rcvRtReason} as rcv_rt_reason,
			#{warehouseArea} as warehouse_area,
			#{warehouseLocator} as warehouse_locator,
			#{executorUser} as executor_user,
			<!-- #{segment1},
			#{segment2},
			#{segment3},
			#{segment4},
			#{segment5},
			#{attribute1},
			#{attribute2},
			#{attribute3},
			#{attribute4},
			#{attribute5},
			#{statusAs},
			 -->
			#{comments} as comments,
			#{createdName} as created_name,
			#{lastUpdatedName} as last_updated_name,
			#{wmsPieceQty} as wms_piece_qty,
			#{srcBillType} as src_bill_type,
			#{mtlOwnerId} as mtl_owner_id,
			#{itemHealthIsDouble} as item_health_is_double,
			#{freeQty} as free_qty,
			#{itemWeight} as item_weight,
			#{itemVolume} as item_volume,
			#{approvalNumber} as approval_number,
			#{productionPlace} as production_place,
			#{warehouseId} as warehouse_id,
			#{warehouseName} as warehouse_name,
			#{warehouseAreaId} as warehouse_area_id,
			#{warehouseAreaName} as warehouse_area_name,
			#{mtlOwnerName} as mtl_owner_name,
			#{itemHealthTwovoteflag} as item_health_twovoteflag,
			#{enterpriseId} as ENTERPRISE_ID,
			#{gmtCreate} as gmt_create,
			#{creator} as creator,
			#{creatorName} as creator_name,
			#{gmtModified} as gmt_modified,
			#{modifier} as modifier,
			#{modifierName} as MODIFIER_NAME,
			#{dataVersion} as data_version,

			#{itemIsPieceOrCase} as item_is_piece_or_case,
			#{warehouseAreaCategorys} as warehouse_area_categorys,
			#{warehouseAreaCode} as warehouse_area_code,
			#{bldgId} as bldg_id,
			#{bldgName} as bldg_name,
			#{bldgCode} as bldg_code,
			#{rcvType} as rcv_type,
			#{rcvDate} as rcv_date,
			#{delegationPartyId} as delegation_party_id,
			#{delegationPartyName} as delegation_party_name,
			#{showProductionDate} as show_production_date,
			#{showExpiredDate} as show_expired_date,
			#{warehouseRoomCodes} as warehouse_room_codes,
			#{pieceConversionRate} as piece_conversion_rate,
			#{asnLineRemark} as asn_line_remark,
			#{itemZjm} as item_zjm,
			#{isDelegate} as is_delegate,
			#{isRetrospect} as is_retrospect,
			#{rqcReportNo} as rqc_report_no,
			
			#{whLocatorId} as wh_locator_id,
			#{whLocatorCode} as wh_locator_code,
			#{whAreaCode} as wh_area_code,
			#{whAreaCategoryCode} as wh_area_category_code,
			#{inventoryOpType} as inventory_op_type,
			#{hostLocatorId} as host_locator_id
			
		from dual
		where #{pieceQty} &lt;= 
			(SELECT
				(nvl(t1.ITEM_QTY,0) + nvl(t1.FREE_QTY,0)
			    	- nvl( ( SELECT SUM( NVL( PIECE_QTY, 0 ) ) FROM WMS_IN_RCV_LINES t2 WHERE t2.ASN_LINE_ID = #{asnLineId} and t2.src_line_id is null  ), 0 )
					- nvl( ( SELECT SUM( NVL( t3.affirmed_qty, 0 ) ) FROM IN_RECEIVING_ABNORMAL_D t3 WHERE t3.attr_str1 = #{asnLineId} ), 0 )
				) as qty
			FROM
				OMS_ASN_BILL_D t1
			WHERE
				t1.LINEID = #{asnLineId} 
				AND t1.P_ENTERPRISEID = #{enterpriseId}
	         )
        )
			<!-- (SELECT
				(nvl(t1.ITEM_QTY,0) + nvl(t1.FREE_QTY,0) - nvl(t2.PIECE_QTY,0) - nvl(t3.PIECE_QTY,0)) as qty
			FROM
				OMS_ASN_BILL_D t1
				LEFT JOIN WMS_IN_RCV_LINES t2 ON t1.LINEID = t2.ASN_LINE_ID 
				LEFT JOIN WMS_IN_RCV_REJECT_LINES t3 ON t1.LINEID = t3.ASN_LINE_ID 
			WHERE
				t1.LINEID = #{asnLineId} 
				AND t1.P_ENTERPRISEID = #{enterpriseId}
	            AND ROWNUM &lt;= 1)
        ) -->
	</insert>
	<select id="getReport" resultMap="mainMap">
		select
		distinct
		<include refid="mainClomuns"></include>
		t1.WAREHOUSE_AREA_CODES as warehouseAreaCodes,
		t1.ITEM_IS_PIECE_OR_CASE as itemIsPieceOrCase,
		t1.WAREHOUSE_AREA_CATEGORYS as warehouseArea_categorys,
		t2.ITEM_NUM,
		t2.ITEM_NAME,
		t2.CATEGORY_NAME,
		t2.ITEM_BARCODE,
		t2.specification as specification,
		t2.ITEM_HEALTH_LISTED_LICENSOR as itemHealthListedLicensor,
		t2.ITEM_HEALTH_PRODUCE_LICENSE as itemHealthProduceLicense,
		t2.ITEM_HEALTH_STORE_CATEGORY as itemHealthStoreCategory,
		t2.ITEM_IS_RECHECK as itemIsRecheck,
		t2.IS_INSTRUMENT as isInstrument,
		t2.ITEM_IS_IMPORTED as itemIsImported,
		
		t2.MANUFACTURER_ID as manufacturerId,
		t2.MANUFACTURER_CODE as manufacturerCode,
		t2.MANUFACTURER_NAME as manufacturerName,
		t2.ITEM_HEALTH_REGISTER_NBR as itemHealthRegisterNbr,
		t2.ITEM_HEALTH_COMMON_NAME as itemHealthCommonName,
		t2.RETURN_INFO as returnInfo,
		t2.RETURN_COLD_QUALITY as returnColdQuality,
		t2.RETURN_EXPLAIN as returnExplain,
		t2.IS_LOCK as isLock,
		t2.IS_HOSTED as isHosted,
		t2.ITEM_IS_SPECIAL as itemIsSpecial,
		t2.IS_BACTERIA as isBacteria,
		t2.SHELF_LIFE_DAYS as shelfLifeDays,
		t2.SHELF_LIFE_UNIT as shelfLifeUnit,
		
		t1.item_zjm as itemZjm,
		t1.production_place as productionPlace
			
		FROM
			wms_in_rcv_lines t1,
			WMS_IN_RCV_LINES_PROFILES t2
		WHERE
		t1.RCV_LINE_ID = t2.RCV_LINE_ID
		<!-- 排除拒收的 -->
		and t1.STOCK_STATUS &lt;&gt; '3'
		<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(t2.item_num) like concat(CONCAT('%',UPPER(#{itemCode})),'%')
		</if>
		<if test="itemName != null  and itemName !=''">
			and UPPER(t2.item_name) like concat(concat('%',UPPER(#{itemName})),'%')
		</if>
		<if test="itemZjm != null  and itemZjm !=''">
		    and UPPER(t1.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>
	<update id="updateAsnDetails" parameterType="String">
		UPDATE OMS_ASN_BILL_D set STATUS = '2000' WHERE LINEID = #{asnLineid} AND (
			( SELECT COALESCE( SUM( COALESCE( PIECE_QTY, 0 ) ), 0 ) FROM WMS_IN_RCV_INSTOCK_LINES WHERE asn_line_ID = #{asnLineid} ) != 0
			AND (
			( SELECT COALESCE( SUM( COALESCE( PIECE_QTY, 0 ) ), 0 ) FROM WMS_IN_RCV_INSTOCK_LINES WHERE asn_line_ID = #{asnLineid} ) = (
			SELECT
				COALESCE( SUM( COALESCE( ITEM_QTY, 0 ) ) + SUM( COALESCE( FREE_QTY, 0 ) ), 0 ) 
			FROM
			OMS_ASN_BILL_D
			WHERE
				LINEID = #{asnLineid} 
			) 
		) 
	)
	</update>
	<update id="updateAsnHeader" parameterType="String">
		UPDATE OMS_ASN_BILL_H 
		SET STATUS = '2000' 
		WHERE
			billid = #{asnHeaderId} 
			AND (
				( SELECT COALESCE( SUM( COALESCE( PIECE_QTY, 0 ) ), 0 ) FROM WMS_IN_RCV_INSTOCK_LINES WHERE ASN_HEADER_ID = #{asnHeaderId} ) != 0 
				AND (
					( SELECT COALESCE( SUM( COALESCE( PIECE_QTY, 0 ) ), 0 ) FROM WMS_IN_RCV_INSTOCK_LINES WHERE ASN_HEADER_ID = #{asnHeaderId} ) = (
					SELECT
						COALESCE( SUM( COALESCE( ITEM_QTY, 0 ) ) + SUM( COALESCE( FREE_QTY, 0 ) ), 0 ) 
					FROM
						OMS_ASN_BILL_D 
					WHERE
						billid = #{asnHeaderId} 
					) 
				) 
			)
	</update>
</mapper>
