<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="成品测量点数据采集">
   <query id="CoreOrderLineSpotLineTask.GetOriginalMeasurePosData" desc="获取成品测量点原始数据">
		<![CDATA[
SELECT  ? + cast(T.ID as varchar) KEY_ID,
            CASE T.WSID
         WHEN 1 THEN 'C028'
         WHEN 2 THEN 'C029'
         WHEN 3 THEN 'C030'
         WHEN 4 THEN 'C031'
         WHEN 5 THEN 'C032'
         WHEN 6 THEN 'C033'
         WHEN 7 THEN 'C056'
          WHEN 8 THEN 'C034'
          WHEN 9 THEN 'C053'
          WHEN 10 THEN 'C035'
          WHEN 11 THEN 'C036'
          WHEN 12 THEN 'C037'
          WHEN 14 THEN 'C052'
          WHEN 16 THEN 'C038'
           WHEN 17 THEN 'C039'
           WHEN 18 THEN 'C057'
           WHEN 19 THEN 'C051'
           WHEN 24 THEN 'C058'
           WHEN 25 THEN 'C059'
           WHEN 26 THEN 'C078'
           WHEN 30 THEN 'C078'
           WHEN 720 THEN 'C020'
           WHEN 1681 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
           WHEN 1682 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
           WHEN 1683 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
         ELSE
          Cast(T.WSID as varchar)
       END PLINE_CODE,
       T.HeatNo JUDGE_STOVE_NO,
       T.Contract PRO_ORDER_NO,
       T.SampNo BATCH_NO,
       T.PipeNo MAT_NO,
       T.Leng ACT_LEN,
       T.Weight ACT_WEIGHT,
       T.PenBiao MAT_INFO,
       CONVERT(varchar, T.PrcDate, 120) MSAUER_DATE,
       CASE ltrim(Upper(LEFT(Turn, 1)))
         WHEN 'A' THEN
          '1'
         WHEN 'B' THEN
          '2'
         WHEN 'C' THEN
          '3'
         WHEN 'D' THEN
          '4'
         WHEN '甲' THEN
          '1'
         WHEN '乙' THEN
          '2'
         WHEN '丙' THEN
          '3'
         WHEN '丁' THEN
          '4'
         ELSE
          ltrim(Upper(LEFT(Turn, 1)))
       END PRO_BZ,
       CASE (SELECT COUNT(1)
           FROM DeleteFlag T1
          WHERE T1.WSID = T.WSID
            AND T1.HeatNo = T.HeatNo collate Chinese_PRC_CI_AI_WS
            AND T1.SampNo = T.SampNo collate Chinese_PRC_CI_AI_WS
            AND T1.PipeNo = T.PipeNo
            AND T1.DeleteDate = T.PrcDate)
         WHEN '0' THEN
          '00'
         ELSE
          '10'
       END FLAG
  FROM (
SELECT     TOP (2000) *
FROM     MeasurePosData
ORDER BY ID DESC) T
 order by PLINE_CODE, PrcDate
		]]>
	</query>


	<query id="CoreOrderLineSpotLineTask.GetOriginalMeasurePosDataAll" desc="获取成品测量点原始数据">
		<![CDATA[
SELECT  ? + cast(T.ID as varchar) KEY_ID,
            CASE T.WSID
         WHEN 1 THEN 'C028'
         WHEN 2 THEN 'C029'
         WHEN 3 THEN 'C030'
         WHEN 4 THEN 'C031'
         WHEN 5 THEN 'C032'
         WHEN 6 THEN 'C033'
         WHEN 7 THEN 'C056'
          WHEN 8 THEN 'C034'
          WHEN 9 THEN 'C053'
          WHEN 10 THEN 'C035'
          WHEN 11 THEN 'C036'
          WHEN 12 THEN 'C037'
          WHEN 14 THEN 'C052'
          WHEN 16 THEN 'C038'
           WHEN 17 THEN 'C039'
           WHEN 18 THEN 'C057'
           WHEN 19 THEN 'C051'
           WHEN 24 THEN 'C058'
           WHEN 25 THEN 'C059'
           WHEN 26 THEN 'C078'
           WHEN 30 THEN 'C078'
           WHEN 720 THEN 'C020'
           WHEN 1681 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
           WHEN 1682 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
           WHEN 1683 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
         ELSE
           Cast(T.WSID as varchar)
       END PLINE_CODE,
       T.HeatNo JUDGE_STOVE_NO,
        T.Contract PRO_ORDER_NO,
       T.SampNo BATCH_NO,
       T.PipeNo MAT_NO,
       T.Leng ACT_LEN,
          T.PenBiao MAT_INFO,
       T.Weight ACT_WEIGHT,
       CONVERT(varchar, T.PrcDate, 120) MSAUER_DATE,
       CASE ltrim(Upper(LEFT(Turn, 1)))
         WHEN 'A' THEN
          '1'
         WHEN 'B' THEN
          '2'
         WHEN 'C' THEN
          '3'
         WHEN 'D' THEN
          '4'
         WHEN '甲' THEN
          '1'
         WHEN '乙' THEN
          '2'
         WHEN '丙' THEN
          '3'
         WHEN '丁' THEN
          '4'
         ELSE
          ltrim(Upper(LEFT(Turn, 1)))
       END PRO_BZ,
       CASE (SELECT COUNT(1)
           FROM DeleteFlag T1
          WHERE T1.WSID = T.WSID
            AND T1.HeatNo = T.HeatNo collate Chinese_PRC_CI_AI_WS
            AND T1.SampNo = T.SampNo collate Chinese_PRC_CI_AI_WS
            AND T1.PipeNo = T.PipeNo
            AND T1.DeleteDate = T.PrcDate)
         WHEN '0' THEN
          '00'
         ELSE
          '10'
       END FLAG
  FROM MeasurePosData T
  WHERE  1=1
		]]>
	</query>

	<query id="CoreOrderLineSpotLineTask.GetOriginalMeasurePosDataByID" desc="获取成品测量点原始数据">
		<![CDATA[
SELECT  ? + cast(T.ID as varchar) KEY_ID,
       CASE T.WSID
         WHEN 1 THEN 'C028'
         WHEN 2 THEN 'C029'
         WHEN 3 THEN 'C030'
         WHEN 4 THEN 'C031'
         WHEN 5 THEN 'C032'
         WHEN 6 THEN 'C033'
         WHEN 7 THEN 'C056'
          WHEN 8 THEN 'C034'
          WHEN 9 THEN 'C053'
          WHEN 10 THEN 'C035'
          WHEN 11 THEN 'C036'
          WHEN 12 THEN 'C037'
          WHEN 14 THEN 'C052'
          WHEN 16 THEN 'C038'
           WHEN 17 THEN 'C039'
           WHEN 18 THEN 'C057'
           WHEN 19 THEN 'C051'
           WHEN 24 THEN 'C058'
           WHEN 25 THEN 'C059'
           WHEN 26 THEN 'C078'
           WHEN 30 THEN 'C078'
           WHEN 720 THEN 'C020'
           WHEN 1681 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
           WHEN 1682 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
           WHEN 1683 THEN CASE SUBSTRING(T.SampNo,1,2)  WHEN '10' THEN 'C010' WHEN '11' THEN 'C011' WHEN '15' THEN 'C015' WHEN '69' THEN 'C069' WHEN '74' THEN 'C074' WHEN '75' THEN 'C075' END
         ELSE
            Cast(T.WSID as varchar)
       END PLINE_CODE,
       T.HeatNo JUDGE_STOVE_NO,
       T.SampNo BATCH_NO,
       T.PipeNo MAT_NO,
        T.Contract PRO_ORDER_NO,
       T.Leng ACT_LEN,
       T.PenBiao MAT_INFO,
       T.Weight ACT_WEIGHT,
       CONVERT(varchar, T.PrcDate, 120) MSAUER_DATE,
       CASE ltrim(Upper(LEFT(Turn, 1)))
         WHEN 'A' THEN
          '1'
         WHEN 'B' THEN
          '2'
         WHEN 'C' THEN
          '3'
         WHEN 'D' THEN
          '4'
         WHEN '甲' THEN
          '1'
         WHEN '乙' THEN
          '2'
         WHEN '丙' THEN
          '3'
         WHEN '丁' THEN
          '4'
         ELSE
          ltrim(Upper(LEFT(Turn, 1)))
       END PRO_BZ,
       CASE (SELECT COUNT(1)
           FROM DeleteFlag T1
          WHERE T1.WSID = T.WSID
            AND T1.HeatNo = T.HeatNo collate Chinese_PRC_CI_AI_WS
            AND T1.SampNo = T.SampNo collate Chinese_PRC_CI_AI_WS
            AND T1.PipeNo = T.PipeNo
            AND T1.DeleteDate = T.PrcDate)
         WHEN '0' THEN
          '00'
         ELSE
          '10'
       END FLAG
  FROM MeasurePosData T
 WHERE ID > ?
 order by  ID
		]]>
	</query>

	<query id="CoreOrderLineSpotLineTask.FindStove" desc="查找数据少的炉号">
		<![CDATA[
         SELECT T1.JUDGE_STOVE_NO
  FROM (SELECT JUDGE_STOVE_NO, COUNT(1) C1
          FROM PORT_MCH_BATCH_SAMPLE_RESULT
         WHERE VALIDFLAG = '1'
         GROUP BY HEAT_PLAN_NO, JUDGE_STOVE_NO) T1 LEFT JOIN
       (SELECT JUDGE_STOVE_NO, COUNT(1)  C2
          FROM (SELECT JUDGE_STOVE_NO, BATCH_NO
                  FROM RTD_MEASURE_POSDATA
                 GROUP BY JUDGE_STOVE_NO, BATCH_NO, MAT_NO)
         GROUP BY JUDGE_STOVE_NO) T2 ON T1.JUDGE_STOVE_NO  = T2.JUDGE_STOVE_NO
         WHERE T2.JUDGE_STOVE_NO IS NULL  OR  C1>C2
		]]>
	</query>

	<query id="CoreOrderLineSpotLineTask.FindID" desc="查找数据少的炉号">
		<![CDATA[
SELECT *
  FROM (SELECT ? || (ROWNUM + (SELECT MAX(MAX_ID) - 10000
                                   FROM RTD_MEASURE_POSDATA_MAX
                                  WHERE HEADER_KEY = ?)) || '' KEY_ID
          FROM DUAL
        CONNECT BY ROWNUM < 10000) M
 WHERE NOT EXISTS
 (SELECT 1 FROM RTD_MEASURE_POSDATA WHERE KEY_ID = M.KEY_ID)
		]]>
	</query>


	<query id="CoreOrderLineSpotLineTask.FindByID" desc="是否存在成品测量点数据">
		<![CDATA[
           SELECT * FROM RTD_MEASURE_POSDATA WHERE KEY_ID ='#KEY_ID#'
		]]>
	</query>
	
		    <query id="CoreOrderLineSpotLineTask.SaveOriginalMeasurePosData" desc="保存成品测量点原始数据">
		<![CDATA[
	
INSERT INTO RTD_MEASURE_POSDATA
  (KEY_ID,
   PLINE_CODE,
   PLINE_NAME,
   JUDGE_STOVE_NO,
   BATCH_NO,
   MAT_NO,
   ACT_LEN,
   ACT_WEIGHT,
   PRO_BC,
   PRO_BZ,
   MSAUER_DATE,
   FLAG,
   MAT_INFO,
   PRO_ORDER_NO)
  SELECT '#KEY_ID#',
         PLINE_CODE,
         PLINE_NAME,
         '#JUDGE_STOVE_NO#',
         '#BATCH_NO#',
         '#MAT_NO#',
         FLOOR('#ACT_LEN#'),
         FLOOR('#ACT_WEIGHT#'),
         '#PRO_BC#',
         '#PRO_BZ#',
         TO_DATE('#MSAUER_DATE#','yyyy-MM-dd HH24:mi:ss') ,
         '#FLAG#',
         '#MAT_INFO#',
         '#PRO_ORDER_NO#'
    FROM DUAL
    LEFT JOIN COM_BASE_PLINE
      --ON PROCESS_CODE IN ( 'G','D')
     AND PLINE_CODE ='#PLINE_CODE#'
           	]]>
	</query>
	
	
		    <query id="CoreOrderLineSpotLineTask.MarkMeasurePosData" desc="标记成品测量点数据为删除数据">
		<![CDATA[
	          UPDATE RTD_MEASURE_POSDATA SET FLAG = '10' WHERE  KEY_ID ='#KEY_ID#'
           	]]>
	</query>

	<query id="CoreOrderLineSpotLineTask.UpdateMaxID" desc="标记成品测量点数据为删除数据">
		<![CDATA[
	          UPDATE RTD_MEASURE_POSDATA_MAX SET MAX_ID = ?   WHERE  HEADER_KEY = ?
           	]]>
	</query>

	<query id="CoreOrderLineSpotLineTask.QueryMaxID" desc="标记成品测量点数据为删除数据">
		<![CDATA[
SELECT MAX_ID ID from RTD_MEASURE_POSDATA_MAX t WHERE HEADER_KEY =?
           	]]>
	</query>




</queryMap>
