", CASE WHEN A.WID<A.LEN THEN A.LEN ELSE A.WID END REM_LEN "+
", A.WGT REM_WGT "+
", A.LEN ORG_LEN "+
", A.WID ORG_WID"+
", A.LEN ACT_LEN "+
",400 as COM_LEN"+
", CASE WHEN (SELECT COUNT(HEAT_NO) FROM NISCO.FP_RHRSLT WHERE HEAT_NO = SUBSTR(A.SLAB_NO,1,8))>0 THEN '1' ELSE '0' END VAC_FLG ");
strSql.AppendLine(",(CASE WHEN(SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET CSDD WHERE (CSDD.EST_CD LIKE '5%' OR CSDD.EST_CD LIKE '6%') AND (CSDD.SLAB_NO = A.SLAB_NO or CSDD.SLAB_NO=substr(A.MOTHER_SLAB,1,10))) > 0 THEN '1'");
strSql.AppendLine(" WHEN(SELECT COUNT(*) FROM(SELECT COM FROM(SELECT CSDD_C.EST_CD || '_' || CSDD_C.EST_COMMENT COM FROM NISCO.CP_SLAB_DELI_DET CSDD_C ");
strSql.AppendLine(" WHERE CSDD_C.SLAB_NO = A.SLAB_NO ORDER BY CSDD_C.EST_DATE DESC) T_COM WHERE ROWNUM = 1) T_L WHERE T_L.COM LIKE '%协议%') > 0 THEN '1' ");
strSql.AppendLine(" ELSE '0' END ) XY_FLG ");
strSql.AppendLine(",(SELECT COM FROM(SELECT CSDD_C.EST_CD || '_' || CSDD_C.EST_COMMENT COM FROM NISCO.CP_SLAB_DELI_DET CSDD_C");
strSql.AppendLine(" WHERE CSDD_C.SLAB_NO = A.SLAB_NO ORDER BY CSDD_C.EST_DATE DESC) T_COM WHERE ROWNUM = 1) EST_COMMENT ");
strSql.AppendLine(" , (case when (select substr(MOTHER_SLAB,1,10) from nisco.fp_slab where slab_no=substr(A.MOTHER_SLAB,1,10)) is not null then (select mother_slab from nisco.fp_slab where slab_no=substr(A.MOTHER_SLAB,1,10)) else '' end) Gmother_slab ");
//低倍标记 0为低倍不合
strSql.AppendLine(" , case when (SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD = '0001' AND C.REASON_CD = '3010' AND C.REASON_COMMENT = '低倍不符合要求') >0 THEN 1 ELSE 0 END FLG_LOWPOWER");
strSql.AppendLine("FROM NISCO.FP_SLAB A ");
strSql.AppendLine("WHERE 1 = 1 ");
//TODO: 测试数据2320047205
// strSql.AppendLine(" AND A.SLAB_NO in (" +
//"'2330680931'" +
//",'2330680932'" +
// ",'2330713002'" +
// ",'2330314731'" +
//",'2330316103'" +
// ",'2310553603'" +
//")");
// strSql.AppendLine(" AND A.SLAB_NO like ('2430210031%')");
strSql.AppendLine(" AND A.PROC_CD = 'CAC' ");
strSql.AppendLine(" AND(A.PROC_CD = 'CAC' OR ");
strSql.AppendLine(" ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.REASON_CD NOT IN('1080','2014','2015','2018','2026','3014','5011','5013','8081') AND EST_CD IS NULL) < 1)");
strSql.AppendLine(" AND A.PROC_CD='CAD' ) ");
strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD IN ('0002','0003','2010')) < 1 )");
//strSql.AppendLine(" AND A.SLAB_NO!='2320297902' ");
strSql.AppendLine(" AND A.CUR_INV in ('00','C7','52','ZZ','HC') ");
//strSql.AppendLine(" AND A.PROC_CD = 'CAC' ");
strSql.AppendLine(" AND A.ORD_FL = '2' ");
strSql.AppendLine(" AND A.REC_STS = '2' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
strSql.AppendLine(" AND A.WGT > 0 ");
strSql.AppendLine(" AND A.WID > 1600 ");
strSql.AppendLine(" AND A.LEN > 3900 ");
strSql.AppendLine(" AND A.THK < 260 ");
strSql.AppendLine(" AND NVL(A.PLT,'99') IN ('B1','BZ') ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD,'N') <> 'N' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND SLAB_NO NOT IN ( SELECT SLAB_NO FROM NISCO.CP_SLAB_MOVE_PLAN WHERE PRC_STS = 'A' AND TO_INV in('ZB','HB') ) ");
strSql.AppendLine(" AND not ((substr(A.LOC,1,7) in ('S7I1701','S7I1702','S7I1703','S7I1801','S7I1802','S7I1803') or substr(A.LOC,1,5) in ('S3E04','S3E05','S3E06') ) and CUR_INV='00') ");
strSql.AppendLine(" AND NVL(A.PLAN_MILL_PLT , ' ') LIKE '%C1' || '%' ");
//3.11.5.4.9 订单有低倍要求并且物料低倍等级不合格的板坯,不允许替代。
//strSql.AppendLine(" AND ( ( (SELECT COUNT(*) FROM NISCO.qp_qlty_slab_lowpower Q WHERE Q.ORD_NO =A.ORD_NO AND Q.ORD_ITEM=A.ORD_ITEM) >= 1) AND A.QUALITY_GRD = '4' AND ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD = '0001' AND C.REASON_CD = '3010' AND C.REASON_COMMENT = '低倍不符合要求') < 1 ))");
strSql.AppendLine(" AND (select COUNT(*) from nisco.fp_slab_C3 WHERE SLAB_NO=A.SLAB_NO AND FL='True')<1");
strSql.AppendLine(" AND (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')<1");
//strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 ) ");//
strSql.AppendLine(" ORDER BY A.LOC DESC, A.SLAB_NO ASC ");
strSql.AppendLine(" AND (boi.ord_knd ='A' OR (boi.ord_knd ='T' AND (SELECT COUNT(*) FROM NISCO.BP_ODER_XY BOXY WHERE BOXY.ORDER_NO=BOI.ORD_NO AND BOXY.ORDER_ITEM=BOI.ORD_ITEM )>0)) ");
strSql.AppendLine("AND (boi.CUST_DEL_TO_DATE>= to_char(sysdate-183,'YYYYMMDD') OR BOI.ORD_NO LIKE 'OMA%' )");
strSql.AppendLine(",CASE WHEN BOI.CUST_DEL_TO_DATE > TO_CHAR(SYSDATE + 7, 'YYYYMMdd') THEN 0 ELSE 1 END DEL_FLG");
//成品成分
strSql.AppendLine(",(CASE WHEN ( SELECT COUNT(*) FROM NISCO.QP_QLTY_CHEM_FP QQCF WHERE QQCF.ORD_NO=BOI.ORD_NO AND QQCF.ORD_ITEM=BOI.ORD_ITEM )>0 THEN '1' ELSE '0' END ) CHEM_FLG ");
//strSql.AppendLine(",QSH.STDSPEC_NAME_ENG ");
strSql.AppendLine(",QSH.STDSPEC_STLGRD");
strSql.AppendLine(",(CASE WHEN ( SELECT COUNT(*) FROM NISCO.BP_ODER_XY BOXY WHERE BOXY.ORDER_NO=BOI.ORD_NO AND BOXY.ORDER_ITEM=BOI.ORD_ITEM )>0 THEN '1' WHEN BOI.STDSPEC LIKE 'NMXY%' THEN '1' ELSE '0' END ) XY_FLG ");
strSql.AppendLine(",(CASE WHEN instr( DECODE(QQT.MLT_PROC_LINE, '1', QQT.MLT_PROC_CD, QQT.MLT_PROC_CD2),'BH') > 0 THEN '1' ELSE '0' END ) VAC_FLG\r\n");
strSql.AppendLine(",(CASE WHEN(SELECT COUNT(*) FROM NISCO.QP_QLTY_MATR_HA QQMH WHERE QQMH.ORD_NO = BOI.ORD_NO AND QQMH.ORD_ITEM = BOI.ORD_ITEM AND QQMH.TEST_KND IN('8', '9')) > 0 THEN '1' ELSE '0' END ) Z_FLG ");
strSql.AppendLine(" ,NVL((SELECT sum(A.WGT) ");
strSql.AppendLine(" FROM NISCO.EP_REQ_SLAB_D A, NISCO.EP_REQ_SLAB B ");
strSql.AppendLine(" WHERE ");
strSql.AppendLine("1 = 1 AND A.ORD_NO = BOI.ORD_NO AND A.ORD_ITEM = BOI.ORD_ITEM ");
strSql.AppendLine(" , case when (SELECT COUNT(*) FROM NISCO.qp_qlty_slab_lowpower where ord_no=boi.ord_no and ord_item=boi.ord_item)<1 THEN 0 ELSE 1 END FLG_LOWPOWER");
// 高表标记 1是高表
strSql.AppendLine(", CASE WHEN BOI.STD_DET_CLASS_LVL IN('G1','G2') and (SELECT STEEL_GRD_DETAIL FROM NISCO.QP_NISCO_CHMC WHERE STLGRD = BOI.STLGRD) not in ('Q550-QT-1','Q550-QT-2','Q906-1','Q960-2','Q960-3','Q890-1','Q890-2') THEN 1 ELSE 0 END FLG_GB");
strSql.AppendLine(" AND (boi.ord_knd ='A' OR (boi.ord_knd ='T' AND (SELECT COUNT(*) FROM NISCO.BP_ODER_XY BOXY WHERE BOXY.ORDER_NO=BOI.ORD_NO AND BOXY.ORDER_ITEM=BOI.ORD_ITEM )>0)) ");
strSql.AppendLine("AND (boi.CUST_DEL_TO_DATE>= to_char(sysdate-183,'YYYYMMDD') OR BOI.ORD_NO LIKE 'OMA%' )");
strSql.AppendLine("AND boi.CFM_MILL_PLT='C1' ");
//strSql.AppendLine(" AND boi.ORD_NO || '-' || boi.ORD_ITEM in ('EM523100005-001')");
// strSql.AppendLine(" AND boi.ORD_NO in ('OMA23060029')");
strSql.AppendLine("SELECT QQC.*, rank() over(partition by QQC.ord_no, QQC.ord_item order by knd desc) rk from NISCO.QP_QLTY_CHEM QQC where (QQC.ORD_NO, QQC.ORD_ITEM) IN(");
strSql.AppendLine(" AND (boi.ord_knd ='A' OR (boi.ord_knd ='T' AND (SELECT COUNT(*) FROM NISCO.BP_ODER_XY BOXY WHERE BOXY.ORDER_NO=BOI.ORD_NO AND BOXY.ORDER_ITEM=BOI.ORD_ITEM )>0)) ");
// strSql.AppendLine(" AND boi.ORD_NO || '-' || boi.ORD_ITEM in ('OMC22110048-001')");
strSql.AppendLine(") ");
strSql.AppendLine(" AND QQC.KND IN ('1','2') ) T WHERE T.rk = 1 ");
strSql.AppendLine("SELECT fsd.SLAB_NO FROM NISCO.FP_SLAB_DES fsd WHERE fsd.SLAB_NO IN ( ");
strSql.AppendLine(" SELECT A.SLAB_NO ");
strSql.AppendLine(" FROM NISCO.FP_SLAB A ");
strSql.AppendLine("WHERE 1 = 1 ");
strSql.AppendLine(" AND(A.PROC_CD = 'CAC' OR ");
strSql.AppendLine(" ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.REASON_CD NOT IN('1080','2014','2015','2018','2026','3014','5011','5013','8081') AND EST_CD IS NULL) < 1)");
strSql.AppendLine(" AND A.PROC_CD='CAD' ) ");
strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD IN ('0002','0003','2010')) < 1 )");
strSql.AppendLine(" AND A.PROC_CD!='CAD' ");
strSql.AppendLine(" AND A.CUR_INV in ('00','C7','52','ZZ','HC') ");
//strSql.AppendLine(" AND A.PROC_CD = 'CAC' ");
strSql.AppendLine(" AND A.ORD_FL = '2' ");
strSql.AppendLine(" AND A.REC_STS = '2' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND A.WGT > 0 ");
strSql.AppendLine(" AND A.WID > 1600 ");
strSql.AppendLine(" AND A.LEN > 3900 ");
strSql.AppendLine(" AND NVL(A.PLT,'99') IN ('B1','BZ') ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD,'N') <> 'N' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND SLAB_NO NOT IN ( SELECT SLAB_NO FROM NISCO.CP_SLAB_MOVE_PLAN WHERE PRC_STS = 'A' AND TO_INV in('ZB','HB') ) ");
strSql.AppendLine(" AND NVL(A.PLAN_MILL_PLT , ' ') LIKE '%C1' || '%' ");
//3.11.5.4.9 订单有低倍要求并且物料低倍等级不合格的板坯,不允许替代。
//strSql.AppendLine(" AND ( ( (SELECT COUNT(*) FROM NISCO.qp_qlty_slab_lowpower Q WHERE Q.ORD_NO =A.ORD_NO AND Q.ORD_ITEM=A.ORD_ITEM) >= 1) AND A.QUALITY_GRD = '4' AND ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD = '0001' AND C.REASON_CD = '3010' AND C.REASON_COMMENT = '低倍不符合要求') < 1 ))");
//strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 )) ");//
strSql.AppendLine("SELECT * FROM NISCO.QP_CHEM_RSLT WHERE HEAT_NO IN ( ");
strSql.AppendLine("SELECT ");
strSql.AppendLine("A.HEAT_NO ");
strSql.AppendLine("FROM NISCO.FP_SLAB A ");
strSql.AppendLine("WHERE 1 = 1 ");
//strSql.AppendLine(" AND A.SLAB_NO = '2310167902' ");
strSql.AppendLine(" AND(A.PROC_CD = 'CAC' OR ");
strSql.AppendLine(" ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.REASON_CD NOT IN('1080','2014','2015','2018','2026','3014','5011','5013','8081') AND EST_CD IS NULL) < 1)");
strSql.AppendLine(" AND A.PROC_CD='CAD' ) ");
strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD IN ('0002','0003','2010')) < 1 )");
//strSql.AppendLine(" AND A.SLAB_NO!='2320297902' ");
strSql.AppendLine(" AND A.CUR_INV in ('00','C7','52','ZZ','HC') ");
//strSql.AppendLine(" AND A.PROC_CD = 'CAC' ");
strSql.AppendLine(" AND A.ORD_FL = '2' ");
strSql.AppendLine(" AND A.REC_STS = '2' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND A.WGT > 0 ");
strSql.AppendLine(" AND A.WID > 1600 ");
strSql.AppendLine(" AND A.LEN > 3900 ");
strSql.AppendLine(" AND NVL(A.PLT,'99') IN ('B1','BZ') ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD,'N') <> 'N' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND SLAB_NO NOT IN ( SELECT SLAB_NO FROM NISCO.CP_SLAB_MOVE_PLAN WHERE PRC_STS = 'A' AND TO_INV in('ZB','HB') ) ");
strSql.AppendLine(" AND not (substr(A.LOC,1,7) in ('S7I1701','S7I1702','S7I1703','S7I1801','S7I1802','S7I1803') and CUR_INV='00') ");
strSql.AppendLine(" AND NVL(A.PLAN_MILL_PLT , ' ') LIKE '%C1' || '%' ");
//3.11.5.4.9 订单有低倍要求并且物料低倍等级不合格的板坯,不允许替代。
//strSql.AppendLine(" AND ( ( (SELECT COUNT(*) FROM NISCO.qp_qlty_slab_lowpower Q WHERE Q.ORD_NO =A.ORD_NO AND Q.ORD_ITEM=A.ORD_ITEM) >= 1) AND A.QUALITY_GRD = '4' AND ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD = '0001' AND C.REASON_CD = '3010' AND C.REASON_COMMENT = '低倍不符合要求') < 1 ))");
//strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 ) ");//
strSql.AppendLine("SELECT * FROM NISCO.FP_CAD_INF ");
strSql.AppendLine("WHERE substr (SLAB_NO,1,8) IN ( ");
strSql.AppendLine("SELECT ");
strSql.AppendLine("substr(A.SLAB_NO,1,8) ");
strSql.AppendLine("FROM NISCO.FP_SLAB A ");
strSql.AppendLine("WHERE 1 = 1 ");
strSql.AppendLine(" AND(A.PROC_CD = 'CAC' OR ");
strSql.AppendLine(" ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.REASON_CD NOT IN('1080','2014','2015','2018','2026','3014','5011','5013','8081') AND EST_CD IS NULL) < 1)");
strSql.AppendLine(" AND A.PROC_CD='CAD' ) ");
strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD IN ('0002','0003','2010')) < 1 )");
strSql.AppendLine(" AND A.CUR_INV in ('00','C7','52','ZZ','HC') ");
//strSql.AppendLine(" AND A.PROC_CD = 'CAC' ");
strSql.AppendLine(" AND A.ORD_FL = '2' ");
strSql.AppendLine(" AND A.REC_STS = '2' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND A.WGT > 0 ");
strSql.AppendLine(" AND A.WID > 1600 ");
strSql.AppendLine(" AND A.LEN > 3900 ");
strSql.AppendLine(" AND NVL(A.PLT,'99') IN ('B1','BZ') ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD,'N') <> 'N' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND SLAB_NO NOT IN ( SELECT SLAB_NO FROM NISCO.CP_SLAB_MOVE_PLAN WHERE PRC_STS = 'A' AND TO_INV in('ZB','HB') ) ");
strSql.AppendLine(" AND not (substr(A.LOC,1,7) in ('S7I1701','S7I1702','S7I1703','S7I1801','S7I1802','S7I1803') and CUR_INV='00') ");
strSql.AppendLine(" AND NVL(A.PLAN_MILL_PLT , ' ') LIKE '%C1' || '%' ");
//3.11.5.4.9 订单有低倍要求并且物料低倍等级不合格的板坯,不允许替代。
//strSql.AppendLine(" AND ( ( (SELECT COUNT(*) FROM NISCO.qp_qlty_slab_lowpower Q WHERE Q.ORD_NO =A.ORD_NO AND Q.ORD_ITEM=A.ORD_ITEM) >= 1) AND A.QUALITY_GRD = '4' AND ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD = '0001' AND C.REASON_CD = '3010' AND C.REASON_COMMENT = '低倍不符合要求') < 1 ))");
//strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 ) )");//
strSql.AppendLine("SELECT fsd.ACT_SLAB_NO FROM NISCO.EP_SLAB_DES fsd WHERE fsd.ACT_SLAB_NO IN ( ");
strSql.AppendLine(" SELECT A.SLAB_NO ");
strSql.AppendLine(" FROM NISCO.FP_SLAB A ");
strSql.AppendLine("WHERE 1 = 1 ");
strSql.AppendLine(" AND A.CUR_INV in ('00','C7','52','ZZ','HC') ");
strSql.AppendLine(" AND(A.PROC_CD = 'CAC' OR ");
strSql.AppendLine(" ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.REASON_CD NOT IN('1080','2014','2015','2018','2026','3014','5011','5013','8081') AND EST_CD IS NULL) < 1)");
strSql.AppendLine(" AND A.PROC_CD='CAD' ) ");
strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD IN ('9010','0002','0003','2010')) < 1 )");
strSql.AppendLine(" AND A.ORD_FL = '2' ");
strSql.AppendLine(" AND A.REC_STS = '2' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND A.WGT > 0 ");
strSql.AppendLine(" AND SUBSTR(A.SLAB_NO,3,1) <> 'F' ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD, 'N') NOT IN('N','E') ");
strSql.AppendLine(" AND NVL(A.PLAN_MILL_PLT , ' ') LIKE '%C1' || '%' ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ) ");
strSql.AppendLine("rank() over(partition BY CMS.MAT_NO order by CMS.SND_TIME desc) rk ,CMS.* ");
strSql.AppendLine("FROM NISCO.CP_MOVE_SLT CMS ");
strSql.AppendLine(" WHERE CMS.MAT_NO IN ( ");
strSql.AppendLine(" SELECT DISTINCT A.SLAB_NO ");
strSql.AppendLine("FROM NISCO.FP_SLAB A ");
strSql.AppendLine("WHERE 1 = 1 ");
strSql.AppendLine(" AND A.PROC_CD = 'CAC' ");
strSql.AppendLine(" AND(A.PROC_CD = 'CAC' OR ");
strSql.AppendLine(" ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.REASON_CD NOT IN('1080','2014','2015','2018','2026','3014','5011','5013','8081') AND EST_CD IS NULL) < 1)");
strSql.AppendLine(" AND A.PROC_CD='CAD' ) ");
strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD IN ('0002','0003','2010')) < 1 )");
//strSql.AppendLine(" AND A.SLAB_NO!='2320297902' ");
strSql.AppendLine(" AND A.CUR_INV in ('00','C7','52','ZZ','HC') ");
//strSql.AppendLine(" AND A.PROC_CD = 'CAC' ");
strSql.AppendLine(" AND A.ORD_FL = '2' ");
strSql.AppendLine(" AND A.REC_STS = '2' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
strSql.AppendLine(" AND A.WGT > 0 ");
strSql.AppendLine(" AND A.WID > 1600 ");
strSql.AppendLine(" AND A.LEN > 3900 ");
strSql.AppendLine(" AND NVL(A.PLT,'99') IN ('B1','BZ') ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD,'N') <> 'N' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND SLAB_NO NOT IN ( SELECT SLAB_NO FROM NISCO.CP_SLAB_MOVE_PLAN WHERE PRC_STS = 'A' AND TO_INV in('ZB','HB') ) ");
strSql.AppendLine(" AND not ((substr(A.LOC,1,7) in ('S7I1701','S7I1702','S7I1703','S7I1801','S7I1802','S7I1803') or substr(A.LOC,1,5) in ('S3E04','S3E05','S3E06') ) and CUR_INV='00') ");
strSql.AppendLine(" AND NVL(A.PLAN_MILL_PLT , ' ') LIKE '%C1' || '%' ");
//3.11.5.4.9 订单有低倍要求并且物料低倍等级不合格的板坯,不允许替代。
//strSql.AppendLine(" AND ( ( (SELECT COUNT(*) FROM NISCO.qp_qlty_slab_lowpower Q WHERE Q.ORD_NO =A.ORD_NO AND Q.ORD_ITEM=A.ORD_ITEM) >= 1) AND A.QUALITY_GRD = '4' AND ((SELECT COUNT(*) FROM NISCO.CP_SLAB_DELI_DET C WHERE C.SLAB_NO = A.SLAB_NO AND C.EST_CD = '0001' AND C.REASON_CD = '3010' AND C.REASON_COMMENT = '低倍不符合要求') < 1 ))");
strSql.AppendLine(" AND (select COUNT(*) from nisco.fp_slab_C3 WHERE SLAB_NO=A.SLAB_NO AND FL='True')<1");
strSql.AppendLine(" AND (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')<1");
//P_SLAB_DELI_DET表中字段EST_CD是5或者6开头是协议板。
//strSql.AppendLine(" ORDER BY A.LOC DESC, A.SLAB_NO ASC ");