<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍订单接箍利库">
	<query id="CoreJgMPropMatch.selectBaseInfoSort" desc="基础信息">
		<![CDATA[
			SELECT T.BASECODE, T.BASENAME
			  FROM COM_BASE_INFO T
			 WHERE T.SORTCODE = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CoreJgMPropMatch.getPlnGxJgMStatus" desc="查询接箍工序订单">
		<![CDATA[
			SELECT T.CODE_JG,
			       T.PLINE_CODE,
			       T.CODE_JG_BL,
			       T.PLANSTATUS,
			       T.AIMLENGTH,
			       T.MATCHWEIGHT,
			       T.MATCHNUM,
			       TO_NUMBER(M.LENGTH_JG) LENGTH_JG,
			       T1.GROUP_STATUS,
			       T1.GROUP_NUM,
			       T1.DEMAND_DETECTION,
			       T1.DEMAND_BONDERIZING,
			       T1.DEMAND_COPPER,
			       T1.DEMAND_BLAST,
			       T1.MATCHWT_BL,
			       T1.MATCHNUM_BL,
			       T1.BATCHED_WT,
			       T1.BATCHED_NUM,
			       NVL(T1.MATCHNUM_JG, 0) MATCHNUM_JG
			  FROM PLN_GX_JG_M T
			  LEFT JOIN COM_MSC_JG M
			    ON M.CODE_JG = T.CODE_JG, PLN_GX_JG_PROP T1
			 WHERE T1.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND T.PRO_PLAN_ID = ?
			   AND T1.JG_GROUP_ID = ?
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.queryJgMButtress" desc="查询接箍利库记录">
		<![CDATA[
			SELECT T1.MAT_NO,
             T1.MAT_NO_XH,
             T1.OFFLINE_LOG,
             T1.PRODUCT_FLAG,
             T1.MAT_STATUS,
             T1.JUDGE_STOVE_NO,
             T1.BATCH_NO,
             T1.PIECES,
             T1.WEIGHT,
             T1.DEMAND_COPPER,
             T1.DEMAND_DETECTION,
             T1.DEMAND_BLAST,
             T1.DEMAND_BONDERIZING,
             T1.CUST_ALPHA_NO,
             T1.ORDER_SPECIAL_DESC,
             T1.ALPHA_CODE,
             T1.Demand_Copper_Lk,
             T1.Demand_Detection_Lk,
             T1.Demand_Blast_Lk,
             T1.Demand_Bonderizing_Lk,
             T1.IMPRESS_DEAL_STATUS,
             T1.COPPER_DEAL_STATUS,
             T1.DETECT_DEAL_STATUS,
             T1.BLAST_DEAL_STATUS,
             T1.PLT_CU_DEAL_STATUS,
             T1.PHOS_DEAL_STATUS,
             M.ALPHA_NAME,
             T.CODE_JG,
             T.GRADECODE,
             T.GRADENAME,
             T.STEELCODE,
             T.STEELNAME,
             T.MODEL_CODE,
             T.MODEL_DESC,
             T.OUTDIAMETER,
             T.WALLTHICK,
             T.SPEC_JG,
             T.SPEC_JG_DESC,
             T.STYLE_JG,
             T.DIAMETER,
             T.CHECK_J_VAL,
             T.AIMLENGTH,
             T.SINGLEWEIGHT
        FROM COUPLING_MAT_M        T,
             COUPLING_MAT_BUTTRESS T1,
             PLN_GX_JG_M           M,
             PLN_GX_JG_PROP        M1
       WHERE T1.MAT_NO = T.MAT_NO
         AND M.CODE_JG = T.CODE_JG
         AND M.CUST_ALPHA_NO = T1.CUST_ALPHA_NO
         AND M.ALPHA_CODE = T1.ALPHA_CODE
         AND T1.PRO_PLAN_ID = M1.PRO_PLAN_ID
         AND T1.JG_GROUP_ID = M1.JG_GROUP_ID
         AND M1.PRO_PLAN_ID = M.PRO_PLAN_ID
         AND M1.PRO_PLAN_ID = ?
         AND M1.JG_GROUP_ID = ?
         AND T1.LOCK_LIKU = 1
		]]>
	</query>
		
	
	<query id="CoreJgMPropMatch.queryMatch" desc="查询接箍利库库存">
		<![CDATA[
			SELECT T1.MAT_NO,
             T1.MAT_NO_XH,
             T1.OFFLINE_LOG,
             T1.PRODUCT_FLAG,
             T1.MAT_STATUS,
             T1.JUDGE_STOVE_NO,
             T1.BATCH_NO,
             0 CHECKED_NUM,
             T1.PIECES,
             T1.WEIGHT,
             T1.DEMAND_COPPER,
             T1.DEMAND_DETECTION,
             T1.DEMAND_BLAST,
             T1.DEMAND_BONDERIZING,
             T1.CUST_ALPHA_NO,
             T1.ORDER_SPECIAL_DESC,
             T1.ALPHA_CODE,
             M.ALPHA_NAME,
             T.CODE_JG,
             T.GRADECODE,
             T.GRADENAME,
             T.STEELCODE,
             T.STEELNAME,
             T.MODEL_CODE,
             T.MODEL_DESC,
             T.OUTDIAMETER,
             T.WALLTHICK,
             T.SPEC_JG,
             T.SPEC_JG_DESC,
             T.STYLE_JG,
             T.DIAMETER,
             T.CHECK_J_VAL,
             T.AIMLENGTH,
             T.SINGLEWEIGHT
        FROM COUPLING_MAT_M        T,
             COUPLING_MAT_BUTTRESS T1,
             PLN_GX_JG_M           M,
             PLN_GX_JG_PROP        M1
       WHERE T1.MAT_NO = T.MAT_NO
         AND T1.OFFLINE_LOG = '0'
         AND T1.PRODUCT_FLAG = '801401'
         AND T1.MAT_STATUS = '80150102'
         AND T1.PRO_PLAN_ID IS NULL
         AND M.CODE_JG = T.CODE_JG
         AND M.CUST_ALPHA_NO = T1.CUST_ALPHA_NO
         AND M.ALPHA_CODE = T1.ALPHA_CODE
         AND M1.PRO_PLAN_ID = M.PRO_PLAN_ID
         AND M1.PRO_PLAN_ID = ?
         AND M1.JG_GROUP_ID = ?
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.getMatButtreStatus" desc="查询接箍库存">
		<![CDATA[
			SELECT T.MAT_NO,
			       T.MAT_NO_XH,
			       T.PRODUCT_FLAG,
			       T.MAT_STATUS,
			       T.JUDGE_STOVE_NO,
			       T.BATCH_NO,
			       T.PRO_PLAN_ID,
			       T.PIECES,
			       T.WEIGHT,
			       T.DEMAND_COPPER,
			       T.DEMAND_DETECTION,
			       T.DEMAND_BLAST,
			       T.DEMAND_BONDERIZING,
			       T.CUST_ALPHA_NO,
			       T.ORDER_SPECIAL_DESC,
			       T.ALPHA_CODE,
			       T.KEP_NO,
			       T.STORAGE_NO,
			       T.LOCATION_NO,
			       T.STORAGE_ATTR,
			       T.STORAGE_ATTR_NAME,
			       T.STORAGE_TYPE_NO,
			       T.STORAGE_TYPE_NAME,
			       T.MANAGEMENT_NO,
			       T.MANAGEMENT_NAME,
			       T.OFFLINE_LOG,
			       T.JG_GROUP_ID,
			       T.LIKU_BILL_ID
			  FROM COUPLING_MAT_BUTTRESS T
			 WHERE T.MAT_NO = ?
			   AND T.MAT_NO_XH = ?
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.updateMatButtre" desc="更新接箍库存子记录">
		<![CDATA[
			UPDATE COUPLING_MAT_BUTTRESS T
			   SET T.MAT_STATUS            = '#MAT_STATUS#',
			       T.PRO_PLAN_ID           = '#PRO_PLAN_ID#',
			       T.JG_GROUP_ID           = '#JG_GROUP_ID#',
			       T.UPDATE_NAME           = '#UPDATE_NAME#',
			       T.UPDATE_TIME           = SYSDATE,
			       T.DEMAND_COPPER_LK      = '#DEMAND_COPPER_LK#',
			       T.DEMAND_DETECTION_LK   = '#DEMAND_DETECTION_LK#',
			       T.DEMAND_BLAST_LK       = '#DEMAND_BLAST_LK#',
			       T.DEMAND_BONDERIZING_LK = '#DEMAND_BONDERIZING_LK#',
			       T.IMPRESS_DEAL_STATUS   = '#IMPRESS_DEAL_STATUS#',
			       T.COPPER_DEAL_STATUS    = '#COPPER_DEAL_STATUS#',
			       T.DETECT_DEAL_STATUS    = '#DETECT_DEAL_STATUS#',
			       T.BLAST_DEAL_STATUS     = '#BLAST_DEAL_STATUS#',
			       T.PLT_CU_DEAL_STATUS    = '#PLT_CU_DEAL_STATUS#',
			       T.PHOS_DEAL_STATUS      = '#PHOS_DEAL_STATUS#',
			       T.LOCK_LIKU             = '#LOCK_LIKU#',
			       T.LIKU_BILL_ID          = '#LIKU_BILL_ID#'
			 WHERE T.MAT_NO = '#MAT_NO#'
			   AND T.MAT_NO_XH = '#MAT_NO_XH#'
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.updateMatButtrePieces" desc="更新接箍库存子记录">
		<![CDATA[
			UPDATE COUPLING_MAT_BUTTRESS T
			   SET T.PIECES      = '#PIECES#',
			       T.WEIGHT      = '#WEIGHT#',
			       T.UPDATE_NAME = '#UPDATE_NAME#',
			       T.UPDATE_TIME = SYSDATE
			 WHERE T.MAT_NO = '#MAT_NO#'
			   AND T.MAT_NO_XH = '#MAT_NO_XH#'
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.addMatButtre" desc="新增接箍库存子记录">
		<![CDATA[
			INSERT INTO COUPLING_MAT_BUTTRESS
				  (MAT_NO,
				   MAT_NO_XH,
				   PRODUCT_FLAG,
				   MAT_STATUS,
				   JUDGE_STOVE_NO,
				   BATCH_NO,
				   RESULT_NO,
				   ZY_PLAN_ID,
				   WO_ID,
				   PRO_PLAN_ID,
				   PIECES,
				   WEIGHT,
				   IF_OUT_CUT,
				   IF_OUT_CJG,
				   IF_OUT_IMPRESS,
				   IF_OUT_LATHE,
				   IF_OUT_DETECT,
				   IF_OUT_BLAST,
				   IF_OUT_PLT_CU,
				   IF_OUT_PHOS,
				   DEMAND_COPPER,
				   DEMAND_DETECTION,
				   DEMAND_BLAST,
				   DEMAND_BONDERIZING,
				   CUST_ALPHA_NO,
				   ORDER_SPECIAL_DESC,
				   ALPHA_CODE,
				   KEP_NO,
				   STORAGE_NO,
				   LOCATION_NO,
				   STORAGE_ATTR,
				   STORAGE_ATTR_NAME,
				   STORAGE_TYPE_NO,
				   STORAGE_TYPE_NAME,
				   MANAGEMENT_NO,
				   MANAGEMENT_NAME,
				   DEMAND_COPPER_LK,
				   DEMAND_DETECTION_LK,
				   DEMAND_BLAST_LK,
				   DEMAND_BONDERIZING_LK,
				   IMPRESS_DEAL_STATUS,
				   COPPER_DEAL_STATUS,
				   DETECT_DEAL_STATUS,
				   BLAST_DEAL_STATUS,
				   PLT_CU_DEAL_STATUS,
				   PHOS_DEAL_STATUS,
				   LOCK_LIKU,
				   LIKU_BILL_ID,
				   MEMO,
				   CREATE_NAME,
				   CREATE_TIME,
				   OFFLINE_LOG,
				   JG_GROUP_ID)
				  SELECT T.MAT_NO,
				         (SELECT LPAD(NVL(MAX(TO_NUMBER(B.MAT_NO_XH)) + 1, 1), 4, '0')
				            FROM COUPLING_MAT_BUTTRESS B
				           WHERE B.MAT_NO = T.MAT_NO),
				         T.PRODUCT_FLAG,
				         '#MAT_STATUS#',
				         T.JUDGE_STOVE_NO,
				         T.BATCH_NO,
				         T.RESULT_NO,
				         T.ZY_PLAN_ID,
				         T.WO_ID,
				         '#PRO_PLAN_ID#',
				         '#PIECES#',
				         '#WEIGHT#',
				         T.IF_OUT_CUT,
				         T.IF_OUT_CJG,
				         T.IF_OUT_IMPRESS,
				         T.IF_OUT_LATHE,
				         T.IF_OUT_DETECT,
				         T.IF_OUT_BLAST,
				         T.IF_OUT_PLT_CU,
				         T.IF_OUT_PHOS,
				         T.DEMAND_COPPER,
				         T.DEMAND_DETECTION,
				         T.DEMAND_BLAST,
				         T.DEMAND_BONDERIZING,
				         T.CUST_ALPHA_NO,
				         T.ORDER_SPECIAL_DESC,
				         T.ALPHA_CODE,
				         T.KEP_NO,
				         T.STORAGE_NO,
				         T.LOCATION_NO,
				         T.STORAGE_ATTR,
				         T.STORAGE_ATTR_NAME,
				         T.STORAGE_TYPE_NO,
				         T.STORAGE_TYPE_NAME,
				         T.MANAGEMENT_NO,
				         T.MANAGEMENT_NAME,
				         '#DEMAND_COPPER_LK#',
				         '#DEMAND_DETECTION_LK#',
				         '#DEMAND_BLAST_LK#',
				         '#DEMAND_BONDERIZING_LK#',
				         '#IMPRESS_DEAL_STATUS#',
				         '#COPPER_DEAL_STATUS#',
				         '#DETECT_DEAL_STATUS#',
				         '#BLAST_DEAL_STATUS#',
				         '#PLT_CU_DEAL_STATUS#',
				         '#PHOS_DEAL_STATUS#',
				         '#LOCK_LIKU#',
				         '#LIKU_BILL_ID#',
				         T.MEMO,
				         '#CREATE_NAME#',
				         SYSDATE,
				         T.OFFLINE_LOG,
				         '#JG_GROUP_ID#'
				    FROM COUPLING_MAT_BUTTRESS T
				   WHERE T.MAT_NO = '#MAT_NO#'
				     AND T.MAT_NO_XH = '#MAT_NO_XH#'
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.updateMatchJgGxm" desc="更新接箍订单利库个数">
		<![CDATA[
			UPDATE PLN_GX_JG_M T
			   SET T.MATCHWEIGHT = ?,
			       T.MATCHNUM = ?
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.updateMatchJgGxProp" desc="更新接箍订单分组利库个数">
		<![CDATA[
			UPDATE PLN_GX_JG_PROP T
			   SET T.MATCHNUM_JG = ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.JG_GROUP_ID = ?
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.getPlnLkJgLogId" desc="生成利库单号">
		<![CDATA[
			SELECT 'LK' || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
			       LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.LIKU_BILL_ID, 11, 3)) + 1), 1),
			            3,
			            '0') LIKU_BILL_ID
			  FROM PLN_LK_JG_LOG T
			 WHERE SUBSTR(T.LIKU_BILL_ID, 0, 10) = 'LK' || TO_CHAR(SYSDATE, 'YYYYMMDD')
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.addPlnLkJgLog" desc="新增利库单">
		<![CDATA[
			INSERT INTO PLN_LK_JG_LOG
				  (LIKU_BILL_ID,
				   PRO_PLAN_ID,
				   JG_GROUP_ID,
				   MAT_NO,
				   MAT_NO_XH,
				   JG_LK_NUM,
				   CREATE_NAME,
				   CREATE_TIME,
				   IF_UNMATCHED)
				VALUES
				  ('#LIKU_BILL_ID#',
				   '#PRO_PLAN_ID#',
				   '#JG_GROUP_ID#',
				   '#MAT_NO#',
				   '#MAT_NO_XH#',
				   '#JG_LK_NUM#',
				   '#CREATE_NAME#',
				   SYSDATE,
				   '0')
		]]>
	</query>
	
	<query id="CoreJgMPropMatch.updatePlnLkJgLog" desc="利库单脱单">
		<![CDATA[
			UPDATE PLN_LK_JG_LOG T
			   SET T.IF_UNMATCHED = '#IF_UNMATCHED#',
			       T.UPDATE_NAME  = '#UPDATE_NAME#',
			       T.UPDATE_TIME  = SYSDATE
			 WHERE T.LIKU_BILL_ID = '#LIKU_BILL_ID#'
		]]>
	</query>
	
	
	
</queryMap>