<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "外委管理">
<query id = "FrmStuffSubContractor.doQueryMat" desc = "查询收料实绩">
<![CDATA[
 SELECT 
       max(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       T.MEMO,
       T.PRODUCT_FLAG,
       T.MAT_STATUS,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.CAST_NO,
       T.CCMID,
       T.SAMPLE_FLAG,
       T.CUTTING_FLAG,
       T.CUTTING_NUM,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.JUDGE_GRADECODE,
       T.JUDGE_GRADENAME,
       T.JUDGE_STD_CODE,
       T.JUDGE_STD_NAME,
       T.PRO_ORDER_NO,
       T.PRO_ORDER_ID,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       sum(nvl(T.ACT_LEN,0))ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_FIX_NUM,
       T.ACT_FIX_LEN,
       sum(T.ACT_COUNT)ACT_COUNT,
       sum(T.ACT_THEORY_WEIGHT)ACT_THEORY_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.BUG_DEAL_CODE as BUG_DEAL,
       DECODE(T.OUTSOURCING_FLAG,'0','未委外','1','委外')OUTSOURCING_FLAG,
       DECODE(T.REPAIR_FLAG,'0','未返线','1','已返线') REPAIR_FLAG,
       T.Groud_No
 FROM MAT_GP_M T
 WHERE T.Stove_No || '&'LIKE ('%'||?||'%')
 AND T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 group by 
 T.MEMO,
       T.PRODUCT_FLAG,
       T.MAT_STATUS,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.CAST_NO,
       T.CCMID,
       T.SAMPLE_FLAG,
       T.CUTTING_FLAG,
       T.CUTTING_NUM,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.JUDGE_GRADECODE,
       T.JUDGE_GRADENAME,
       T.JUDGE_STD_CODE,
       T.JUDGE_STD_NAME,
       T.PRO_ORDER_NO,
       T.PRO_ORDER_ID,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_FIX_NUM,
       T.ACT_FIX_LEN,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.BUG_DEAL_CODE,
       T.OUTSOURCING_FLAG,
       T.REPAIR_FLAG,
       T.Groud_No
        
 ]]>
</query>
<query id = "FrmStuffSubContractor.doQuerySubContractor" desc = "查询外委实绩">
<![CDATA[
 SELECT 
       PROCESSING_NO,
       DEAL_NAME,
       PROCESSING_TYPE,
       MAT_STATUS,
       PRODUCT_FLAG,
       STOVE_NO,
       FLAG_STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       GROUD_NO,
       BATCH_NO,
       CAST_NO,
       CCMID,
       FLOWNO,
       SAMPLE_FLAG,
       CUTTING_FLAG,
       CUTTING_NUM,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       ORIGIN_MAT_NO,
       ORIGIN_STOVE_NO,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       JUDGE_GRADECODE,
       JUDGE_GRADENAME,
       JUDGE_STD_CODE,
       JUDGE_STD_NAME,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       PLINE_NAME,
       OLD_DIMATER,
       OLD_HEIGHT,
       sum(OLD_LEN)OLD_LEN,
       OLD_LEN_MIN,
       OLD_LEN_MAX,
       OLD_FIX_NUM,
       OLD_FIX_LEN,
       sum(OLD_COUNT)OLD_COUNT,
       sum(OLD_WEIGHT)OLD_WEIGHT,
       sum(OLD_THEORY_WEIGHT)OLD_THEORY_WEIGHT,
       ACT_DIMATER,
       ACT_HEIGHT,
       sum(ACT_LEN)ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_FIX_NUM,
       ACT_FIX_LEN,
       sum(ACT_COUNT)ACT_COUNT,
       sum(ACT_WEIGHT)ACT_WEIGHT,
       sum(ACT_THEORY_WEIGHT)ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       OUTSOURCING_FLAG,
       REPAIR_FLAG,
       BAL_YEAR_MONTH,
       MEMO,
       CREATE_NAME,
       max(TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME
 FROM MAT_GP_PROCESSING
 where 
 Stove_No || '&'LIKE ('%'||?||'%')
 AND JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 Group by  PROCESSING_NO,
       DEAL_NAME,
       PROCESSING_TYPE,
       MAT_STATUS,
       PRODUCT_FLAG,
       STOVE_NO,
       FLAG_STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       GROUD_NO,
       BATCH_NO,
       CAST_NO,
       CCMID,
       FLOWNO,
       SAMPLE_FLAG,
       CUTTING_FLAG,
       CUTTING_NUM,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       ORIGIN_MAT_NO,
       ORIGIN_STOVE_NO,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       JUDGE_GRADECODE,
       JUDGE_GRADENAME,
       JUDGE_STD_CODE,
       JUDGE_STD_NAME,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       PLINE_NAME,
       OLD_DIMATER,
       OLD_HEIGHT,
       OLD_LEN_MIN,
       OLD_LEN_MAX,
       OLD_FIX_NUM,
       OLD_FIX_LEN,
       ACT_DIMATER,
       ACT_HEIGHT,
       
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_FIX_NUM,
       ACT_FIX_LEN,
       
       BELONG_CODE,
       BELONG_NAME,
       OUTSOURCING_FLAG,
       REPAIR_FLAG,
       BAL_YEAR_MONTH,
       MEMO,
       CREATE_NAME
]]>
</query>
<query id = "FrmStuffSubContractor.doQueryBugDel"  desc = "获取缺陷处置方式">
SELECT T.BASENAME,T.BASECODE FROM COM_BASE_INFO T WHERE T.SORTCODE = '8018'
</query>
<query id = "doSubContractor.selectCount" desc = "查询支数是否满足">
SELECT SUM(T.ACT_COUNT)ACOUNT
  FROM MAT_GP_M T
 WHERE T.STOVE_NO = '#STOVE_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.GROUD_NO = '#GROUD_NO#'
   --AND T.PRODUCT_FLAG = '#PRODUCT_FLAG#'
   --AND T.MAT_STATUS = '#MAT_STATUS#'
   AND T.CAST_NO = '#CAST_NO#'
   AND T.PRODUCCODE = '#PRODUCCODE#'
   AND T.JUDGE_GRADECODE = '#JUDGE_GRADECODE#'
   AND NVL(T.JUDGE_STD_CODE,'/') = NVL('#JUDGE_STD_CODE#','/')
   AND T.ACT_DIMATER = '#ACT_DIMATER#'
   AND NVL(T.ACT_LEN_MIN, 0) = NVL('#ACT_LEN_MIN#', 0)
   AND NVL(T.ACT_LEN_MAX, 0) = NVL('#ACT_LEN_MAX#', 0)
   AND NVL(T.ACT_FIX_NUM, 0) = NVL('#ACT_FIX_NUM#', 0)
   AND NVL(T.ACT_FIX_LEN, 0) = NVL('#ACT_FIX_LEN#', 0)
</query>
<query id = "doSubContractor.insertMatProcessing" desc = "插入外委实绩">
<![CDATA[
DECLARE
  v_PROCESSING_NO     mat_gp_processing.processing_no%type := null; --外委单号
  v_PROCESSING_SQE    mat_gp_processing.processing_sqe%type := null; --外委流水号
  v_DEAL_NAME         mat_gp_processing.deal_name%type := null; --处置方式名称
  v_Icount            NUMBER := 1;
  v_ACT_WEIGHT        mat_gp_processing.old_weight%type := null;
  v_ACT_THEORY_WEIGHT mat_gp_processing.old_theory_weight%type := null;
  v_time              mat_gp_processing.create_time%type := sysdate;
  v_bathYear          mat_gp_processing.bal_year_month%type := to_char(sysdate,
                                                                       'yyyyMM');
BEGIN
  SELECT T.BASENAME
    INTO V_DEAL_NAME
    FROM COM_BASE_INFO T
   WHERE T.BASECODE = ?;
  --生成外委单号
  select 'A' || to_char(sysdate, 'yymmdd') ||
         Lpad(NVL(MAX(substr(t.processing_no, 9)), 0) + 1, 4, 0) processing_no
    into v_PROCESSING_NO
    from mat_gp_processing t
   where to_char(t.CREATE_TIME, 'YYYY-MM-DD') =
         to_char(sysdate, 'YYYY-MM-DD');
  select act_weight,act_theory_weight
   into v_ACT_WEIGHT, v_ACT_THEORY_WEIGHT from (select sum(t.act_weight)act_weight,
   sum(t.act_theory_weight)act_theory_weight
    from mat_gp_m t
   WHERE T.STOVE_NO = ?
     AND T.JUDGE_STOVE_NO = ?
     AND T.Groud_No = ?
     AND NVL(T.Act_Len_Min, 0) = NVL(?, 0)
     AND NVL(T.Act_Len_Max, 0) = NVL(?, 0)
     AND NVL(T.Act_Fix_Num, 0) = NVL(?, 0)
     AND NVL(T.Act_Fix_Len, 0) = NVL(?, 0)
     AND T.OUTSOURCING_FLAG = '0'
   ORDER BY T.MAT_NO DESC) where rownum<?;
    v_PROCESSING_SQE := v_PROCESSING_NO || Lpad(v_Icount, 5, 0);
  INSERT INTO MAT_GP_PROCESSING
    (PROCESSING_NO,
     PROCESSING_SQE,
     MAT_NO,
     DEAL_NAME,
     DEAL_CODE,
     PROCESSING_TYPE,
     MAT_STATUS,
     PRODUCT_FLAG,
     STOVE_NO,
     JUDGE_STOVE_NO,
     GROUD_NO,
     BATCH_NO,
     CAST_NO,
     CCMID,
     SAMPLE_FLAG,
     CUTTING_FLAG,
     CUTTING_NUM,
     MAT_ORIGIN_CODE,
     MAT_ORIGIN_NAME,
     ORIGIN_MAT_NO,
     
     SOURE_CODE,
     SOURE_NAME,
     MATERIAL_NO,
     MATERIAL_NAME,
     PRODUCCODE,
     PRODUCNAME,
     JUDGE_GRADECODE,
     JUDGE_GRADENAME,
     JUDGE_STD_CODE,
     JUDGE_STD_NAME,
     PRO_ORDER_NO,
     PRO_ORDER_ID,
     ORDER_NO,
     ORDER_SEQ,
     ORDER_SEQ_NO,
     ORD_PK,
     ORD_LN_PK,
     ORD_LN_DLY_PK,
     PLINE_CODE,
     PLINE_NAME,
     OLD_DIMATER,
     OLD_HEIGHT,
     OLD_LEN,
     OLD_LEN_MIN,
     OLD_LEN_MAX,
     OLD_FIX_NUM,
     OLD_FIX_LEN,
     OLD_COUNT,
     OLD_WEIGHT,
     OLD_THEORY_WEIGHT,
     BELONG_CODE,
     BELONG_NAME,
     BUG_NO,
     OUTSTOCK_TIME,
     BAL_YEAR_MONTH,
     MEMO,
     CREATE_NAME,
     CREATE_TIME)
  VALUES
    (v_PROCESSING_NO,
     v_PROCESSING_SQE,
     '',
     v_DEAL_NAME,
     ?,
     'A',
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     v_ACT_WEIGHT,
     v_ACT_THEORY_WEIGHT,
     ?,
     ?,
     ?,
     v_time,
     v_bathYear,
     ?,
     ?,
     v_time);
  FOR MYROW IN (select * from (SELECT T.*
                  FROM Mat_Gp_m T
                 WHERE T.STOVE_NO = ?
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.Groud_No = ?
                   AND NVL(T.Act_Len_Min, 0) = NVL(?, 0)
                   AND NVL(T.Act_Len_Max, 0) = NVL(?, 0)
                   AND NVL(T.Act_Fix_Num, 0) = NVL(?, 0)
                   AND NVL(T.Act_Fix_Len, 0) = NVL(?, 0)
                   AND T.OUTSOURCING_FLAG = '0'
                 ORDER BY T.MAT_NO DESC)where rownum<?) LOOP
    UPDATE mat_gp_m T
       SET T.OUTSOURCING_DOC = v_PROCESSING_NO, T.OUTSOURCING_FLAG = '1'
     WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
<query id = "cancelSubContractor.selectMatGpProcessing" desc = "查询外委实绩是否回报实绩">
SELECT COUNT(T.ACT_COUNT)ACOUNT FROM MAT_GP_PROCESSING T WHERE T.PROCESSING_NO = ? AND T.ACT_COUNT IS NOT NULL
</query>
<query id = "cancelSubContractor.deleteMatGpProcessing" desc = "撤销外委实绩">
<![CDATA[
DECLARE
BEGIN
    DELETE MAT_GP_PROCESSING T WHERE T.PROCESSING_NO = ?;
    UPDATE mat_gp_m T SET T.OUTSOURCING_DOC = '',T.OUTSOURCING_FLAG = '0' WHERE T.Outsourcing_Doc = ?;
END;
]]>
</query>
<query id = "FrmStuffSubContractor.backActual" desc = "回报实绩">
UPDATE MAT_GP_PROCESSING T
   SET T.ACT_COUNT = TO_NUMBER(?),
       T.ACT_THEORY_WEIGHT = TO_NUMBER(?),
       T.ACT_FIX_NUM = TO_NUMBER(?),
       T.ACT_FIX_LEN = TO_NUMBER(?),
       T.UPDATE_NAME = ?,
       T.UPDATE_TIME = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE T.PROCESSING_NO = ?
</query>
</queryMap>