<?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.rqc.RqcLinesMapper">
<resultMap id="mainMap" type="com.prolog.cs.biz.inbound.dto.rqc.RqcLinesDTO">
	<result column="rqc_line_id" property="rqcLineId"/>
	<result column="rqc_header_id" property="rqcHeaderId"/>
	<result column="task_rqc_id" property="taskRqcId"/>
	<result column="rcv_header_id" property="rcvHeaderId"/>
	<result column="rcv_line_id" property="rcvLineId"/>
	
	<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"/>
	<result column="item_id" property="itemId"/>
	<result column="container_code" property="containerCode"/>
	<result column="goods_case_code" property="goodsCaseCode"/>
	<result column="batch_id" property="batchId"/>
	<result column="uom" property="uom"/>
	<result column="uom_type" property="uomType"/>
	<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="qc_odd_case_qty" property="qcOddCaseQty"/>
	<result column="qc_odd_piece_qty" property="qcOddPieceQty"/>
	<result column="qc_odd_case_act_qty" property="qcOddCaseActQty"/>
	<result column="qc_odd_piece_act_qty" property="qcOddPieceActQty"/>
	<result column="line_remark" property="lineRemark"/>
	<result column="qc_status1" property="qcStatus1"/>
	<result column="qc_result1" property="qcResult1"/>
	<result column="qc_reason1" property="qcReason1"/>
	<result column="qc_grade1" property="qcGrade1"/>
	<result column="qc_opcode1" property="qcOpcode1"/>
	<result column="qc_date1" property="qcDate1"/>
	<result column="qc_status2" property="qcStatus2"/>
	<result column="qc_result2" property="qcResult2"/>
	<result column="qc_reason2" property="qcReason2"/>
	<result column="qc_grade2" property="qcGrade2"/>
	<result column="qc_opcode2" property="qcOpcode2"/>
	<result column="qc_status3" property="qcStatus3"/>
	<result column="qc_result3" property="qcResult3"/>
	<result column="qc_reason3" property="qcReason3"/>
	<result column="qc_grade3" property="qcGrade3"/>
	<result column="qc_opcode3" property="qcOpcode3"/>
	<result column="qc_date2" property="qcDate2"/>
	<result column="qc_date3" property="qcDate3"/>
	<result column="stock_status" property="stockStatus"/>
	<result column="item_flag" property="itemFlag"/>
	<result column="manufacturer_lot_num"
			property="manufacturerLotNum" />
	<result column="batch_num" property="batchNum" />
	<!-- <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="modifier_name" property="modifierName"/> -->
	<result column="times" property="times"/>
	<result column="item_health_is_double" property="itemHealthIsDouble"/>
	<result column="ITEM_VOLUME" property="itemVolume" />
	<result column="ITEM_WEIGHT" property="itemWeight" />
	<result column="ITEM_HEALTH_TWOVOTEFLAG"
		property="itemHealthTwovoflag" />
	<result column="WAREHOUSE_NAME" property="warehouseName" />
	<result column="WAREHOUSE_AREA_NAME"
		property="warehouseAreaName" />
	<result column="ITEM_NUM" property="itemNum" />
	<result column="ITEM_NAME" property="itemName" />
	<result column="CATEGORY_NAME" property="categoryName" />
	<result column="ITEM_BARCODE" property="itemBarcode" />
