<?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.failure.ExceptionLogMapper">
	<resultMap id="mainMap" type="com.prolog.cs.biz.inbound.dto.failure.ExceptionLogQueryDTO">
		<result column="exception_log_id" property="exceptionLogId"/>
		<result column="exception_line_id" property="exceptionLineId"/>
		<result column="exception_header_id" property="exceptionHeaderId"/>
		<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="line_num" property="lineNum"/>
		<result column="mtl_owner_id" property="mtlOwnerId"/>
		<result column="warehouse_id" property="warehouseId"/>
		<result column="item_id" property="itemId"/>
		<result column="container_code" property="containerCode"/>
		<result column="goods_case_code" property="goodsCaseCode"/>
		<result column="batch_id_old" property="batchIdOld"/>
		<result column="batch_num_old" property="batchNumOld"/>
		<result column="production_date_old" property="productionDateOld"/>
		<result column="expired_date_old" property="expiredDateOld"/>
		<result column="vendor_batch_num_old" property="vendorBatchNumOld"/>
		<result column="manufacturer_lot_num_old" property="manufacturerLotNumOld"/>
		<result column="batch_id_new" property="batchIdNew"/>
		<result column="batch_num_new" property="batchNumNew"/>
		<result column="production_date_new" property="productionDateNew"/>
		<result column="expired_date_new" property="expiredDateNew"/>
		<result column="vendor_batch_num_new" property="vendorBatchNumNew"/>
		<result column="manufacturer_lot_num_new" property="manufacturerLotNumNew"/>
		<result column="qty_old" property="qtyOld"/>
		<result column="qty_new" property="qtyNew"/>
		<result column="uom" property="uom"/>
		<result column="uom_type" property="uomType"/>
		<result column="conversion_rate" property="conversionRate"/>
		<result column="piece_qty_old" property="pieceQtyOld"/>
		<result column="piece_qty_new" property="pieceQtyNew"/>
		<result column="executor_user" property="executorUser"/>
		<result column="executor_date" property="executorDate"/>
		<result column="node_type" property="nodeType"/>
		<result column="node_task_id" property="nodeTaskId"/>
		<result column="src_bill_type" property="srcBillType"/>
		
		<!-- <result column="creator" property="creator"/>
		<result column="creator_name" property="creatorName"/>
		<result column="gmt_create" property="gmtCreate"/>
		<result column="modifier" property="modifier"/>
		<result column="modifier_name" property="modifierName"/>
		<result column="gmt_modified" property="gmtModified"/>
		<result column="enterprise_id" property="enterpriseId"/> -->
		
		<result column="ITEM_VOLUME" property="itemVolume" />
		<result column="ITEM_WEIGHT" property="itemWeight" />
		<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.exception_log_id,
		t1.exception_line_id,
		t1.exception_header_id,
		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.line_num,
		t1.mtl_owner_id,
		t1.warehouse_id,
		t1.item_id,
		t1.container_code,
		t1.goods_case_code,
		t1.batch_id_old,
		t1.batch_num_old,
		t1.production_date_old,
		t1.expired_date_old,
		t1.vendor_batch_num_old,
		t1.manufacturer_lot_num_old,
		t1.batch_id_new,
		t1.batch_num_new,
		t1.production_date_new,
		t1.expired_date_new,
		t1.vendor_batch_num_new,
		t1.manufacturer_lot_num_new,
		t1.qty_old,
		t1.qty_new,
		t1.uom,
		t1.uom_type,
		t1.conversion_rate,
		t1.piece_qty_old,
		t1.piece_qty_new,
		t1.executor_user,
		t1.executor_date,
		t1.node_type,
		t1.node_task_id,
		t1.src_bill_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.ITEM_VOLUME,
			t2.ITEM_WEIGHT,
			t2.WAREHOUSE_NAME,
			t2.WAREHOUSE_AREA_NAME,
			t3.ITEM_NUM,
			t3.ITEM_NAME,
			t3.CATEGORY_NAME,
			t3.ITEM_BARCODE
		FROM
		wms_in_exception_log 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="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="exceptionHeaderId != null  and exceptionHeaderId !=''">
			and t1.exception_header_id = #{exceptionHeaderId}
		</if>
		<if test="exceptionLineId != null  and exceptionLineId !=''">
			and t1.exception_line_id = #{exceptionLineId}
		</if>
		<if test="nodeType != null  and nodeType !=''">
			and t1.node_type = #{nodeType}
		</if>
		<if test="itemId != null  and itemId !=''">
			and t1.item_id = #{itemId}
		</if>
		<!-- 根据执行时间来做 -->
		<if test="startTime != null ">
			and t1.executor_date  &gt;= #{startTime}
		</if>
		<if test="endTime != null ">
			and t1.executor_date &lt;= #{endTime}
		</if>
		order by t1.gmt_modified
		desc
	</select>
	<select id="findByPkId" resultMap="mainMap">
		select
		<include refid="mainClomuns"></include>
			t2.ITEM_VOLUME,
			t2.ITEM_WEIGHT,
			t2.WAREHOUSE_NAME,
			t2.WAREHOUSE_AREA_NAME,
			t3.ITEM_NUM,
			t3.ITEM_NAME,
			t3.CATEGORY_NAME,
			t3.ITEM_BARCODE
		FROM
		wms_in_exception_log 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.exception_log_id = #{pkId}
	</select>
</mapper>
