<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="查询上料炉计划">

<query id="GetSQLDate.FeedPlanQueryNEW" desc="查询子计划">
<![CDATA[
SELECT  [id]   AS FEED_ROW_NO

       ,[轧批号]  AS LOT_NO
	   , [产出炉号] AS heatno
       ,[产出炉号] +'-01' AS JUDGE_STOVE_NO
       ,[坯长度上料] AS FEED_LENGTH
       
      ,[单倍尺长度]
      ,[坯子倍尺] AS DB_NUM
      ,[余长轧否轧切]
      ,[备注]
      ,[管坯上料支] AS FEED_NUM
      ,[管坯上料单倍尺支]
      ,[管坯上料吨]  AS MAT_TOTAL_HEIGHT
      ,[定尺长度] AS DB_LENGTH
      ,[切余长度]
      ,[切余处理] AS CUT_TARGET
      ,[切余重]
      ,[使用长度] AS USE_LENGTH
      ,[上料切余重]
      ,[坯断面] AS PIPE_SECTION
	  ,[产线] AS PCODE
      , CASE [产线]
	  WHEN '250机组' THEN 'C008'
	  WHEN '168机组' THEN 'C010'
	  WHEN '460机组' THEN 'C017'
	  WHEN '258机组' THEN 'C009'
	  WHEN 'ASSEL机组' THEN 'C012'
	  END AS PLINE_CODE
	  ,[管坯上料支] AS FEED_NUM_PLAN
	  ,'0' AS MAT_HEIGHT
	  ,'0' AS CUT_LENGTH
	  ,'0' AS CUT_WEIGHT
	  ,'0' AS NON_USE_LENGTH
      ,'0' AS DB_HEIGHT
      ,[订单号] AS PRO_PLAN_ID
	 ,[排产序号] AS GX_PLAN_NO
  FROM [tabcxslsj]
  WHERE cxstu = '00'

]]>

</query>

