<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "成品利库申请审批管理">
<query id = "FrmLikuExamine.doQueryApply" desc = "查询利库申请信息">
 SELECT 
       T.JUDGE_ID,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.ACT_COUNT,
       T.ACT_WEIGHT,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ORDER_NO || '/' ||T.ORDER_SEQ AS ORDER_NO,
       T.ORDER_SEQ,
       T.ORDER_SEQ_NO,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.LOT_NO,
       T.STOVE_NO,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.AGREE_NAME,
       TO_CHAR(T.AGREE_TIME, 'YYYY-MM-DD HH24:MI:SS') AGREE_TIME,
       DECODE(T.AGREE_FLAG,'0','未审批','1','审批通过','2','审批不通过','3','已判定')AGREE_FLAG,
       T.AGREE_MEMO,
       DECODE(T.IS_VD,'0','否','1','是')IS_VD,
       T.PRO_ORDER_NO,
       T.MANAGE_NO,
       T.MANAGE_MENT,
       T.STD_CODE,
       T.STD_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.JUDGE_STD_NAME,
       T.CRAFT_NO,
       T.CRAFT_SEQ,
       T.CRAFT_PATH,
       T.INDEX_SEQ,
       T.CIC,
       T.OLD_CIC,
       T.JUGDE_APPLY_CODE,
       T.SUPPLY_UNIT_CODE,
       T.SUPPLY_UNIT
 FROM QCM_LK_JUDGE_CHANGE T
 WHERE 1 = 1
</query>
<query id = "FrmLikuExamine.doQueryIndexSeq" desc = "查询制程号">
SELECT S.MSC_PLINE INDEX_SEQ,S.MSC_PLINE INDEX_CODE 
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_MSC_PL S
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
   AND T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
</query>
<query id = "FrmLikuExamine.doQueryCic" desc = "查询CIC">
SELECT S.CIC,S.CIC CIC_CODE,S1.GRADENAME
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_CIC S,COM_MSC_STD_CIC S1
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
    AND S.CIC = S1.CIC
    AND S.PROCESS_CODE = 'A'
    AND T.CRAFT_SEQ = ?
    AND T.ORD_LN_PK = ?
    AND S.MSC_PLINE = ?
    AND S.CRAFT_SOURCE = '0'
    GROUP BY S.CIC,S1.GRADENAME
</query>
<query id = "FrmLikuExamine.selectLkFlag" desc = "查询审批单状态">
SELECT T.AGREE_FLAG FROM QCM_LK_JUDGE_CHANGE T WHERE T.JUDGE_ID = '#JUDGE_ID#'
</query>
<query id = "FrmLikuExamine.auditNoCross" desc = "审批不通过">
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM MAT_ZC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.LOCK_ID = '#JUDGE_ID#'
                 ORDER BY T.MAT_NO DESC) LOOP
    DELETE FROM MAT_ZC_TRACK T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PRO_NO = MYROW.PRO_NO;
  END LOOP;
  UPDATE QCM_LK_JUDGE_CHANGE T
     SET T.AGREE_FLAG = '#AGREE_FLAG#',
         T.AGREE_NAME = '#AGREE_NAME#',
         T.AGREE_MEMO = '#AGREE_MEMO#',
         T.AGREE_TIME = SYSDATE
   WHERE T.JUDGE_ID = '#JUDGE_ID#';
  UPDATE MAT_ZC_M T
     SET T.LOCK_FLAG     = '0',
         T.ORDER_NO      = '',
         T.ORDER_SEQ     = '',
         T.ORDER_SEQ_NO  = '',
         T.ORD_PK        = '',
         T.ORD_LN_PK     = '',
         T.ORD_LN_DLY_PK = '',
         T.PRODUCT_FLAG  = '801402',
         T.MAT_STATUS    = '80150202'
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#'
     AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
     AND T.LOCK_ID = '#JUDGE_ID#'
     AND T.PRODUCT_FLAG  = '801403';

    UPDATE PROCESS_ORDER_M T
    SET T.CHARGE_NUM = TO_NUMBER(NVL(T.CHARGE_NUM, 0)) - TO_NUMBER('#ACT_COUNT#'),
    T.CHARGE_WGT = TO_NUMBER(NVL(T.CHARGE_WGT, 0)) - TO_NUMBER('#ACT_WEIGHT#'),
    T.CHARGE_LEN = TO_NUMBER(NVL(T.CHARGE_LEN, 0)) - TO_NUMBER('#ACT_LEN#')
    WHERE ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
END;
</query>
<query id = "FrmLikuExamine.updateQcmLk" desc = "审批通过">
UPDATE QCM_LK_JUDGE_CHANGE T
     SET T.AGREE_FLAG = '#AGREE_FLAG#',
         T.AGREE_NAME = '#AGREE_NAME#',
         T.AGREE_MEMO = '#AGREE_MEMO#',
         T.INDEX_SEQ  = '#INDEX_SEQ#',
         T.CIC        = '#CIC#',
         T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#',
         T.AGREE_TIME = SYSDATE
   WHERE T.JUDGE_ID = '#JUDGE_ID#'
