<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="加工组、热处理组默认原则">
	<query id="CoreAdjustWellMonth.GetCycle" desc="查询产能井最近一次占井情况">
		<![CDATA[
		SELECT R.*
   FROM (SELECT T.*,
               ROW_NUMBER() OVER(PARTITION BY T.WELL_CODE ORDER BY T.CREATE_TIME DESC) RN
          FROM SLM_WELL_USE_LIST T
         WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
           AND T.USE_TYPE = '消耗') R
   WHERE R.RN = 1

		]]>
	</query>
	
	<query id="CoreAdjustWellMonth.InsertWellList" desc="插入占井情况">
		<![CDATA[
			 INSERT INTO SLM_WELL_USE_LIST
  (WELL_CODE,
   WELL_NAME,
   WELL_YEAR,
   USE_MONTH,
   USE_CODE,
   SALE_ORG,
   SALE_ORG_DESC,
   ORD_LN_DLY_PK,
   USE_OBJ,
   USE_TYPE,
   USE_WGT,
   CREATE_NAME,
   CREATE_TIME)
VALUES
  ('#WELL_CODE#',
   (SELECT WELL_NAME FROM COM_BASE_WELL WHERE WELL_CODE = '#WELL_CODE#'),
   '#WELL_YEAR#',
   '#USE_MONTH#',
   (SELECT SUBSTR('#WELL_YEAR#', 3, 2) || LPAD('#USE_MONTH#', 2, '0') ||
           LPAD(TO_NUMBER(NVL(SUBSTR(MAX(USE_CODE), 5, 6), 0)) + 1, 6, '0')
      FROM SLM_WELL_USE_LIST
     WHERE WELL_CODE = '#WELL_CODE#'
       AND WELL_YEAR = '#WELL_YEAR#'
       AND USE_MONTH = '#USE_MONTH#'),
   '#SALE_ORG#',
   '#SALE_ORG_DESC#',
   '#ORD_LN_DLY_PK#',
   '1',
   '#USE_TYPE#',
   TO_NUMBER('#USE_WGT#'),
   '#CREATE_NAME#',
   SYSDATE)
			 
		]]>
	</query>
</queryMap>