<?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.GspUpkeepCheckMapper">
	<resultMap id="map" type="com.prolog.cs.base.gsp.model.GspUpkeepCheck">
		<result column="id" property="id"/>
		<result column="code" property="code"/>
		<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="batch_id" property="batchId"/>
		<result column="plan_id" property="planId"/>
		<result column="plan_code" property="planCode"/>
		<result column="item_id" property="itemId"/>
		<result column="item_code" property="itemCode"/>
		<result column="LOT_NUM" property="lotNum"/>
		<result column="locator_id" property="locatorId"/>
		<result column="locator_code" property="locatorCode"/>
		<result column="stock_qty" property="stockQty"/>
		<result column="upkeep_qty" property="upkeepQty"/>
		<result column="pending_qty" property="pendingQty"/>
		<result column="IS_PROTECTED" property="isProtected"/>
		<result column="UPKEEP_TYPE" property="upkeepType"/>
		<result column="upkeep_operator" property="upkeepOperator"/>
		<result column="status" property="status"/>
		<result column="source_type" property="sourceType"/>
		<result column="upkeep_conclusion" property="upkeepConclusion"/>
		<result column="check_conclusion" property="checkConclusion"/>
		<result column="recheck_conclusion" property="recheckConclusion"/>
		<result column="conclusion" property="conclusion"/>
		<result column="process_opinion" property="processOpinion"/>
		<result column="check_operator" property="checkOperator"/>
		<result column="check_opinion" property="checkOpinion"/>
		<result column="recheck_operator" property="recheckOperator"/>
		<result column="recheck_opinion" property="recheckOpinion"/>
		<result column="check_wai_guan" property="checkWaiGuan"/>
		<result column="check_bao_zhuang" property="checkBaoZhuang"/>
		<result column="check_chen_chu_tiao_jian" property="checkChenChuTiaoJian"/>
		<result column="check_fan_duo" property="checkFanDuo"/>
		<result column="check_chu_shi" property="checkChuShi"/>
		<result column="check_jia_shi" property="checkJiaShi"/>
		<result column="check_shen_wen" property="checkShenWen"/>
		<result column="check_jiang_wen" property="checkJiangWen"/>
		<result column="check_tong_feng" property="checkTongFeng"/>
		<result column="check_chu_chen" property="checkChuChen"/>
		<result column="check_zhe_guang" property="checkZheGuang"/>
		<result column="check_bi_guang" property="checkBiGuang"/>
		<result column="quality_status" property="qualityStatus"/>
		<result column="ths_tatus" property="thsTatus"/>
		<result column="pending_reason" property="pendingReason"/>
		<result column="plan_upkeep_date" property="planUpkeepDate"/>
		<result column="upkeep_date" property="upkeepDate"/>
		<result column="check_date" property="checkDate"/>
		<result column="recheck_date" property="recheckDate"/>
		<result column="PDATE_FROM" property="pdateFrom"/>
		<result column="VALID_UNTIL" property="validUntil"/>
		<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="BLDG_ID" property="bldgId"/>
		<result column="ITEM_HEALTH_CATEGORY" property="itemHealthCategory"/>
		<result column="IS_NEAR_DATE" property="isNearDate"/>
		<result column="PLAN_STOCK_QTY" property="planStockQty"/>
	</resultMap>

    <update id="updateOutboundInstructById">
		UPDATE gsp_upkeep_check SET outbound_instruct = 2,GMT_MODIFIED = #{now} WHERE id in
		<foreach collection="ids" index="index" item="id" close=")" open="(" separator=",">
			#{id}
		</foreach>
	</update>


    <select id="findList" resultMap="map">
		SELECT
		*
		FROM
		GSP_UPKEEP_CHECK c
		WHERE 1=1
		<if test='type != null and type =="1"'>
			and c.STATUS = 0
		</if>
		<if test='type != null and type =="2"'>
			and c.conclusion = 2 and status &lt;&gt; 6
		</if>
		<if test="upkeepType != null  and upkeepType !=''">
			and c.UPKEEP_TYPE = #{upkeepType}
		</if>
		<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="itemHealthCategory != null  and itemHealthCategory !=''">
			and c.ITEM_HEALTH_CATEGORY = #{itemHealthCategory}
		</if>
		<if test="itemId != null  and itemId !=''">
			and c.ITEM_ID = #{itemId}
		</if>
		<!-- 根据执行时间来做 -->
		<if test="startTime != null ">
			and c.PLAN_UPKEEP_DATE  &gt;= #{startTime}
		</if>
		<if test="endTime != null ">
			and c.PLAN_UPKEEP_DATE &lt; #{endTime}
		</if>
		<if test="isProtected != null ">
			and c.IS_PROTECTED = #{isProtected}
		</if>
		<if test="planId != null and planId !=''">
			and c.plan_id = #{planId}
		</if>
		order by LOCATOR_CODE,ITEM_CODE,LOT_NUM asc
	</select>

    <select id="findUpkeepPageByRf" resultType="com.prolog.cs.base.gsp.vo.RfGspUpkeepCheckVO">
		SELECT id, WAREHOUSE_ID, CARGO_OWNER_ID, ITEM_ID, LOCATOR_ID
			 , LOCATOR_CODE, LOT_NUM, plan_Stock_Qty
		FROM GSP_UPKEEP_CHECK
		WHERE ENTERPRISE_ID = #{enterpriseId}
		  AND WAREHOUSE_ID = #{warehouseId}
		  AND UPKEEP_CONCLUSION = 0
		  <if test="itemBarcode!=null and itemBarcode!=''">
			  AND item_barcode like concat(#{itemBarcode},'%')
		  </if>
		<if test="containerCode!=null and containerCode!=''">
			AND container_code like concat(#{containerCode},'%')
		</if>
		order by container_code
	</select>

</mapper>