</resultMap>
	<sql id="mainClomuns">
		t1.rqc_line_id,
		t1.rqc_header_id,
		t1.task_rqc_id,
		t1.rcv_header_id,
		t1.rcv_line_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.item_id,
		t1.container_code,
		t1.goods_case_code,
		t1.batch_id,
		t1.uom,
		t1.uom_type,
		t1.conversion_rate,
		t1.piece_qty,
		t1.odd_case_qty,
		t1.odd_piece_qty,
		t1.qc_odd_case_qty,
		t1.qc_odd_piece_qty,
		t1.qc_odd_case_act_qty,
		t1.qc_odd_piece_act_qty,
		t1.line_remark,
		t1.qc_status1,
		t1.qc_result1,
		t1.qc_reason1,
		t1.qc_grade1,
		t1.qc_opcode1,
		t1.qc_date1,
		t1.qc_status2,
		t1.qc_result2,
		t1.qc_reason2,
		t1.qc_grade2,
		t1.qc_opcode2,
		t1.qc_status3,
		t1.qc_result3,
		t1.qc_reason3,
		t1.qc_grade3,
		t1.qc_opcode3,
		t1.qc_date2,
		t1.qc_date3,
		t1.stock_status,
		t1.item_flag,
		t1.times,
		t1.item_health_is_double,
		t1.manufacturer_lot_num,
		t1.batch_num,
		t1.ENTERPRISE_ID as enterpriseId,
		t1.GMT_CREATE as gmtCreate,
		t1.CREATOR,
		t1.CREATOR_NAME as creatorName,
		t1.GMT_MODIFIED as gmtModified,
		t1.MODIFIER,
		t1.MODIFIER_NAME as modifierName,
		t1.RQC_TEMPERATURE as rqcTemperature,
	</sql>
	<select id="findList" resultMap="mainMap">
		select
		distinct
		<include refid="mainClomuns"></include>
		t1.WH_AREA_CATEGORY as whAreaCategory,
		t1.WH_AREA_CODES as whAreaCodes,
		t2.WAREHOUSE_AREA_CODES as warehouseAreaCodes,
		t2.ITEM_IS_PIECE_OR_CASE as itemIsPieceOrCase,
		t2.WAREHOUSE_AREA_CATEGORYS as warehouseAreaCategorys,
		t2.ITEM_VOLUME,
		t2.ITEM_WEIGHT,
		t2.ITEM_HEALTH_TWOVOTEFLAG,
		t2.WAREHOUSE_NAME,
		t2.WAREHOUSE_AREA_NAME,
		t3.ITEM_NUM,
		t3.ITEM_NAME,
		t3.CATEGORY_NAME,
		t3.ITEM_BARCODE,
		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.ITEM_IS_RECHECK as itemIsRecheck,
		t3.IS_INSTRUMENT as isInstrument,
		t3.ITEM_IS_IMPORTED as itemIsImported,
		
		t3.MANUFACTURER_ID as manufacturerId,
		t3.MANUFACTURER_CODE as manufacturerCode,
		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,
		
		t4.bill_date as rqcDate,
		coalesce(t6.vendor_name,t6.CUSTOMER_NAME) as vendorName,
		t5.executor_user as rcvUser,
		t6.orgn_name as orgnName,
		t6.mtl_owner_name as mtlOwnerName,
		t6.buyer_mane as linkMan,
		t5.asn_auto_bill_num as poNum,
		t2.BATCH_PRODUCTION_DATE as batchProductionDate,
		t2.BATCH_EXPIRED_DATE as batchExpiredDate,
		t2.show_production_date as showProductionDate,	
		t2.show_expired_date as showExpiredDate,
		t5.sale_bill_type as saleBillType,
		concat(concat(t5.COMMENTS, '-'),t4.REMARK) as remarks,
		t7.WH_AREA_CATEGORY_CODE as whAreaCategoryCode,
		t7.WH_LOCATOR_ID as whLocatorId,
		t7.WH_LOCATOR_CODE as whLocatorCode,
		t7.WH_LOCATOR_NAME as whLocatorName,
		t7.BLDG_CODE as bldgCode,
		t7.WH_AREA_CODE as whAreaCode,
		t7.INSTOCK_LABEL as instockLabel,
		t7.LOCATOR_FLOOR_NUM as locatorFloorNum,
		t2.RCV_RT_REASON as rcvRtReason,
		case  t2.is_retrospect  when 0 then 0 else 1 end as uploadCircubillStatus,
		(select  count(upload_times) FROM wms_supervision_code c WHERE  c.REF_BILL_ID = t2.RCV_HEADER_ID
		and c.REF_BILL_LINE_ID = t2.RCV_LINE_ID and c.ITEM_ID = t2.ITEM_ID) as uploadTimes,
		(select  max(last_upload_time) FROM wms_supervision_code c WHERE  c.REF_BILL_ID = t2.RCV_HEADER_ID
		and c.REF_BILL_LINE_ID = t2.RCV_LINE_ID and c.ITEM_ID = t2.ITEM_ID) as lastUploadTime
		FROM
		wms_in_rqc_lines t1
		JOIN wms_in_rcv_lines t2 on t1.rcv_line_id = t2.RCV_LINE_ID
		JOIN wms_in_rcv_lines_profiles t3 on t1.rcv_line_id = t3.RCV_LINE_ID
		JOIN wms_in_rqc_headers t4 on t1.rqc_header_id = t4.rqc_header_id
		JOIN wms_in_rcv_headers t5 on t1.rcv_header_id = t5.rcv_header_id
		JOIN wms_in_rcv_headers_profiles t6 on t1.rcv_header_id = t6.rcv_header_id
		LEFT JOIN WMS_IN_TASK_INSTOCK_DETAIL t7 on t1.rcv_line_id = t7.rcv_line_id
		where
		1=1 and t1.stock_status in('0','1')
		<if test="enterpriseId != null  and enterpriseId !=''">
			and t1.enterprise_id = #{enterpriseId}
		</if>
		<if test="itemHealthIsDouble != null">
			and t7.TASK_INBOUND_ID is not null
		</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="rcvLineId != null  and rcvLineId !=''">
			and t1.rcv_line_id = #{rcvLineId}
		</if>
		<if test="rqcHeaderId != null  and rqcHeaderId !=''">
			and t1.rqc_header_id = #{rqcHeaderId}
		</if>
		<if test="itemId != null  and itemId !=''">
			and t1.item_id = #{itemId}
		</if>
		<if test="stockStatus != null  and stockStatus !=''">
			and t1.stock_status = #{stockStatus}
		</if>
		<if test="includeIds != null and includeIds.size() >0 ">
            and t1.rqc_line_id in
            <foreach collection="includeIds" item="item" open="("
                     separator="," close=")">
                #{item}
            </foreach>
        </if>
		<if test="excludeIds != null and excludeIds.size() >0 ">
            and t1.rqc_line_id not in
            <foreach collection="excludeIds" item="item" open="("
                     separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="includeHIds != null and includeHIds.size() >0 ">
            and t1.rqc_header_id in
            <foreach collection="includeHIds" item="item" open="("
                     separator="," close=")">
                #{item}
            </foreach>
        </if>
		<if test="excludeHIds != null and excludeHIds.size() >0 ">
            and t1.rqc_header_id not in
            <foreach collection="excludeHIds" item="item" open="("
                     separator="," close=")">
                #{item}
            </foreach>
        </if>
		<if test="printStatus != null  and printStatus !=''">
			<choose>
				<when test="printStatus != null and printStatus == 1">
					AND t1.second_status = '1'
				</when>
				<otherwise>
					AND (t1.second_status = '0' or t1.second_status is null)
				</otherwise>
			</choose>
		</if>
		order by t1.gmt_modified
		desc
	</select>
	
	<select id="findByPkId" resultMap="mainMap" parameterType="String">
		select
		<include refid="mainClomuns"></include>
		t2.WAREHOUSE_AREA_CODES as warehouseAreaCodes,
		t2.ITEM_IS_PIECE_OR_CASE as itemIsPieceOrCase,
		t2.WAREHOUSE_AREA_CATEGORYS as warehouseAreaCategorys,
		t2.ITEM_VOLUME,
		t2.ITEM_WEIGHT,
		t2.ITEM_HEALTH_TWOVOTEFLAG,
		t2.WAREHOUSE_NAME,
		t2.WAREHOUSE_AREA_NAME,
		t3.ITEM_NUM,
		t3.ITEM_NAME,
		t3.CATEGORY_NAME,
		t3.ITEM_BARCODE,
		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.ITEM_IS_RECHECK as itemIsRecheck,
		t3.IS_INSTRUMENT as isInstrument,
		t3.ITEM_IS_IMPORTED as itemIsImported,
		
		t3.MANUFACTURER_ID as manufacturerId,
		t3.MANUFACTURER_CODE as manufacturerCode,
		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
		
		FROM
		wms_in_rqc_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
		t1.rqc_line_id = #{pkId}
	</select>
	<select id="getReport" resultMap="mainMap">
		select
		distinct
		<include refid="mainClomuns"></include>
		t1.WH_AREA_CATEGORY as whAreaCategory,
		t1.WH_AREA_CODES as whAreaCodes,
		t2.WAREHOUSE_AREA_CODES as warehouseAreaCodes,
		t2.ITEM_IS_PIECE_OR_CASE as itemIsPieceOrCase,
		t2.WAREHOUSE_AREA_CATEGORYS as warehouseAreaCategorys,
		t2.ITEM_VOLUME,
		t2.ITEM_WEIGHT,
		t2.ITEM_HEALTH_TWOVOTEFLAG,
		t2.WAREHOUSE_NAME,
		t2.WAREHOUSE_AREA_NAME,
		t3.ITEM_NUM,
		t3.ITEM_NAME,
		t3.CATEGORY_NAME,
		t3.ITEM_BARCODE,
		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.ITEM_IS_RECHECK as itemIsRecheck,
		t3.IS_INSTRUMENT as isInstrument,
		t3.ITEM_IS_IMPORTED as itemIsImported,
		
		t3.MANUFACTURER_ID as manufacturerId,
		t3.MANUFACTURER_CODE as manufacturerCode,
		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,
		
		t4.bill_date as rqcDate,
		t6.vendor_name as vendorName,
		t5.executor_user as rcvUser,
		t6.orgn_name as orgnName,
		t6.mtl_owner_name as mtlOwnerName,
		t6.buyer_mane as linkMan,
		t5.asn_auto_bill_num as poNum,
		t2.BATCH_PRODUCTION_DATE as batchProductionDate,
		t2.BATCH_EXPIRED_DATE as batchExpiredDate,
		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_rqc_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
		LEFT JOIN
		wms_in_rqc_headers t4
		on t1.rqc_header_id = t4.rqc_header_id
		LEFT JOIN
		wms_in_rcv_headers t5
		on t1.rcv_header_id = t5.rcv_header_id
		LEFT JOIN
		WMS_IN_RCV_HEADERS_PROFILES t6
		on t1.rcv_header_id = t6.rcv_header_id
		where
		1=1
		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(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>
	<select id="findCountByRcvHeaderId" resultType="Long">
		<!-- SELECT COUNT(RQC_LINE_ID) FROM WMS_IN_RQC_LINES WHERE RCV_HEADER_ID = #{rcvHeaderId} AND PIECE_QTY &lt;&gt; 0 -->
		<!-- SELECT COUNT(1) FROM WMS_IN_RQC_HEADERS WHERE RCV_HEADER_ID = #{rcvHeaderId} -->
		SELECT COUNT(1) FROM WMS_IN_RQC_HEADERS head WHERE head.RCV_HEADER_ID = #{rcvHeaderId} AND EXISTS (SELECT temp.RQC_HEADER_ID,temp.sum  FROM( SELECT RQC_HEADER_ID,SUM(PIECE_QTY) sum FROM WMS_IN_RQC_LINES line  GROUP BY line.RQC_HEADER_ID) temp WHERE temp.sum &lt;&gt; 0 AND temp.RQC_HEADER_ID = head.RQC_HEADER_ID )  
	</select>
	
	<select id="getHostRqcResult" resultMap="mainMap">
		SELECT distinct
		<include refid="mainClomuns"></include>
		t1.WH_AREA_CATEGORY as whAreaCategory
		 FROM WMS_IN_RQC_LINES t1 LEFT JOIN WMS_IN_RCV_HEADERS t2 ON t1.RCV_HEADER_ID = t2.RCV_HEADER_ID
		  WHERE t2.RCV_TYPE = '8' AND t1.ITEM_ID = #{itemId} AND t1.BATCH_ID = #{batchId}
	</select>

	<select id="findListNew" resultMap="mainMap">
		select
		distinct
		<include refid="mainClomuns"></include>
		t1.WH_AREA_CATEGORY as whAreaCategory,
		t1.WH_AREA_CODES as whAreaCodes,
		t2.IS_RETROSPECT as isRetpospect,
		t2.APPROVAL_NUMBER as approvalNumber,
		t2.ATTRIBUTE1 as itemHealthType,
		t2.WAREHOUSE_AREA_CODES as warehouseAreaCodes,
		t2.ITEM_IS_PIECE_OR_CASE as itemIsPieceOrCase,
		t2.WAREHOUSE_AREA_CATEGORYS as warehouseAreaCategorys,
		t2.ITEM_VOLUME,
		t2.ITEM_WEIGHT,
		t2.ITEM_HEALTH_TWOVOTEFLAG,
		t2.WAREHOUSE_NAME,
		t2.WAREHOUSE_AREA_NAME,
		t3.ITEM_NUM,
		t3.ITEM_NAME,
		t3.CATEGORY_NAME,
		t3.ITEM_BARCODE,
		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.ITEM_IS_RECHECK as itemIsRecheck,
		t3.IS_INSTRUMENT as isInstrument,
		t3.ITEM_IS_IMPORTED as itemIsImported,

		t3.MANUFACTURER_ID as manufacturerId,
		t3.MANUFACTURER_CODE as manufacturerCode,
		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,

		t4.bill_date as rqcDate,
		t4.qc_operator1 as rqcUser,
		coalesce(t6.vendor_name,t6.CUSTOMER_NAME) as vendorName,
		t6.vendor_num as vendorNum,
		t5.executor_user as rcvUser,
		t6.orgn_name as orgnName,
		t6.mtl_owner_name as mtlOwnerName,
		t6.buyer_mane as linkMan,
		t5.auto_bill_num as rcvNo,
		t5.asn_auto_bill_num as poNum,
		t5.auto_bill_num as rqcNo,
		t5.gmt_modified as rcvDate,
		CASE
		WHEN t5.RCV_TYPE = '1' THEN '采购入库'
		WHEN t5.RCV_TYPE = '2' THEN '销退入库'
		ELSE '采购入库'
		END AS billTypeName,
		t2.BATCH_PRODUCTION_DATE as batchProductionDate,
		t2.BATCH_EXPIRED_DATE as batchExpiredDate,
		t2.show_production_date as showProductionDate,
		t2.show_expired_date as showExpiredDate,
		t5.sale_bill_type as saleBillType,
		t4.REMARK as remarks,
		t7.WH_AREA_CATEGORY_CODE as whAreaCategoryCode,
		t7.WH_LOCATOR_ID as whLocatorId,
		t7.WH_LOCATOR_CODE as whLocatorCode,
		t7.WH_LOCATOR_NAME as whLocatorName,
		t7.BLDG_CODE as bldgCode,
		t7.WH_AREA_CODE as whAreaCode,
		t7.INSTOCK_LABEL as instockLabel,
		t7.LOCATOR_FLOOR_NUM as locatorFloorNum,
		t2.RCV_RT_REASON as rcvRtReason,
		coalesce(t8.phone_mobile,t8.phone) as vendorPhone
		FROM
		wms_in_rqc_lines t1
		JOIN
		WMS_IN_RCV_LINES t2
		on t1.rcv_line_id = t2.RCV_LINE_ID
		JOIN
		WMS_IN_RCV_LINES_PROFILES t3
		on t1.rcv_line_id = t3.RCV_LINE_ID
		JOIN
		wms_in_rqc_headers t4
		on t1.rqc_header_id = t4.rqc_header_id
		left join
		upcloud_base_chain_qingniu.base_supplier_contacts_all t8
		on t4.vendor_id = t8.supplier_id
		JOIN
		wms_in_rcv_headers t5
		on t1.rcv_header_id = t5.rcv_header_id
		JOIN
		WMS_IN_RCV_HEADERS_PROFILES t6
		on t1.rcv_header_id = t6.rcv_header_id
		LEFT JOIN
		WMS_IN_TASK_INSTOCK_DETAIL t7
		on t1.rcv_line_id = t7.rcv_line_id
		where
		1=1 and t1.stock_status in('0','1')
		<if test="enterpriseId != null  and enterpriseId !=''">
			and t1.enterprise_id = #{enterpriseId}
		</if>
		<if test="itemHealthIsDouble != null">
			and t7.TASK_INBOUND_ID is not null
		</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="rcvLineId != null  and rcvLineId !=''">
			and t1.rcv_line_id = #{rcvLineId}
		</if>
		<if test="rqcHeaderId != null  and rqcHeaderId !=''">
			and t1.rqc_header_id = #{rqcHeaderId}
		</if>
		<if test="itemId != null  and itemId !=''">
			and t1.item_id = #{itemId}
		</if>
		<if test="stockStatus != null  and stockStatus !=''">
			and t1.stock_status = #{stockStatus}
		</if>
		<if test="includeIds != null and includeIds.size() >0 ">
			and t1.rqc_line_id in
			<foreach collection="includeIds" item="item" open="("
					 separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="excludeIds != null and excludeIds.size() >0 ">
			and t1.rqc_line_id not in
			<foreach collection="excludeIds" item="item" open="("
					 separator="," close=")">
				#{item}
			</foreach>
		</if>
		<!-- 6.11新加 -->
		<if test="includeHIds != null and includeHIds.size() >0 ">
			and t1.rqc_header_id in
			<foreach collection="includeHIds" item="item" open="("
					 separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="excludeHIds != null and excludeHIds.size() >0 ">
			and t1.rqc_header_id not in
			<foreach collection="excludeHIds" item="item" open="("
					 separator="," close=")">
				#{item}
			</foreach>
		</if>
		<!-- 6.11新加 -->
		order by t1.gmt_modified
		desc
	</select>
</mapper>
