", 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) or CSDD.SLAB_NO=(select substr(MOTHER_SLAB,1,10) from nisco.fp_slab where 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(" FROM NISCO.CP_SLAB_DELI_DET ");
strSql.AppendLine(" WHERE SLAB_NO = A.MOTHER_SLAB ");
strSql.AppendLine(" AND EST_CD IS NOT NULL) ");
strSql.AppendLine(" ELSE '' ");
strSql.AppendLine(" END ) 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 substr(MOTHER_SLAB,1,10) 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 ");
//测试数据
// strSql.AppendLine(" AND SLAB_NO like ('2430307505%') ");
// strSql.AppendLine(" AND SLAB_NO in ('2311219005','2311219709','2410008808','2331057509','2311143003','2311143004','2311143005','2311143006','2321109301','2311059508','2311137502','2311172402','2430010002','2430010104') ");
//strSql.AppendLine(" AND A.CUR_INV in ( 'H2','52','00','ZZ','HB'" +
// ",'C7'" +
// ") ");
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('2015','5019','1080','2018','2025','2024') 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 = '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 NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD, 'N') NOT IN('N','E') ");
strSql.AppendLine(" AND LEAST(A.WID, A.LEN) >= 1600 ");
strSql.AppendLine(" AND GREATEST(A.WID, A.LEN) >= 2500 ");
strSql.AppendLine(" AND A.THK >= 120 ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ");
strSql.AppendLine(" AND ( (NVL(A.PLAN_MILL_PLT,'N') LIKE '%C2' || '%') OR ((NVL(A.PLAN_MILL_PLT,'N') LIKE 'C1'|| '%') AND (A.CUR_INV ='HB' OR A.THK>230 OR A.LEN<3900) ) or (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')>0 ) ");
//strSql.AppendLine(" AND NOT (A.THK>=200 AND THK<=320 AND A.WGT <12 ) ");
strSql.AppendLine(" AND NOT (A.THK>=360 AND A.LEN <2500 ) ");
strSql.AppendLine(" AND NOT (A.THK<160 AND A.LEN >12000 ) ");
strSql.AppendLine(" AND not ( (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')<1 and (select COUNT(*) from nisco.fp_slab_C3 WHERE SLAB_NO=A.SLAB_NO AND FL='True')>0 )");
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') ");
// 2.2.4.4.4.3.5.人工锁定的板 坯,不允许替代
//strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 )");
//2.2.4.4.4.3.6.订单有低倍要求并且物料低倍等级不合格的板坯,不允许替代。
/// 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 ))");
/// 2.2.4.4.4.3.8.板坯已有往板卷0库或宽厚板库的转库计划,不允许替代。
/// strSql.AppendLine("and (SELECT COUNT(*) FROM NISCO.CP_SLAB_MOVE_PLAN M WHERE M.SLAB_NO = A.SLAB_NO AND M.TO_INV IN ('00','ZB') AND M.PRC_STS = 'A')=0");
strSql.AppendLine(" ORDER BY A.LOC DESC, A.SLAB_NO ASC ");
strSql.AppendLine(" and boi.ORD_STS IN('E', 'D') ");
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) or boi.ord_no in('OMH23040079','OMH23040083','EMH23060012') or boi.ord_no like 'OM6%' )) ");
strSql.AppendLine("AND boi.CFM_MILL_PLT='C2'");
//strSql.AppendLine(" boi.ORD_NO || '-' || boi.ORD_ITEM in ('OMZ23030001-003')");
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(",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_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) or boi.ord_no in('OMH23040079','OMH23040083') or boi.ord_no like 'OM6%' )) ");
strSql.AppendLine("AND boi.CFM_MILL_PLT='C2'");
strSql.AppendLine("AND (boi.CUST_DEL_TO_DATE>= to_char(sysdate-183,'YYYYMMDD') OR BOI.ORD_NO LIKE 'OMA%' )");
strSql.AppendLine("AND boi.STDSPEC NOT LIKE '%-KP'");
strSql.AppendLine(" and (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("AND A.BLOCK_SEQ >= '01' ");
strSql.AppendLine("AND A.SEQ >= '01' and A.ord_fl='1' ");
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) or boi.ord_no in('OMH23040079','OMH23040083') or boi.ord_no like 'OM6%')) ");
strSql.AppendLine("AND boi.CFM_MILL_PLT='C2'");
//strSql.AppendLine(" boi.ORD_NO || '-' || boi.ORD_ITEM in ('OMZ23030001-003')");
strSql.AppendLine(") ");
strSql.AppendLine(" AND QQC.KND IN ('1','2') ) T WHERE T.rk = 1 ");
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) or boi.ord_no in('OMH23040079','OMH23040083') or boi.ord_no like 'OM6%' )) ");
//strSql.AppendLine(" boi.ORD_NO || '-' || boi.ORD_ITEM in ('EM523010005-009')");
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.CUR_INV IN ( 'H2','52','00','ZZ','HB','C7') ");
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.ORD_FL = '2' ");
strSql.AppendLine(" AND A.REC_STS = '2' ");
strSql.AppendLine(" AND NVL(A.OUT_PLT_CD,'9') <> '0' ");
strSql.AppendLine(" AND NOT (A.THK>=360 AND A.LEN <2500 ) ");
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 slab_no='2330896106' ");
// 2.2.4.4.4.3.5.人工锁定的板 坯,不允许替代
//strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 )");
strSql.AppendLine(" AND A.WGT > 0 ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
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,'N') LIKE '%C2' || '%') OR ((NVL(A.PLAN_MILL_PLT,'N') LIKE 'C1'|| '%') AND (A.CUR_INV ='HB' OR A.THK>230 OR A.LEN<3900) ) or (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')>0 ) ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ) ");
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 SLAB_NO in ('2320231308')");
//strSql.AppendLine(" AND A.CUR_INV IN ('H2','52', '00','ZZ','HB','C7') ");
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('2015','5019','1080','2018','2025','2024') 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.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 NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
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 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,'N') LIKE '%C2' || '%') OR ((NVL(A.PLAN_MILL_PLT,'N') LIKE 'C1'|| '%') AND (A.CUR_INV ='HB' OR A.THK>230 OR A.LEN<3900) ) or (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')>0 ) ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ");
strSql.AppendLine(" SELECT* FROM NISCO.FP_CAD_INF WHERE substr(SLAB_NO, 1, 8) IN( ");
strSql.AppendLine("SELECT ");
strSql.AppendLine("substr(SLAB_NO, 1, 8) ");
strSql.AppendLine("FROM NISCO.FP_SLAB A ");
strSql.AppendLine("WHERE 1 = 1 ");
//strSql.AppendLine(" AND A.CUR_INV in ('H2','52', '00','ZZ','HB','C7') ");
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('2015','5019','1080','2018','2025','2024') 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.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 NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD, 'N') NOT IN('N','E') ");
strSql.AppendLine(" AND LEAST(A.WID, A.LEN) >= 1600 ");
strSql.AppendLine(" AND GREATEST(A.WID, A.LEN) >= 2500 ");
strSql.AppendLine(" AND A.THK >= 120 ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ");
strSql.AppendLine(" AND ( (NVL(A.PLAN_MILL_PLT,'N') LIKE '%C2' || '%') OR ((NVL(A.PLAN_MILL_PLT,'N') LIKE 'C1'|| '%') AND (A.CUR_INV ='HB' OR A.THK>230 OR A.LEN<3900)) or (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')>0 ) ");
//strSql.AppendLine(" AND NOT (A.THK>=200 AND THK<=320 AND A.WGT <12 ) ");
strSql.AppendLine(" AND NOT (A.THK>=360 AND A.LEN <2500 ) ");
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') ) ");
// 2.2.4.4.4.3.5.人工锁定的板 坯,不允许替代
//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 ( 'ZB','00','ZZ','HB','C7') ");
// 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('2015','5019','1080','2018','2025','2024') 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.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 NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
// strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD, 'N') NOT IN('N','E') ");
// strSql.AppendLine(" AND LEAST(A.WID, A.LEN) >= 1600 ");
// strSql.AppendLine(" AND GREATEST(A.WID, A.LEN) >= 2500 ");
// strSql.AppendLine(" AND NOT (A.THK>=360 AND A.LEN <2500 ) ");
// strSql.AppendLine(" AND not (substr(A.LOC,1,7) in ('S7I1701','S7I1702','S7I1703','S7I1801','S7I1802','S7I1803') and CUR_INV='00') ");
// strSql.AppendLine(" AND((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 )");
// strSql.AppendLine(" AND A.THK >= 120 ");
// strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ");
// strSql.AppendLine(" AND NVL(A.PLAN_MILL_PLT,'N') LIKE 'C2' || '%' ) ");
// strSql.AppendLine(" GROUP BY fsd.ACT_SLAB_NO ");
strSql.AppendLine("SELECT fsd.SLAB_NO FROM NISCO.EP_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.CUR_INV in ('H2','52','00','ZZ','HB','C7') ");
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('2015','5019','1080','2018','2025','2024') 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.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 NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD, 'N') NOT IN('N','E') ");
strSql.AppendLine(" AND LEAST(A.WID, A.LEN) >= 1600 ");
strSql.AppendLine(" AND GREATEST(A.WID, A.LEN) >= 2500 ");
strSql.AppendLine(" AND NOT (A.THK>=360 AND A.LEN <2500 ) ");
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((SELECT COUNT(*) FROM NISCO.FB_SLAB_001 R WHERE R.SLAB_NO = A.SLAB_NO) < 1 )");
strSql.AppendLine(" AND A.THK >= 120 ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ");
strSql.AppendLine(" AND ( (NVL(A.PLAN_MILL_PLT,'N') LIKE '%C2' || '%') OR ((NVL(A.PLAN_MILL_PLT,'N') LIKE 'C1'|| '%') AND (A.CUR_INV ='HB' OR A.THK>230 OR A.LEN<3900) ) or (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')>0 ) ");
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' 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('2015','5019','1080','2018','2025','2024') 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 = '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 NVL(A.PLAN_SLAB_CUT_FL,'N') = 'N' ");
strSql.AppendLine(" AND NVL(A.QUALITY_UPD_GRD, 'N') NOT IN('N','E') ");
strSql.AppendLine(" AND LEAST(A.WID, A.LEN) >= 1600 ");
strSql.AppendLine(" AND GREATEST(A.WID, A.LEN) >= 2500 ");
strSql.AppendLine(" AND A.THK >= 120 ");
strSql.AppendLine(" AND NVL(A.PLAN_SLAB_MERGE_FL,'N') = 'N' ");
strSql.AppendLine(" AND ( (NVL(A.PLAN_MILL_PLT,'N') LIKE '%C2' || '%') OR ((NVL(A.PLAN_MILL_PLT,'N') LIKE 'C1'|| '%') AND (A.CUR_INV ='HB' OR A.THK>230 OR A.LEN<3900) ) or (select COUNT(*) from nisco.fp_slab_C2 WHERE SLAB_NO=A.SLAB_NO AND FL='1')>0 ) ");
//strSql.AppendLine(" AND NOT (A.THK>=200 AND THK<=320 AND A.WGT <12 ) ");
strSql.AppendLine(" AND NOT (A.THK>=360 AND A.LEN <2500 ) ");
strSql.AppendLine(" AND NOT (A.THK<160 AND A.LEN >12000 ) ");
strSql.AppendLine(" AND (select COUNT(*) from nisco.fp_slab_C3 WHERE SLAB_NO=A.SLAB_NO AND FL='True')<1");
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') ");
//P_SLAB_DELI_DET表中字段EST_CD是5或者6开头是协议板。
//strSql.AppendLine(" ORDER BY A.LOC DESC, A.SLAB_NO ASC ");