<?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.RqcReHeadersMapper">
<resultMap id="mainMap" type="com.prolog.cs.biz.inbound.dto.rqc.RqcReHeadersDTO">
	<result column="rqc_re_header_id" property="rqcReHeaderId"/>
	<result column="custom_bill_num" property="customBillNum"/>
	<result column="auto_bill_num" property="autoBillNum"/>
	<result column="mtl_owner_id" property="mtlOwnerId"/>
	<result column="warehouse_id" property="warehouseId"/>
	<result column="vendor_id" property="vendorId"/>
	<result column="src_bill_type" property="srcBillType"/>
	<result column="src_header_id" property="srcHeaderId"/>
	<result column="asn_header_id" property="asnHeaderId"/>
	<result column="rcv_header_id" property="rcvHeaderId"/>
	<result column="bill_date" property="billDate"/>
	<result column="status" property="status"/>
	<result column="remark" property="remark"/>
	<result column="work_bench" property="workBench"/>
	<result column="qc_operator1" property="qcOperator1"/>
	<result column="qc_operator2" property="qcOperator2"/>
	<result column="data_src_type" property="dataSrcType"/>
	<!-- <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="enterprise_id" property="enterpriseId"/> -->
</resultMap>
<sql id="mainClomuns">
		t1.rqc_re_header_id,
		t1.custom_bill_num,
		t1.auto_bill_num,
		t1.mtl_owner_id,
		t1.warehouse_id,
		t1.vendor_id,
		t1.src_bill_type,
		t1.src_header_id,
		t1.asn_header_id,
		t1.rcv_header_id,
		t1.bill_date,
		t1.status,
		t1.remark,
		t1.work_bench,
		t1.qc_operator1,
		t1.qc_operator2,
		t1.data_src_type,
		t1.ENTERPRISE_ID,
		t1.GMT_CREATE,
		t1.CREATOR,
		t1.CREATOR_NAME,
		t1.GMT_MODIFIED,
		t1.MODIFIER,
		t1.MODIFIER_NAME ,
	</sql>
	
	<select id="findList" resultMap="mainMap">
		select
		distinct
		<include refid="mainClomuns"></include>
			t2.rcv_date as rcvDate,
			t2.rcv_type as rcvType,
			t3.ship_type as shipType,
			t3.arrival_mode as arrivalMode,
			t3.vendor_name as vendorName,
			t3.warehouse_name as warehouseName,
			t3.buyer_mane as buyerMane,
			t3.customer_name as customerName,
			t3.mtl_owner_name as mtlOwnerName,
			t3.ORGN_NAME  as orgnName
		FROM
			wms_in_rqc_re_headers t1 
		
		LEFT JOIN wms_in_rcv_headers t2 on t1.RCV_HEADER_ID = t2.RCV_HEADER_ID
		LEFT JOIN wms_in_rcv_headers_profiles t3 on t1.RCV_HEADER_ID = t3.RCV_HEADER_ID	 
		WHERE
			1=1
		<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="status != null  and status !=''">
			and t1.status = #{status}
		</if>	
		<if test="autoBillNum != null  and autoBillNum !=''">
			and t1.auto_bill_num = #{autoBillNum}
		</if>
	<!-- 	<if test="rcvType != null  and rcvType !=''">
			and t2.rcv_type = #{rcvType}
		</if> -->
		<if test="customBillNum != null  and customBillNum !=''">
			and t1.custom_bill_num like CONCAT(CONCAT('%',#{customBillNum}),'%')
		</if>
		order by t1.gmt_modified
		desc
	</select>
	<select id="findByPkId" resultMap="mainMap" parameterType="String">
		select
		distinct
		<include refid="mainClomuns"></include>
			t2.rcv_date as rcvDate,
			t2.rcv_type as rcvType,
			t3.ship_type as shipType,
			t3.arrival_mode as arrivalMode,
			t3.vendor_name as vendorName,
			t3.warehouse_name as warehouseName,
			t3.buyer_mane as buyerMane,
			t3.customer_name as customerName,
			t3.mtl_owner_name as mtlOwnerName,
			t3.ORGN_NAME  as orgnName
		FROM
			wms_in_rqc_re_headers t1 
		LEFT JOIN wms_in_rcv_headers t2 on t1.RCV_HEADER_ID = t2.RCV_HEADER_ID
		LEFT JOIN wms_in_rcv_headers_profiles t3 on t1.RCV_HEADER_ID = t3.RCV_HEADER_ID	 
		WHERE
		t1.rqc_re_header_id = #{pkId}
	</select>
</mapper>
