package com.steering.pss.sale.order.bomGeneration;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.steering.comm.db.DBCommon;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SC01.CoreConstantData;

public class FrmGreaBom extends DBCommon {

	public CoreReturnObject greaBom(ArrayList<String> designKeys) {
		CoreReturnObject core = new CoreReturnObject();
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			for (String designKey : designKeys) {
				BOMGeneration.generationBomMain(con, designKey, "2", "1");
			}
			core.setV_errMsg("生成成功");
			con.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.toString());
			e.printStackTrace();
		} finally {
			if (con != null)
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
		return core;
	}

	public CoreReturnObject queryOrderNo(String ordNo) {
		List<String> params = new ArrayList<String>();
		// String sql =
		// "SELECT T.ORD_LN_PK, T1.DESGIN_KEY, T2.ORDER_NO, T1.ORDER_SEQ FROM SLM_ORDER_LINE T, SLM_ORD_DESIGN_MSC T1, SLM_ORDER_HEAD T2 WHERE T.ORD_LN_PK = T1.ORD_LN_PK"
		// +
		// " AND T.ORD_PK = T2.ORD_PK   AND T.VALIDFLAG = '1'   AND T1.VALIDFLAG = '1'   AND T.ORDER_LN_STATUS >= '12020202'   AND T2.ORDER_NO || '&' LIKE '%' || ? || '%' ORDER BY T2.ORDER_NO, T.ORDER_SEQ ";
		String sql = "SELECT T2.DESGIN_KEY, T2.ORD_LN_PK, T3.ORDER_NO, T2.ORDER_SEQ "
				+ "  FROM CRAFT_ORD_DESIGN T1, CRAFT_ORD_DESIGN_MSC T2, SLM_ORDER_HEAD T3, CRAFT_ORD_DESIGN_STS_TKLG T4"
				+ "  WHERE T2.DESGIN_KEY = T1.DESGIN_KEY  AND T1.DESGIN_KEY = T4.DESGIN_KEY  AND T4.DESIGN_STS = 'S'"
				+ "  AND T2.ORD_PK = T3.ORD_PK(+)  AND T1.VALIDFLAG = '1'";
		if (ordNo.length() > 0) {
			params.add(ordNo);
			sql += " AND T3.ORDER_NO=? ";
		}
		sql += "  ORDER BY T3.ORDER_NO,T2.ORDER_SEQ,T2.ORD_LN_PK";
		return this.getData(sql, params.toArray());
	}

}