<query id="GetSQLDate.FeedPlanQueryNEWHas" desc="查询已同步子计划">
 SELECT 
       FEED_ROW_NO,
       SEQ,
       LOT_NO,
       STOVE_NO,
       REGEXP_REPLACE(JUDGE_STOVE_NO, '-.*', '') AS heatno,
       JUDGE_STOVE_NO,
       CASE PLINE_CODE
       WHEN 'C008' THEN '250机组'
	   WHEN 'C010' THEN '168机组'
	   WHEN 'C017' THEN '460机组'
	   WHEN 'C009' THEN '258机组'
	   WHEN 'C012' THEN 'ASSEL机组'
	   END AS PLINE_CODE,
       DB_NUM,
       MAT_HEIGHT,
       MAT_TOTAL_HEIGHT,
       FEED_NUM,
       FEED_LENGTH,
       USE_LENGTH,
       CUT_TARGET,
       CUT_LENGTH,
       CUT_WEIGHT,
       SAW_FALG,
       REMARK,
       COL_MODE,
       TO_CHAR(COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       COL_USER,
       COL_SHIFT,
       COL_GROUP,
       DB_LENGTH,
       NON_USE_LENGTH,
       PIPE_SECTION,
       SCRAP_DBNUM,
       SCRAP_FEEDNUM,
       DB_HEIGHT,
       QUALIFIED_NUM,
       CHANGE_NUM,
       FEED_NUM_PLAN
 FROM MIL_FEED_PLAN
 WHERE
 1=1
 AND saw_falg = '0'
</query>
	
	
<query id="GetSQLDate.FeedPlanQuery" desc="修改主计划开始状态">
    <![CDATA[
      SELECT  [id]
       ,[轧批号]
       ,[产出炉号]
       ,[坯长度上料]
      ,[单倍尺长度]
      ,[坯子倍尺]
      ,[余长轧否轧切]
      ,[备注]
      ,[管坯上料支]
      ,[管坯上料单倍尺支]
      ,[管坯上料吨]
      ,[定尺长度]
      ,[切余长度]
      ,[切余处理]
      ,[切余重]
      ,[使用长度]
      ,[上料切余重]
      ,[坯断面]
      ,[产线]
  FROM [tabcxslsj]
  WHERE cxstu = '00'
		    
        ]]>
</query>


<query id="GetSQLDate.PlanQueryNEW" desc="查询主计划">
<![CDATA[
 SELECT  min([id]) as ID
      ,min([产线计划id]) as SEQ
      ,[轧批号] AS   LOT_NO
	  ,[产出炉号] AS heatno
      ,[产出炉号] +'-01' AS JUDGE_STOVE_NO
      ,[上料炉号] AS FEED_HEAT_NO
      ,[钢种]    AS GRADENAME
      ,[坯断面]  AS PIPE_SECTION
      ,max([坯标准])  as  [坯标准]
      ,[轧制长度m] AS ROLL_LENGTH
      ,[分切]  AS SAW_NUM
      ,[目标长度m]  AS TARGET_LENGTH
      ,sum([成品计划支]) AS BRANCH
      ,sum([成品计划吨]) AS TON
      ,[工艺状态]  AS   PROCESS_STATUS
	  ,[产线] as PCODE
      ,CASE [产线] 
       WHEN '250机组' THEN 'C008'
	  WHEN '168机组' THEN 'C010'
	  WHEN '460机组' THEN 'C017'
	  WHEN '258机组' THEN 'C009'
	  WHEN 'ASSEL机组' THEN 'C012'
	  END AS PLINE_CODE
      ,[合同号]  AS CONTRACT_NO
      ,[工艺号]   AS IMP_PROCESS
      ,[备注]
      ,sum([管坯上料支]) as 管坯上料支
      ,sum([管坯上料单倍尺支]) AS DB_NUM
      ,sum([管坯上料吨]) as 管坯上料吨
      ,[定尺长度] AS DB_LENGTH
      ,min(isnull(切余处理,'')) AS CUT_TARGET
      ,sum([切余重]) AS CUT_WEIGHT
      ,sum([上料切余重]) as 上料切余重
      ,[KIND]  AS VARIETIES
      ,[STEELLEVEL] AS STEELNAME
      ,CAST([WAIJING] AS VARCHAR(20)) +'*'+CAST([BIHOU] AS VARCHAR(20)) AS PIPE_SIZE
      ,KOUXING AS BUCKLE_TYPE
      ,[ZGSTANDARD] AS ROLL_STANDRAD
      ,[LGSTANDARD]  AS STEEL_STANDRAD
      ,[CUSTOMER] AS   FINISH_USER
      ,[TARGET] AS  TARGET_LIABRARY
	  ,[TARGET] AS TARGET
      , CAST(CAST([LENGTHMIN] AS DECIMAL(18,2)) AS VARCHAR(20))  + '-' +
	    CAST(CAST([LENGTHMAX] AS DECIMAL(18,2)) AS VARCHAR(20))  AS LENGTH_RANGE
      ,min(changedate) AS START_TIME
      ,cxstu
      ,min(isnull(切余长度,'')) AS CUT_LENGTH
      ,[QIET] AS CUT_HEAD_LENGTHP
      ,[QIEW] AS CUT_TRAIL_LENGTHP
      ,CPSTANDARD AS PRODUCE_STANDRAD
	  ,'00' AS STATUS
	  ,'00' AS  NODE_STATUS
	  ,'0' AS DB_HEIGHT
	  ,[JZ] As PRODUCER
	  ,LENGTHCP AS LENGTHCP,
	  PKNO AS ORD_LN_DLY_PK,
	  KZBIHOU AS CONTROL_THICKP,
	  [订单号] AS PRO_PLAN_ID,
	 [排产序号] AS GX_PLAN_NO,
	 [坯类型] AS TUBE_TYPE,
	 [坯来源] AS TUBE_SUORCE,
	 CASE TYPE
	 WHEN '0' THEN '正常计划'
	 WHEN '1' THEN '试轧料'
	 END AS TYPE
  FROM [tabcxslsj]
  group by 
       [排产序号]
      ,[订单号]
      ,[轧批号]
      ,[产出炉号]
      ,[钢种]
      ,[坯断面]
      ,[上料炉号]
      ,[轧制长度m]
      ,[分切]
      ,[目标长度m]
      ,[工艺状态]
      ,[产线]
      ,[合同号]
      ,[工艺号]
      ,[备注]
      ,[定尺长度]
      ,[KIND]
      ,[STEELLEVEL]
      ,[WAIJING]
      ,[BIHOU]
      ,[ZGSTANDARD]
      ,[LGSTANDARD]
      ,[CUSTOMER]
      ,[TARGET]
      ,[LENGTHMIN]
      ,[LENGTHMAX]
      ,cxstu
      ,[QIET]
      ,[QIEW]
      ,CPSTANDARD
      ,JZ
      ,LENGTHCP
      ,KOUXING,
      PKNO,
      KZBIHOU,
      [坯类型],
      [坯来源],
      TYPE
  HAVING cxstu = '00'
 
]]>
</query>


<query id="GetSQLDate.PlanQueryNEWHas" desc="查询已同步主计划">
SELECT 
       BACK_LINE_FLAG,
       BACK_PLAN_FLAG,
       SIMPLE_PROCESS,
       PRODUCE_STANDRAD,
       ID,
       SEQ,
       STOVE_NO,
       REGEXP_REPLACE(JUDGE_STOVE_NO, '-.*', '') AS heatno,
       JUDGE_STOVE_NO,
       LOT_NO,
       CONTRACT_NO,
       IMP_PROCESS,
       CASE PLINE_CODE
       WHEN 'C008' THEN '250机组'
     WHEN 'C010' THEN '168机组'
     WHEN 'C017' THEN '460机组'
     WHEN 'C009' THEN '258机组'
     WHEN 'C012' THEN 'ASSEL机组'
     END AS PLINE_CODE,
       STATUS,
       PRODUCER,
       PROCESS_STATUS,
       DB_LENGTH,
       DB_HEIGHT,
       ROLL_LENGTH,
       SAW_NUM,
       TARGET_LENGTH,
       FINISH_USER,
       TARGET_LIABRARY,
       VARIETIES,
       PIPE_SIZE,
       BUCKLE_TYPE,
       LENGTH_RANGE,
       ROLL_STANDRAD,
       PIPE_SECTION,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       STEEL_STANDRAD,
       TARGET,
       BRANCH,
       TON,
       CUT_TARGET,
       CUT_LENGTH,
       CUT_WEIGHT,
       DB_NUM,
       TO_CHAR(START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME,
       TO_CHAR(END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       TO_CHAR(TOM, 'YYYY-MM-DD HH24:MI:SS') TOM,
       TO_CHAR(TOC, 'YYYY-MM-DD HH24:MI:SS') TOC,
       NODE_STATUS,
       CUT_HEAD_LENGTHP,
       CUT_TRAIL_LENGTHP,
       CONTROL_THICKP,
       OFFLINE_FLAG,
       IS_BATCH,
      
       TO_CHAR(OFFLINE_DATE, 'YYYY-MM-DD HH24:MI:SS') OFFLINE_DATE,
       CUT_TYPE,
       ROLLING_STATUS
       ,FEED_HEAT_NO
 FROM MIL_PLAN
 WHERE
  status = '00'
</query>


<query id="GetSQLDate.PlanQuery" desc="修改主计划开始状态">
<![CDATA[
SELECT  min([id]) as id
      ,min([产线计划id]) as 产线计划id
      ,[轧批号]
      ,[产出炉号]
      ,[钢种]
      ,[坯断面]
      ,[坯标准]
      ,[轧制长度m]
      ,[分切]
      ,[目标长度m]
      ,sum([成品计划支]) as 成品计划支
      ,sum([成品计划吨]) as 成品计划吨
      ,[工艺状态]
      ,[产线]
      ,[合同号]
      ,[工艺号]
      ,[备注]
      ,sum([管坯上料支]) as 管坯上料支
      ,sum([管坯上料单倍尺支]) as 管坯上料单倍尺支
      ,sum([管坯上料吨]) as 管坯上料吨
      ,[定尺长度]
      ,min(isnull(切余处理,'')) as 切余处理
      ,sum([切余重]) as 切余重
      ,sum([上料切余重]) as 上料切余重
      ,[KIND]
      ,[STEELLEVEL]
      ,[WAIJING]
      ,[BIHOU]
      ,[ZGSTANDARD]
      ,[LGSTANDARD]
      ,[CUSTOMER]
      ,[TARGET]
      ,[LENGTHMIN]
      ,[LENGTHMAX]
      ,min(changedate) as changedate
      ,cxstu
      ,min(isnull(切余长度,'')) as 切余长度
      ,[QIET]
      ,[QIEW]
      ,CPSTANDARD
  FROM [tabcxslsj]
  group by 
      [轧批号]
      ,[产出炉号]
      ,[钢种]
      ,[坯断面]
      ,[坯标准]
      ,[轧制长度m]
      ,[分切]
      ,[目标长度m]
      ,[工艺状态]
      ,[产线]
      ,[合同号]
      ,[工艺号]
      ,[备注]
      ,[定尺长度]
      ,[KIND]
      ,[STEELLEVEL]
      ,[WAIJING]
      ,[BIHOU]
      ,[ZGSTANDARD]
      ,[LGSTANDARD]
      ,[CUSTOMER]
      ,[TARGET]
      ,[LENGTHMIN]
      ,[LENGTHMAX]
      ,cxstu
      ,[QIET]
      ,[QIEW]
      ,CPSTANDARD
  HAVING cxstu = '00' 
		    
        ]]>
</query>
<query id="GetSQLDate.AddPlan" desc="">
 INSERT INTO MIL_PLAN(
 ID,
SEQ,
JUDGE_STOVE_NO,
LOT_NO,
CONTRACT_NO,
IMP_PROCESS,
PLINE_CODE,
PROCESS_STATUS,
DB_LENGTH,
DB_HEIGHT,
ROLL_LENGTH,
SAW_NUM,
TARGET_LENGTH,
FINISH_USER,
TARGET_LIABRARY,
VARIETIES,
PIPE_SIZE,
BUCKLE_TYPE,
LENGTH_RANGE,
ROLL_STANDRAD,
PIPE_SECTION,
STEELNAME,
GRADENAME,
STEEL_STANDRAD,
TARGET,
BRANCH,
TON,
CUT_TARGET,
CUT_LENGTH,
CUT_WEIGHT,
DB_NUM,
START_TIME,
STATUS,
NODE_STATUS,
CUT_HEAD_LENGTHP,
CUT_TRAIL_LENGTHP,
PRODUCE_STANDRAD,
PRODUCER,
FEED_HEAT_NO,
LENGTHCP,
ORD_LN_DLY_PK,
CONTROL_THICKP,
PRT_FLAG,
PRO_PLAN_ID,
GX_PLAN_NO,
TUBE_TYPE,
TUBE_SUORCE,
TYPE)
 VALUES( 
 '#ID#',
'#SEQ#',
'#JUDGE_STOVE_NO#',
'#LOT_NO#',
'#CONTRACT_NO#',
'#IMP_PROCESS#',
'#PLINE_CODE#',
'#PROCESS_STATUS#',
'#DB_LENGTH#',
'#DB_HEIGHT#',
'#ROLL_LENGTH#',
'#SAW_NUM#',
'#TARGET_LENGTH#',
'#FINISH_USER#',
'#TARGET_LIABRARY#',
'#VARIETIES#',
'#PIPE_SIZE#',
'#BUCKLE_TYPE#',
'#LENGTH_RANGE#',
'#ROLL_STANDRAD#',
'#PIPE_SECTION#',
'#STEELNAME#',
'#GRADENAME#',
'#STEEL_STANDRAD#',
'#TARGET#',
'#BRANCH#',
'#TON#',
'#CUT_TARGET#',
'#CUT_LENGTH#',
'#CUT_WEIGHT#',
'#DB_NUM#',
TO_Date('#START_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
'#STATUS#',
'#NODE_STATUS#',
'#CUT_HEAD_LENGTHP#',
'#CUT_TRAIL_LENGTHP#',
'#PRODUCE_STANDRAD#',
'#PRODUCER#',
'#FEED_HEAT_NO#',
'#LENGTHCP#',
'#ORD_LN_DLY_PK#',
'#CONTROL_THICKP#',
'#PRT_FLAG#',
'#PRO_PLAN_ID#',
'#GX_PLAN_NO#',
'#TUBE_TYPE#',
'#TUBE_SUORCE#',
'#TYPE#')
</query>
<query id="GetSQLDate.AddFeed" desc="添加子表">
 INSERT INTO MIL_FEED_PLAN
  (FEED_ROW_NO,
   LOT_NO,
   JUDGE_STOVE_NO,
   DB_NUM,
   MAT_HEIGHT,
   MAT_TOTAL_HEIGHT,
   FEED_NUM,
   FEED_LENGTH,
   USE_LENGTH,
   CUT_TARGET,
   CUT_LENGTH,
   CUT_WEIGHT,
   DB_LENGTH,
   NON_USE_LENGTH,
   PIPE_SECTION,
   DB_HEIGHT,
   FEED_NUM_PLAN,
   PLINE_CODE,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  ('#FEED_ROW_NO#',
   '#LOT_NO#',
   '#JUDGE_STOVE_NO#',
   '#DB_NUM#',
   '#MAT_HEIGHT#',
   '#MAT_TOTAL_HEIGHT#',
   '#FEED_NUM#',
   '#FEED_LENGTH#',
   '#USE_LENGTH#',
   '#CUT_TARGET#',
   '#CUT_LENGTH#',
   '#CUT_WEIGHT#' / '#FEED_NUM_PLAN#',
   '#DB_LENGTH#',
   '#NON_USE_LENGTH#' / '#FEED_NUM_PLAN#',
   '#PIPE_SECTION#',
   '#DB_HEIGHT#',
   '#FEED_NUM_PLAN#',
   '#PLINE_CODE#',
   '#PRO_PLAN_ID#',
   '#GX_PLAN_NO#')
</query>
<query id="GetSQLDate.AfterSysncPlan" desc="">
UPDATE  [tabcxslsj]
SET [cxstu]='20' WHERE  id='#FEED_ROW_NO#'   AND [产出炉号]=SUBSTRING ('#JUDGE_STOVE_NO#',1,6)
</query>
<query id="GetSQLDate.AfterSysncPlanBack" desc="">
UPDATE  [tabcxslsj]
SET [cxstu]='00' WHERE   [产出炉号]=SUBSTRING ('#JUDGE_STOVE_NO#',1,6)
</query>
<query id="GetSQLDate.BackPlan" desc="主计划回退">
delete from MIL_PLAN WHERE  JUDGE_STOVE_NO='#JUDGE_STOVE_NO#'
</query>
<query id="GetSQLDate.BackFeed" desc="从计划回退">
delete from MIL_FEED_PLAN WHERE  JUDGE_STOVE_NO='#JUDGE_STOVE_NO#'
</query>

<query id="GetSQLDate.SelectPlanStatus" desc="查询计划状态">
 <![CDATA[
SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') || '已开始上料' STATUS
  from MIL_PLAN T
 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.STATUS <> '00'
   ]]>
</query>

</queryMap>