<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="工艺评审主表">
	<query id="CraftOrdDesignDAL.query" desc="查询工艺评审主表">
		<![CDATA[
SELECT *
  FROM (SELECT T.ORD_LN_PK,
               T.CRAFT_SEQ,
               T.CRAFT_NO,
               T.DESGIN_KEY,
               T.LOCK_FLAG,
               DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
               T.VALIDFLAG,
               DECODE(T.VALIDFLAG,
                      '0',
                      '无效',
                      '1',
                      '生效',
                      '2',
                      '制定中',
                      '3',
                      '待科室审核',
                      '4',
                      '待审批',
                      '5',
                      '审核失败',
                      '6',
                      '待相关科室审核',
                      '7',
                      '待批准',
                      '未识别') VALIDFLAG_DESC,
               T.CREATE_NAME,
               TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
               T.UPDATE_NAME,
               TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
               T.DELETE_NAME,
               TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
               T.AUDIT_NAME,
               TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
               T.APPROVAL_NAME,
               TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
               T.AUDIT_NAME1,
               TO_CHAR(T.AUDIT_TIME1, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME1,
               T.APPROVAL_NAME1,
               TO_CHAR(T.APPROVAL_TIME1, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME1,
               A.ORDER_NO,
               B.ORDER_SEQ,
               DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
               T.REASON,
               SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
               T.CRAFT_PATH CRAFT_PATH_Old,
               T.CRAFT_NO_V,
               T.CRAFT_SOURCE,
               T.MEMO,
               T.CRAFT_CHANGE_MEMO,
               T.CRAFT_FILE_LV2_D,
               T.CRAFT_FILE_LV2_E,
               T.CRAFT_FILE_LV2_F,
               T.CRAFT_FILE_LV2_G,
               T.CRAFT_FILE_LV2_H,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_E, A.PK) > 0) CRAFT_FILE_LV2_E_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_F, A.PK) > 0) CRAFT_FILE_LV2_F_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_G, A.PK) > 0) CRAFT_FILE_LV2_G_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_H, A.PK) > 0) CRAFT_FILE_LV2_H_DESC,
               B.MSC,
               T.OTHER_EDIT_NAME
          FROM CRAFT_ORD_DESIGN T
          LEFT JOIN CRAFT_ORD_DESIGN_UNIT C
            ON C.ORD_LN_PK = T.ORD_LN_PK, SLM_ORDER_HEAD A, SLM_ORDER_LINE B
         WHERE DECODE('#ORD_LN_PK#', NULL, '1', T.ORD_LN_PK) =
               DECODE('#ORD_LN_PK#', NULL, '1', '#ORD_LN_PK#')
           AND A.ORD_PK = B.ORD_PK
           AND B.ORD_LN_PK = T.ORD_LN_PK
           AND DECODE('#ORDER_NO#', NULL, '1', LOWER(A.ORDER_NO)) LIKE
               DECODE('#ORDER_NO#', NULL, '1', LOWER('%#ORDER_NO#%'))
           AND DECODE('#ORDER_SEQ#', NULL, '1', B.ORDER_SEQ) =
               NVL('#ORDER_SEQ#', '1')
           AND DECODE('#VALIDFLAG#', NULL, '1', T.VALIDFLAG) =
               DECODE('#VALIDFLAG#', NULL, '1', '#VALIDFLAG#')
           AND DECODE('#CREATE_TIME1#', NULL, SYSDATE, T.CREATE_TIME) BETWEEN
               DECODE('#CREATE_TIME1#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME1#', 'YYYY-MM-DD HH24:MI:SS')) AND
               DECODE('#CREATE_TIME2#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME2#', 'YYYY-MM-DD HH24:MI:SS'))
           AND (DECODE('#VALIDFLAG#',
                       '3',
                       C.AUDIT_CODE,
                       '6',
                       C.AUDIT_CODE1,
                       '4',
                       C.APPROVE_CODE,
                       '7',
                       C.APPROVE_CODE1,
                       '1') = DECODE('#VALIDFLAG#',
                                     '3',
                                     '#USER_ID#',
                                     '6',
                                     '#USER_ID#',
                                     '4',
                                     '#USER_ID#',
                                     '7',
                                     '#USER_ID#',
                                     '1') OR '#USER_ID#' = 'admin' OR
                C.ORD_LN_PK IS NULL)
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.CRAFT_SEQ,
               T.CRAFT_NO,
               T.DESGIN_KEY,
               T.LOCK_FLAG,
               DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
               T.VALIDFLAG,
               DECODE(T.VALIDFLAG,
                      '0',
                      '无效',
                      '1',
                      '生效',
                      '2',
                      '制定中',
                      '3',
                      '待审核',
                      '4',
                      '待审批',
                      '5',
                      '审核失败',
                      '未识别') VALIDFLAG_DESC,
               T.CREATE_NAME,
               TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
               T.UPDATE_NAME,
               TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
               T.DELETE_NAME,
               TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
               T.AUDIT_NAME,
               TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
               T.APPROVAL_NAME,
               TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
               T.AUDIT_NAME1,
               TO_CHAR(T.AUDIT_TIME1, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME1,
               T.APPROVAL_NAME1,
               TO_CHAR(T.APPROVAL_TIME1, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME1,
               BL.PSC_BL,
               NULL,
               DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
               T.REASON,
               SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
               T.CRAFT_PATH CRAFT_PATH_Old,
               T.CRAFT_NO_V,
               T.CRAFT_SOURCE,
               T.MEMO,
               T.CRAFT_CHANGE_MEMO,
               T.CRAFT_FILE_LV2_D,
               T.CRAFT_FILE_LV2_E,
               T.CRAFT_FILE_LV2_F,
               T.CRAFT_FILE_LV2_G,
               T.CRAFT_FILE_LV2_H,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_E, A.PK) > 0) CRAFT_FILE_LV2_E_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_F, A.PK) > 0) CRAFT_FILE_LV2_F_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_G, A.PK) > 0) CRAFT_FILE_LV2_G_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_H, A.PK) > 0) CRAFT_FILE_LV2_H_DESC,
               M.MSC,
               T.OTHER_EDIT_NAME
          FROM CRAFT_ORD_DESIGN T
          LEFT JOIN CRAFT_ORD_DESIGN_UNIT C
            ON C.ORD_LN_PK = T.ORD_LN_PK, COM_MSC_BL BL
          LEFT JOIN COM_PSC P
            ON P.STD_CODE = BL.STD_CODE
           AND P.PRODUCCODE = BL.PRODUCCODE
           AND P.STEELCODE = BL.STEELCODE
           AND NVL(P.STD_STYLE, '1') = NVL(BL.STD_STYLE, '1')
          LEFT JOIN COM_PSC_R_MSC PRM
            ON PRM.PSC = P.PSC
          LEFT JOIN COM_MSC M
            ON M.MSC = PRM.MSC
         WHERE DECODE('#ORD_LN_PK#', NULL, '1', T.ORD_LN_PK) =
               DECODE('#ORD_LN_PK#', NULL, '1', '#ORD_LN_PK#')
           AND BL.PSC_BL = T.ORD_LN_PK
           AND DECODE(M.MSC, NULL, '1', M.USE_CODE) =
               DECODE(M.MSC, NULL, '1', BL.USE_CODE)
           AND DECODE('#ORDER_NO#', NULL, '1', LOWER(BL.PSC_BL)) LIKE
               DECODE('#ORDER_NO#', NULL, '1', LOWER('%#ORDER_NO#%'))
           AND DECODE('#VALIDFLAG#', NULL, '1', T.VALIDFLAG) =
               DECODE('#VALIDFLAG#', NULL, '1', '#VALIDFLAG#')
           AND DECODE('#CREATE_TIME1#', NULL, SYSDATE, T.CREATE_TIME) BETWEEN
               DECODE('#CREATE_TIME1#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME1#', 'YYYY-MM-DD HH24:MI:SS')) AND
               DECODE('#CREATE_TIME2#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME2#', 'YYYY-MM-DD HH24:MI:SS'))
           AND (DECODE('#VALIDFLAG#',
                       '3',
                       C.AUDIT_CODE,
                       '6',
                       C.AUDIT_CODE1,
                       '4',
                       C.APPROVE_CODE,
                       '7',
                       C.APPROVE_CODE1,
                       '1') = DECODE('#VALIDFLAG#',
                                     '3',
                                     '#USER_ID#',
                                     '6',
                                     '#USER_ID#',
                                     '4',
                                     '#USER_ID#',
                                     '7',
                                     '#USER_ID#',
                                     '1') OR '#USER_ID#' = 'admin' OR
                C.ORD_LN_PK IS NULL))
 ORDER BY ORDER_NO, ORDER_SEQ, CRAFT_SEQ
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.queryAudit" desc="查询工艺评审主表(审核审批专用)">
		<![CDATA[
SELECT *
  FROM (SELECT T.ORD_LN_PK,
               T.CRAFT_SEQ,
               T.CRAFT_NO,
               T.DESGIN_KEY,
               T.LOCK_FLAG,
               DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
               T.VALIDFLAG,
               DECODE(T.VALIDFLAG,
                      '0',
                      '无效',
                      '1',
                      '生效',
                      '2',
                      '制定中',
                      '3',
                      '待科室审核',
                      '4',
                      '待审批',
                      '5',
                      '审核失败',
                      '6',
                      '待相关科室审核',
                      '7',
                      '待批准',
                      '未识别') VALIDFLAG_DESC,
               T.CREATE_NAME,
               TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
               T.UPDATE_NAME,
               TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
               T.DELETE_NAME,
               TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
               T.AUDIT_NAME,
               TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
               T.APPROVAL_NAME,
               TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
               T.AUDIT_NAME1,
               TO_CHAR(T.AUDIT_TIME1, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME1,
               T.APPROVAL_NAME1,
               TO_CHAR(T.APPROVAL_TIME1, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME1,
               A.ORDER_NO,
               B.ORDER_SEQ,
               DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
               T.REASON,
               SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
               T.CRAFT_PATH CRAFT_PATH_Old,
               T.CRAFT_NO_V,
               T.CRAFT_SOURCE,
               T.MEMO,
               T.CRAFT_CHANGE_MEMO,
               T.CRAFT_FILE_LV2_D,
               T.CRAFT_FILE_LV2_E,
               T.CRAFT_FILE_LV2_F,
               T.CRAFT_FILE_LV2_G,
               T.CRAFT_FILE_LV2_H,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_E, A.PK) > 0) CRAFT_FILE_LV2_E_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_F, A.PK) > 0) CRAFT_FILE_LV2_F_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_G, A.PK) > 0) CRAFT_FILE_LV2_G_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_H, A.PK) > 0) CRAFT_FILE_LV2_H_DESC,
               B.MSC,
               B.PSC_DESC,
               B.SPEC_NAME,
               B.MODEL_DESC,
               B.ORDER_SPECIAL_DESC,
               O.DESCRIPTION_ALL ORDER_ADD_DESC,
               O.DESCRIPTION_DIFF ORDER_SPECIAL_DESC_A,
               B.FINAL_USER_DESC,
               B.MPS_NO,
               B.PRDCT_WGT,
               D.BASENAME OUTS_BILLET_FL_DESC,
               E.BASENAME OUTS_STL_PIPE_FL_DESC
          FROM CRAFT_ORD_DESIGN T
          LEFT JOIN (SELECT MAX(O.DESCRIPTION_DIFF) DESCRIPTION_DIFF,
                           MAX(O.DESCRIPTION_ALL) DESCRIPTION_ALL,
                           O.DESGIN_KEY
                      FROM CRAFT_ORD_DESIGN_ADD_ASK O
                     GROUP BY O.Desgin_Key) O
            ON O.DESGIN_KEY = T.DESGIN_KEY
          LEFT JOIN CRAFT_ORD_DESIGN_UNIT C
            ON C.ORD_LN_PK = T.ORD_LN_PK, SLM_ORDER_HEAD A, SLM_ORDER_LINE B
          LEFT JOIN COM_BASE_INFO D
            ON D.BASECODE = B.OUTS_BILLET_FL
          LEFT JOIN COM_BASE_INFO E
            ON E.BASECODE = B.OUTS_STL_PIPE_FL
         WHERE DECODE('#ORD_LN_PK#', NULL, '1', T.ORD_LN_PK) =
               DECODE('#ORD_LN_PK#', NULL, '1', '#ORD_LN_PK#')
           AND A.ORD_PK = B.ORD_PK
           AND B.ORD_LN_PK = T.ORD_LN_PK
           AND DECODE('#ORDER_NO#', NULL, '1', LOWER(A.ORDER_NO)) LIKE
               DECODE('#ORDER_NO#', NULL, '1', LOWER('%#ORDER_NO#%'))
           AND DECODE('#ORDER_SEQ#', NULL, '1', B.ORDER_SEQ) =
               NVL('#ORDER_SEQ#', '1')
           AND DECODE('#VALIDFLAG#', NULL, '1', T.VALIDFLAG) =
               DECODE('#VALIDFLAG#', NULL, '1', '#VALIDFLAG#')
           AND DECODE('#CREATE_TIME1#', NULL, SYSDATE, T.CREATE_TIME) BETWEEN
               DECODE('#CREATE_TIME1#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME1#', 'YYYY-MM-DD HH24:MI:SS')) AND
               DECODE('#CREATE_TIME2#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME2#', 'YYYY-MM-DD HH24:MI:SS'))
           AND (DECODE('#VALIDFLAG#',
                       '3',
                       C.AUDIT_CODE,
                       '6',
                       C.AUDIT_CODE1,
                       '4',
                       C.APPROVE_CODE,
                       '7',
                       C.APPROVE_CODE1,
                       '1') = DECODE('#VALIDFLAG#',
                                     '3',
                                     '#USER_ID#',
                                     '6',
                                     '#USER_ID#',
                                     '4',
                                     '#USER_ID#',
                                     '7',
                                     '#USER_ID#',
                                     '1') OR '#USER_ID#' = 'admin' OR
                C.ORD_LN_PK IS NULL)
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.CRAFT_SEQ,
               T.CRAFT_NO,
               T.DESGIN_KEY,
               T.LOCK_FLAG,
               DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
               T.VALIDFLAG,
               DECODE(T.VALIDFLAG,
                      '0',
                      '无效',
                      '1',
                      '生效',
                      '2',
                      '制定中',
                      '3',
                      '待审核',
                      '4',
                      '待审批',
                      '5',
                      '审核失败',
                      '未识别') VALIDFLAG_DESC,
               T.CREATE_NAME,
               TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
               T.UPDATE_NAME,
               TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
               T.DELETE_NAME,
               TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
               T.AUDIT_NAME,
               TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
               T.APPROVAL_NAME,
               TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
               T.AUDIT_NAME1,
               TO_CHAR(T.AUDIT_TIME1, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME1,
               T.APPROVAL_NAME1,
               TO_CHAR(T.APPROVAL_TIME1, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME1,
               BL.PSC_BL,
               NULL,
               DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
               T.REASON,
               SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
               T.CRAFT_PATH CRAFT_PATH_Old,
               T.CRAFT_NO_V,
               T.CRAFT_SOURCE,
               T.MEMO,
               T.CRAFT_CHANGE_MEMO,
               T.CRAFT_FILE_LV2_D,
               T.CRAFT_FILE_LV2_E,
               T.CRAFT_FILE_LV2_F,
               T.CRAFT_FILE_LV2_G,
               T.CRAFT_FILE_LV2_H,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_E, A.PK) > 0) CRAFT_FILE_LV2_E_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_F, A.PK) > 0) CRAFT_FILE_LV2_F_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_G, A.PK) > 0) CRAFT_FILE_LV2_G_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_H, A.PK) > 0) CRAFT_FILE_LV2_H_DESC,
               M.MSC,
               P.PSC_DESC,
               (BL.MIN_D || 'x' || BL.MIN_H) SPEC_NAME,
               BL.MODEL_DESC,
               NULL ORDER_SPECIAL_DESC,
               NULL ORDER_ADD_DESC,
               NULL ORDER_ADD_DESC_A,
               NULL FINAL_USER_DESC,
               NULL MPS_NO,
               NULL PRDCT_WGT,
               NULL OUTS_BILLET_FL_DESC,
               NULL OUTS_STL_PIPE_FL_DESC
          FROM CRAFT_ORD_DESIGN T
          LEFT JOIN CRAFT_ORD_DESIGN_UNIT C
            ON C.ORD_LN_PK = T.ORD_LN_PK, COM_MSC_BL BL
          LEFT JOIN COM_PSC P
            ON P.STD_CODE = BL.STD_CODE
           AND P.PRODUCCODE = BL.PRODUCCODE
           AND P.STEELCODE = BL.STEELCODE
           AND NVL(P.STD_STYLE, '1') = NVL(BL.STD_STYLE, '1')
          LEFT JOIN COM_PSC_R_MSC PRM
            ON PRM.PSC = P.PSC
          LEFT JOIN COM_MSC M
            ON M.MSC = PRM.MSC
         WHERE DECODE('#ORD_LN_PK#', NULL, '1', T.ORD_LN_PK) =
               DECODE('#ORD_LN_PK#', NULL, '1', '#ORD_LN_PK#')
           AND BL.PSC_BL = T.ORD_LN_PK
           AND DECODE(M.MSC, NULL, '1', M.USE_CODE) =
               DECODE(M.MSC, NULL, '1', BL.USE_CODE)
           AND DECODE('#ORDER_NO#', NULL, '1', LOWER(BL.PSC_BL)) LIKE
               DECODE('#ORDER_NO#', NULL, '1', LOWER('%#ORDER_NO#%'))
           AND DECODE('#VALIDFLAG#', NULL, '1', T.VALIDFLAG) =
               DECODE('#VALIDFLAG#', NULL, '1', '#VALIDFLAG#')
           AND DECODE('#CREATE_TIME1#', NULL, SYSDATE, T.CREATE_TIME) BETWEEN
               DECODE('#CREATE_TIME1#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME1#', 'YYYY-MM-DD HH24:MI:SS')) AND
               DECODE('#CREATE_TIME2#',
                      NULL,
                      SYSDATE,
                      TO_DATE('#CREATE_TIME2#', 'YYYY-MM-DD HH24:MI:SS'))
           AND (DECODE('#VALIDFLAG#',
                       '3',
                       C.AUDIT_CODE,
                       '6',
                       C.AUDIT_CODE1,
                       '4',
                       C.APPROVE_CODE,
                       '7',
                       C.APPROVE_CODE1,
                       '1') = DECODE('#VALIDFLAG#',
                                     '3',
                                     '#USER_ID#',
                                     '6',
                                     '#USER_ID#',
                                     '4',
                                     '#USER_ID#',
                                     '7',
                                     '#USER_ID#',
                                     '1') OR '#USER_ID#' = 'admin' OR
                C.ORD_LN_PK IS NULL))
 ORDER BY ORDER_NO, ORDER_SEQ, CRAFT_SEQ
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.queryCraftLv2" desc="二级工艺文件查询">
		<![CDATA[
SELECT *
  FROM (SELECT T.ORD_LN_PK,
               T.CRAFT_SEQ,
               T.CRAFT_NO,
               T.DESGIN_KEY,
               T.LOCK_FLAG,
               DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
               T.VALIDFLAG,
               DECODE(T.VALIDFLAG,
                      '0',
                      '无效',
                      '1',
                      '生效',
                      '2',
                      '制定中',
                      '3',
                      '待科室审核',
                      '4',
                      '待审批',
                      '5',
                      '审核失败',
                      '6',
                      '待相关科室审核',
                      '7',
                      '待批准',
                      '未识别') VALIDFLAG_DESC,
               T.CREATE_NAME,
               TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
               T.UPDATE_NAME,
               TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
               T.DELETE_NAME,
               TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
               T.AUDIT_NAME,
               TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
               T.APPROVAL_NAME,
               TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
               A.ORDER_NO,
               B.ORDER_SEQ,
               DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
               T.REASON,
               SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
               T.CRAFT_PATH CRAFT_PATH_Old,
               T.CRAFT_NO_V,
               T.CRAFT_SOURCE,
               T.MEMO,
               T.CRAFT_FILE_LV2_D,
               T.CRAFT_FILE_LV2_E,
               T.CRAFT_FILE_LV2_F,
               T.CRAFT_FILE_LV2_G,
               T.CRAFT_FILE_LV2_H,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_E, A.PK) > 0) CRAFT_FILE_LV2_E_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_F, A.PK) > 0) CRAFT_FILE_LV2_F_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_G, A.PK) > 0) CRAFT_FILE_LV2_G_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_H, A.PK) > 0) CRAFT_FILE_LV2_H_DESC,
               T.UPDATE_NAME_LV2,
               T.UPDATE_TIME_LV2,
               (SELECT WM_CONCAT(C.PROCESS_CODE)
                  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                 WHERE C.DESGIN_KEY = T.DESGIN_KEY) PROCESS_CODES,
               B.PRODUCNAME,
               B.STD_STYLE_DESC,
               B.STEELNAME,
               B.MSC,
               B.DIMATER,
               B.HEIGHT,
               B.SPEC_NAME,
               B.ORDER_SPEC_DESC,
               B.MODEL_DESC,
               B.ORDER_SPECIAL_DESC,
               D.DESCRIPTION_DIFF,
               D.DESCRIPTION_ALL,
               CHG.CHGE_VAL,
               B.LEN_DESC,
               B.FINAL_USER_DESC,
               DECODE(B.MAN_INSPECTION, '0', '不可手探', '1', '手探') MAN_INSPECTION,
               B.INSPECTION_VALUE,
               B.ORDER_UNIT,
               E.BASENAME OUTS_BILLET_FL,
               F.BASENAME OUTS_STL_PIPE_FL,
               DECODE(B.ASSEL_FL, '0', 'False', '1', 'True') ASSEL_FL,
               DECODE(B.PRODUCER_FL, '0', 'False', '1', 'True') PRODUCER_FL,
               TO_CHAR(ZG.PLAN_TIME_B_ZG, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_ZG,
               TO_CHAR(DBK.PLAN_TIME_B_DBK, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_DBK,
               TO_CHAR(RCL.PLAN_TIME_B_RCL, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_RCL,
               TO_CHAR(JGX.PLAN_TIME_B_JGX, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_JGX,
               TO_CHAR(PROP.PLAN_TIME_B_PROP, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_PROP,
               B.MODEL_CODE
          FROM CRAFT_ORD_DESIGN T
          LEFT JOIN (SELECT ROW_NUMBER() OVER(PARTITION BY J.ORD_LN_PK ORDER BY J.DELIVERY_NO) PLAN_RN,
                           J.PORDERSTATUS,
                           J.ROLL_MONTH,
                           J.ORD_LN_PK
                      FROM PLN_SALEORD J) JJ
            ON JJ.ORD_LN_PK = T.ORD_LN_PK
           AND JJ.PLAN_RN <= 1
          LEFT JOIN (SELECT MAX(D.DESCRIPTION_DIFF) DESCRIPTION_DIFF,
                           MAX(D.DESCRIPTION_ALL) DESCRIPTION_ALL,
                           D.DESGIN_KEY
                      FROM CRAFT_ORD_DESIGN_ADD_ASK D
                     GROUP BY D.DESGIN_KEY) D
            ON D.DESGIN_KEY = T.DESGIN_KEY, SLM_ORDER_HEAD A, SLM_ORDER_LINE B
          LEFT JOIN CHGE_SLM_APPLY_M CHG
            ON CHG.ORDER_CHGE_NO = B.ORDER_CHGE_NO
          LEFT JOIN COM_BASE_INFO E
            ON E.BASECODE = B.OUTS_BILLET_FL
          LEFT JOIN COM_BASE_INFO F
            ON E.BASECODE = B.OUTS_STL_PIPE_FL
          LEFT JOIN (SELECT PLN.ORD_LN_PK, MIN(ZG.PLAN_TIME_B) PLAN_TIME_B_ZG
                      FROM PLN_SALEORD PLN, PLN_ORDER_ZG_S ZG
                     WHERE PLN.ORD_LN_DLY_PK = ZG.ORD_LN_DLY_PK
                     GROUP BY PLN.ORD_LN_PK) ZG
            ON ZG.ORD_LN_PK = B.ORD_LN_PK
          LEFT JOIN (SELECT PLN.ORD_LN_PK,
                           MIN(DBK.PLAN_TIME_B) PLAN_TIME_B_DBK
                      FROM PLN_SALEORD PLN, PLN_ORDER_DBK_S DBK
                     WHERE PLN.ORD_LN_DLY_PK = DBK.ORD_LN_DLY_PK
                     GROUP BY PLN.ORD_LN_PK) DBK
            ON DBK.ORD_LN_PK = B.ORD_LN_PK
          LEFT JOIN (SELECT PLN.ORD_LN_PK,
                           MIN(RCL.PLAN_TIME_B) PLAN_TIME_B_RCL
                      FROM PLN_SALEORD PLN, PLN_ORDER_RCL_S RCL
                     WHERE PLN.ORD_LN_DLY_PK = RCL.ORD_LN_DLY_PK
                     GROUP BY PLN.ORD_LN_PK) RCL
            ON RCL.ORD_LN_PK = B.ORD_LN_PK
          LEFT JOIN (SELECT PLN.ORD_LN_PK,
                           MIN(JGX.PLAN_TIME_B) PLAN_TIME_B_JGX
                      FROM PLN_SALEORD PLN, PLN_ORDER_JGX_S JGX
                     WHERE PLN.ORD_LN_DLY_PK = JGX.ORD_LN_DLY_PK
                     GROUP BY PLN.ORD_LN_PK) JGX
            ON JGX.ORD_LN_PK = B.ORD_LN_PK
          LEFT JOIN (SELECT PLN.ORD_LN_PK,
                           MIN(PROP.PLAN_TIME_B) PLAN_TIME_B_PROP
                      FROM PLN_SALEORD      PLN,
                           PLN_ORDER_JG     JG,
                           PLN_GX_JG_PROP_S PROP
                     WHERE PLN.ORD_LN_DLY_PK = JG.ORD_LN_DLY_PK
                       AND JG.PRO_PLAN_ID = PROP.PRO_PLAN_ID
                       AND JG.JG_GROUP_ID = PROP.JG_GROUP_ID
                     GROUP BY PLN.ORD_LN_PK) PROP
            ON PROP.ORD_LN_PK = B.ORD_LN_PK
         WHERE A.ORD_PK = B.ORD_PK
           AND B.ORD_LN_PK = T.ORD_LN_PK
           AND T.VALIDFLAG = '1'
           AND ('#PLAN_STATUS#' IS NULL OR '#PLAN_STATUS#' = '1' OR
               (JJ.PORDERSTATUS IN ('1', '2', '3') OR
               (JJ.PORDERSTATUS IN ('4', '5') AND
               TO_DATE(JJ.ROLL_MONTH, 'YYYY-MM') =
               TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))))
           AND #ORDER_NO#
           AND #CRAFT_NO#
           AND #maintenanceStatus#
           AND EXISTS (SELECT 1
                  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                 WHERE T.DESGIN_KEY = C.DESGIN_KEY
                   AND C.PROCESS_CODE = '#PROCESS_CODE#')
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.CRAFT_SEQ,
               T.CRAFT_NO,
               T.DESGIN_KEY,
               T.LOCK_FLAG,
               DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
               T.VALIDFLAG,
               DECODE(T.VALIDFLAG,
                      '0',
                      '无效',
                      '1',
                      '生效',
                      '2',
                      '制定中',
                      '3',
                      '待审核',
                      '4',
                      '待审批',
                      '5',
                      '审核失败',
                      '未识别') VALIDFLAG_DESC,
               T.CREATE_NAME,
               TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
               T.UPDATE_NAME,
               TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
               T.DELETE_NAME,
               TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
               T.AUDIT_NAME,
               TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
               T.APPROVAL_NAME,
               TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
               BL.PSC_BL,
               NULL,
               DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
               T.REASON,
               SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
               T.CRAFT_PATH CRAFT_PATH_Old,
               T.CRAFT_NO_V,
               T.CRAFT_SOURCE,
               T.MEMO,
               T.CRAFT_FILE_LV2_D,
               T.CRAFT_FILE_LV2_E,
               T.CRAFT_FILE_LV2_F,
               T.CRAFT_FILE_LV2_G,
               T.CRAFT_FILE_LV2_H,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_E, A.PK) > 0) CRAFT_FILE_LV2_E_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_F, A.PK) > 0) CRAFT_FILE_LV2_F_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_G, A.PK) > 0) CRAFT_FILE_LV2_G_DESC,
               (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                               ';') within group(order by A.CRAFT_NO_LV2)
                  FROM CRAFT_FILE_LV2 A
                 WHERE INSTR(T.CRAFT_FILE_LV2_H, A.PK) > 0) CRAFT_FILE_LV2_H_DESC,
               T.UPDATE_NAME_LV2,
               T.UPDATE_TIME_LV2,
               (SELECT WM_CONCAT(C.PROCESS_CODE)
                  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                 WHERE C.DESGIN_KEY = T.DESGIN_KEY) PROCESS_CODES,
               P.PRODUCNAME,
               P.STD_STYLE_DESC,
               P.STEELNAME,
               NULL MSC,
               A.DIMATER,
               A.HEIGHT,
               NULL SPEC_NAME,
               NULL ORDER_SPEC_DESC,
               NULL MODEL_DESC,
               NULL ORDER_SPECIAL_DESC,
               NULL DESCRIPTION_DIFF,
               NULL DESCRIPTION_ALL,
               NULL CHGE_VAL,
               NULL LEN_DESC,
               NULL FINAL_USER_DESC,
               NULL MAN_INSPECTION,
               NULL INSPECTION_VALUE,
               NULL ORDER_UNIT,
               NULL OUTS_BILLET_FL,
               NULL OUTS_STL_PIPE_FL,
               NULL ASSEL_FL,
               NULL PRODUCER_FL,
               NULL PLAN_TIME_B_ZG,
               NULL PLAN_TIME_B_DBK,
               NULL PLAN_TIME_B_RCL,
               NULL PLAN_TIME_B_JGX,
               NULL PLAN_TIME_B_PROP,
               A.MODEL_CODE
          FROM CRAFT_ORD_DESIGN T
          LEFT JOIN (SELECT ROW_NUMBER() OVER(PARTITION BY J.ORD_LN_PK ORDER BY J.DELIVERY_NO) PLAN_RN,
                           J.PORDERSTATUS,
                           J.ROLL_MONTH,
                           J.ORD_LN_PK
                      FROM PLN_SALEORD J) JJ
            ON JJ.ORD_LN_PK = T.ORD_LN_PK
           AND JJ.PLAN_RN <= 1, COM_MSC_BL BL
          LEFT JOIN COM_PSC P
            ON P.PRODUCCODE = BL.PRODUCCODE
           AND P.STEELCODE = BL.STEELCODE
           AND P.STD_CODE = BL.STD_CODE
           AND NVL(P.STD_STYLE, '/') = NVL(BL.STD_STYLE, '/')
           AND P.VALIDFLAG = '0', SLM_ORDER_LINE A
         WHERE BL.PSC_BL = T.ORD_LN_PK
           AND A.ORD_LN_PK = T.ORD_LN_PK
           AND T.VALIDFLAG = '1'
           AND ('#PLAN_STATUS#' IS NULL OR '#PLAN_STATUS#' = '1' OR
               (JJ.PORDERSTATUS IN ('1', '2', '3') OR
               (JJ.PORDERSTATUS IN ('4', '5') AND
               TO_DATE(JJ.ROLL_MONTH, 'YYYY-MM') =
               TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))))
           AND #PSC_BL#
           AND #CRAFT_NO#
           AND #maintenanceStatus#
           AND EXISTS (SELECT 1
                  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                 WHERE T.DESGIN_KEY = C.DESGIN_KEY
                   AND C.PROCESS_CODE = '#PROCESS_CODE#'))
 ORDER BY ORDER_NO, ORDER_SEQ, CRAFT_SEQ
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.queryCraftLv2New" desc="二级工艺文件查询">
		<![CDATA[
SELECT DISTINCT T.ORD_LN_PK,
                T.CRAFT_SEQ,
                T.CRAFT_NO,
                T.DESGIN_KEY,
                T.LOCK_FLAG,
                DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
                T.VALIDFLAG,
                DECODE(T.VALIDFLAG,
                       '0',
                       '无效',
                       '1',
                       '生效',
                       '2',
                       '制定中',
                       '3',
                       '待科室审核',
                       '4',
                       '待审批',
                       '5',
                       '审核失败',
                       '6',
                       '待相关科室审核',
                       '7',
                       '待批准',
                       '未识别') VALIDFLAG_DESC,
                T.CREATE_NAME,
                TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                T.UPDATE_NAME,
                TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
                T.DELETE_NAME,
                TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
                T.AUDIT_NAME,
                TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
                T.APPROVAL_NAME,
                TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
                E.ORDER_NO,
                E.ORDER_SEQ,
                DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
                T.REASON,
                SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
                T.CRAFT_PATH CRAFT_PATH_OLD,
                T.CRAFT_NO_V,
                T.CRAFT_SOURCE,
                T.MEMO,
                T.CRAFT_FILE_LV2_D,
                T.CRAFT_FILE_LV2_D_DESC,
                T.UPDATE_NAME_LV2,
                T.UPDATE_TIME_LV2,
                (SELECT TO_CHAR(WM_CONCAT(C.PROCESS_CODE))
                   FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                  WHERE C.DESGIN_KEY = T.DESGIN_KEY
                    AND C.MSC_PLINE = ZGS.INDEX_SEQ) PROCESS_CODES,
                ZGS.INDEX_SEQ MSC_PLINE,
                ZGS.WHOLE_BACKLOG_DESC,
                E.PRODUCNAME,
                E.STD_STYLE_DESC,
                E.STEELNAME,
                E.STD_NAME,
                E.MSC,
                ZGS.OUTDIAMETER_ZG DIMATER,
                ZGS.WALLTHICK_ZG HEIGHT,
                E.SPEC_NAME,
                B.ORDER_SPEC_DESC,
                B.MODEL_DESC,
                B.ORDER_SPECIAL_DESC,
                D.DESCRIPTION_DIFF,
                D.DESCRIPTION_ALL,
                CHG.CHGE_VAL,
                B.LEN_DESC,
                B.FINAL_USER_DESC,
                DECODE(B.MAN_INSPECTION, '0', '不可手探', '1', '手探') MAN_INSPECTION,
                B.INSPECTION_VALUE,
                B.ORDER_UNIT,
                E.BASENAME OUTS_BILLET_FL,
                F.BASENAME OUTS_STL_PIPE_FL,
                DECODE(B.ASSEL_FL, '0', 'False', '1', 'True') ASSEL_FL,
                DECODE(B.PRODUCER_FL, '0', 'False', '1', 'True') PRODUCER_FL,
                TO_CHAR(ZGS.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_ZG,
                E.MODEL_CODE,
                ZGS.PLINE_NAME,
                DECODE(ZGS.EXE_STATUS,
                       '0',
                       '计划',
                       '1',
                       '生产中',
                       '2',
                       '完成',
                       '3',
                       '关闭A') EXE_STATUS,
                ZGS.PRO_PLAN_ID,
                ZGS.GX_PLAN_NO,
                ZGS.PLN_DIVIDE_ID,
                ZGS.ORD_LN_DLY_PK,
                DECODE(ZGS.ISENDGX, '1', '是', '否') ISENDGX,
                ZGS.GX_PRO_SEQ,
                ZGS.CIC_GP CIC,
                ZGS.PIC_GP PIC,
                ZGS.SIC_GP SIC,
                ZGS.DIC_GP DIC,
                ZGS.WIC_GP WIC,
                ZGS.GIC_GP GIC,
                DECODE(T.FLAG_D, '1', 'True', 'False') FLAG_D,
                DECODE(T.FLAG_E, '1', 'True', 'False') FLAG_E,
                DECODE(T.FLAG_F, '1', 'True', 'False') FLAG_F,
                DECODE(T.FLAG_G, '1', 'True', 'False') FLAG_G,
                DECODE(T.FLAG_H, '1', 'True', 'False') FLAG_H,
                DECODE(T.FLAG_JHD, '1', 'True', 'False') FLAG_JHD,
                ZGS.DECISION,
                ZGS.OUTNUM_CUT   CUT_NUM,
                NVL(T.DELETE_NAME, (SELECT  NVL(T5.UPDATE_NAME, T5.CREATE_NAME)
  FROM  CRAFT_ORD_DESIGN_MSC_PL T4,
       COM_MSC_BACKLOG         T5,
       CRAFT_ORD_DESIGN_MSC    T6
 WHERE   T4.DESGIN_KEY = T.DESGIN_KEY
   AND T5.MSC_PLINE = T4.MSC_PLINE
   AND T5.MSC = T6.MSC
   AND T6.DESGIN_KEY = T.DESGIN_KEY
   AND ROWNUM <= 1))  PROCESS_NAME
  FROM CRAFT_ORD_DESIGN T
  LEFT JOIN SLM_ORDER_LINE B
    ON T.ORD_LN_PK = B.ORD_LN_PK
  LEFT JOIN SLM_ORDER_HEAD A
    ON A.ORD_PK = B.ORD_PK
  LEFT JOIN COM_BASE_INFO E
    ON E.BASECODE = B.OUTS_BILLET_FL
  LEFT JOIN COM_BASE_INFO F
    ON E.BASECODE = B.OUTS_STL_PIPE_FL
  LEFT JOIN CHGE_SLM_APPLY_M CHG
    ON CHG.ORDER_CHGE_NO = B.ORDER_CHGE_NO
  LEFT JOIN (SELECT MAX(D.DESCRIPTION_DIFF) DESCRIPTION_DIFF,
                    MAX(D.DESCRIPTION_ALL) DESCRIPTION_ALL,
                    D.DESGIN_KEY
               FROM CRAFT_ORD_DESIGN_ADD_ASK D
              GROUP BY D.DESGIN_KEY) D
    ON D.DESGIN_KEY = T.DESGIN_KEY, PLN_ORDER_ZG_S ZGS, PLN_SALEORD E
 WHERE E.ORD_LN_PK = T.ORD_LN_PK
   AND E.ORD_LN_DLY_PK = ZGS.ORD_LN_DLY_PK
   AND T.CRAFT_SEQ = ZGS.CRAFT_SEQ
   AND {0} =  {0}
   AND ZGS.PLINE_NAME NOT LIKE '%外购%'
   AND ( {1} IS NULL OR  {1} = '1' OR
       (E.PORDERSTATUS IN ('1', '2', '3') OR
       (E.PORDERSTATUS IN ('4', '5') AND
       TO_DATE(E.ROLL_MONTH, 'YYYY-MM') =
       TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))))
   AND DECODE( {2}, NULL, '1', E.ORDER_NO) LIKE
       '%' || NVL( {2}, '1') || '%'
   AND DECODE( {3}, NULL, '1', E.ORDER_SEQ) LIKE
       '%' || NVL( {3}, '1') || '%'
   AND DECODE( {4}, NULL, '1', T.CRAFT_NO) LIKE '%' || NVL( {4}, '1') || '%'
   AND DECODE( {5}, NULL, NULL, T.CRAFT_FILE_LV2_D) IS NULL
   AND EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
         WHERE T.DESGIN_KEY = C.DESGIN_KEY
           AND C.PROCESS_CODE = {6}) #PLINE_CODE#
 ORDER BY PLINE_NAME, TO_NUMBER(GX_PRO_SEQ), ORDER_NO, ORDER_SEQ, CRAFT_SEQ

		]]>
	</query>

	<query id="CraftOrdDesignDAL.queryCraftLv2New_DBK" desc="二级工艺文件查询">
		<![CDATA[
SELECT DISTINCT T.ORD_LN_PK,
                T.CRAFT_SEQ,
                T.CRAFT_NO,
                T.DESGIN_KEY,
                T.LOCK_FLAG,
                DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
                T.VALIDFLAG,
                DECODE(T.VALIDFLAG,
                       '0',
                       '无效',
                       '1',
                       '生效',
                       '2',
                       '制定中',
                       '3',
                       '待科室审核',
                       '4',
                       '待审批',
                       '5',
                       '审核失败',
                       '6',
                       '待相关科室审核',
                       '7',
                       '待批准',
                       '未识别') VALIDFLAG_DESC,
                T.CREATE_NAME,
                TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                T.UPDATE_NAME,
                TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
                T.DELETE_NAME,
                TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
                T.AUDIT_NAME,
                TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
                T.APPROVAL_NAME,
                TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
                E.ORDER_NO,
                E.ORDER_SEQ,
                DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
                T.REASON,
                SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
                T.CRAFT_PATH CRAFT_PATH_OLD,
                T.CRAFT_NO_V,
                T.CRAFT_SOURCE,
                T.MEMO,
                T.CRAFT_FILE_LV2_D,
                (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                                ';') WITHIN GROUP(ORDER BY A.CRAFT_NO_LV2)
                   FROM CRAFT_FILE_LV2 A
                  WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
                T.UPDATE_NAME_LV2,
                T.UPDATE_TIME_LV2,
                (SELECT TO_CHAR(WM_CONCAT(C.PROCESS_CODE))
                   FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                  WHERE C.DESGIN_KEY = T.DESGIN_KEY
                    AND C.MSC_PLINE = DBKS.INDEX_SEQ) PROCESS_CODES,
                DBKS.INDEX_SEQ MSC_PLINE,
                DBKS.WHOLE_BACKLOG_DESC,
                E.PRODUCNAME,
                E.STD_STYLE_DESC,
                E.STEELNAME,
                E.STD_NAME,
                E.MSC,
                DBKS.AIMOUTDIAMETER DIMATER,
                DBKS.AIMWALLTHICK HEIGHT,
                E.SPEC_NAME,
                B.ORDER_SPEC_DESC,
                B.MODEL_DESC,
                B.ORDER_SPECIAL_DESC,
                D.DESCRIPTION_DIFF,
                D.DESCRIPTION_ALL,
                CHG.CHGE_VAL,
                B.LEN_DESC,
                B.FINAL_USER_DESC,
                DECODE(B.MAN_INSPECTION, '0', '不可手探', '1', '手探') MAN_INSPECTION,
                B.INSPECTION_VALUE,
                B.ORDER_UNIT,
                E.BASENAME OUTS_BILLET_FL,
                F.BASENAME OUTS_STL_PIPE_FL,
                DECODE(B.ASSEL_FL, '0', 'False', '1', 'True') ASSEL_FL,
                DECODE(B.PRODUCER_FL, '0', 'False', '1', 'True') PRODUCER_FL,
                TO_CHAR(DBKS.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_DBK,
                E.MODEL_CODE,
                DBKS.PLINE_NAME,
                DECODE(DBKS.EXE_STATUS,
                       '0',
                       '计划',
                       '1',
                       '生产中',
                       '2',
                       '完成',
                       '3',
                       '关闭A') EXE_STATUS,
                DBKS.PRO_PLAN_ID,
                DBKS.GX_PLAN_NO,
                DBKS.PLN_DIVIDE_ID,
                DBKS.ORD_LN_DLY_PK,
                DECODE(DBKS.ISENDGX, '1', '是', '否') ISENDGX,
                DBKS.GX_PRO_SEQ,
                (SELECT REGEXP_SUBSTR(DBKS.CIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) CIC,
                (SELECT REGEXP_SUBSTR(DBKS.PIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) PIC,
                (SELECT REGEXP_SUBSTR(DBKS.SIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) SIC,
                (SELECT REGEXP_SUBSTR(DBKS.DIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) DIC,
                (SELECT REGEXP_SUBSTR(DBKS.WIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) WIC,
                (SELECT REGEXP_SUBSTR(DBKS.GIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) GIC,
                DECODE(T.FLAG_D, '1', 'True', 'False') FLAG_D,
                DECODE(T.FLAG_E, '1', 'True', 'False') FLAG_E,
                DECODE(T.FLAG_F, '1', 'True', 'False') FLAG_F,
                DECODE(T.FLAG_G, '1', 'True', 'False') FLAG_G,
                DECODE(T.FLAG_H, '1', 'True', 'False') FLAG_H,
                DBKS.DECISION,
                NVL(T.DELETE_NAME, (SELECT  NVL(T5.UPDATE_NAME, T5.CREATE_NAME)
  FROM  CRAFT_ORD_DESIGN_MSC_PL T4,
       COM_MSC_BACKLOG         T5,
       CRAFT_ORD_DESIGN_MSC    T6
 WHERE   T4.DESGIN_KEY = T.DESGIN_KEY
   AND T5.MSC_PLINE = T4.MSC_PLINE
   AND T5.MSC = T6.MSC
   AND T6.DESGIN_KEY = T.DESGIN_KEY
   AND ROWNUM <= 1))  PROCESS_NAME
  FROM CRAFT_ORD_DESIGN T
  LEFT JOIN SLM_ORDER_LINE B
    ON T.ORD_LN_PK = B.ORD_LN_PK
  LEFT JOIN SLM_ORDER_HEAD A
    ON A.ORD_PK = B.ORD_PK
  LEFT JOIN COM_BASE_INFO E
    ON E.BASECODE = B.OUTS_BILLET_FL
  LEFT JOIN COM_BASE_INFO F
    ON E.BASECODE = B.OUTS_STL_PIPE_FL
  LEFT JOIN CHGE_SLM_APPLY_M CHG
    ON CHG.ORDER_CHGE_NO = B.ORDER_CHGE_NO
  LEFT JOIN (SELECT MAX(D.DESCRIPTION_DIFF) DESCRIPTION_DIFF,
                    MAX(D.DESCRIPTION_ALL) DESCRIPTION_ALL,
                    D.DESGIN_KEY
               FROM CRAFT_ORD_DESIGN_ADD_ASK D
              GROUP BY D.DESGIN_KEY) D
    ON D.DESGIN_KEY = T.DESGIN_KEY, PLN_ORDER_DBK_S DBKS, PLN_SALEORD E
 WHERE E.ORD_LN_PK = T.ORD_LN_PK
   AND E.ORD_LN_DLY_PK = DBKS.ORD_LN_DLY_PK
   AND T.CRAFT_SEQ = DBKS.CRAFT_SEQ
   AND  {0} =  {0}
   AND DBKS.PLINE_NAME NOT LIKE '%外购%'
   AND ({1} IS NULL OR {1} = '1' OR
       (E.PORDERSTATUS IN ('1', '2', '3') OR
       (E.PORDERSTATUS IN ('4', '5') AND
       TO_DATE(E.ROLL_MONTH, 'YYYY-MM') =
       TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))))
   AND DECODE({2}, NULL, '1', E.ORDER_NO) LIKE '%' || NVL({2}, '1') || '%'
   AND DECODE({3}, NULL, '1', E.ORDER_SEQ) LIKE '%' || NVL({3}, '1') || '%'
   AND DECODE({4}, NULL, '1', T.CRAFT_NO) LIKE '%' || NVL({4}, '1') || '%'
   AND DECODE({5}, NULL, NULL, T.CRAFT_FILE_LV2_D) IS NULL
   AND EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
         WHERE T.DESGIN_KEY = C.DESGIN_KEY
           AND C.PROCESS_CODE = {6}) #PLINE_CODE#
 ORDER BY PLINE_NAME, TO_NUMBER(GX_PRO_SEQ), ORDER_NO, ORDER_SEQ, CRAFT_SEQ

    ]]>
	</query>

	<query id="CraftOrdDesignDAL.queryCraftLv2New_RCL" desc="二级工艺文件查询">
		<![CDATA[
SELECT DISTINCT T.ORD_LN_PK,
                T.CRAFT_SEQ,
                T.CRAFT_NO,
                T.DESGIN_KEY,
                T.LOCK_FLAG,
                DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
                T.VALIDFLAG,
                DECODE(T.VALIDFLAG,
                       '0',
                       '无效',
                       '1',
                       '生效',
                       '2',
                       '制定中',
                       '3',
                       '待科室审核',
                       '4',
                       '待审批',
                       '5',
                       '审核失败',
                       '6',
                       '待相关科室审核',
                       '7',
                       '待批准',
                       '未识别') VALIDFLAG_DESC,
                T.CREATE_NAME,
                TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                T.UPDATE_NAME,
                TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
                T.DELETE_NAME,
                TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
                T.AUDIT_NAME,
                TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
                T.APPROVAL_NAME,
                TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
                E.ORDER_NO,
                E.ORDER_SEQ,
                DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
                T.REASON,
                SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
                T.CRAFT_PATH CRAFT_PATH_OLD,
                T.CRAFT_NO_V,
                T.CRAFT_SOURCE,
                T.MEMO,
                T.CRAFT_FILE_LV2_F,
                T.CRAFT_FILE_LV2_F_DESC,
                T.UPDATE_NAME_LV2,
                T.UPDATE_TIME_LV2,
                (SELECT TO_CHAR(WM_CONCAT(C.PROCESS_CODE))
                   FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                  WHERE C.DESGIN_KEY = T.DESGIN_KEY
                    AND C.MSC_PLINE = RCLS.INDEX_SEQ) PROCESS_CODES,
                RCLS.INDEX_SEQ MSC_PLINE,
                RCLS.WHOLE_BACKLOG_DESC,
                E.PRODUCNAME,
                E.STD_STYLE_DESC,
                E.STEELNAME,
                E.STD_NAME,
                E.MSC,
               RCLS.OUTDIAMETER DIMATER,
               RCLS.WALLTHICK HEIGHT,
                E.SPEC_NAME,
                B.ORDER_SPEC_DESC,
                B.MODEL_DESC,
                B.ORDER_SPECIAL_DESC,
                D.DESCRIPTION_DIFF,
                D.DESCRIPTION_ALL,
                CHG.CHGE_VAL,
                B.LEN_DESC,
                B.FINAL_USER_DESC,
                DECODE(B.MAN_INSPECTION, '0', '不可手探', '1', '手探') MAN_INSPECTION,
                B.INSPECTION_VALUE,
                B.ORDER_UNIT,
                E.BASENAME OUTS_BILLET_FL,
                F.BASENAME OUTS_STL_PIPE_FL,
                DECODE(B.ASSEL_FL, '0', 'False', '1', 'True') ASSEL_FL,
                DECODE(B.PRODUCER_FL, '0', 'False', '1', 'True') PRODUCER_FL,
                TO_CHAR(RCLS.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_RCL,
                E.MODEL_CODE,
                RCLS.PLINE_NAME,
                DECODE(RCLS.EXE_STATUS,
                       '0',
                       '计划',
                       '1',
                       '生产中',
                       '2',
                       '完成',
                       '3',
                       '关闭A') EXE_STATUS,
                RCLS.PRO_PLAN_ID,
                RCLS.GX_PLAN_NO,
                RCLS.PLN_DIVIDE_ID,
                RCLS.ORD_LN_DLY_PK,
                DECODE(RCLS.ISENDGX, '1', '是', '否') ISENDGX,
                RCLS.GX_PRO_SEQ,
                (SELECT REGEXP_SUBSTR(RCLS.CIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) CIC,
                (SELECT REGEXP_SUBSTR(RCLS.PIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) PIC,
                (SELECT REGEXP_SUBSTR(RCLS.SIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) SIC,
                (SELECT REGEXP_SUBSTR(RCLS.DIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) DIC,
                (SELECT REGEXP_SUBSTR(RCLS.WIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) WIC,
                (SELECT REGEXP_SUBSTR(RCLS.GIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) GIC,
                DECODE(T.FLAG_D, '1', 'True', 'False') FLAG_D,
                DECODE(T.FLAG_E, '1', 'True', 'False') FLAG_E,
                DECODE(T.FLAG_F, '1', 'True', 'False') FLAG_F,
                DECODE(T.FLAG_G, '1', 'True', 'False') FLAG_G,
                DECODE(T.FLAG_H, '1', 'True', 'False') FLAG_H,
                RCLS.DECISION,
                NVL(T.DELETE_NAME, (SELECT  NVL(T5.UPDATE_NAME, T5.CREATE_NAME)
  FROM  CRAFT_ORD_DESIGN_MSC_PL T4,
       COM_MSC_BACKLOG         T5,
       CRAFT_ORD_DESIGN_MSC    T6
 WHERE   T4.DESGIN_KEY = T.DESGIN_KEY
   AND T5.MSC_PLINE = T4.MSC_PLINE
   AND T5.MSC = T6.MSC
   AND T6.DESGIN_KEY = T.DESGIN_KEY
   AND ROWNUM <= 1))  PROCESS_NAME
  FROM CRAFT_ORD_DESIGN T
  LEFT JOIN SLM_ORDER_LINE B
    ON T.ORD_LN_PK = B.ORD_LN_PK
  LEFT JOIN SLM_ORDER_HEAD A
    ON A.ORD_PK = B.ORD_PK
  LEFT JOIN COM_BASE_INFO E
    ON E.BASECODE = B.OUTS_BILLET_FL
  LEFT JOIN COM_BASE_INFO F
    ON E.BASECODE = B.OUTS_STL_PIPE_FL
  LEFT JOIN CHGE_SLM_APPLY_M CHG
    ON CHG.ORDER_CHGE_NO = B.ORDER_CHGE_NO
  LEFT JOIN (SELECT MAX(D.DESCRIPTION_DIFF) DESCRIPTION_DIFF,
                    MAX(D.DESCRIPTION_ALL) DESCRIPTION_ALL,
                    D.DESGIN_KEY
               FROM CRAFT_ORD_DESIGN_ADD_ASK D
              GROUP BY D.DESGIN_KEY) D
    ON D.DESGIN_KEY = T.DESGIN_KEY, PLN_ORDER_RCL_S RCLS, PLN_SALEORD E
 WHERE E.ORD_LN_PK = T.ORD_LN_PK
   AND E.ORD_LN_DLY_PK = RCLS.ORD_LN_DLY_PK
   AND T.CRAFT_SEQ = RCLS.CRAFT_SEQ
   AND  {0} =  {0}
   AND RCLS.PLINE_NAME NOT LIKE '%外购%'
   AND ({1} IS NULL OR {1} = '1' OR
       (E.PORDERSTATUS IN ('1', '2', '3') OR
       (E.PORDERSTATUS IN ('4', '5') AND
       TO_DATE(E.ROLL_MONTH, 'YYYY-MM') =
       TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))))
   AND DECODE({2}, NULL, '1', E.ORDER_NO) LIKE '%' || NVL({2}, '1') || '%'
   AND DECODE({3}, NULL, '1', E.ORDER_SEQ) LIKE '%' || NVL({3}, '1') || '%'
   AND DECODE({4}, NULL, '1', T.CRAFT_NO) LIKE '%' || NVL({4}, '1') || '%'
   AND DECODE({5}, NULL, NULL, T.CRAFT_FILE_LV2_D) IS NULL
   AND EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
         WHERE T.DESGIN_KEY = C.DESGIN_KEY
           AND C.PROCESS_CODE = {6}) #PLINE_CODE#
 ORDER BY PLINE_NAME, TO_NUMBER(GX_PRO_SEQ), ORDER_NO, ORDER_SEQ, CRAFT_SEQ
    ]]>
	</query>

	<query id="CraftOrdDesignDAL.queryCraftLv2New_JGX" desc="二级工艺文件查询">
		<![CDATA[
SELECT DISTINCT T.ORD_LN_PK,
                T.CRAFT_SEQ,
                T.CRAFT_NO,
                T.DESGIN_KEY,
                T.LOCK_FLAG,
                DECODE(T.LOCK_FLAG, '0', '解锁', '1', '封锁', '未识别') LOCK_FLAG_DESC,
                T.VALIDFLAG,
                DECODE(T.VALIDFLAG,
                       '0',
                       '无效',
                       '1',
                       '生效',
                       '2',
                       '制定中',
                       '3',
                       '待科室审核',
                       '4',
                       '待审批',
                       '5',
                       '审核失败',
                       '6',
                       '待相关科室审核',
                       '7',
                       '待批准',
                       '未识别') VALIDFLAG_DESC,
                T.CREATE_NAME,
                TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                T.UPDATE_NAME,
                TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
                T.DELETE_NAME,
                TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
                T.AUDIT_NAME,
                TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
                T.APPROVAL_NAME,
                TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
                E.ORDER_NO,
                E.ORDER_SEQ,
                DECODE(T.QUALITY_FLAG, '1', '取MPS', '取MSC') QUALITY_FLAG,
                T.REASON,
                SUBSTR(T.CRAFT_PATH, INSTR(T.CRAFT_PATH, '/', -1, 1) + 1) CRAFT_PATH,
                T.CRAFT_PATH CRAFT_PATH_OLD,
                T.CRAFT_NO_V,
                T.CRAFT_SOURCE,
                T.MEMO,
                T.CRAFT_FILE_LV2_D,
                (SELECT LISTAGG(A.CRAFT_NO_LV2 || '【' || T.CREATE_NAME || '】',
                                ';') WITHIN GROUP(ORDER BY A.CRAFT_NO_LV2)
                   FROM CRAFT_FILE_LV2 A
                  WHERE INSTR(T.CRAFT_FILE_LV2_D, A.PK) > 0) CRAFT_FILE_LV2_D_DESC,
                T.UPDATE_NAME_LV2,
                T.UPDATE_TIME_LV2,
                (SELECT TO_CHAR(WM_CONCAT(C.PROCESS_CODE))
                   FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
                  WHERE C.DESGIN_KEY = T.DESGIN_KEY
                    AND C.MSC_PLINE = JGXS.INDEX_SEQ) PROCESS_CODES,
                JGXS.INDEX_SEQ MSC_PLINE,
                JGXS.WHOLE_BACKLOG_DESC,
                E.PRODUCNAME,
                E.STD_STYLE_DESC,
                E.STEELNAME,
                E.STD_NAME,
                E.MSC,
               JGXS.OUTDIAMETER DIMATER,
               JGXS.WALLTHICK HEIGHT,
                E.SPEC_NAME,
                B.ORDER_SPEC_DESC,
                B.MODEL_DESC,
                B.ORDER_SPECIAL_DESC,
                D.DESCRIPTION_DIFF,
                D.DESCRIPTION_ALL,
                CHG.CHGE_VAL,
                B.LEN_DESC,
                B.FINAL_USER_DESC,
                DECODE(B.MAN_INSPECTION, '0', '不可手探', '1', '手探') MAN_INSPECTION,
                B.INSPECTION_VALUE,
                B.ORDER_UNIT,
                E.BASENAME OUTS_BILLET_FL,
                F.BASENAME OUTS_STL_PIPE_FL,
                DECODE(B.ASSEL_FL, '0', 'False', '1', 'True') ASSEL_FL,
                DECODE(B.PRODUCER_FL, '0', 'False', '1', 'True') PRODUCER_FL,
                TO_CHAR(JGXS.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B_JGX,
                E.MODEL_CODE,
                JGXS.PLINE_NAME,
                DECODE(JGXS.EXE_STATUS,
                       '0',
                       '计划',
                       '1',
                       '生产中',
                       '2',
                       '完成',
                       '3',
                       '关闭A') EXE_STATUS,
                JGXS.PRO_PLAN_ID,
                JGXS.GX_PLAN_NO,
                JGXS.PLN_DIVIDE_ID,
                JGXS.ORD_LN_DLY_PK,
                DECODE(JGXS.ISENDGX, '1', '是', '否') ISENDGX,
                JGXS.GX_PRO_SEQ,
                (SELECT REGEXP_SUBSTR(JGXS.CIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) CIC,
                (SELECT REGEXP_SUBSTR(JGXS.PIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) PIC,
                (SELECT REGEXP_SUBSTR(JGXS.SIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) SIC,
                (SELECT REGEXP_SUBSTR(JGXS.DIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) DIC,
                (SELECT REGEXP_SUBSTR(JGXS.WIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) WIC,
                (SELECT REGEXP_SUBSTR(JGXS.GIC, '[^,]+', 1, ROWNUM)
                   FROM DUAL
                 CONNECT BY ROWNUM <= 1) GIC,
                DECODE(T.FLAG_D, '1', 'True', 'False') FLAG_D,
                DECODE(T.FLAG_E, '1', 'True', 'False') FLAG_E,
                DECODE(T.FLAG_F, '1', 'True', 'False') FLAG_F,
                DECODE(T.FLAG_G, '1', 'True', 'False') FLAG_G,
                DECODE(T.FLAG_H, '1', 'True', 'False') FLAG_H,
                JGXS.DECISION,
                NVL(T.DELETE_NAME, (SELECT  NVL(T5.UPDATE_NAME, T5.CREATE_NAME)
  FROM  CRAFT_ORD_DESIGN_MSC_PL T4,
       COM_MSC_BACKLOG         T5,
       CRAFT_ORD_DESIGN_MSC    T6
 WHERE   T4.DESGIN_KEY = T.DESGIN_KEY
   AND T5.MSC_PLINE = T4.MSC_PLINE
   AND T5.MSC = T6.MSC
   AND T6.DESGIN_KEY = T.DESGIN_KEY
   AND ROWNUM <= 1))  PROCESS_NAME
  FROM CRAFT_ORD_DESIGN T
  LEFT JOIN SLM_ORDER_LINE B
    ON T.ORD_LN_PK = B.ORD_LN_PK
  LEFT JOIN SLM_ORDER_HEAD A
    ON A.ORD_PK = B.ORD_PK
  LEFT JOIN COM_BASE_INFO E
    ON E.BASECODE = B.OUTS_BILLET_FL
  LEFT JOIN COM_BASE_INFO F
    ON E.BASECODE = B.OUTS_STL_PIPE_FL
  LEFT JOIN CHGE_SLM_APPLY_M CHG
    ON CHG.ORDER_CHGE_NO = B.ORDER_CHGE_NO
  LEFT JOIN (SELECT MAX(D.DESCRIPTION_DIFF) DESCRIPTION_DIFF,
                    MAX(D.DESCRIPTION_ALL) DESCRIPTION_ALL,
                    D.DESGIN_KEY
               FROM CRAFT_ORD_DESIGN_ADD_ASK D
              GROUP BY D.DESGIN_KEY) D
    ON D.DESGIN_KEY = T.DESGIN_KEY, PLN_ORDER_JGX_S JGXS, PLN_SALEORD E
 WHERE E.ORD_LN_PK = T.ORD_LN_PK
   AND E.ORD_LN_DLY_PK = JGXS.ORD_LN_DLY_PK
   AND T.CRAFT_SEQ = JGXS.CRAFT_SEQ
   AND  {0} =  {0}
   AND JGXS.PLINE_NAME NOT LIKE '%外购%'
   AND ({1} IS NULL OR {1} = '1' OR
       (E.PORDERSTATUS IN ('1', '2', '3') OR
       (E.PORDERSTATUS IN ('4', '5') AND
       TO_DATE(E.ROLL_MONTH, 'YYYY-MM') =
       TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))))
   AND DECODE({2}, NULL, '1', E.ORDER_NO) LIKE '%' || NVL({2}, '1') || '%'
   AND DECODE({3}, NULL, '1', E.ORDER_SEQ) LIKE '%' || NVL({3}, '1') || '%'
   AND DECODE({4}, NULL, '1', T.CRAFT_NO) LIKE '%' || NVL({4}, '1') || '%'
   AND DECODE({5}, NULL, NULL, T.CRAFT_FILE_LV2_D) IS NULL
   AND EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_MSC_PL_PRC C
         WHERE T.DESGIN_KEY = C.DESGIN_KEY
           AND C.PROCESS_CODE = {6}) #PLINE_CODE#
 ORDER BY PLINE_NAME, TO_NUMBER(GX_PRO_SEQ), ORDER_NO, ORDER_SEQ, CRAFT_SEQ
    ]]>
	</query>

	<query id="CraftOrdDesignDAL.GetUnfinishTimeZg" desc="获取轧管未完成时间">
		<![CDATA[
select CONVERT(varchar(100),
               min(case 状态
                     when 1 then
                      生产时间
                     when 2 then
                      生产时间
                     else
                      null
                   end),
               20) UNFINISH_TIME,  PK码  PK
  from V_LZ_CX_STATUS t
 group by t.PK码
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.queryByPk" desc="通过主键查询工艺评审主表">
		<![CDATA[
 SELECT *
 FROM CRAFT_ORD_DESIGN T
 WHERE
T.ORD_LN_PK = '#ORD_LN_PK#'
AND T.CRAFT_SEQ = '#CRAFT_SEQ#'	
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.updateByPk" desc="修改工艺评审主表">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.CRAFT_NO    = '#CRAFT_NO#',
       T.DESGIN_KEY  = '#DESGIN_KEY#',
       T.LOCK_FLAG   = '#LOCK_FLAG#',
       T.VALIDFLAG   = '#VALIDFLAG#',
       T.UPDATE_NAME = '#UPDATE_NAME#',
       T.UPDATE_TIME = SYSDATE
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.audit" desc="科室审核">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET 
       T.LOCK_FLAG   = '#LOCK_FLAG#',
       T.VALIDFLAG   = '#VALIDFLAG#',
       T.REASON = DECODE('#REASON#', NULL, T.REASON, '#REASON#'),
       T.AUDIT_TIME = SYSDATE
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
		<query id="CraftOrdDesignDAL.updateMessage" desc="科室审核">
		<![CDATA[
		UPDATE APP_MESSAGE T
		   SET 
		       T.APPROVAL_NODE   = {0},
		       T.EVENT_KEY   = {1}
		 WHERE T.REFER_KEY = {2}
		 AND T.VALIDFLAG='20'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.deleteMessage" desc="科室审核">
		<![CDATA[
		UPDATE APP_MESSAGE T
		   SET 
		       T.VALIDFLAG   = {0}
		 WHERE T.REFER_KEY = {1}
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.audit1" desc="相关科室审核">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET 
       T.LOCK_FLAG   = '#LOCK_FLAG#',
       T.VALIDFLAG   = '#VALIDFLAG#',
       T.REASON = DECODE('#REASON#', NULL, T.REASON, '#REASON#'),
       T.AUDIT_TIME1 = SYSDATE
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.approval" desc="审批">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET 
       T.LOCK_FLAG   = '#LOCK_FLAG#',
       T.VALIDFLAG   = '#VALIDFLAG#',
       T.REASON = DECODE('#REASON#', NULL, T.REASON, '#REASON#'),
       T.APPROVAL_TIME = SYSDATE
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.approval1" desc="批准">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET 
       T.LOCK_FLAG   = '#LOCK_FLAG#',
       T.VALIDFLAG   = '#VALIDFLAG#',
       T.REASON = DECODE('#REASON#', NULL, T.REASON, '#REASON#'),
       T.APPROVAL_TIME1 = SYSDATE
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.createCraft" desc="创建工艺文件">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.LOCK_FLAG    = '#LOCK_FLAG#',
       T.REASON       = '',
       T.DELETE_NAME  = '#DELETE_NAME#',
       T.DELETE_TIME  = SYSDATE,
       T.CREATE_NAME = '#DELETE_NAME#',
       T.CRAFT_NO     = '#CRAFT_NO#',
       T.CRAFT_PATH   = '#CRAFT_PATH#',
       T.CRAFT_NO_V   = '#CRAFT_NO_V#',
       T.CRAFT_SOURCE = '#CRAFT_SOURCE#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.insertCraftDesignAppoint" desc="新增工艺负责人">
		<![CDATA[
INSERT INTO CRAFT_ORD_DESIGN_APPOINT(ORD_LN_PK, CRAFT_NAME, CRAFT_ID) VALUES({0}, {1}, {2})
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftDesignAppointCnt" desc="获取工艺负责人">
		<![CDATA[
SELECT COUNT(1) VALUE FROM CRAFT_ORD_DESIGN_APPOINT T WHERE T.ORD_LN_PK = {0}
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.unLock" desc="解锁工艺文件">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.LOCK_FLAG = '0',
       T.VALIDFLAG = '2'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.lock" desc="解锁工艺文件">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.LOCK_FLAG = '1'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.setMemo" desc="修改备注">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.MEMO                  = '#MEMO#',
       T.OTHER_EDIT_NAME       = '#OTHER_EDIT_NAME#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.SaveCraftLv2" desc="修改二级工艺文件">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET 
       T.CRAFT_FILE_LV2_D      = '#CRAFT_FILE_LV2_D#',
       T.CRAFT_FILE_LV2_D_DESC = '#CRAFT_FILE_LV2_D_DESC#',
       T.CRAFT_FILE_LV2_E      = '#CRAFT_FILE_LV2_E#',
       T.CRAFT_FILE_LV2_E_DESC = '#CRAFT_FILE_LV2_E_DESC#',
       T.CRAFT_FILE_LV2_F      = '#CRAFT_FILE_LV2_F#',
       T.CRAFT_FILE_LV2_F_DESC = '#CRAFT_FILE_LV2_F_DESC#',
       T.CRAFT_FILE_LV2_G      = '#CRAFT_FILE_LV2_G#',
       T.CRAFT_FILE_LV2_G_DESC = '#CRAFT_FILE_LV2_G_DESC#',
       T.CRAFT_FILE_LV2_H      = '#CRAFT_FILE_LV2_H#',
       T.CRAFT_FILE_LV2_H_DESC = '#CRAFT_FILE_LV2_H_DESC#',
       T.UPDATE_NAME_LV2 = '#UPDATE_NAME_LV2#',
       T.UPDATE_TIME_LV2 = '#UPDATE_TIME_LV2#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.updateCraftNo" desc="创建工艺文件号">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.CRAFT_NO     = '#CRAFT_NO#',
       T.LOCK_FLAG    = '0',
       T.VALIDFLAG    = '3',
       T.REASON       = '',
       T.DELETE_NAME  = '#UPDATE_NAME#',
       T.DELETE_TIME  = SYSDATE,
       T.CRAFT_NO_V  = '#CRAFT_NO_V#',
       T.CRAFT_SOURCE = '#CRAFT_SOURCE#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.createCraftNo" desc="创建工艺文件号">
		<![CDATA[
SELECT DECODE(SUBSTR('#ORD_LN_PK#', 1, 2),
              'BL',
              T.ORD_LN_PK || '-' || LPAD(T.CRAFT_SEQ, 3, '0'),
              (SELECT A.ORDER_NO || '/' || B.ORDER_SEQ || '-' || LPAD(T.CRAFT_SEQ, 3, '0')
                 FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B
                WHERE A.ORD_PK = B.ORD_PK
                  AND B.ORD_LN_PK = T.ORD_LN_PK)) VALUE
  FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.createCraftPDFName" desc="创建PDF名称">
		<![CDATA[
SELECT DECODE(SUBSTR('#ORD_LN_PK#', 1, 2),
              'BL',
              T.ORD_LN_PK || '-' || LPAD(T.CRAFT_SEQ, 3, '0'),
              (SELECT A.ORDER_NO || '-' || B.ORDER_SEQ || '-' || LPAD(T.CRAFT_SEQ, 3, '0')
                 FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B
                WHERE A.ORD_PK = B.ORD_PK
                  AND B.ORD_LN_PK = T.ORD_LN_PK)) VALUE
  FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.queryCraftByOrLnPk" desc="通过合同行主键查询工艺评审记录">
		<![CDATA[
SELECT *
  FROM CRAFT_ORD_DESIGN A
 WHERE A.ORD_LN_PK = '#ORD_LN_PK#'
   AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN
                       WHERE ORD_LN_PK = A.ORD_LN_PK)
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.updateCraftPath" desc="修改工艺文件路径">
		<![CDATA[
DECLARE
BEGIN
  UPDATE CRAFT_ORD_DESIGN T
     SET T.CRAFT_PATH   = '#CRAFT_PATH#',
         T.CRAFT_NO     = '#CRAFT_NO#',
         T.REASON       = '',
         T.DELETE_NAME  = '#UPDATE_NAME#',
         T.DELETE_TIME  = SYSDATE,
         T.VALIDFLAG    = '#VALIDFLAG#',
         T.LOCK_FLAG    = '#LOCK_FLAG#',
         T.CRAFT_NO_V   = '#CRAFT_NO_V#',
         T.CRAFT_SOURCE = '#CRAFT_SOURCE#'
   WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
     AND T.CRAFT_SEQ = '#CRAFT_SEQ#';

  UPDATE CRAFT_ORD_DESIGN T
     SET T.CRAFT_PATH = '#CRAFT_PATH#'
   WHERE T.CRAFT_NO = '#CRAFT_NO#'
     AND T.CRAFT_NO_V = '#CRAFT_NO_V#';
END;
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getMaxCraftNoV" desc="获取最大的工艺文件版本号">
		<![CDATA[
SELECT LPAD(MAX(CRAFT_NO_V) + 1, 2, '0') VALUE
    FROM CRAFT_ORD_DESIGN
   WHERE CRAFT_NO = '#CRAFT_NO#'
     AND (ORD_LN_PK <> '#ORD_LN_PK#' OR
         CRAFT_SEQ <> '#CRAFT_SEQ#')
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftOrdDesignByPk" desc="通过主键查询工艺记录">
		<![CDATA[
SELECT * FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.updateOrdLnCraft" desc="修改合同行表工艺数据">
		<![CDATA[
UPDATE SLM_ORDER_LINE T
   SET T.CRAFT_NO = '#CRAFT_NO#', T.CRAFT_NO_V = '#CRAFT_NO_V#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.setCraftValidByOrdLnPk" desc="通过工艺文件号把低版本的置为无效">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.VALIDFLAG = '0'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ < #CRAFT_SEQ#
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.insertCraftOrdDesignFile" desc="新增工艺文件记录">
		<![CDATA[
DECLARE
  P_COUNT     VARCHAR(5);
  P_ORD_LN_PK CRAFT_ORD_DESIGN.ORD_LN_PK%TYPE;
  P_CRAFT_SEQ CRAFT_ORD_DESIGN.CRAFT_SEQ%TYPE;
BEGIN

  INSERT INTO CRAFT_ORD_DESIGN_FILE
    (CRAFT_NO, CRAFT_PATH, CRAFT_NO_V, CREATE_NAME, CREATE_TIME, CRAFT_KEY)
  VALUES
    ('#CRAFT_NO#',
     '#CRAFT_PATH#',
     '#CRAFT_NO_V#',
     '#CREATE_NAME#',
     SYSDATE,
     '#CRAFT_KEY#');

  IF '#CRAFT_NO_V#' <> '00' THEN
    FOR V_ROW IN (SELECT T.ORD_LN_PK, T.CRAFT_SEQ
                    FROM CRAFT_ORD_DESIGN T
                   WHERE T.Craft_No = '#CRAFT_NO#'
                     AND T.CRAFT_SOURCE = '人工上传'
                     AND T.VALIDFLAG = '1'
                     AND T.CRAFT_SEQ =
                         (SELECT MAX(CRAFT_SEQ)
                            FROM CRAFT_ORD_DESIGN
                           WHERE Craft_No = '#CRAFT_NO#'
                             AND CRAFT_SOURCE = '人工上传'
                             AND VALIDFLAG = '1')) LOOP
    
      UPDATE CRAFT_ORD_DESIGN T
         SET T.CRAFT_NO     = '#CRAFT_NO#',
             T.CRAFT_PATH   = '#CRAFT_PATH#',
             T.VALIDFLAG    = '1',
             T.CRAFT_NO_V   = '#CRAFT_NO_V#',
             T.CRAFT_SOURCE = '人工上传'
       WHERE T.ORD_LN_PK = V_ROW.ORD_LN_PK
         AND T.CRAFT_SEQ = V_ROW.CRAFT_SEQ;
    
      UPDATE CRAFT_ORD_DESIGN T
         SET T.VALIDFLAG = '0'
       WHERE T.ORD_LN_PK = V_ROW.ORD_LN_PK
         AND T.CRAFT_SEQ < V_ROW.CRAFT_SEQ;
    
      UPDATE SLM_ORDER_LINE T
         SET T.CRAFT_NO = '#CRAFT_NO#', T.CRAFT_NO_V = '#CRAFT_NO_V#'
       WHERE T.ORD_LN_PK = V_ROW.ORD_LN_PK;
    END LOOP;
  END IF;
END;
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftFileByPk" desc="通过主键查询工艺文件记录">
		<![CDATA[
SELECT *
  FROM CRAFT_ORD_DESIGN_FILE T
 WHERE T.CRAFT_NO = '#CRAFT_NO#'
   AND T.CRAFT_NO_V = '#CRAFT_NO_V#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftFileMaxCraftNoV" desc="查询最大的工艺文件版本号">
		<![CDATA[
SELECT LPAD(NVL(MAX(T.CRAFT_NO_V), '00') + 1, 2, '0') CRAFT_NO_V
  FROM CRAFT_ORD_DESIGN_FILE T
 WHERE T.CRAFT_NO = '#CRAFT_NO#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftFileCraftNoCnt" desc="获取工艺文件表中的工艺文件号数目">
		<![CDATA[
SELECT COUNT(1) FROM CRAFT_ORD_DESIGN_FILE T WHERE T.CRAFT_NO = '#CRAFT_NO#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftNoCnt" desc="获取工艺文件号的数目">
		<![CDATA[
SELECT COUNT(1) FROM CRAFT_ORD_DESIGN T WHERE T.CRAFT_NO = '#CRAFT_NO#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getRefCraftNoCnt" desc="获取引用的工艺文件号的数目">
		<![CDATA[
SELECT COUNT(1) FROM CRAFT_ORD_DESIGN T WHERE T.CRAFT_NO = '#CRAFT_NO#'
AND T.ORD_LN_PK <> '#ORD_LN_PK#' AND T.CRAFT_SEQ <> '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftMaxCraftNoV" desc="查询最大的工艺文件版本号">
		<![CDATA[
SELECT LPAD(NVL(MAX(T.CRAFT_NO_V), '00') + 1, 2, '0') CRAFT_NO_V
  FROM CRAFT_ORD_DESIGN T
 WHERE T.CRAFT_NO = '#CRAFT_NO#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.copyCraftDesign" desc="复制工艺制定主信息">
		<![CDATA[
DECLARE
  P_ORD_LN_PK_OLD  CRAFT_ORD_DESIGN.ORD_LN_PK%TYPE := '#ORD_LN_PK_OLD#';
  P_ORD_LN_PK_NEW  CRAFT_ORD_DESIGN.ORD_LN_PK%TYPE := '#ORD_LN_PK_NEW#';
  P_DESIGN_KEY_OLD CRAFT_ORD_DESIGN.DESGIN_KEY%TYPE;
  P_DESIGN_KEY_NEW CRAFT_ORD_DESIGN.DESGIN_KEY%TYPE;
  P_COUNT          NUMBER(5);
  P_CRAFT_SEQ      CRAFT_ORD_DESIGN.CRAFT_SEQ%TYPE;
  P_CRAFT_SEQ_OLD  CRAFT_ORD_DESIGN.CRAFT_SEQ%TYPE := '#CRAFT_SEQ_OLD#';
  P_CRAFT_NO       CRAFT_ORD_DESIGN.CRAFT_NO%TYPE := '#CRAFT_NO#';

BEGIN
  SELECT DESGIN_KEY
    INTO P_DESIGN_KEY_OLD
    FROM CRAFT_ORD_DESIGN
   WHERE ORD_LN_PK = P_ORD_LN_PK_OLD
     AND CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN
                       WHERE ORD_LN_PK = P_ORD_LN_PK_OLD);


  SELECT NVL(MAX(CRAFT_SEQ), 0) + 1
    INTO P_CRAFT_SEQ
    FROM CRAFT_ORD_DESIGN
   WHERE ORD_LN_PK = P_ORD_LN_PK_NEW;
  SELECT COUNT(1)
    INTO P_COUNT
    FROM CRAFT_ORD_DESIGN
   WHERE ORD_LN_PK = P_ORD_LN_PK_NEW
     AND CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN
                       WHERE ORD_LN_PK = P_ORD_LN_PK_NEW);
  IF P_COUNT > 0 THEN
    SELECT DESGIN_KEY
      INTO P_DESIGN_KEY_NEW
      FROM CRAFT_ORD_DESIGN
     WHERE ORD_LN_PK = P_ORD_LN_PK_NEW
       AND CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                          FROM CRAFT_ORD_DESIGN
                         WHERE ORD_LN_PK = P_ORD_LN_PK_NEW);
  END IF;
  
  IF P_COUNT > 0 THEN
    DELETE FROM CRAFT_ORD_DESIGN WHERE ORD_LN_PK = P_ORD_LN_PK_NEW
       AND CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                          FROM CRAFT_ORD_DESIGN
                         WHERE ORD_LN_PK = P_ORD_LN_PK_NEW);
    DELETE FROM CRAFT_ORD_DESIGN_MSC WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_BILT
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_BILT_C
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_BILT_C_PL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_BILT_PL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_BL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_GZ_GG
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_GZ_GG_PL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_JG
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_JG_BL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_JG_PL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_JG_PL_STI
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL_GX_PRL
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL_GZ
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL_PC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL_PC_LST
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL_PRC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL_STI
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_MSC_PL_STI_TC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD_CIC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD_DIC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD_GIC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD_PIC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD_PIC_SMP
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD_SIC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STD_WIC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STS_PL_PC
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STS_PL_PC_LST
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STS_TKLG
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_STS_TKLG_LST
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
    DELETE FROM CRAFT_ORD_DESIGN_ADD_ASK
     WHERE DESGIN_KEY = P_DESIGN_KEY_NEW;
  END IF;
  INSERT INTO CRAFT_ORD_DESIGN
    (ORD_LN_PK,
     CRAFT_SEQ,
     CRAFT_NO,
     DESGIN_KEY,
     LOCK_FLAG,
     VALIDFLAG,
     CREATE_NAME,
     CREATE_TIME,
     UPDATE_NAME,
     UPDATE_TIME,
     DELETE_NAME,
     DELETE_TIME,
     AUDIT_NAME,
     AUDIT_TIME,
     APPROVAL_NAME,
     APPROVAL_TIME,
     CRAFT_NAME,
     CRAFT_TIME,
     CRAFT_ID,
     QUALITY_FLAG,
     REASON,
     CRAFT_PATH,
     CRAFT_NO_V,
     CRAFT_SOURCE,
     MEMO)
    SELECT P_ORD_LN_PK_NEW,
           P_CRAFT_SEQ,
           P_CRAFT_NO,
           DESGIN_KEY,
           LOCK_FLAG,
           VALIDFLAG,
           CREATE_NAME,
           CREATE_TIME,
           UPDATE_NAME,
           UPDATE_TIME,
           DELETE_NAME,
           DELETE_TIME,
           AUDIT_NAME,
           AUDIT_TIME,
           APPROVAL_NAME,
           APPROVAL_TIME,
           CRAFT_NAME,
           CRAFT_TIME,
           CRAFT_ID,
           QUALITY_FLAG,
           REASON,
           CRAFT_PATH,
           CRAFT_NO_V,
	       CRAFT_SOURCE,
	       MEMO
      FROM CRAFT_ORD_DESIGN
     WHERE DESGIN_KEY = P_DESIGN_KEY_OLD
       AND CRAFT_SEQ = P_CRAFT_SEQ_OLD;
END;
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftValidCntByOrLnPk" desc="通过合同行主键查询有效数目">
		<![CDATA[
SELECT COUNT(1)
  FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.matchCraftFile" desc="匹配工艺文件">
		<![CDATA[
DECLARE
  P_CRAFT_SEQ CRAFT_ORD_DESIGN.CRAFT_SEQ%TYPE;
  P_COUNT     NUMBER(5);
BEGIN
  SELECT COUNT(1)
    INTO P_COUNT
    FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STS_TKLG A
   WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
     AND T.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                          FROM CRAFT_ORD_DESIGN
                         WHERE ORD_LN_PK = '#ORD_LN_PK#')
     AND T.VALIDFLAG = '2'
     AND T.LOCK_FLAG = '1'
     AND T.DESGIN_KEY = A.DESGIN_KEY
     AND A.DESIGN_STS = 'S';

  IF P_COUNT > 0 THEN
    SELECT CRAFT_SEQ
      INTO P_CRAFT_SEQ
      FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STS_TKLG A
     WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
       AND T.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                            FROM CRAFT_ORD_DESIGN
                           WHERE ORD_LN_PK = '#ORD_LN_PK#')
       AND T.VALIDFLAG = '2'
       AND T.LOCK_FLAG = '1'
       AND T.DESGIN_KEY = A.DESGIN_KEY
       AND A.DESIGN_STS = 'S';
  
    UPDATE CRAFT_ORD_DESIGN T
       SET T.CRAFT_NO     = '#CRAFT_NO#',
           T.CRAFT_PATH   = '#CRAFT_PATH#',
           T.VALIDFLAG    = '1',
           T.CRAFT_NO_V   = '#CRAFT_NO_V#',
           T.CRAFT_SOURCE = '人工上传',
           T.DELETE_NAME = '#DELETE_NAME#',
           T.DELETE_TIME = SYSDATE
     WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
       AND T.CRAFT_SEQ = P_CRAFT_SEQ;
  
    UPDATE CRAFT_ORD_DESIGN T
       SET T.VALIDFLAG = '0'
     WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
       AND T.CRAFT_SEQ < P_CRAFT_SEQ;
    UPDATE SLM_ORDER_LINE T
       SET T.CRAFT_NO = '#CRAFT_NO#', T.CRAFT_NO_V = '#CRAFT_NO_V#'
     WHERE T.ORD_LN_PK = '#ORD_LN_PK#';
  END IF;
END;
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getNewValidCraft" desc="查询最大的工艺号并且有效的。">
		<![CDATA[
SELECT *
     FROM CRAFT_ORD_DESIGN T
    WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
      AND T.VALIDFLAG = '1'
      AND T.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                           FROM CRAFT_ORD_DESIGN
                          WHERE ORD_LN_PK = '#ORD_LN_PK#'
                            AND VALIDFLAG = '1')
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.setCraftOrDesignValid" desc="设置最大的工艺序号生效">
		<![CDATA[
DECLARE
BEGIN
  UPDATE CRAFT_ORD_DESIGN T
     SET T.VALIDFLAG = '1'
   WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
     AND T.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                          FROM CRAFT_ORD_DESIGN
                         WHERE ORD_LN_PK = T.ORD_LN_PK)
     AND 'S' = (SELECT DESIGN_STS
                  FROM CRAFT_ORD_DESIGN_STS_TKLG
                 WHERE DESGIN_KEY = T.DESGIN_KEY);

  --除了最大的工艺记录生效，其它都置为无效
  UPDATE CRAFT_ORD_DESIGN T
     SET T.VALIDFLAG = '0'
   WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
     AND T.CRAFT_SEQ <> (SELECT MAX(CRAFT_SEQ)
                           FROM CRAFT_ORD_DESIGN
                          WHERE ORD_LN_PK = T.ORD_LN_PK);
END;
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftNoCntOutLn" desc="获取排除合同行的工艺文件数目">
		<![CDATA[
SELECT COUNT(1)
   FROM CRAFT_ORD_DESIGN T
  WHERE T.CRAFT_NO = '#CRAFT_NO#'
    AND T.CRAFT_NO_V = '#CRAFT_NO_V#'
    AND T.ORD_LN_PK <> '#ORD_LN_PK#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getDesignKeyCnt" desc="获取DESIGN_KEY数目">
		<![CDATA[
SELECT COUNT(1) FROM CRAFT_ORD_DESIGN T WHERE T.DESGIN_KEY = '#DESGIN_KEY#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCntByDesignKeyProcess" desc="查询一级工艺文件是否包含工序">
		<![CDATA[
 SELECT COUNT(1)
      FROM CRAFT_ORD_DESIGN_MSC_PL_PRC A
     WHERE A.DESGIN_KEY = '#DESGIN_KEY#'
     AND A.PROCESS_CODE = '#PROCESS_CODE#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.CopyCraftFileLv2" desc="复制二级工艺文件">
		<![CDATA[
MERGE INTO CRAFT_ORD_DESIGN A
USING CRAFT_ORD_DESIGN B
ON (B.ORD_LN_PK = '#ORD_LN_PK#' AND A.ORD_LN_PK = B.ORD_LN_PK
 AND B.CRAFT_SEQ = '#CRAFT_SEQ#' AND A.CRAFT_SEQ = '#CRAFT_SEQ2#')
WHEN MATCHED THEN
  UPDATE
     SET A.CRAFT_FILE_LV2_D      = B.CRAFT_FILE_LV2_D,
         A.CRAFT_FILE_LV2_D_DESC = B.CRAFT_FILE_LV2_D_DESC,
         A.CRAFT_FILE_LV2_E      = B.CRAFT_FILE_LV2_E,
         A.CRAFT_FILE_LV2_E_DESC = B.CRAFT_FILE_LV2_E_DESC,
         A.CRAFT_FILE_LV2_F      = B.CRAFT_FILE_LV2_F,
         A.CRAFT_FILE_LV2_F_DESC = B.CRAFT_FILE_LV2_F_DESC,
         A.CRAFT_FILE_LV2_G      = B.CRAFT_FILE_LV2_G,
         A.CRAFT_FILE_LV2_G_DESC = B.CRAFT_FILE_LV2_G_DESC,
         A.CRAFT_FILE_LV2_H      = B.CRAFT_FILE_LV2_H,
         A.CRAFT_FILE_LV2_H_DESC = B.CRAFT_FILE_LV2_H_DESC
		]]>
	</query>
	<query id="CraftOrdDesignDAL.GetPreviousCraftLv2" desc="获取上一个二级工艺文件">
		<![CDATA[
SELECT T.ORD_LN_PK, T.CRAFT_SEQ
  FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = TO_NUMBER('#CRAFT_SEQ#') - 1
   AND (T.CRAFT_FILE_LV2_D IS NOT NULL OR T.CRAFT_FILE_LV2_E IS NOT NULL OR
       T.CRAFT_FILE_LV2_F IS NOT NULL OR
       T.CRAFT_FILE_LV2_G IS NOT NULL AND T.CRAFT_FILE_LV2_H IS NOT NULL)
		]]>
	</query>
	<query id="CraftOrdDesignDAL.DeleteCraftFile" desc="删除工艺文件">
		<![CDATA[
DELETE FROM CRAFT_ORD_DESIGN T
 WHERE T.CRAFT_NO = '#CRAFT_NO#'
   AND T.CRAFT_NO_V = '#CRAFT_NO_V#'
		]]>
	</query>
	<query id="CraftOrdDesignDAL.AutoCreateCraft" desc="自动生成工艺文件">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.CRAFT_NO       = '#CRAFT_NO#',
       T.CRAFT_NO_V     = '#CRAFT_NO_V#',
       T.CRAFT_PATH     = '#CRAFT_PATH#',
       T.CRAFT_SOURCE   = '#CRAFT_SOURCE#',
       T.UPDATE_NAME    = '#UPDATE_NAME#',
       T.UPDATE_TIME    = SYSDATE,
       T.AUDIT_NAME     = '#AUDIT_NAME#',
       T.AUDIT_TIME     = SYSDATE,
       T.APPROVAL_NAME  = '#APPROVAL_NAME#',
       T.APPROVAL_TIME  = SYSDATE,
       T.AUDIT_NAME1    = '#AUDIT_NAME1#',
       T.AUDIT_TIME1    = SYSDATE,
       T.APPROVAL_NAME1 = '#APPROVAL_NAME1#',
       T.APPROVAL_TIME1 = SYSDATE,
       T.DELETE_NAME = '#DELETE_NAME#',
       T.DELETE_TIME = SYSDATE
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	<query id="CraftOrdDesignDAL.SetValidflagByPk" desc="设置工艺文件生效">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.VALIDFLAG     = {0}
 WHERE T.ORD_LN_PK = {1}
   AND T.CRAFT_SEQ = {2}
		]]>
	</query>
	<query id="CraftOrdDesignDAL.GetAutoPeople" desc="获取自动生成工艺文件评审人">
		<![CDATA[
SELECT D.USERNAME AUDIT_DESC,
       E.USERNAME AUDIT_DESC1,
       F.USERNAME APPROVE_DESC,
       G.USERNAME APPROVE_DESC1,
       NVL(J.UPDATE_NAME, J.CREATE_NAME) UPDATE_NAME
  FROM SLM_ORDER_LINE A, COM_MSC B, CRAFT_AUTO_PEOPLE C
  LEFT JOIN CORE_APP_USER D
    ON D.USERID = C.AUDIT_CODE
  LEFT JOIN CORE_APP_USER E
    ON E.USERID = C.AUDIT_CODE1
  LEFT JOIN CORE_APP_USER F
    ON F.USERID = C.APPROVE_CODE
  LEFT JOIN CORE_APP_USER G
    ON G.USERID = C.APPROVE_CODE1, CRAFT_ORD_DESIGN H,
 CRAFT_ORD_DESIGN_MSC_PL I, COM_MSC_BACKLOG J
 WHERE A.ORD_LN_PK = {0}
   AND A.MSC = B.MSC
   AND B.UNIT_CODE_PROCESS = C.UNIT_CODE
   AND C.AUTO_FLAG = '1'
   AND H.ORD_LN_PK = {1}
   AND H.CRAFT_SEQ = {2}
   AND I.DESGIN_KEY = H.DESGIN_KEY
   AND J.MSC = B.MSC
   AND J.MSC_PLINE = I.MSC_PLINE
   AND ROWNUM <= 1
UNION ALL
SELECT D.USERNAME AUDIT_DESC,
       E.USERNAME AUDIT_DESC1,
       F.USERNAME APPROVE_DESC,
       G.USERNAME APPROVE_DESC1,
       NVL(J.UPDATE_NAME, J.CREATE_NAME) UPDATE_NAME
  FROM COM_MSC_BL A, COM_MSC B, CRAFT_AUTO_PEOPLE C
  LEFT JOIN CORE_APP_USER D
    ON D.USERID = C.AUDIT_CODE
  LEFT JOIN CORE_APP_USER E
    ON E.USERID = C.AUDIT_CODE1
  LEFT JOIN CORE_APP_USER F
    ON F.USERID = C.APPROVE_CODE
  LEFT JOIN CORE_APP_USER G
    ON G.USERID = C.APPROVE_CODE1, CRAFT_ORD_DESIGN H,
 CRAFT_ORD_DESIGN_MSC_PL I, COM_MSC_BACKLOG J
 WHERE A.PSC_BL = {0}
   AND A.PRODUCCODE = B.PRODUCCODE
   AND A.STD_CODE = B.STD_CODE
   AND A.STEELCODE = B.STEELCODE
   AND NVL(A.STD_STYLE, '1') = NVL(B.STD_STYLE, '1')
   AND B.UNIT_CODE_PROCESS = C.UNIT_CODE
   AND INSTR({0}, 'BL') > 0
   AND A.USE_CODE = B.USE_CODE
   AND C.AUTO_FLAG = '1'
   AND H.ORD_LN_PK = {1}
   AND H.CRAFT_SEQ = {2}
   AND I.DESGIN_KEY = H.DESGIN_KEY
   AND J.MSC = B.MSC
   AND J.MSC_PLINE = I.MSC_PLINE
   AND ROWNUM <= 1
		]]>
	</query>


	<query id="CraftOrdDesignDAL.GetAutoPeopleTh" desc="获取自动生成工艺文件评审人">
		<![CDATA[
SELECT D.USERNAME AUDIT_DESC,
       E.USERNAME AUDIT_DESC1,
       F.USERNAME APPROVE_DESC,
       G.USERNAME APPROVE_DESC1,
       NVL(J.UPDATE_NAME, J.CREATE_NAME) UPDATE_NAME
  FROM SLM_ORDER_LINE A, COM_MSC B, CRAFT_AUTO_PEOPLE C
  LEFT JOIN CORE_APP_USER D
    ON D.USERID = C.AUDIT_CODE
  LEFT JOIN CORE_APP_USER E
    ON E.USERID = C.AUDIT_CODE1
  LEFT JOIN CORE_APP_USER F
    ON F.USERID = C.APPROVE_CODE
  LEFT JOIN CORE_APP_USER G
    ON G.USERID = C.APPROVE_CODE1, CRAFT_ORD_DESIGN H,
 CRAFT_ORD_DESIGN_MSC_PL I, COM_MSC_BACKLOG J
 WHERE A.ORD_LN_PK = {0}
   AND A.MSC = B.MSC
   -- AND B.UNIT_CODE_PROCESS = C.UNIT_CODE
   AND C.UNIT_CODE = '002023005003'
   AND C.AUTO_FLAG = '1'
   AND H.ORD_LN_PK = {1}
   AND H.CRAFT_SEQ = {2}
   AND I.DESGIN_KEY = H.DESGIN_KEY
   AND J.MSC = B.MSC
   AND J.MSC_PLINE = I.MSC_PLINE
   AND ROWNUM <= 1
UNION ALL
SELECT D.USERNAME AUDIT_DESC,
       E.USERNAME AUDIT_DESC1,
       F.USERNAME APPROVE_DESC,
       G.USERNAME APPROVE_DESC1,
       NVL(J.UPDATE_NAME, J.CREATE_NAME) UPDATE_NAME
  FROM COM_MSC_BL A, COM_MSC B, CRAFT_AUTO_PEOPLE C
  LEFT JOIN CORE_APP_USER D
    ON D.USERID = C.AUDIT_CODE
  LEFT JOIN CORE_APP_USER E
    ON E.USERID = C.AUDIT_CODE1
  LEFT JOIN CORE_APP_USER F
    ON F.USERID = C.APPROVE_CODE
  LEFT JOIN CORE_APP_USER G
    ON G.USERID = C.APPROVE_CODE1, CRAFT_ORD_DESIGN H,
 CRAFT_ORD_DESIGN_MSC_PL I, COM_MSC_BACKLOG J
 WHERE A.PSC_BL = {0}
   AND A.PRODUCCODE = B.PRODUCCODE
   AND A.STD_CODE = B.STD_CODE
   AND A.STEELCODE = B.STEELCODE
   AND NVL(A.STD_STYLE, '1') = NVL(B.STD_STYLE, '1')
   AND B.UNIT_CODE_PROCESS = C.UNIT_CODE
   AND INSTR({0}, 'BL') > 0
   AND A.USE_CODE = B.USE_CODE
   AND C.AUTO_FLAG = '1'
   AND H.ORD_LN_PK = {1}
   AND H.CRAFT_SEQ = {2}
   AND I.DESGIN_KEY = H.DESGIN_KEY
   AND J.MSC = B.MSC
   AND J.MSC_PLINE = I.MSC_PLINE
   AND ROWNUM <= 1
		]]>
	</query>
	
    <query id="CraftOrdDesignDAL.GetCraftNoV" desc="获取文件版本号">
		<![CDATA[
(SELECT NVl(LPAD(MAX(T.CRAFT_NO_V) + 1, 2, '0'), '00') MAX_VALUE
          FROM CRAFT_ORD_DESIGN T
         WHERE T.CRAFT_NO = '#CRAFT_NO#')
		]]>
	</query>
	<query id="CraftOrdDesignDAL.GetMaxCraftSeq" desc="获取最大的工艺文件序号">
		<![CDATA[
SELECT MAX(CRAFT_SEQ) MAX_VALUE
  FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
		]]>
	</query>
	<query id="CraftOrdDesignDAL.GetMaterialAutoCraft" desc="获取该物料是否可以自动生成工艺文件">
		<![CDATA[
SELECT C.AUTO_CRAFT VALUE
  FROM CRAFT_ORD_LINE_BOM A,
       SLM_ORD_DESIGN_BOM B,
       SLM_BASE_MATERIAL  C,
       CRAFT_ORD_DESIGN   D
 WHERE D.ORD_LN_PK = '#ORD_LN_PK#'
   AND D.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN E
                       WHERE E.ORD_LN_PK = D.ORD_LN_PK)
   AND A.DESGIN_KEY = D.DESGIN_KEY
   AND B.BOM = A.BOM
   AND C.MATERIAL_NO = B.MATERIAL_NO
		]]>
	</query>
	<query id="CraftOrdDesignDAL.GetBacklogAutoCraft" desc="获取该所有的制程是否可以自动生成工艺文件">
		<![CDATA[
SELECT COUNT(1) COUNT
   FROM COM_MSC_BACKLOG A, SLM_ORDER_LINE B
  WHERE B.ORD_LN_PK = '#ORD_LN_PK#'
    AND A.MSC = B.MSC
    AND A.AUTO_CRAFT = '0'
    AND A.VALIDFLAG <> '0'
		]]>
	</query>
	<query id="CraftOrdDesignDAL.SetMaterialAutoCraft" desc="设置物料自动生成工艺文件">
		<![CDATA[
UPDATE SLM_BASE_MATERIAL C
   SET C.AUTO_CRAFT = '1'
 WHERE EXISTS (SELECT 1
          FROM CRAFT_ORD_LINE_BOM A,
               SLM_ORD_DESIGN_BOM B,
               CRAFT_ORD_DESIGN   D
         WHERE D.ORD_LN_PK = '#ORD_LN_PK#'
           AND D.CRAFT_SEQ =
               (SELECT MAX(CRAFT_SEQ)
                  FROM CRAFT_ORD_DESIGN E
                 WHERE E.ORD_LN_PK = D.ORD_LN_PK)
           AND A.DESGIN_KEY = D.DESGIN_KEY
           AND B.BOM = A.BOM
           AND C.MATERIAL_NO = B.MATERIAL_NO)
		]]>
	</query>
	<query id="CraftOrdDesignDAL.SetBacklogAutoCraft" desc="设置制程自动生成工艺文件">
		<![CDATA[
UPDATE COM_MSC_BACKLOG C
   SET C.AUTO_CRAFT = '1'
 WHERE EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_MSC_PL A,
               CRAFT_ORD_DESIGN        B,
               CRAFT_ORD_DESIGN_MSC    D
         WHERE B.ORD_LN_PK = '#ORD_LN_PK#'
           AND B.CRAFT_SEQ =
               (SELECT MAX(CRAFT_SEQ)
                  FROM CRAFT_ORD_DESIGN C
                 WHERE C.ORD_LN_PK = B.ORD_LN_PK)
           AND A.DESGIN_KEY = B.DESGIN_KEY
           AND D.DESGIN_KEY = B.DESGIN_KEY
           AND C.MSC = D.MSC
           AND C.MSC_PLINE = A.MSC_PLINE)
		]]>
	</query>
	<query id="CraftOrdDesignDAL.SetCraftOrdDesignMaterial" desc="标记在评审通过的时候，把物料表的自动工艺文件置为‘1’">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.MATERIAL_AUTO_CRAFT = '1'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = (SELECT MAX(A.CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN A
                       WHERE A.ORD_LN_PK = T.ORD_LN_PK)
		]]>
	</query>
	<query id="CraftOrdDesignDAL.SetCraftOrdDesignBacklog" desc="标记在评审通过的时候，把制程表的自动工艺文件置为‘1’">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.BACKLOG_AUTO_CRAFT = '1'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = (SELECT MAX(A.CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN A
                       WHERE A.ORD_LN_PK = T.ORD_LN_PK)
		]]>
	</query>
	<query id="CraftOrdDesignDAL.GetMaterialBacklog" desc="获取工艺主表中的物料和制程是否自动工艺文件">
		<![CDATA[
SELECT T.MATERIAL_AUTO_CRAFT VALUE, T.BACKLOG_AUTO_CRAFT VALUE2
  FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = (SELECT MAX(A.CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN A
                       WHERE A.ORD_LN_PK = T.ORD_LN_PK)
		]]>
	</query>
	<query id="CraftOrdDesignDAL.GetMscByOrdLnPk" desc="通过合同行(或者备料码)查询msc">
		<![CDATA[
SELECT A.*
  FROM COM_MSC A, SLM_ORDER_LINE B
 WHERE B.ORD_LN_PK = {0}
   AND A.MSC = B.MSC
UNION ALL
SELECT A.*
  FROM COM_MSC A, COM_PSC B, COM_MSC_BL C, COM_PSC_R_MSC D
 WHERE C.PSC_BL = {0}
   AND B.PRODUCCODE = C.PRODUCCODE
   AND B.STD_CODE = C.STD_CODE
   AND B.STEELCODE = C.STEELCODE
   AND NVL(B.STD_STYLE, '1') = NVL(C.STD_STYLE, '1')
   AND D.PSC = B.PSC
   AND D.MSC = A.MSC
   AND A.USE_CODE = C.USE_CODE
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.UpdateApproveName" desc="修改评审人">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.APPROVAL_NAME = '#APPROVAL_NAME#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.UpdateApprove1Name" desc="修改批准人">
		<![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.APPROVAL_NAME1 = '#APPROVAL_NAME1#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_SEQ = '#CRAFT_SEQ#'
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.SetProcessFlag" desc="设置工序检验计划是否确认">
		<![CDATA[
UPDATE craft_ord_design T
   SET T.FLAG_D = DECODE({0}, 'D', {1}, T.FLAG_D),
       T.FLAG_E = DECODE({0}, 'E', {1}, T.FLAG_E),
       T.FLAG_F = DECODE({0}, 'F', {1}, T.FLAG_F),
       T.FLAG_G = DECODE({0}, 'G', {1}, T.FLAG_G),
       T.FLAG_H = DECODE({0}, 'H', {1}, T.FLAG_H)
 WHERE T.ORD_LN_PK = {2} 
   AND T.CRAFT_SEQ = {3}
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.SetProcessJhFlag" desc="设置工序检验是否计划科委托">
		<![CDATA[
UPDATE craft_ord_design T
   SET T.FLAG_JHD = DECODE({0}, 'D', {1}, T.FLAG_JHD)
 WHERE T.ORD_LN_PK = {2} 
   AND T.CRAFT_SEQ = {3}
		]]>
	</query>

	<query id="CraftOrdDesignDAL.checkRate" desc="设置工序检验计划是否确认">
		<![CDATA[
     SELECT * FROM COM_BASE_INFO  T WHERE T.BASECODE =?  AND VALIDFLAG ='1'
		]]>
	</query>

	<query id="CraftOrdDesignDAL.SetProcessFlagNew" desc="设置工序检验计划是否确认">
		<![CDATA[
UPDATE craft_ord_design T
   SET T.FLAG_D = DECODE({0}, 'D', {1}, T.FLAG_D),
       T.FLAG_E = DECODE({0}, 'E', {1}, T.FLAG_E),
       T.FLAG_F = DECODE({0}, 'F', {1}, T.FLAG_F),
       T.FLAG_G = DECODE({0}, 'G', {1}, T.FLAG_G),
       T.FLAG_H = DECODE({0}, 'H', {1}, T.FLAG_H)
 WHERE T.CRAFT_NO = {2}
		]]>
	</query>
	
	<query id="CraftOrdDesignDAL.getCraftStationType" desc="获取工序点类型">
        <![CDATA[
SELECT DISTINCT T.STATION_TYPE
       FROM CRAFT_ORD_DESIGN_MSC_PL_STI T
      WHERE T.DESGIN_KEY = {0}
        AND T.PROCESS_CODE = {1}
        AND EXISTS
      (SELECT 1
               FROM CRAFT_ORD_DESIGN A, PLN_SALEORD B, PLN_SALEORD_PROC C
              WHERE A.DESGIN_KEY = T.DESGIN_KEY
                AND A.ORD_LN_PK = B.ORD_LN_PK
                AND B.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK
                AND C.INDEX_SEQ = T.MSC_PLINE
                AND C.PLN_DIVIDE_ID =
                    (SELECT MAX(D.PLN_DIVIDE_ID)
                       FROM PLN_SALEORD_PROC D
                      WHERE D.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK))
        ]]>
    </query>
    
    <query id="CraftOrdDesignDAL.getCraftPicSmp" desc="获取工艺评审取样要求">
        <![CDATA[
SELECT 'CC001' PHY_CODE_MIN,
       '成分' PHY_NAME_MIN,
       '0' LENGTH,
       NVL(T.PRODUCT_CNT_N, 0) DESC_COUNT,
       1 SAMPLE_COUNT,
       '408101' SAMPLE_STYLE,
       0 WIDTH,
       NULL PHY_DIR,
       NULL SIZE_DESC,
       NULL SPLINE_ITEM_CODE_S,
       NULL SPLINE_ITEM_NAME_S,
       NULL SPLINE_ITEM_CODE_F,
       NULL SPLINE_ITEM_NAME_F,
       NULL SAMPLE_STYLE_DESC
  FROM CRAFT_ORD_DESIGN_STD T
 WHERE T.DESGIN_KEY = {0}
 UNION ALL
SELECT T.PHY_CODE_MIN,
       T.PHY_NAME_MIN,
       T.LENGTH,
       T.DESC_COUNT,
       T.SAMPLE_COUNT,
       T.SAMPLE_STYLE,
       T.WIDTH,
       T.PHY_DIR,
       T.SIZE_DESC,
       T.SPLINE_ITEM_CODE_S,
       T.SPLINE_ITEM_NAME_S,
       T.SPLINE_ITEM_CODE_F,
       T.SPLINE_ITEM_NAME_F,
       A.BASENAME SAMPLE_STYLE_DESC
  FROM CRAFT_ORD_DESIGN_STD_PIC_SMP T
  LEFT JOIN COM_BASE_INFO A
    ON A.BASECODE = T.SAMPLE_STYLE
 WHERE T.DESGIN_KEY = {0}
   AND T.PROCESS_CODE = {1}
   AND EXISTS
 (SELECT 1
          FROM CRAFT_ORD_DESIGN D, PLN_SALEORD E, PLN_SALEORD_PROC F
         WHERE D.DESGIN_KEY = T.DESGIN_KEY
           AND D.ORD_LN_PK = E.ORD_LN_PK
           AND E.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK
           AND F.INDEX_SEQ = T.MSC_PLINE
           AND F.PLN_DIVIDE_ID =
               (SELECT MAX(F.PLN_DIVIDE_ID)
                  FROM PLN_SALEORD_PROC G
                 WHERE G.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK))
        ]]>
    </query>

	<query id="CraftOrdDesignDAL.getCraftPicSmpGroupNew" desc="获取工艺评审取样要求分组">
		<![CDATA[
	SELECT
	  '' PIC,
	  '0' TYPE,
         '/' SPLINE_NO,
       'HX' PHY_CODE_MIN,
        '成分' PHY_NAME_MIN,
         NVL(NVL(RATE_N,T.RATE),'408603') RATE,
         (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE =  NVL(NVL(RATE_N,T.RATE),'408603')) DESC_RATE,
        '/' BATCH_UNIT,
         '' BATCH_CNT,
          '' BATCH_CNT_M,
       '' SAMPLE_COUNT,
        NVL(NVL(PRODUCT_CNT_N,T.PRODUCT_CNT),2)  DESC_COUNT,
        '401203' POSITION,
        'A端或B端' DESC_POSITION,
       DECODE((SELECT COUNT(1)
  FROM CRAFT_ORD_DESIGN_STD_CIC T
 WHERE T.DESGIN_KEY = {0}
   AND ( CHEM_NAME = 'H' OR CHEM_NAME = 'O' )
   AND SPECL_FL  IN ('0','1')),0,'50','100') LENGTH,
      DECODE((SELECT COUNT(1)
  FROM CRAFT_ORD_DESIGN_STD_CIC T
 WHERE T.DESGIN_KEY = {0}
   AND T.MSC_PLINE ={1}
   AND T.PROCESS_CODE = {2}
   AND ( CHEM_NAME = 'H' OR CHEM_NAME = 'O' )
   AND SPECL_FL  IN ('1','0')
   AND CIC={3}),0,'50','100') WIDTH,
         A.BASECODE SAMPLE_STYLE,
        A.BASENAME SAMPLE_STYLE_DESC,
       '/'  PHY_NAME_GROUP,
       '/'  PHY_CODE_GROUP,
       '' ATTACH_PERCENT,
       ''  ATTACH_COUNT,
       ''  TOP_STOVE,
       ''  LOOP_VALUE,
       {4} CRAFT_NO,
       {2} PROCESS_CODE
   FROM CRAFT_ORD_DESIGN_STD T
   LEFT JOIN COM_BASE_INFO A ON A.BASECODE =  '408101'
 WHERE T.DESGIN_KEY = {0}
 AND EXISTS (
SELECT 1
       FROM CRAFT_ORD_DESIGN_STD_CIC T
      WHERE T.DESGIN_KEY ={0}
        AND T.PROCESS_CODE =  {2}
        AND EXISTS
      (SELECT 1
               FROM CRAFT_ORD_DESIGN A, PLN_SALEORD B, PLN_SALEORD_PROC C
              WHERE A.DESGIN_KEY = T.DESGIN_KEY
                AND A.ORD_LN_PK = B.ORD_LN_PK
                AND B.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK
                AND C.INDEX_SEQ = T.MSC_PLINE
                AND C.PLN_DIVIDE_ID =
                    (SELECT MAX(D.PLN_DIVIDE_ID)
                       FROM PLN_SALEORD_PROC D
                      WHERE D.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK)))
  UNION ALL
 SELECT
       T.PIC,
       '0' TYPE,
       B.SPLINE_NO,
       T.PHY_CODE_MIN,
       T.PHY_NAME_MIN,
       T.RATE,
       T.DESC_RATE,
       T.BATCH_UNIT,
       T.BATCH_CNT || '',
       T.BATCH_CNT || '' BATCH_CNT_M,
       T.SAMPLE_COUNT || '',
       T.DESC_COUNT,
       POSITION,
       DESC_POSITION,
       T.LENGTH || '',
       T.WIDTH || '',
       T.SAMPLE_STYLE,
       A.BASENAME SAMPLE_STYLE_DESC,
       (SELECT DBMS_LOB.SUBSTR(WM_CONCAT(T1.PHY_NAME))
          FROM CRAFT_ORD_DESIGN_STD_PIC T1
         WHERE T1.DESGIN_KEY = T.DESGIN_KEY
           AND T1.MSC_PLINE = {1}
           AND T.PROCESS_CODE = T.PROCESS_CODE
           AND T1.PHY_CODE_MIN = T.PHY_CODE_MIN) PHY_NAME_GROUP,
       (SELECT DBMS_LOB.SUBSTR(WM_CONCAT(T1.PHY_CODE))
          FROM CRAFT_ORD_DESIGN_STD_PIC T1
         WHERE T1.DESGIN_KEY = T.DESGIN_KEY
           AND T1.MSC_PLINE = {1}
           AND T.PROCESS_CODE = T.PROCESS_CODE
           AND T1.PHY_CODE_MIN = T.PHY_CODE_MIN) PHY_CODE_GROUP,
       T.ATTACH_PERCENT || '',
       T.ATTACH_COUNT || '',
       T.TOP_STOVE || '',
       T.LOOP_VALUE || '',
      {4}  CRAFT_NO,
      {2} PROCESS_CODE
  FROM (SELECT EIC,PIC,
               MAX(SAMPLE_STYLE) SAMPLE_STYLE,
               MAX(LOOP_VALUE) LOOP_VALUE,
               MAX(TOP_STOVE) TOP_STOVE,
               MAX(ATTACH_COUNT) ATTACH_COUNT,
               MAX(ATTACH_PERCENT) ATTACH_PERCENT,
               MAX(PHY_CODE_MIN) PHY_CODE_MIN,
               MAX(PHY_NAME_MIN) PHY_NAME_MIN,
               MAX(RATE) RATE,
               MAX(DESC_RATE) DESC_RATE,
               MAX(BATCH_UNIT) BATCH_UNIT,
               MAX(BATCH_CNT) BATCH_CNT,
               MAX(SAMPLE_COUNT) SAMPLE_COUNT,
               MAX(DESC_POSITION) DESC_POSITION,
               MAX(POSITION) POSITION,
               MAX(DESC_COUNT) DESC_COUNT,
               MAX(PROCESS_CODE) PROCESS_CODE,
               MAX(DESGIN_KEY) DESGIN_KEY,
               MSC_PLINE,
               LENGTH,
               WIDTH
          FROM CRAFT_ORD_DESIGN_STD_PIC_SMP
         WHERE DESGIN_KEY ={0}
           AND PROCESS_CODE = {2}
           AND CRAFT_SOURCE = '0'
           AND MSC_PLINE = {1}
         GROUP BY PIC,EIC,MSC_PLINE, SPLINE_ITEM_CODE_S, SPLINE_ITEM_CODE_F,LENGTH,WIDTH
         ORDER BY PHY_CODE_MIN) T
  LEFT JOIN COM_BASE_INFO A
    ON A.BASECODE = T.SAMPLE_STYLE
  LEFT JOIN COM_BASE_SPLINE B
    ON B.EIC = T.EIC
 WHERE EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN D, PLN_SALEORD E, PLN_SALEORD_PROC F
         WHERE D.DESGIN_KEY = T.DESGIN_KEY
           AND D.ORD_LN_PK = E.ORD_LN_PK
           AND E.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK
           AND F.INDEX_SEQ = T.MSC_PLINE
           AND F.PLN_DIVIDE_ID =
               (SELECT MAX(F.PLN_DIVIDE_ID)
                  FROM PLN_SALEORD_PROC G
                 WHERE G.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK))
        ]]>
	</query>

	<query id="CraftOrdDesignDAL.getSampleDetail" desc="">
		<![CDATA[
SELECT DESGIN_KEY,
       PIC,
       USE_CODE,
       USE_DESC,
       SPECL_FL,
       INDEX_SEQ,
       PHY_CODE_MAX,
       PHY_NAME_MAX,
       PHY_CODE_MIN,
       PHY_NAME_MIN,
       PHY_CODE,
       PHY_NAME,
       ITEM_CODE_F,
       ITEM_NAME_F,
       ITEM_CODE_W,
       ITEM_NAME_W,
       ITEM_CODE_S,
       ITEM_NAME_S
FROM CRAFT_ORD_DESIGN_STD_PIC t
         WHERE DESGIN_KEY =?
           AND PROCESS_CODE = ?
           AND CRAFT_SOURCE = '0'
           AND SPECL_FL IN ('1','2')
        ]]>
	</query>


	<query id="CraftOrdDesignDAL.getCraftSamplingDetail" desc="获取工艺评审取样要求分组">
		<![CDATA[
                SELECT * FROM CRAFT_SAMPLING_DETAIL WHERE ORD_LN_PK = {0} AND CRAFT_SEQ={1} AND PROCESS_CODE ={2}
        ]]>
	</query>

	<query id="CraftOrdDesignDAL.getCraftSamplingTotal" desc="获取工艺评审取样要求分组">
		<![CDATA[
           SELECT * FROM CRAFT_SAMPLING_M WHERE ORD_LN_PK = {0} AND CRAFT_SEQ={1} AND PROCESS_CODE ={2} ORDER BY STOVE_NUM,BATCH_NUM,BATCH_NO,BATCH_SEQ,POSITION
        ]]>
	</query>

	<query id="CraftOrdDesignDAL.DeleteCraftSamplingDetail" desc="">
		<![CDATA[
                DELETE  FROM CRAFT_SAMPLING_DETAIL WHERE ORD_LN_PK = '#ORD_LN_PK#' AND CRAFT_SEQ='#CRAFT_SEQ#' AND PROCESS_CODE ='#PROCESS_CODE#'
        ]]>
	</query>

	<query id="CraftOrdDesignDAL.DeleteCraftSamplingTotal" desc="">
		<![CDATA[
           DELETE FROM CRAFT_SAMPLING_M WHERE ORD_LN_PK = '#ORD_LN_PK#' AND CRAFT_SEQ='#CRAFT_SEQ#' AND PROCESS_CODE ='#PROCESS_CODE#'
        ]]>
	</query>

	<query id="CraftOrdDesignDAL.InsertCraftSamplingDetail" desc="">
		<![CDATA[
               INSERT INTO CRAFT_SAMPLING_DETAIL
  (ORD_LN_PK,
  CRAFT_SEQ,
  CRAFT_NO,
   PROCESS_CODE,
   TYPE,
   SPLINE_NO,
   PHY_CODE_MIN,
   PHY_NAME_MIN,
   RATE,
   DESC_RATE,
   BATCH_UNIT,
   BATCH_CNT,
   BATCH_CNT_M,
   DESC_COUNT,
   SAMPLE_COUNT,
   POSITION,
   DESC_POSITION,
   LENGTH,
   WIDTH,
   SAMPLE_STYLE,
   SAMPLE_STYLE_DESC,
   PHY_CODE_GROUP,
   PHY_NAME_GROUP,
   ATTACH_PERCENT,
   ATTACH_COUNT,
   TOP_STOVE,
   LOOP_VALUE,
   PIC)
VALUES
  ('#ORD_LN_PK#',
  '#CRAFT_SEQ#',
  '#CRAFT_NO#',
   '#PROCESS_CODE#',
   '#TYPE#',
   '#SPLINE_NO#',
   '#PHY_CODE_MIN#',
   '#PHY_NAME_MIN#',
   '#RATE#',
   '#DESC_RATE#',
   '#BATCH_UNIT#',
   '#BATCH_CNT#',
    '#BATCH_CNT_M#',
   '#DESC_COUNT#',
   '#SAMPLE_COUNT#',
   '#POSITION#',
   '#DESC_POSITION#',
   '#LENGTH#',
   '#WIDTH#',
   '#SAMPLE_STYLE#',
   '#SAMPLE_STYLE_DESC#',
   '#PHY_CODE_GROUP#',
   '#PHY_NAME_GROUP#',
   '#ATTACH_PERCENT#',
   '#ATTACH_COUNT#',
   '#TOP_STOVE#',
   '#LOOP_VALUE#',
    '#PIC#')
        ]]>
	</query>

	<query id="CraftOrdDesignDAL.InsertCraftSamplingTotal" desc="">
		<![CDATA[
                  INSERT INTO CRAFT_SAMPLING_M
  (ORD_LN_PK,
  CRAFT_SEQ,
   CRAFT_NO,
   PROCESS_CODE,
   BATCH_NUM,
   BATCH_NO,
   SAMPLE_LENGTH,
   POSITION,
   DESC_POSITION,
   SAMPLE_COUNT,
   REMARK,
   PHY_NAME_GROUP,
   PHY_CODE_GROUP,
   STOVE_NUM)
VALUES
  ('#ORD_LN_PK#',
  '#CRAFT_SEQ#',
   '#CRAFT_NO#',
   '#PROCESS_CODE#',
   '#BATCH_NUM#',
   '#BATCH_NO#',
   '#SAMPLE_LENGTH#',
   '#POSITION#',
   '#DESC_POSITION#',
   '#SAMPLE_COUNT#',
   '#REMARK#',
   '#PHY_NAME_GROUP#',
   '#PHY_CODE_GROUP#',
   '#STOVE_NUM#')
        ]]>
	</query>
    
    <query id="CraftOrdDesignDAL.getCraftPicSmpGroup" desc="获取工艺评审取样要求分组">
        <![CDATA[
SELECT MAX(T.PHY_NAME_MIN) PHY_NAME_MIN,
       SUM(T.DESC_COUNT * T.SAMPLE_COUNT) SAMPLE_COUNT,
       MAX(T.LENGTH) LENGTH,
       MAX(T.WIDTH) WIDTH,
       MAX(T.SPLINE_ITEM_NAME_S) SPLINE_ITEM_NAME_S,
       MAX(T.SIZE_DESC) SIZE_DESC,
       MAX(T.SPLINE_ITEM_NAME_F) SPLINE_ITEM_NAME_F,
       MAX(T.DESC_POSITION) DESC_POSITION,
       MAX(A.BASENAME) SAMPLE_STYLE_DESC
  FROM CRAFT_ORD_DESIGN_STD_PIC_SMP T
  LEFT JOIN COM_BASE_INFO A
    ON A.BASECODE = T.SAMPLE_STYLE
 WHERE T.DESGIN_KEY = {0}
   AND T.PROCESS_CODE = {1}
   AND EXISTS
 (SELECT 1
          FROM CRAFT_ORD_DESIGN D, PLN_SALEORD E, PLN_SALEORD_PROC F
         WHERE D.DESGIN_KEY = T.DESGIN_KEY
           AND D.ORD_LN_PK = E.ORD_LN_PK
           AND E.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK
           AND F.INDEX_SEQ = T.MSC_PLINE
           AND F.PLN_DIVIDE_ID =
               (SELECT MAX(F.PLN_DIVIDE_ID)
                  FROM PLN_SALEORD_PROC G
                 WHERE G.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK))
 GROUP BY T.PHY_CODE_MIN
        ]]>
    </query>
</queryMap>