</query>
<query id = "FrmLikuExamine.selectMatZcInfo" desc = "查询物料信息">
SELECT *
  FROM MAT_ZC_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
   AND T.LOCK_ID = '#JUDGE_ID#'
</query>
	<query id = "FrmLikuExamine.getApplyNo" desc = "生成申请判定单号">
	SELECT 'L' || ? || '801401' || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
       LPAD(NVL(MAX(SUBSTR(T.JUGDE_APPLY_CODE, 20)), 0) + 1, 5, 0) JUGDE_APPLY_CODE
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUGDE_APPLY_CODE LIKE
       'L' || ? || '801401' || TO_CHAR(SYSDATE, 'YYYYMMDD') || '_____'
       AND T.IS_ALL_SCRAP = '4'
	</query>
	<query id = "FrmLikuExamine.selectProcessCode" desc = "查询工序代码">
	SELECT T.PROCESS_CODE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE = '#PLINE_CODE#'
	</query>
	<query id = "FrmLikuExamine.selectPic" desc = "查询Pic">
	SELECT MIN(S.PIC)PIC
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_PIC S
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
    AND S.PROCESS_CODE = '#PROCESS_CODE#'
    AND T.VALIDFLAG = '1'
    AND T.ORD_LN_PK = '#ORD_LN_PK#'
    AND S.MSC_PLINE = '#INDEX_SEQ#'
    AND S.CRAFT_SOURCE = '0'
	</query>
	<query id = "FrmLikuExamine.selectSic" desc = "查询Sic">
	SELECT MIN(S.SIC)SIC
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_SIC S
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
    AND S.PROCESS_CODE = '#PROCESS_CODE#'
    AND T.VALIDFLAG = '1'
    AND T.ORD_LN_PK = '#ORD_LN_PK#'
    AND S.MSC_PLINE = '#INDEX_SEQ#'
    AND S.CRAFT_SOURCE = '0'
	</query>
	<query id = "FrmLikuExamine.selectDic" desc = "查询Dic">
	SELECT MIN(S.DIC)DIC
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_DIC S
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
    AND S.PROCESS_CODE = '#PROCESS_CODE#'
    AND T.VALIDFLAG = '1'
    AND T.ORD_LN_PK = '#ORD_LN_PK#'
    AND S.MSC_PLINE = '#INDEX_SEQ#'
    AND S.CRAFT_SOURCE = '0'
	</query>
	<query id = "FrmLikuExamine.selectWic" desc = "查询Wic">
	SELECT MIN(S.WIC)WIC
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_WIC S
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
    AND S.PROCESS_CODE = '#PROCESS_CODE#'
    AND T.VALIDFLAG = '1'
    AND T.ORD_LN_PK = '#ORD_LN_PK#'
    AND S.MSC_PLINE = '#INDEX_SEQ#'
    AND S.CRAFT_SOURCE = '0'
	</query>
	<query id = "FrmLikuExamine.selectGic" desc = "查询Gic">
	SELECT MIN(S.GIC)GIC
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_GIC S
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
    AND S.PROCESS_CODE = '#PROCESS_CODE#'
    AND T.VALIDFLAG = '1'
    AND T.ORD_LN_PK = '#ORD_LN_PK#'
    AND S.MSC_PLINE = '#INDEX_SEQ#'
    AND S.CRAFT_SOURCE = '0'
	</query>
	<query id = "FrmLikuExamine.selectIsType" desc = "成品点是否成品成分">
	SELECT COUNT(1) ACOUNT
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_MSC_JG_PL_STI S
 WHERE T.DESGIN_KEY = S.DESGIN_KEY
   AND S.MSC_PLINE = '#INDEX_SEQ#'
   AND S.PROCESS_CODE = '#PROCESS_CODE#'
   AND S.STATION_TYPE = '403201'
   AND T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.VALIDFLAG = '1'
	</query>
	<query id = "FrmLikuExamine.selectQcmApply" desc = "查询申请判定记录">
	SELECT T.*
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   --AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
   AND T.TARGET = 'A'
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
	</query>
