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

import com.steering.pss.sale.order.ReviewForm.CoreOrderReviewTechnology;
import com.steering.pss.sale.order.craftDesign.dao.CraftStatusDao;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStsTklgLstEntity;

import java.sql.Connection;
import java.sql.SQLException;
import java.text.DecimalFormat;

/**
 * 初始化状态
 * 
 * @author Administrator
 * 
 */
public class CraftStatus {
	public void initStatus(Connection con, String designKey, String ordLnPk,
						   String psc, String msc, String finalUser, String useCode,
						   String userName, String operateType, String designStyle, String[] saleInfo) throws SQLException {
		CraftStatusDao craftStatusDao = new CraftStatusDao();
		String[] listItems = new String[] { "MSC(0)", "成分标准", "理化标准", "公差标准",
				"探伤标准", "水压标准", "加工标准", "MSC(n)", "接箍", "接箍制程", "备料", "附件图片", "制程",
				"钢种", "镦拔扩", "内控标准", "适用产线", "成分偏差标准", "在线机探盲区切长", "投入/产出物料",
				"试样码", "首日检" };
		// 增加状态明细记录
		CraftOrdDesignStsTklgLstEntity status = null;
		for (int i = 0; i < listItems.length; i++) {
			status = new CraftOrdDesignStsTklgLstEntity();
			status.setDesginKey(designKey);
			status.setOrdLnPk(ordLnPk);
			status.setLstItem(listItems[i]);
			status.setUseCode(useCode);
			status.setPsc(psc);
			status.setMsc("");
			status.setDesignSts("W");
			status.setDesignStsRs("");
			status.setDesignStsDesc("");
			status.setFinalUser(finalUser);
			status.setDesignObjKey("");
			status.setUnitCode("002001001003");
			status.setUnitDesc("工艺科");
			if (saleInfo != null && saleInfo.length > 0 && "100105".equals(saleInfo[0])) {	// 天淮合同
				status.setUnitCode("002023005003");
				status.setUnitDesc("工艺科");
			}
			status.setCreateName(userName);
			DecimalFormat df = new DecimalFormat("000");
			String index = df.format(i + 1);
			status.setSeqIndex(index);
			craftStatusDao.addCraftOrdDesignStsTklgLst(con, status);
		}
		craftStatusDao.addCraftOrdDesignStsTklg(con, designKey, ordLnPk,
				userName);
		CoreOrderReviewTechnology coreOrderReviewTechnology = new CoreOrderReviewTechnology();
		coreOrderReviewTechnology.insrtOrUpdtCrafte(ordLnPk, designKey,
				userName, operateType, designStyle, con);
	}
}
