<?xml version="1.0" encoding="UTF-8"?>

<queryMap desc = "库存信息汇总">
<query id = "FrmStoreSummary.queryData" desc= "查询库存信息(仓库)">
select 
 #columns#
 sum(T1.ACT_COUNT) as ACT_COUNT,
 sum(T1.ACT_WEIGHT) as ACT_WEIGHT，
 sum(T1.ACT_LEN) as ACT_LEN,
 MAX((CASE
 WHEN T1.Pro_Plan_Id_Next LIKE '%DBK%' THEN
 (SELECT S3.PLINE_NAME
 FROM PLN_ORDER_DBK_S S3
 WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
 AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
 WHEN T1.Pro_Plan_Id_Next LIKE '%RCL%' THEN
 (SELECT S3.PLINE_NAME
 FROM PLN_ORDER_RCL_S S3
 WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
 AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
 WHEN T1.Pro_Plan_Id_Next LIKE '%JGX%' THEN
 (SELECT S3.PLINE_NAME
 FROM PLN_ORDER_JGX_S S3
 WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
 AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
 ELSE
 ''
 END)) LOAD_PLINE,
MAX((CASE
 WHEN T1.JUGDE_APPLY_CODE IS NOT NULL OR T1.MAT_STATUS NOT IN('80150101','80150201') THEN
 '已送判'
 ELSE
 '未送判'
 END)) IS_APPLY_FLAG
 FROM MAT_BC_M T1 LEFT JOIN  YDM_BC_BUTTRESS T2
 on T1.MAT_NO=T2.MAT_NO
 LEFT JOIN YDM_BS_STORAGE S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.MAT_NO = T2.MAT_NO
 #conditions#
 #conditions1#
 UNION ALL
 select 
 #columns#
 sum(T1.ACT_COUNT) as ACT_COUNT,
 sum(T1.ACT_WEIGHT) as ACT_WEIGHT,
 sum(T1.ACT_LEN) as ACT_LEN,
 '' LOAD_PLINE,
 '已送判' IS_APPLY_FLAG
 FROM MAT_ZC_M T1 LEFT JOIN  YDM_ZC_BUTTRESS T2
 on T1.MAT_NO=T2.MAT_NO
 LEFT JOIN YDM_BS_STORAGE S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.MAT_NO = T2.MAT_NO
 #conditions#
 #conditions1#
</query>

<query id = "FrmStoreSummary.queryDataBelong" desc= "查询库存信息(所属权)">
select 
 #columns#
 sum(T1.ACT_COUNT) as ACT_COUNT,
 sum(T1.ACT_WEIGHT) as ACT_WEIGHT,
 sum(T1.ACT_LEN) as ACT_LEN
 FROM MAT_BC_M T1 LEFT JOIN  YDM_BC_BUTTRESS T2
 on T1.MAT_NO=T2.MAT_NO
 LEFT JOIN YDM_BS_STORAGE S ON S.STORAGE_NO=T2.STORAGE_NO

 WHERE T1.MAT_NO = T2.MAT_NO
 #conditions# 
</query>
<query id = "FrmStoreSummary.queryDataAll" desc= "查询库存信息(所属权)">
select 
 #columns#
 sum(T1.ACT_COUNT) as ACT_COUNT,
 sum(T1.ACT_WEIGHT) as ACT_WEIGHT,
 sum(T1.ACT_LEN) as ACT_LEN,
 MAX((CASE
 WHEN T1.Pro_Plan_Id_Next LIKE '%DBK%' THEN
 (SELECT S3.PLINE_NAME
 FROM PLN_ORDER_DBK_S S3
 WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
 AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
 WHEN T1.Pro_Plan_Id_Next LIKE '%RCL%' THEN
 (SELECT S3.PLINE_NAME
 FROM PLN_ORDER_RCL_S S3
 WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
 AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
 WHEN T1.Pro_Plan_Id_Next LIKE '%JGX%' THEN
 (SELECT S3.PLINE_NAME
 FROM PLN_ORDER_JGX_S S3
 WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
 AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
 ELSE
 ''
 END)) LOAD_PLINE,
 MAX((CASE
 WHEN T1.JUGDE_APPLY_CODE IS NOT NULL OR T1.MAT_STATUS NOT IN('80150101','80150104', '80150201') THEN
 '已送判'
 ELSE
 '未送判'
 END)) IS_APPLY_FLAG
 FROM MAT_BC_M T1 LEFT JOIN  YDM_BC_BUTTRESS T2
 on T1.MAT_NO=T2.MAT_NO
 LEFT JOIN YDM_BS_STORAGE S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.MAT_NO = T2.MAT_NO
 #conditions#
 #conditions1#
 UNION ALL
 select 
 #columns#
 sum(T1.ACT_COUNT) as ACT_COUNT,
 sum(T1.ACT_WEIGHT) as ACT_WEIGHT,
 sum(T1.ACT_LEN) as ACT_LEN,
 ''LOAD_PLINE,
 '已送判'IS_APPLY_FLAG
 FROM MAT_ZC_M T1 LEFT JOIN  YDM_ZC_BUTTRESS T2
 on T1.MAT_NO=T2.MAT_NO
 LEFT JOIN YDM_BS_STORAGE S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.MAT_NO = T2.MAT_NO
 #conditions#
 #conditions1#
</query>

<query id = "FrmStoreSummary.queryDataMemo" desc= "查询库存信息(仓库)">
<![CDATA[
select (SELECT T3.STORAGE_NAME
          FROM YDM_BS_STORAGE T3
         WHERE T3.STORAGE_NO = T2.STORAGE_NO) STORAGE_NAME,
       T2.STORAGE_NO,
       (SELECT T4.LOCATION_NAME
          FROM YDM_BS_LOCATION T4
         WHERE T4.LOCATION_NO = T2.LOCATION_NO) LOCATION_NAME,
       T2.LOCATION_NO,
       T1.PRODUCT_FLAG,
       T1.MAT_STATUS,
       T1.STOVE_NO,
       T1.JUDGE_STOVE_NO,
       t1.BATCH_NO,
       T1.MEMO1 MEMO,
       T1.MEMO1 MEMO2,
       t1.Batch_Groud_No,
       t1.MATERIAL_NAME,
       t1.PRODUCNAME,
       t1.STEELNAME,
       t1.GRADENAME,
       t1.SPEC_NAME,
       t1.MODEL_DESC,
       t1.STD_STYLE_DESC,
       T1.PRO_ORDER_NO,
       T1.PLINE_NAME,
       t1.ACT_DIMATER,
       t1.ACT_HEIGHT,
       t1.ACT_LEN_MIN,
       t1.ACT_LEN_MAX,
       T1.BELONG_NAME,
       T1.JUDGE_RESULT,
       MAX(TO_CHAR(T1.JUDGE_RESULT_TIME, 'YYYY-MM-DD HH24:MI:SS')) JUDGE_RESULT_TIME,
       MAX(TO_CHAR(T1.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       DECODE(T1.QCM_STAUS, '00', '合格', '11', '待处理', '22', '废品') QCM_STAUS,
       '0' STAUS,
       sum(T1.ACT_COUNT) as ACT_COUNT,
       sum(T1.ACT_WEIGHT) as ACT_WEIGHT， sum(T1.ACT_LEN) as ACT_LEN
  FROM MAT_BC_M T1
  LEFT JOIN YDM_BC_BUTTRESS T2
    on T1.MAT_NO = T2.MAT_NO
  LEFT JOIN YDM_BS_STORAGE S
    ON S.STORAGE_NO = T2.STORAGE_NO
 WHERE T1.MAT_NO = T2.MAT_NO

 #something#
 group by T2.STORAGE_NO,
          T2.LOCATION_NO,
          T1.PRODUCT_FLAG,
          T1.MAT_STATUS,
          T1.STOVE_NO,
          T1.JUDGE_STOVE_NO,
          t1.BATCH_NO,
          T1.MEMO1,
          t1.Batch_Groud_No,
          t1.MATERIAL_NAME,
          t1.PRODUCNAME,
          t1.STEELNAME,
          t1.GRADENAME,
          t1.SPEC_NAME,
          t1.MODEL_DESC,
          t1.STD_STYLE_DESC,
          T1.PRO_ORDER_NO,
          T1.PLINE_NAME,
          t1.ACT_DIMATER,
          t1.ACT_HEIGHT,
          t1.ACT_LEN_MIN,
          t1.ACT_LEN_MAX,
          T1.BELONG_NAME,
          T1.JUDGE_RESULT,
          T1.QCM_STAUS
UNION ALL
select (SELECT T3.STORAGE_NAME
          FROM YDM_BS_STORAGE T3
         WHERE T3.STORAGE_NO = T2.STORAGE_NO) STORAGE_NAME,
       T2.STORAGE_NO,
       (SELECT T4.LOCATION_NAME
          FROM YDM_BS_LOCATION T4
         WHERE T4.LOCATION_NO = T2.LOCATION_NO) LOCATION_NAME,
       T2.LOCATION_NO,
       T1.PRODUCT_FLAG,
       T1.MAT_STATUS,
       T1.STOVE_NO,
       T1.JUDGE_STOVE_NO,
       t1.BATCH_NO,
       T1.MEMO1 MEMO,
       T1.MEMO1 MEMO2,
       t1.Batch_Groud_No,
       t1.MATERIAL_NAME,
       t1.PRODUCNAME,
       t1.STEELNAME,
       t1.GRADENAME,
       t1.SPEC_NAME,
       t1.MODEL_DESC,
       t1.STD_STYLE_DESC,
       T1.PRO_ORDER_NO,
       T1.PLINE_NAME,
       t1.ACT_DIMATER,
       t1.ACT_HEIGHT,
       t1.ACT_LEN_MIN,
       t1.ACT_LEN_MAX,
       T1.BELONG_NAME,
       T1.JUDGE_RESULT,
       MAX(TO_CHAR(T1.JUDGE_RESULT_TIME, 'YYYY-MM-DD HH24:MI:SS')) JUDGE_RESULT_TIME,
       MAX(TO_CHAR(T1.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       DECODE(T1.QCM_STAUS, '00', '合格', '11', '待处理', '22', '废品') QCM_STAUS,
       '1' STAUS,
       sum(T1.ACT_COUNT) as ACT_COUNT,
       sum(T1.ACT_WEIGHT) as ACT_WEIGHT,
       sum(T1.ACT_LEN) as ACT_LEN
  FROM MAT_ZC_M T1
  LEFT JOIN YDM_ZC_BUTTRESS T2
    on T1.MAT_NO = T2.MAT_NO
  LEFT JOIN YDM_BS_STORAGE S
    ON S.STORAGE_NO = T2.STORAGE_NO
 WHERE T1.MAT_NO = T2.MAT_NO

 #something#
 group by T2.STORAGE_NO,
          T2.LOCATION_NO,
          T1.PRODUCT_FLAG,
          T1.MAT_STATUS,
          T1.STOVE_NO,
          T1.JUDGE_STOVE_NO,
          t1.BATCH_NO,
          T1.MEMO1,
          t1.Batch_Groud_No,
          t1.MATERIAL_NAME,
          t1.PRODUCNAME,
          t1.STEELNAME,
          t1.GRADENAME,
          t1.SPEC_NAME,
          t1.MODEL_DESC,
          t1.STD_STYLE_DESC,
          T1.PRO_ORDER_NO,
          T1.PLINE_NAME,
          t1.ACT_DIMATER,
          t1.ACT_HEIGHT,
          t1.ACT_LEN_MIN,
          t1.ACT_LEN_MAX,
          T1.BELONG_NAME,
          T1.JUDGE_RESULT,
          T1.QCM_STAUS
 ]]>
</query>

<query id = "FrmStoreSummary.updateMemo" desc= "修改备注">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%type := ?;
  V_BATCH_NO       MAT_BC_M.BATCH_NO%type := ?;
  V_BATCH_GROUD_NO MAT_BC_M.BATCH_GROUD_NO%type := ?;
  V_ACT_COUNT      MAT_BC_M.ACT_COUNT%type := ?;
  V_MEMO           MAT_BC_M.MEMO%type := ?;
  V_LOCATION_NO    YDM_BC_BUTTRESS.LOCATION_NO%type := ?;
  V_MEMO2          MAT_BC_M.MEMO%type := ?;
  V_PRO_ORDER_NO   MAT_BC_M.PRO_ORDER_NO%type := ?;
  V_MAT_STATUS     MAT_BC_M.MAT_STATUS%type := ?;
  V_PLINE_NAME     MAT_BC_M.PLINE_NAME%type := ?;
  V_STATE          MAT_BC_M.LOCK_LIKU%type := ?;
BEGIN
  IF (V_STATE = '0') THEN
    FOR MYROW IN (SELECT *
                    FROM (select T1.*
                            FROM MAT_BC_M T1
                            LEFT JOIN YDM_BC_BUTTRESS T2
                              ON T1.MAT_NO = T2.MAT_NO
                           WHERE T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                             AND T1.BATCH_NO = V_BATCH_NO
                             AND NVL(T1.BATCH_GROUD_NO, '/') =
                                 NVL(V_BATCH_GROUD_NO, '/')
                             AND NVL(T1.MEMO1, '/') = NVL(V_MEMO2, '/')
                             AND T1.MAT_STATUS = V_MAT_STATUS
                             AND NVL(T1.PRO_ORDER_NO, '/') =
                                 NVL(V_PRO_ORDER_NO, '/')
                             AND NVL(T2.LOCATION_NO, '/') =
                                 NVL(V_LOCATION_NO, '/')
                             AND NVL(T1.PLINE_NAME, '/') =
                                 NVL(V_PLINE_NAME, '/'))
                   WHERE ROWNUM <= V_ACT_COUNT) LOOP
      UPDATE MAT_BC_M T SET T.MEMO1 = V_MEMO WHERE T.MAT_NO = MYROW.MAT_NO;
    END LOOP;
  ELSIF (V_STATE = '1') THEN
    FOR MYROW1 IN (SELECT *
                     FROM (select T1.*
                             FROM MAT_ZC_M T1
                             LEFT JOIN YDM_ZC_BUTTRESS T2
                               ON T1.MAT_NO = T2.MAT_NO
                            WHERE T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                              AND T1.BATCH_NO = V_BATCH_NO
                              AND NVL(T1.BATCH_GROUD_NO, '/') =
                                  NVL(V_BATCH_GROUD_NO, '/')
                              AND NVL(T1.MEMO1, '/') = NVL(V_MEMO2, '/')
                              AND T1.MAT_STATUS = V_MAT_STATUS
                              AND NVL(T1.PRO_ORDER_NO, '/') =
                                  NVL(V_PRO_ORDER_NO, '/')
                              AND NVL(T2.LOCATION_NO, '/') =
                                  NVL(V_LOCATION_NO, '/')
                              AND NVL(T1.PLINE_NAME, '/') =
                                  NVL(V_PLINE_NAME, '/'))
                    WHERE ROWNUM <= V_ACT_COUNT) LOOP
      UPDATE MAT_ZC_M T SET T.MEMO1 = V_MEMO WHERE T.MAT_NO = MYROW1.MAT_NO;
    END LOOP;
  END IF;
END;

 ]]>
</query>
</queryMap>