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

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

import com.steering.pss.sale.order.craftDesign.dao.CraftBlDao;
import com.steering.pss.sale.order.craftDesign.dao.Msc0Dao;
import com.steering.pss.sale.order.craftDesign.model.ComMscEntity;
import com.steering.pss.sale.order.craftDesign.model.ComPscEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscEntity;

/**
 * 备料码数据初始化
 * 
 * @author Administrator
 * 
 */
public class CraftBl {
	public CraftOrdDesignMscEntity innerCraftBl(Connection con,
			CraftOrdDesignMscEntity craftOrdEntity) throws SQLException {
		CraftBlDao craftBlDao = new CraftBlDao();
		String[] specCodes = craftBlDao.getBaseSpecByDH(con,
				craftOrdEntity.getDimater(), craftOrdEntity.getHeight());
		if (specCodes != null && specCodes.length > 0) {
			craftOrdEntity.setSpecCode(specCodes[0]);
			craftOrdEntity.setSpecName(specCodes[1]);
			craftOrdEntity.setOrderSpecCode(specCodes[0]);
			craftOrdEntity.setOrderSpecDesc(specCodes[1]);
		}
		// 产品码
		ComPscEntity comPscEntity = craftBlDao.getPsc(con,
				craftOrdEntity.getProduccode(), craftOrdEntity.getStdCode(),
				craftOrdEntity.getSteelcode(), craftOrdEntity.getStdStyle());
		if (comPscEntity != null) {
			craftOrdEntity.setPsc(comPscEntity.getPsc());
			craftOrdEntity.setPscDesc(comPscEntity.getPscDesc());
		}
		// 冶金规范码
		String msc = craftBlDao.getMscByPscAndUseCode(con,
				craftOrdEntity.getPsc(), craftOrdEntity.getUseCode());
		if (!msc.equals("")) {
			Msc0Dao msc0Dao = new Msc0Dao();
			ComMscEntity mscEntity = msc0Dao.getMscInfo(con, msc);
			if (mscEntity != null) {
				craftOrdEntity.setMsc(msc);
				craftOrdEntity.setMscDesc(mscEntity.getMscDesc());
				craftOrdEntity.setMscStyle(mscEntity.getMscStyle());
				craftOrdEntity.setJudgeflag(mscEntity.getJudgeflag());
			}
		}
		craftOrdEntity.setAsselFl("0");
		craftOrdEntity.setLenUnit("米");
		craftOrdEntity.setFinalUser(craftOrdEntity.getUseCode());
		craftOrdEntity.setFinalUserDesc(craftOrdEntity.getUseDesc());
		craftOrdEntity.setOrdPk(craftOrdEntity.getOrdLnPk());
		craftOrdEntity.setOrderSeq("1");
		
		return craftOrdEntity;
	}
}
