<?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.GspUnqualifiedLossDMapper">
	<resultMap id="map" type="com.prolog.cs.base.gsp.model.GspUnqualifiedLossD">
		<result column="id" property="id"/>
		<result column="code" property="code"/>
		<result column="loss_id" property="lossId"/>
		<result column="loss_code" property="lossCode"/>
		<result column="enterprise_id" property="enterpriseId"/>
		<result column="dc_id" property="dcId"/>
		<result column="warehouse_id" property="warehouseId"/>
		<result column="cargo_owner_id" property="cargoOwnerId"/>
		<result column="locator_id" property="locatorId"/>
		<result column="locator_code" property="locatorCode"/>
		<result column="item_id" property="itemId"/>
		<result column="item_code" property="itemCode"/>
		<result column="lot_num" property="lotNum"/>
		<result column="unqualified_qty" property="unqualifiedQty"/>
		<result column="unqualified_reason" property="unqualifiedReason"/>
		<result column="quality_status" property="qualityStatus"/>
		<result column="opinion" property="opinion"/>
		<result column="ref_bill_id" property="refBillId"/>
		<result column="REF_BILL_TYPE" property="refBillType"/>
		<result column="status" property="status"/>
		<result column="loss_qty" property="lossQty"/>
		<result column="destroying_qty" property="destroyingQty"/>
		<result column="destroyed_qty" property="destroyedQty"/>
		<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="remark" property="remark"/>
		<result column="batch_id" property="batchId"/>
		<result column="seq_no" property="seqNo"/>
	</resultMap>

	<select id="listPagePick" resultMap="map">
		SELECT
		c.*
		FROM
		gsp_unqualified_loss_d c
		WHERE c.STATUS=20 and c.LOSS_QTY &gt; c.DESTROYING_QTY
		<if test="enterpriseId != null  and enterpriseId !=''">
			and c.enterprise_id = #{enterpriseId}
		</if>
		<if test="warehouseId != null  and warehouseId !=''">
			and c.warehouse_id = #{warehouseId}
		</if>
		<if test="cargoOwnerId != null  and cargoOwnerId !=''">
			and c.CARGO_OWNER_ID = #{cargoOwnerId}
		</if>
		<if test="itemId != null  and itemId !=''">
			and c.ITEM_ID = #{itemId}
		</if>
		<if test="lossCode != null  and lossCode !=''">
			and c.loss_code like concat(concat('%',#{lossCode}),'%')
		</if>
		order by c.GMT_CREATE asc
	</select>
	
	<update id="updateDestroyedQty" >
		UPDATE gsp_unqualified_loss_d set DESTROYED_QTY = DESTROYED_QTY+#{destroyedQty}  WHERE id = #{id}
	</update>

	<update id="updateDestroyingQty" >
		UPDATE gsp_unqualified_loss_d set DESTROYING_QTY = DESTROYING_QTY+#{destroyingQty}  WHERE id = #{id}
	</update>
	
</mapper>
