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

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

import com.steering.pss.sale.order.bomGeneration.daoImp.BomCheckDaoImp;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomFactoryDao;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomJGDaoImp;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomSaveDaoImp;
import com.steering.pss.sale.order.bomGeneration.model.BaseMaterialEntity;
import com.steering.pss.sale.order.bomGeneration.model.DesignBomEntity;
import com.steering.pss.sale.order.bomGeneration.model.MscJgEntity;
import com.steering.pss.sale.order.bomGeneration.serverImp.BomJGImp;

/**
 * 接箍码物料
 * 
 * @author Administrator
 * 
 */
public class BomJG implements BomJGImp {
	private static BomJGDaoImp bomJGDaoImp = BomFactoryDao.getBomJGDaoImp();
	private static BomSaveDaoImp bomSaveDaoImp = BomFactoryDao
			.getBomSaveDaoImp();
	private static BomCheckDaoImp bomCheckDaoImp = BomFactoryDao
			.getBomCheckDaoImp();

	public DesignBomEntity generationJG(Connection con, String jgCode)
			throws SQLException {
		// 先验证是否存在接箍的BOM,如果存在则不生成
		DesignBomEntity bomJGNo = bomJGDaoImp.getJGBom(con, jgCode);
		if (bomJGNo != null) {
			return bomJGNo;
		}
		// 查询接箍码基础信息
		MscJgEntity mscJg = bomJGDaoImp.getJGInfo(con, jgCode);
		// 形成接箍的成品物料描述(品种、规格、标准类别 钢级、扣型)
		String prefix = "A"
				+ BomMaterial.generationPrefix(con, mscJg.getProduccode())
				+ "接箍" + "," + mscJg.getSpecJgDesc().trim() + ","
				+ mscJg.getStdStyleDesc().trim() + ","
				+ mscJg.getSteelcodeJgDesc().trim() + ","
				+ mscJg.getModelDesc().trim();
		DesignBomEntity bomJG = new DesignBomEntity();
		bomJG.setMaterialDesc(prefix);
		// 编码就是接箍码
		bomJG.setMaterialNo(mscJg.getCodeJg());
		bomJG.setBomTyp("D");
		// 形成接箍BOM
		bomJGDaoImp.saveJGBom(con, bomJG);
		bomJGNo = bomJGDaoImp.getJGBom(con, jgCode);
		// 基础数据-物料编码(接箍)
		if (bomCheckDaoImp.checkBaseMaterial(con, bomJG.getMaterialNo()) == 0) {
			BaseMaterialEntity baseMaterial = BomMaterial.generationJGBase(con,
					mscJg, bomJG.getMaterialNo(), bomJG.getMaterialDesc());
			bomSaveDaoImp.saveBaseMaterial(con, baseMaterial);
		}
		return bomJGNo;
	}

}
