package com.steering.pss.ydm.base;

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

import com.steering.pss.sale.order.bomGeneration.daoImp.BomFactoryDao;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomQueryDaoImp;
import com.steering.pss.sale.order.bomGeneration.server.BomMaterial;
import com.steering.pss.sale.order.model.BaseProductEntity;

public class FrmEndMaterial {
	/**
	 * 形成成品最终物料编码
	 * 
	 * @return String[]
	 * @throws SQLException
	 */
	public static String[] formEndMaterial(ArrayList<String> list, Connection con)
			throws SQLException {
		String[] material = new String[2];
		String materialNo = "A";
		String materialDesc = "A";
		// 产品大类
		String prefix = FrmEndMaterial.generationPrefix(con,
				list.get(0));
		if(prefix==null)
		{
			return null;
		}
		materialNo += prefix;
		materialDesc += prefix;
		// 品名
		materialNo += list.get(0);
		materialDesc += list.get(1);
		// 规格
		materialNo = materialNo + list.get(2);
		materialDesc = materialDesc + "," + list.get(3);
		// 标准类别
		if (!list.get(4).equals("")) {
			materialNo = materialNo + list.get(4);
			materialDesc = materialDesc + "," + list.get(5)
					+ " ";
		}
		// 钢级
		materialNo = materialNo + list.get(6);
		materialDesc = materialDesc + "," + list.get(7);
		// 扣型
		materialNo = materialNo + list.get(8);
		materialDesc = materialDesc + "," + list.get(9);
		material[0] = materialNo;
		material[1] = materialDesc;
		return material;
	}

	/**
	 * 形成物料编码前缀（针对产品大类）
	 * 
	 * @param con
	 *            连接字符串
	 * @param proDucCode
	 *            品名代码
	 * @return
	 * @throws SQLException
	 */
	public static String generationPrefix(Connection con, String proDucCode)
			throws SQLException {
		BomQueryDaoImp bomQueryDaoImp = BomFactoryDao.getBomQueryDaoImp();
		BaseProductEntity baseProductEntity = bomQueryDaoImp.getProductCode(
				con, proDucCode);
		if(baseProductEntity ==null)
		{
		     return null;	
		}
		String producHead = baseProductEntity.getProducHead();
		String second = "";
		if (producHead.equals("404901")) {
			// 热轧无缝管
			second = "W";
		} else if (producHead.equals("404902")) {
			// 冷轧（拔）无缝管
			second = "L";
		} else if (producHead.equals("404903")) {
			// 焊管
			second = "H";
		} else if (producHead.equals("404904")) {
			// 机加工
			second = "J";
		} else if (producHead.equals("404905")) {
			// 铸坯
			second = "A";
		} else if (producHead.equals("404906")) {
			// 锻坯
			second = "C";
		} else if (producHead.equals("404907")) {
			// 轧坯
			second = "B";
		} else {
			// 钢锭
			second = "D";
		}
		return second;
	}

}
