<?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.base.gsp.dao.DxiGspQualityReviewHMapper">
	<resultMap id="map" type="com.prolog.cs.base.gsp.model.DxiGspQualityReviewH">
		<result column="BILLID" property="billid"/>
		<result column="BILLNO" property="billno"/>
		<result column="BRANCHID" property="branchid"/>
		<result column="BRANCHCODE" property="branchcode"/>
		<result column="BRANCHNAME" property="branchname"/>
		<result column="CONSIGNORID" property="consignorid"/>
		<result column="CONSIGNORCODE" property="consignorcode"/>
		<result column="CONSIGNORNAME" property="consignorname"/>
		<result column="REF_BILLTYPE" property="refBilltype"/>
		<result column="REQUEST_BILLTYPE" property="requestBilltype"/>
		<result column="REQUEST_BILLID" property="requestBillid"/>
		<result column="REQUEST_BILLNO" property="requestBillno"/>
		<result column="OPERATOR" property="operator"/>
		<result column="BILL_DATE" property="billDate"/>
		<result column="REVIEW_REASON" property="reviewReason"/>
		<result column="STATUS" property="status"/>
		<result column="REMARK" property="remark"/>
		<result column="ATTR_STR1" property="attrStr1"/>
		<result column="ATTR_STR2" property="attrStr2"/>
		<result column="ATTR_STR3" property="attrStr3"/>
		<result column="ATTR_STR4" property="attrStr4"/>
		<result column="ATTR_STR5" property="attrStr5"/>
		<result column="CREATEBY" property="createby"/>
		<result column="CREATEDATE" property="createdate"/>
		<result column="LASTMODIFYBY" property="lastmodifyby"/>
		<result column="LASTMODIFYDATE" property="lastmodifydate"/>
		<result column="P_ENTERPRISEID" property="enterpriseid"/>
		<result column="P_ENTERPRISENAME" property="enterprisename"/>
		<result column="WAREHOUSE_ID" property="warehouseId"/>
	</resultMap>


	<select id="findList" resultMap="map">
		SELECT
		h.*
		FROM
		DXI_GSP_QUALITY_REVIEW_H h
		WHERE
		EXISTS (
		SELECT
		*
		FROM
		DXI_GSP_QUALITY_REVIEW_D d
		WHERE
		h.billid = d.billid
		<if test="endStatus != null  and endStatus !=''">
			and d.end_status = #{endStatus}
		</if>
		<if test="itemId != null  and itemId !=''">
			and d.itemid = #{itemId}
		</if>
		)
		<if test="enterpriseId != null  and enterpriseId !=''">
			and h.enterpriseid = #{enterpriseId}
		</if>
		<if test="warehouseId != null  and warehouseId !=''">
			and h.branchid = #{warehouseId}
		</if>
		<if test="cargoOwnerId != null  and cargoOwnerId !=''">
			and h.consignorid = #{cargoOwnerId}
		</if>
		order by h.CREATEDATE desc
	</select>


	<select id="findNoEnd" resultMap="map">
		SELECT * FROM DXI_GSP_QUALITY_REVIEW_H h WHERE BILLID IN (
		SELECT DISTINCT(BILLNO)
		FROM DXI_GSP_QUALITY_REVIEW_D
		WHERE END_STATUS = #{status} )
		<if test="branchcode != null  and branchcode !=''">
			and h.BRANCHCODE = #{branchcode}
		</if>
		<if test="consignorcode != null  and consignorcode !=''">
			and h.CONSIGNORCODE = #{consignorcode}
		</if>
		<if test="requestBilltype != null  and requestBilltype !=''">
			and h.REQUEST_BILLTYPE = #{requestBilltype}
		</if>
		<if test="billNo != null  and billNo !=''">
			and h.BILLNO = #{billNo}
		</if>
		order by h.CREATEDATE desc
	</select>

</mapper>