<query id = "FrmLikuExamine.insertQcmApply" desc = "插入申请判定表">
 INSERT INTO QCM_ZG_JUGDE_APPLY(
        JUGDE_APPLY_CODE,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PROCESS_CODE,
        PLINE_CODE,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_THEORY_WEIGHT,
        PRO_ORDER_ID,
        FACE_RESULT_CODE,
        SPEC_RESULT_CODE,
        CHEM_RESULT_CODE,
        PHY_RESULT_CODE,
        DETECT_RESULT_CODE,
        WPRESSURE_RESULT_CODE,
        PROCESS_RESULT_CODE,
        FACE_RESULT_PATH,
        SPEC_RESULT_PATH,
        CHEM_RESULT_PATH,
        PHY_RESULT_PATH,
        DETECT_RESULT_PATH,
        WPRESSURE_RESULT_PATH,
        PROCESS_RESULT_PATH,
        VALIDFLAG,
        APPLY_NAME,
        APPLY_TIME,
        MEMO,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STEELCODE,
        STEELNAME,
        GRADECODE,
        GRADENAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        CRAF_NO,
        LOT_NO,
        PLINE_NAME,
        PRO_ORDER_NO,
        TARGET,
        PROCESS_STATUS,
        MAT_GOWHERE_CODE,
        MAT_GOWHERE_NAME,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        TESTING_GRADE,
        TESTING_TYPE,
        TESTING_GRADE1,
        TESTING_TYPE1,
        DETECT_RESULT_CODE1,
        DETECT_RESULT_PATH1,
        ORD_LN_DLY_PK,
        INSTOCK_FLAG,
        BELONG_CODE,
        BELONG_NAME,
        ISENDGX,
        EXIT_TEMP,
        SAMPLE_NEWS,
        ACT_LEN,
        BELONG_CODE_JUGDE,
        BELONG_NAME_JUGDE,
        GX_PLAN_NO,
        BAL_YEAR_MONTH,
        STOVE_NO,
        STEEL_STANDRAD,
        PRO_PLAN_ID_NEXT,
        GX_PLAN_NO_NEXT,
        LK_FLAG,
        IS_ALL_SCRAP,
        JUDGE_STOVE_NO_SEQ,
        JUGDE_APPLY_SEQUENO,
        CRAFT_SEQ,
        INDEX_SEQ,
        CIC,
        PIC,
        SIC,
        DIC,
        WIC,
        GIC,
        CHECK_NO,
        HEAT_PLAN_NO,
        DELIVERY_STATE_CODE,
        DELIVERY_STATE_NAME,
        LOAD_JUDGE_STOVE_NO,
        ZP_M_LH,
        ZP_COLL,
        HTT_TYPE,
        MIN_TEMP,
        HTT_TECHNOLOGY,
        NOTCH_INFO,
        NOTCH_LENGTH,
        NOTCH_WIDTH,
        NOTCH_DEPTH,
        LOT_NO_GROUP,
        TEST_PRESSURE,
        HOLDTIME_TIME,
        TEST_PRESSURE_Y,
        MCH_WATERGAGE_RESULT,
        MCH_PATH_RESULT,
        MCH_CHAMFERING_RESULT,
        MCH_TWISTINGLY_RESULT,
        MCH_DIMENSIONS_RESULT,
        MCH_VISUAL_RESULT,
        MCH_THREAD_INSPECTION_RESULT,
        MCH_REMANENCE_RESULT,
        MCH_RADIOACTIVITY_RESULT,
        MCH_BEVEL_RESULT,
        ANGLE_VAL,
        EDGE_VAL,
        ZBS_FLAG,
        TESTING_STANDAR,
        DRIFT_MODEL_MIN,
        MEASURED_END_PART,
        MEASURED_MIDDLE_PART,
        MEASURED_TAIL_PART,
        QUALITY_GROUP,
        JUDGE_RESULT_CODE,
        JUDGE_RESULT,
        LOAD_BATCH_NO,
    	SUPPLY_UNIT,
    	SUPPLY_UNIT_DESC)
 VALUES( 
        '#JUGDE_APPLY_CODE#',
        '#JUDGE_STOVE_NO#',
        '#BATCH_NO#',
        '#BATCH_GROUD_NO#',
        '#PROCESS_CODE#',
        '#PLINE_CODE#',
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        '#ACT_THEORY_WEIGHT#',
        '#PRO_ORDER_ID#',
        '#FACE_RESULT_CODE#',
        '#SPEC_RESULT_CODE#',
        '#CHEM_RESULT_CODE#',
        '#PHY_RESULT_CODE#',
        '#DETECT_RESULT_CODE#',
        '#WPRESSURE_RESULT_CODE#',
        '#PROCESS_RESULT_CODE#',
        '#FACE_RESULT_PATH#',
        '#SPEC_RESULT_PATH#',
        '#CHEM_RESULT_PATH#',
        '#PHY_RESULT_PATH#',
        '#DETECT_RESULT_PATH#',
        '#WPRESSURE_RESULT_PATH#',
        '#PROCESS_RESULT_PATH#',
        '#VALIDFLAG#',
        '#APPLY_NAME#',
        SYSDATE,
        '#MEMO#',
        '#MATERIAL_NO#',
        '#MATERIAL_NAME#',
        '#PRODUCCODE#',
        '#PRODUCNAME#',
        '#STEELCODE#',
        '#STEELNAME#',
        '#GRADECODE#',
        '#GRADENAME#',
        '#SPEC_CODE#',
        '#SPEC_NAME#',
        '#MODEL_CODE#',
        '#MODEL_DESC#',
        '#STD_CODE#',
        '#STD_NAME#',
        '#STD_STYLE#',
        '#STD_STYLE_DESC#',
        '#CRAF_NO#',
        '#LOT_NO#',
        '#PLINE_NAME#',
        '#PRO_ORDER_NO#',
        '#TARGET#',
        '#PROCESS_STATUS#',
        '#MAT_GOWHERE_CODE#',
        '#MAT_GOWHERE_NAME#',
        '#ACT_DIMATER#',
        '#ACT_HEIGHT#',
        '#ACT_LEN_MIN#',
        '#ACT_LEN_MAX#',
        '#TESTING_GRADE#',
        '#TESTING_TYPE#',
        '#TESTING_GRADE1#',
        '#TESTING_TYPE1#',
        '#DETECT_RESULT_CODE1#',
        '#DETECT_RESULT_PATH1#',
        '#ORD_LN_DLY_PK#',
        '#INSTOCK_FLAG#',
        '#BELONG_CODE#',
        '#BELONG_NAME#',
        '#ISENDGX#',
        '#EXIT_TEMP#',
        '#SAMPLE_NEWS#',
        '#ACT_LEN#',
        '#BELONG_CODE_JUGDE#',
        '#BELONG_NAME_JUGDE#',
        '#GX_PLAN_NO#',
        '#BAL_YEAR_MONTH#',
        '#STOVE_NO#',
        '#STEEL_STANDRAD#',
        '#PRO_PLAN_ID_NEXT#',
        '#GX_PLAN_NO_NEXT#',
        '#LK_FLAG#',
        '#IS_ALL_SCRAP#',
        '#JUDGE_STOVE_NO_SEQ#',
        '#JUGDE_APPLY_SEQUENO#',
        '#CRAFT_SEQ#',
        '#INDEX_SEQ#',
        '#CIC#',
        '#PIC#',
        '#SIC#',
        '#DIC#',
        '#WIC#',
        '#GIC#',
        '#CHECK_NO#',
        '#HEAT_PLAN_NO#',
        '#DELIVERY_STATE_CODE#',
        '#DELIVERY_STATE_NAME#',
        '#LOAD_JUDGE_STOVE_NO#',
        '#ZP_M_LH#',
        '#ZP_COLL#',
        '#HTT_TYPE#',
        '#MIN_TEMP#',
        '#HTT_TECHNOLOGY#',
        '#NOTCH_INFO#',
        '#NOTCH_LENGTH#',
        '#NOTCH_WIDTH#',
        '#NOTCH_DEPTH#',
        '#LOT_NO_GROUP#',
        '#TEST_PRESSURE#',
        '#HOLDTIME_TIME#',
        '#TEST_PRESSURE_Y#',
        '#MCH_WATERGAGE_RESULT#',
        '#MCH_PATH_RESULT#',
        '#MCH_CHAMFERING_RESULT#',
        '#MCH_TWISTINGLY_RESULT#',
        '#MCH_DIMENSIONS_RESULT#',
        '#MCH_VISUAL_RESULT#',
        '#MCH_THREAD_INSPECTION_RESULT#',
        '#MCH_REMANENCE_RESULT#',
        '#MCH_RADIOACTIVITY_RESULT#',
        '#MCH_BEVEL_RESULT#',
        '#ANGLE_VAL#',
        '#EDGE_VAL#',
        '#ZBS_FLAG#',
        '#TESTING_STANDAR#',
        '#DRIFT_MODEL_MIN#',
        '#MEASURED_END_PART#',
        '#MEASURED_MIDDLE_PART#',
        '#MEASURED_TAIL_PART#',
        '1',
        '#JUDGE_RESULT_CODE#',
        '#JUDGE_RESULT#',
        '#LOAD_BATCH_NO#',
    '#SUPPLY_UNIT_CODE#',
    '#SUPPLY_UNIT#')
</query>
<query id = "FrmLikuExamine.cancelAudit" desc = "撤销审批">
DECLARE
BEGIN
  DELETE FROM QCM_ZG_JUGDE_APPLY T
   WHERE T.JUGDE_APPLY_CODE || T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_CODE#'
   AND T.IS_ALL_SCRAP = '4';
  UPDATE QCM_LK_JUDGE_CHANGE T
     SET T.AGREE_FLAG = '0', T.JUGDE_APPLY_CODE = '',
     T.AGREE_NAME = '',T.AGREE_TIME = ''
   WHERE T.JUDGE_ID = '#JUDGE_ID#';
END;
</query>
</queryMap>