package com.steering.pss.sale.order.qualityDesign.server.iserver;

import java.sql.Connection;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import com.steering.pss.sale.order.qualityDesign.Dao.factory.FactoryDao;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.MscBLDaoImp;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.MscJGDaoImp;
import com.steering.pss.sale.order.qualityDesign.server.imp.MscBLImp;

/**
 * 验证备料码业务类
 * 
 * @author Administrator
 * 
 */
public class IMscBL implements MscBLImp {

	public Object[] checkBL(Connection con, String msc, String dimater,
			String height, String steelCode, String steelName, String specCode,
			String specName, String specStyle, String designKey, String modelCode,
			String modelDesc)
			throws SQLException {
		MscBLDaoImp mscBLDaoImp = FactoryDao.getMscBLDaoImp();
		MscJGDaoImp mscJGDaoImp = FactoryDao.getMscJGDaoImp();
		// 钢级暂不考虑
		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){
				errMessage = "备料码:" + blCode + "为无效的备料码，请选择其它备料码！";
				blInfo[0] = errMessage;
				return blInfo;
			}
			String designKeyBl = blInfomation[0];
			String blStatus = blInfomation[1];
			if (!blStatus.equals("2")) {
				errMessage = "备料码:" + blCode + "未通过技术评审,请选评审备料码!";
				blInfo[0] = errMessage;
				return blInfo;
			}
			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;

	}

}
