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

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

import com.steering.pss.sale.order.bomGeneration.daoImp.BomQueryDaoImp;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomFactoryDao;
import com.steering.pss.sale.order.bomGeneration.model.BaseMaterialEntity;
import com.steering.pss.sale.order.bomGeneration.model.BomEntity;
import com.steering.pss.sale.order.bomGeneration.model.MscJgEntity;
import com.steering.pss.sale.order.model.BaseProductEntity;

/**
 * 成品物料编码类
 * 
 * @author Administrator
 * 
 */
public class BomMaterial {
	/**
	 * 形成成品最终物料编码
	 * 
	 * @return String[]
	 * @throws SQLException
	 */
	public static String[] formEndMaterial(BomEntity bomEntity, Connection con)
			throws SQLException {
		String[] material = new String[2];
		String materialNo = "A";
		String materialDesc = "A";
		// 产品大类
		String prefix = BomMaterial.generationPrefix(con,
				bomEntity.getProduccode());
		materialNo += prefix;
		materialDesc += prefix;
		// 品名
		materialNo += bomEntity.getProduccode().trim();
		materialDesc += bomEntity.getProducname().trim();
		// 规格
		materialNo = materialNo + bomEntity.getSpecCode().trim();
		materialDesc = materialDesc + "," + bomEntity.getSpecName().trim();
		// 标准类别
		materialNo = materialNo + bomEntity.getStdStyle().trim();
		materialDesc = materialDesc + "," + bomEntity.getStdStyleDesc().trim();
		// 钢级
		materialNo = materialNo + bomEntity.getSteelcode().trim();
		materialDesc = materialDesc + "," + bomEntity.getSteelname().trim();
		// 扣型
		materialNo = materialNo + bomEntity.getModelCode().trim();
		materialDesc = materialDesc + "," + bomEntity.getModelDesc().trim();
		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);
		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;
	}

	/**
	 * 生成基础物料编码(暂时针对成品)
	 * 
	 * @param con
	 *            连接字符串
	 * @param bomEntity
	 *            质量设计行
	 * @param materialNo
	 *            成品物料编码
	 * @param materialDesc
	 *            描述
	 * @return BaseMaterialEntity
	 * @throws SQLException
	 */
	public static BaseMaterialEntity generBaseMater(Connection con,
			BomEntity bomEntity, String materialNo, String materialDesc)
			throws SQLException {
		BaseMaterialEntity baseMaterial = new BaseMaterialEntity();
		BomQueryDaoImp bomQueryDaoImp = BomFactoryDao.getBomQueryDaoImp();
		BaseProductEntity proDuct = bomQueryDaoImp.getProductCode(con,
				bomEntity.getProduccode());
		baseMaterial.setMaterialNo(materialNo);
		baseMaterial.setMaterialDesc(materialDesc);
		baseMaterial.setDimater(bomEntity.getDimater());
		baseMaterial.setHeight(bomEntity.getHeight());
		baseMaterial.setFirstPrdc("1");
		baseMaterial.setSteelcode(bomEntity.getSteelcode());
		baseMaterial.setSteelname(bomEntity.getSteelname());
		baseMaterial.setModelCode(bomEntity.getModelCode());
		baseMaterial.setModelDesc(bomEntity.getModelDesc());
		baseMaterial.setOutsrcAllow("1");
		baseMaterial.setProduccode(bomEntity.getProduccode());
		baseMaterial.setProducname(bomEntity.getProducname());
		baseMaterial.setProducJx(proDuct.getProducJx());
		baseMaterial.setProducEng(proDuct.getProducEng());
		baseMaterial.setStdStyle(bomEntity.getStdStyle());
		baseMaterial.setStdStyleDesc(bomEntity.getStdStyleDesc());
		baseMaterial.setSpecCode(bomEntity.getSpecCode());
		baseMaterial.setSpecName(bomEntity.getSpecName());
		return baseMaterial;
	}

	/**
	 * 接箍码
	 * 
	 * @param con
	 * @param mscJg
	 * @param materialNo
	 * @param materialDesc
	 * @return
	 * @throws SQLException
	 */
	public static BaseMaterialEntity generationJGBase(Connection con,
			MscJgEntity mscJg, String materialNo, String materialDesc)
			throws SQLException {
		BomQueryDaoImp bomQueryDaoImp = BomFactoryDao.getBomQueryDaoImp();
		BaseMaterialEntity jgBase = new BaseMaterialEntity();
		// 查询品种大类
		BaseProductEntity proDuct = bomQueryDaoImp.getProductCode(con,
				mscJg.getProduccode());
		jgBase.setMaterialNo(materialNo);
		jgBase.setMaterialDesc(materialDesc);
		jgBase.setDimater(mscJg.getMinD());
		jgBase.setHeight(mscJg.getMinH());
		jgBase.setFirstPrdc("1");
		jgBase.setSteelcode(mscJg.getSteelcodeJg());
		jgBase.setSteelname(mscJg.getSteelcodeJgDesc());
		jgBase.setModelCode(mscJg.getModelCode());
		jgBase.setModelDesc(mscJg.getModelDesc());
		jgBase.setOutsrcAllow("1");
		jgBase.setProduccode(mscJg.getProduccode());
		jgBase.setProducname(mscJg.getProducname());
		jgBase.setProducJx(proDuct.getProducJx());
		jgBase.setProducEng(proDuct.getProducEng());
		jgBase.setStdStyle(mscJg.getStdStyle());
		jgBase.setStdStyleDesc(mscJg.getStdStyleDesc());
		jgBase.setSpecCode(mscJg.getSpecJg());
		jgBase.setSpecName(mscJg.getSpecJgDesc());
		return jgBase;
	}

}
