package com.steering.pss.sale.order.craftDesign.server;

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

import com.steering.pss.sale.order.craftDesign.dao.MscBLDao;
import com.steering.pss.sale.order.craftDesign.dao.MscJGDao;
import com.steering.pss.sale.order.craftDesign.main.CraftDesignMain;

public class MscBL {
	/**
	 * 备料码
	 * 
	 * @param con
	 * @param msc
	 * @param dimater
	 *            外径
	 * @param height
	 *            壁厚
	 * @param steelCode
	 *            钢级
	 * @param steelName
	 * @param specCode
	 *            规格
	 * @param specName
	 * @param specStyle
	 *            标准类别
	 * @param designKey
	 * @return
	 * @throws SQLException
	 */
	public Object[] checkBL(Connection con, String msc, String dimater,
			String height, String steelCode, String steelName, String specCode,
			String specName, String specStyle, String designKey,
			String userName, String designKeyFlag, String flag,
			String operateType, String designStyle, String modelCode, 
			String modelDesc) throws SQLException {
		MscBLDao mscBLDaoImp = new MscBLDao();
		MscJGDao mscJGDaoImp = new MscJGDao();
		// 钢级暂不考虑
		Object[] blInfo = new Object[2];
		String errMessage = "";
		List<String[]> codeBLs = null;
		if (specStyle.equals("C")) {
			codeBLs = mscBLDaoImp.getCodeBLBySpecCode(con, msc, steelCode,
					specCode, modelCode);
			if (codeBLs == null || codeBLs.size() == 0) {
				errMessage = "没有找到符合产品规格(" + specName + ") 扣型:"+ modelDesc + "的备料码分组号， 请维护分组号适用条件!";
				blInfo[0] = errMessage;
				return blInfo;
			}
		} else {
			codeBLs = mscBLDaoImp.getCodeBLByDAndH(con, msc, steelCode,
					dimater, height, modelCode);
			if (codeBLs == null || codeBLs.size() == 0) {
				errMessage = "没有找到符合(外径:" + dimater + "、壁厚:" + height
						+ ") 扣型:"+ modelDesc + "的备料码分组号，请维护分组号适用条件!";
				blInfo[0] = errMessage;
				return blInfo;
			}
		}
		List<String[]> list = new ArrayList<String[]>();
		for (String[] bl : codeBLs) {
			String blCode = bl[0];
			String num = bl[1];
			String[] blInfomation = mscJGDaoImp.getJGBLInfo(con, blCode);
			if (blInfomation == null || blInfomation[2].equals("2")) {
				CraftDesignMain craftDesignMain = new CraftDesignMain();
				craftDesignMain.craftDesign(blCode, userName, designKeyFlag,
						"1", operateType, designStyle);
				
			}
			blInfomation = mscJGDaoImp.getJGBLInfo(con, blCode);
			if (!blInfomation[2].equals("1")) {
				errMessage = "备料码(" + blCode + " )未通过工艺评审!";
				blInfo[0] = errMessage;
				return blInfo;
			}
			String designKeyBl = blInfomation[1];
			String[] str = new String[4];
			str[0] = designKey;
			str[1] = blCode;
			str[2] = num;
			str[3] = designKeyBl;
			list.add(str);
		}
		errMessage = "备料码验证通过";
		blInfo[0] = errMessage;
		blInfo[1] = list;
		return blInfo;
	}
}
