package com.steering.pss.sale.order.qualityDesign;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import net.sf.json.JSONObject;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import com.steering.pss.qcm.model.BaseStdAlphaEntity;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.sale.order.CoreOrderSpecialInfo;
import com.steering.pss.sale.order.model.BaseStdRCustEntity;
import com.steering.pss.sale.order.model.ComBaseProductEntity;
import com.steering.pss.sale.order.model.ComBaseStdEntity;
import com.steering.pss.sale.order.model.ComMscEntity;
import com.steering.pss.sale.order.model.ComPscEntity;
import com.steering.pss.sale.order.model.ComPscRMscEntity;
import com.steering.pss.sale.order.model.CreateUserAndMscParms;
import com.steering.pss.sale.order.model.SlmCustAlphaEntity;
import com.steering.pss.sale.order.model.SlmCustChemObject;
import com.steering.pss.sale.order.model.SlmCustDetectionObject;
import com.steering.pss.sale.order.model.SlmCustPhyObject;
import com.steering.pss.sale.order.model.SlmCustProcessEntity;
import com.steering.pss.sale.order.model.SlmCustSpecObject;
import com.steering.pss.sale.order.model.SlmCustWaterObject;
import com.steering.pss.sale.order.model.SlmOrdDesignDeptEntity;

/**
 * 质量冶金规范处理类
 * @author Administrator
 *
 */
public class QualityMsc extends DBCommon{
	private String maxMsc = "";
	private ComBaseStdEntity stdEntity;
	private String strMaxAlphaCode = "";
	private String alphaName = "";
	private ComPscEntity pscEntity;
	private CreateUserAndMscParms parms;
	private ComBaseProductEntity productEntity;
	private String modeDesc = "";
	private String cic = "";
	private String pic = "";
	private String dic = "";
	private String sic = "";
	private String wic = "";
	private String gic = "";
	
	@SuppressWarnings("unchecked")
	public CoreReturnObject createUserAndMsc(String strJSON, ArrayList<Object> noSameData){
		CreateUserAndMscParms parms = EntityTool.getEntityByJSONStr(strJSON, CreateUserAndMscParms.class);
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try{
			con.setAutoCommit(false);
			this.parms = parms;
			int custChemCnt = getSaleCustChemCnt(con);
			String msc = noSameData.get(1).toString();
			String cic = noSameData.get(2).toString();
			String pic = noSameData.get(3).toString();
			String sic = noSameData.get(4).toString();
			String dic = noSameData.get(5).toString();
			String wic = noSameData.get(6).toString();
			String gic = noSameData.get(7).toString();
			ArrayList<Object> insrtChemData = (ArrayList<Object>)noSameData.get(8);
			ArrayList<Object> insrtPhyData = (ArrayList<Object>)noSameData.get(9);
			ArrayList<Object> insrtDetectionData = (ArrayList<Object>)noSameData.get(11);
			ArrayList<Object> insrtSpecData = (ArrayList<Object>)noSameData.get(10);
			ArrayList<Object> insrtWaterData = (ArrayList<Object>)noSameData.get(12);
			ArrayList<Object> insrtProcessData = (ArrayList<Object>)noSameData.get(13);
			int flag = Integer.parseInt(noSameData.get(14).toString());
			int noSameCnt = insrtChemData.size() + insrtPhyData.size() + insrtDetectionData.size() + insrtSpecData.size()
					+ insrtWaterData.size() + insrtProcessData.size();
//			SlmCustAlphaEntity custAlpha = getCustAlphaEntity(con);
//			if(custAlpha.getMsc().equals("") == false && custAlpha.getCustAlphaSts().equals("S")){
//				ComMscEntity mscEntity = getMscEntity(con, custAlpha.getMsc());
//				BaseStdAlphaEntity bseStdAlphaEntity = getBseStdAlphaEntity(con, custAlpha.getMsc());
//				BaseStdRCustEntity bseStdRCustEntity = getBseStdRCustEntity(con, bseStdAlphaEntity.getAlphaCode(), parms.getUser());
//				if(bseStdRCustEntity == null){
//					insertBseStdRCust(con, bseStdAlphaEntity);
//				}
//				String[] strs = new String[]{custAlpha.getMsc(), mscEntity.getMscDesc(), mscEntity.getUseCode(), mscEntity.getUseDesc(),
//						mscEntity.getMscStyle(), cic, pic, dic, sic, wic, gic};
//				cro.setResult(strs);
//				return cro;
//			}
			stdEntity = getStdEntity(con);
			strMaxAlphaCode = getMaxAlphaCode(con);
			//alphaName = parms.getReviewNumber() + "+" + getUserName(con);
			alphaName = parms.getReviewNumber();
			if(flag != 0){
				maxMsc = msc;
			}
			createUser(noSameCnt, con);
			modeDesc = getModeDesc(con);
			pscEntity = getPscEntity(con);
			productEntity = getProductEntity(con, parms);
			if(flag == 0){
				createMsc(con);
				createMscItem(con);
			}else{
				setPscRMscCustAlpaNo(con, maxMsc, parms.getCustAlphaNo());
			}
			
			if(custChemCnt > 0){
				
				if(cic.equals("")){
					createMscCic(con);
				}else{
					this.cic = cic;
				}
				createMscChem(cic, insrtChemData, con);
				setModelToChem(con);
			}
			int custPhyCnt = getSaleCustPhyCnt(con);
			if(custPhyCnt > 0){
				if(pic.equals("")){
					createMscPic(con);
				}else{
					this.pic = pic;
				}
				createMscPhy(pic, insrtPhyData, con);
				setModelToPhy(con);
			}
			int custDetectionCnt = getSaleCustDetectionCnt(con);
			if(custDetectionCnt > 0){
				
				if(dic.equals("")){
					createMscDic(con);
				}else{
					this.dic = dic;
				}
				createMsDetection(dic, insrtDetectionData, con);
				setModelToDetection(con);
			}
			int custSpecCnt = getSaleCustSpecCnt(con);
			if(custSpecCnt > 0){
				if(sic.equals("")){
					createMscSic(con);
				}else{
					this.sic = sic;
				}
				createMscSpec(sic, insrtSpecData, con);
				setModelToSpec(con);
			}
			int custWaterCnt = getSaleCustWaterCnt(con);
			if(custWaterCnt > 0){
				if(wic.equals("")){
					createMscWic(con);
					
				}else{
					this.wic = wic;
				}
				createMscWater(wic, insrtWaterData, con);
				//创建扣型
				setModelToWater(con);
			}
			int custProcessCnt = getSaleCustProcessCnt(con);
			if(custProcessCnt > 0){
				if(gic.equals("")){
					createMscGic(con);
				}else{
					this.gic = gic;
				}
				createMscProcess(gic, insrtProcessData, con);
				setModelToProcess(con);
			}
			
			updateCustAlphaState(con);
			
			con.commit();
		}
		catch(Exception e){
			try{
				con.rollback();
			}
			catch(Exception e2){
				
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg("服务端处理失败： " + e.getMessage());
			return cro;
		}
		finally{
			try{
				con.close();
			}
			catch(Exception e2){
				
			}
		}
		
		String[] strs = new String[]{maxMsc, pscEntity.getPscDesc(), strMaxAlphaCode, alphaName,
				pscEntity.getProducType(), cic, pic, dic, sic, wic, gic};
		cro.setResult(strs);
		return cro;
	}
	
	/**
	 * 创建冶金规范码
	 * @param jsonParm
	 * @return
	 */
	public CoreReturnObject CreateMsc(String jsonParm){
		parms = EntityTool.getEntityByJSONStr(jsonParm, CreateUserAndMscParms.class);
		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		CoreReturnObject cro = new CoreReturnObject();
		
		try{
			stdEntity = getStdEntity(con);
			strMaxAlphaCode = getMaxAlphaCode(con);
			alphaName = parms.getReviewNumber() + "+" + getUserName(con);
			String msc = getMscByCustAlphaNo(parms.getPsc(), parms.getCustAlphaNo(), con);
			if(msc.equals("")){
				createUser(0, con);
				
			}else{
				maxMsc = msc;
				createUser(1, con);
			}
			modeDesc = getModeDesc(con);
			pscEntity = getPscEntity(con);
			productEntity = getProductEntity(con, parms);
			
			if(msc.equals("")){
				createMsc(con);
				createMscItem(con);
			}else{
				setPscRMscCustAlpaNo(con, maxMsc, parms.getCustAlphaNo());
			}
			updateCustAlphaState(con);
			con.commit();
		}catch(Exception ex){
			try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.SetErrInfo(ex.getMessage());
		}finally{
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		cro.setResult(new String[]{maxMsc, pscEntity.getPscDesc(), strMaxAlphaCode, alphaName,
				pscEntity.getProducType(),  cic, pic, dic, sic, wic, gic});
		return cro;
	}
	
	public CoreReturnObject getMscByCustAlphaNo(String psc, String custAlphaNo){
		SqlBuilder b = new SqlBuilder("QualityMsc.getMscByCustAlphaNo");
		b.Fill(new String[]{custAlphaNo, psc});
		return this.getData(b.toString());
	}
	
	private String getMscByCustAlphaNo(String psc, String custAlphaNo, Connection con){
		SqlBuilder b = new SqlBuilder("QualityMsc.getMscByCustAlphaNo");
		b.Fill(new String[]{custAlphaNo, psc});
		GenericEntity value = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
		if(value == null){
			return "";
		}else{
			return value.getValue();
		}
	}
	
	/**
	 * 创建接箍的交付标准
	 * @param parms
	 * @return
	 * @throws SQLException 
	 */
	public CoreReturnObject CreateJgStandPay(CreateUserAndMscParms parms, String keyJg, Connection con) throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		con.setAutoCommit(false);
		this.parms = parms;
		maxMsc = parms.getMsc();
		int custChemCnt = getSaleCustChemCnt(con);
		stdEntity = getStdEntity(con);
		modeDesc = getModeDesc(con);
		pscEntity = getPscEntity(con);
		productEntity = getProductEntity(con, parms);
		
		if(custChemCnt > 0){
			createMscCic(con);
			createMscChem("", null, con);
			setModelToChem(con);
		}
		int custPhyCnt = getSaleCustPhyCnt(con);
		if(custPhyCnt > 0){
			createMscPic(con);
			createMscPhy("", null, con);
			setModelToPhy(con);
		}
		int custDetectionCnt = getSaleCustDetectionCnt(con);
		if(custDetectionCnt > 0){
			createMscDic(con);
			createMsDetection("", null, con);
			setModelToDetection(con);
		}
		int custSpecCnt = getSaleCustSpecCnt(con);
		if(custSpecCnt > 0){
			createMscSic(con);
			createMscSpec("", null, con);
			setModelToSpec(con);
		}
		int custWaterCnt = getSaleCustWaterCnt(con);
		if(custWaterCnt > 0){
			createMscWic(con);
			createMscWater("", null, con);
			//创建扣型
			setModelToWater(con);
		}
		int custProcessCnt = getSaleCustProcessCnt(con);
		if(custProcessCnt > 0){
			createMscGic(con);
			createMscProcess("", null, con);
			setModelToProcess(con);
		}
		
		updateCustAlphaState(con);
		return cro;
	}
	
	private Boolean createUser(int noSameCnt, Connection con) throws SQLException{
		if(noSameCnt == 0){
			if(parms.getUseCode().equals("")){
				createUse(con, parms);
			}else{
				BaseStdAlphaEntity baseStdAlpha = getStdAlphaEntity(parms.getUseCode(), con);
				strMaxAlphaCode = parms.getUseCode();
				alphaName = baseStdAlpha.getAlphaName();
			}
		}else{
			String useCode = getMscEntity(con, maxMsc).getUseCode();
			BaseStdAlphaEntity baseStdAlpha = getStdAlphaEntity(useCode, con);
			strMaxAlphaCode = useCode;
			alphaName = baseStdAlpha.getAlphaName();
		}
		
		BaseStdRCustEntity bseStdRCstEntity = getBseStdRCustEntity(con, strMaxAlphaCode, parms.getUser());
		if(bseStdRCstEntity == null){
			String sqlInsertStdRCust = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertStdRCust");
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#VALIDFLAG#", "1");
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#MEMO#", "");
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#STD_CODE_OLD#", "");
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#CUST_CODE_OLD#", "");
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#STD_CODE#", strMaxAlphaCode);
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#STD_NAME#", alphaName);
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#CUST_CODE#", parms.getUser());
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#CUST_NAME#", getUserName(con));
			sqlInsertStdRCust = StringTool.ReplaceAll(sqlInsertStdRCust, "#CREATE_NAME#", parms.getCreateName());
			Statement st = con.createStatement();
			st.executeUpdate(sqlInsertStdRCust);
			st.close();
		}
		return false;
	}
	
	private Boolean createUse(Connection con, CreateUserAndMscParms parms) throws SQLException{
		//stdAlphaObj.setAlphaCode()
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertUse");
		sql = StringTool.ReplaceAll(sql, "#ALPHA_CODE#", strMaxAlphaCode);
		sql = StringTool.ReplaceAll(sql, "#ALPHA_NAME#", alphaName);
		sql = StringTool.ReplaceAll(sql, "#STD_CODE#", stdEntity.getStdCode());
		sql = StringTool.ReplaceAll(sql, "#STD_NOTE#", "");
		sql = StringTool.ReplaceAll(sql, "#STD_STYLE#", "");
		sql = StringTool.ReplaceAll(sql, "#STD_STYLE_NAME#", "");
		sql = StringTool.ReplaceAll(sql, "#STD_VERSION#", "");
		sql = StringTool.ReplaceAll(sql, "#DEPARTMENT_CODE#", parms.getDepartmentCode());
		sql = StringTool.ReplaceAll(sql, "#DEPARTMENT_DESC#", parms.getDepartmentDesc());
		sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", parms.getUnitCode());
		sql = StringTool.ReplaceAll(sql, "#UNIT_DESC#", parms.getUnitDesc());
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
		sql = StringTool.ReplaceAll(sql, "#ALPHA_CODE_OLD#", "");
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private BaseStdAlphaEntity getStdAlphaEntity(String useCode, Connection con)throws SQLException{
		String sqlGetStdAlpha = CoreXmlSqlParsersFactory.getSql("QualityMsc.getBaseStdAlpha");
		sqlGetStdAlpha = StringTool.ReplaceAll(sqlGetStdAlpha, "#ALPHA_CODE#", useCode);
		ArrayList<BaseStdAlphaEntity> listStdAlpha = EntityTool.getEntitysBySqlNoClsCon(
				sqlGetStdAlpha, con, BaseStdAlphaEntity.class);
		return listStdAlpha.get(0);
	}
	
//	private SlmCustAlphaEntity getCustAlphaEntity(Connection con)throws SQLException{
//		String sqlGetCustAlpha = CoreXmlSqlParsersFactory.getSql("QualityMsc.getCustAlpha");
//		sqlGetCustAlpha = StringTool.ReplaceAll(sqlGetCustAlpha, "#CUST_ALPHA_NO#", parms.getCustAlphaNo());
//		ArrayList<SlmCustAlphaEntity> listCustAlpha = EntityTool.getEntitysBySqlNoClsCon(
//				sqlGetCustAlpha, con, SlmCustAlphaEntity.class);
//		
//		return listCustAlpha.get(0);
//	}
	
	private ComMscEntity getMscEntity(Connection con, String msc)throws SQLException{
		String sqlGetMsc = CoreXmlSqlParsersFactory.getSql("QualityMsc.getMsc");
		sqlGetMsc = StringTool.ReplaceAll(sqlGetMsc, "#MSC#", msc);
		ArrayList<ComMscEntity> listMsc = EntityTool.getEntitysBySqlNoClsCon(
				sqlGetMsc, con, ComMscEntity.class);
		
		return listMsc.get(0);
	}
	
//	private BaseStdAlphaEntity getBseStdAlphaEntity(Connection con, String msc)throws SQLException{
//		String sqlGetBseStdAlpha = CoreXmlSqlParsersFactory.getSql("QualityMsc.getBseStdAlpha");
//		sqlGetBseStdAlpha = StringTool.ReplaceAll(sqlGetBseStdAlpha, "#MSC#", msc);
//		ArrayList<BaseStdAlphaEntity> listBseStdAlpha = EntityTool.getEntitysBySqlNoClsCon(
//				sqlGetBseStdAlpha, con, BaseStdAlphaEntity.class);
//		
//		return listBseStdAlpha.get(0);
//	}
	
	private BaseStdRCustEntity getBseStdRCustEntity(Connection con, String alphaCode, String user){
		String sqlGetBseStdCust = CoreXmlSqlParsersFactory.getSql("QualityMsc.getBseStdCust");
		sqlGetBseStdCust = StringTool.ReplaceAll(sqlGetBseStdCust, "#STD_CODE#", alphaCode);
		sqlGetBseStdCust = StringTool.ReplaceAll(sqlGetBseStdCust, "#CUST_CODE#", user);
		ArrayList<BaseStdRCustEntity> listBseStdCust = EntityTool.getEntitysBySqlNoClsCon(
				sqlGetBseStdCust, con, BaseStdRCustEntity.class);
		
		if(listBseStdCust.size() > 0){
			return listBseStdCust.get(0);
		}else{
			return null;
		}
	}
	
//	private void insertBseStdRCust(Connection con, BaseStdAlphaEntity bseStdAlpha)throws SQLException{
//		String sqlInsertBseStdRCust = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertBseStdRCust");
//		sqlInsertBseStdRCust = StringTool.ReplaceAll(sqlInsertBseStdRCust, "STD_CODE", bseStdAlpha.getAlphaCode());
//		sqlInsertBseStdRCust = StringTool.ReplaceAll(sqlInsertBseStdRCust, "STD_NAME", bseStdAlpha.getAlphaName());
//		sqlInsertBseStdRCust = StringTool.ReplaceAll(sqlInsertBseStdRCust, "CUST_CODE", parms.getUser());
//		String userName = getUserName(con);
//		sqlInsertBseStdRCust = StringTool.ReplaceAll(sqlInsertBseStdRCust, "CUST_NAME", userName);
//		
//		PreparedStatement ps = con.prepareStatement(sqlInsertBseStdRCust);
//		ps.executeUpdate();
//		ps.close();
//	}
	
	private ComBaseStdEntity getStdEntity(Connection con) throws SQLException{
		String sqlQueryStd = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryStd");
		sqlQueryStd = StringTool.ReplaceAll(sqlQueryStd, "#PSC#", parms.getPsc());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sqlQueryStd);
		rs.next();
		ComBaseStdEntity stdEntity = new ComBaseStdEntity();
		stdEntity.setCreateName(rs.getString("CREATE_NAME") == null ? "" : rs.getString("CREATE_NAME"));
		stdEntity.setDepartmentCode(rs.getString("DEPARTMENT_CODE") == null ? "" : rs.getString("DEPARTMENT_CODE"));
		stdEntity.setDepartmentDesc(rs.getString("DEPARTMENT_DESC") == null ? "" : rs.getString("DEPARTMENT_DESC"));
		stdEntity.setStdCode(rs.getString("STD_CODE") == null ? "" : rs.getString("STD_CODE"));
		stdEntity.setStdName(rs.getString("STD_NAME") == null ? "" : rs.getString("STD_NAME"));
		stdEntity.setStdNote(rs.getString("STD_NOTE") == null ? "" : rs.getString("STD_NOTE"));
		stdEntity.setStdStyle(rs.getString("STD_STYLE") == null ? "" : rs.getString("STD_STYLE"));
		stdEntity.setStdstyle(rs.getString("STDSTYLE") == null ? "" : rs.getString("STDSTYLE"));
		stdEntity.setStdStyleName(rs.getString("STD_STYLE_NAME") == null ? "" : rs.getString("STD_STYLE_NAME"));
		stdEntity.setStdVersion(rs.getString("STD_VERSION") == null ? "" : rs.getString("STD_VERSION"));
		stdEntity.setUnitCode(rs.getString("UNIT_CODE") == null ? "" : rs.getString("UNIT_CODE"));
		stdEntity.setUnitDesc(rs.getString("UNIT_DESC") == null ? "" : rs.getString("UNIT_DESC"));
		stdEntity.setUpdateName(rs.getString("UPDATE_NAME") == null ? "" : rs.getString("UPDATE_NAME"));
		rs.close();
		st.close();
		return stdEntity;
	}
	
	private ComPscEntity getPscEntity(Connection con) throws SQLException{
		String sqlQueryPsc = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryPsc");
		sqlQueryPsc = StringTool.ReplaceAll(sqlQueryPsc, "#PSC#", parms.getPsc());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sqlQueryPsc);
		rs.next();
		ComPscEntity pscEntity = new ComPscEntity();
		pscEntity.setNewProcCode(rs.getString("NEW_PROC_CODE") == null ? "" : rs.getString("NEW_PROC_CODE"));
		pscEntity.setNewProcDesc(rs.getString("NEW_PROC_DESC") == null ? "" : rs.getString("NEW_PROC_DESC"));
		pscEntity.setProduccode(rs.getString("PRODUCCODE") == null ? "" : rs.getString("PRODUCCODE"));
		pscEntity.setProducname(rs.getString("PRODUCNAME") == null ? "" : rs.getString("PRODUCNAME"));
		pscEntity.setProducHead(rs.getString("PRODUC_HEAD") == null ? "" : rs.getString("PRODUC_HEAD"));
		pscEntity.setProducStyle(rs.getString("PRODUC_STYLE") == null ? "" : rs.getString("PRODUC_STYLE"));
		pscEntity.setProducDesc(rs.getString("PRODUC_DESC") == null ? "" : rs.getString("PRODUC_DESC"));
		pscEntity.setProducType(rs.getString("PRODUC_TYPE") == null ? "" : rs.getString("PRODUC_TYPE"));
		pscEntity.setPsc(rs.getString("PSC") == null ? "" : rs.getString("PSC"));
		pscEntity.setPscDesc(rs.getString("PSC_DESC") == null ? "" : rs.getString("PSC_DESC"));
		pscEntity.setStdCode(rs.getString("STD_CODE") == null ? "" : rs.getString("STD_CODE"));
		pscEntity.setStdName(rs.getString("STD_NAME") == null ? "" : rs.getString("STD_NAME"));
		pscEntity.setStdStyle(rs.getString("STD_STYLE") == null ? "" : rs.getString("STD_STYLE"));
		pscEntity.setStdStyleDesc(rs.getString("STD_STYLE_DESC") == null ? "" : rs.getString("STD_STYLE_DESC"));
		pscEntity.setSteelcode(rs.getString("STEELCODE") == null ? "" : rs.getString("STEELCODE"));
		pscEntity.setSteelname(rs.getString("STEELNAME") == null ? "" : rs.getString("STEELNAME"));
		rs.close();
		st.close();
		return pscEntity;
	}
	
	private String getMaxAlphaCode(Connection con) throws SQLException{
		String sqlQueryMaxAlphaCode = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxAlphaCode");
		sqlQueryMaxAlphaCode = StringTool.ReplaceAll(sqlQueryMaxAlphaCode, "#STD_CODE#", stdEntity.getStdCode());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sqlQueryMaxAlphaCode);
		rs.next();
		String maxAlphaCode = rs.getString("MAX_ALPHA_CODE");
		rs.close();
		st.close();
		return maxAlphaCode;
	}
	
	private String getUserName(Connection con) throws SQLException{
		String sqlqueryUserName = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryUserName");
		sqlqueryUserName = StringTool.ReplaceAll(sqlqueryUserName, "#CUSTOMER_NO#", parms.getUser());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sqlqueryUserName);
		String userName = "";
		if(rs.next()){
			userName = rs.getString("CUSTOMER_NM") == null ? "" : rs.getString("CUSTOMER_NM");
		}
		else
		{
			userName = "";
		}
		rs.close();
		st.close();
		return userName;
	}
	
	private Boolean createMsc(Connection con) throws SQLException{
		ComMscEntity mscEntity = getMscEntity(con, parms);
		maxMsc = getMaxMsc(con, parms);
		SlmOrdDesignDeptEntity designDept = getDesignDept(con);
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMsc");
		sql = StringTool.ReplaceAll(sql, "#FILE_JPEG#", "");
		sql = StringTool.ReplaceAll(sql, "#PRODUC_HEAD#", productEntity.getProducHead());
		sql = StringTool.ReplaceAll(sql, "#UNIT_CODE_PROCESS#", designDept.getTechDeptCode());
		sql = StringTool.ReplaceAll(sql, "#UNIT_DESC_PROCESS#", designDept.getTechDeptDesc());
		sql = StringTool.ReplaceAll(sql, "#MSC_OLD#", "");
		sql = StringTool.ReplaceAll(sql, "#USE_CODE_OLD#", "");
		sql = StringTool.ReplaceAll(sql, "#REMARK#", "");
		sql = StringTool.ReplaceAll(sql, "#AUDIT_NAME#", "");
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG_NK#", "A");
		sql = StringTool.ReplaceAll(sql, "#AUDIT_NAME_NK#", "");
		sql = StringTool.ReplaceAll(sql, "#REMARK_NK#", "");
		sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
		sql = StringTool.ReplaceAll(sql, "#MSC_DESC#", pscEntity.getPscDesc());
		sql = StringTool.ReplaceAll(sql, "#USE_CODE#", strMaxAlphaCode);
		sql = StringTool.ReplaceAll(sql, "#USE_DESC#", alphaName);
		sql = StringTool.ReplaceAll(sql, "#DEPARTMENT_CODE#", designDept.getDeptCode());
		sql = StringTool.ReplaceAll(sql, "#DEPARTMENT_DESC#", designDept.getDeptDesc());
		sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", designDept.getDelivyDeptCode());
		sql = StringTool.ReplaceAll(sql, "#UNIT_DESC#", designDept.getDelivyDeptDesc());
		sql = StringTool.ReplaceAll(sql, "#MSC_STYLE#", productEntity.getProducType());
		sql = StringTool.ReplaceAll(sql, "#USER_COUNT#", "1");
		sql = StringTool.ReplaceAll(sql, "#PRODUCCODE#", pscEntity.getProduccode());
		sql = StringTool.ReplaceAll(sql, "#PRODUCNAME#", pscEntity.getProducname());
		sql = StringTool.ReplaceAll(sql, "#STD_CODE#", stdEntity.getStdCode());
		sql = StringTool.ReplaceAll(sql, "#STD_NAME#", stdEntity.getStdName());
		sql = StringTool.ReplaceAll(sql, "#STEELCODE#", pscEntity.getSteelcode());
		sql = StringTool.ReplaceAll(sql, "#STEELNAME#", pscEntity.getSteelname());
		sql = StringTool.ReplaceAll(sql, "#STD_STYLE#", pscEntity.getStdStyle());
		sql = StringTool.ReplaceAll(sql, "#STD_STYLE_DESC#", pscEntity.getStdStyleDesc());
		sql = StringTool.ReplaceAll(sql, "#NEW_PROC_CODE#", pscEntity.getNewProcCode());
		sql = StringTool.ReplaceAll(sql, "#NEW_PROC_DESC#", pscEntity.getNewProcDesc());
		sql = StringTool.ReplaceAll(sql, "#ALLOW_NK#", "0");
		sql = StringTool.ReplaceAll(sql,"#MSC_SEQ#", mscEntity.getMsc());
		sql = StringTool.ReplaceAll(sql, "#MSC_DESC_SEQ#", mscEntity.getMscDesc());
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "A");
		sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		
		ComPscRMscEntity pscRMscEntity = new ComPscRMscEntity();
		pscRMscEntity.setPsc(parms.getPsc());
		pscRMscEntity.setPscDesc(pscEntity.getPscDesc());
		pscRMscEntity.setUseCode(strMaxAlphaCode);
		pscRMscEntity.setUseDesc(alphaName);
		pscRMscEntity.setMsc(maxMsc);
		pscRMscEntity.setMscDesc(pscEntity.getPscDesc());
		pscRMscEntity.setCreateName(stdEntity.getCreateName());
		pscRMscEntity.setCustAlphaNo(parms.getCustAlphaNo());
		createPscRMsc(con, pscRMscEntity);
		return true;
	}
	
	private boolean createPscRMsc(Connection con, ComPscRMscEntity pscRMscEntity) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertPscRMsc");
		sql = StringTool.ReplaceAll(sql, "#PSC#", pscRMscEntity.getPsc());
		sql = StringTool.ReplaceAll(sql, "#PSC_DESC#", pscRMscEntity.getPscDesc());
		sql = StringTool.ReplaceAll(sql, "#USE_CODE#", pscRMscEntity.getUseCode());
		sql = StringTool.ReplaceAll(sql, "#USE_DESC#", pscRMscEntity.getUseDesc());
		sql = StringTool.ReplaceAll(sql, "#MSC#", pscRMscEntity.getMsc());
		sql = StringTool.ReplaceAll(sql, "#MSC_DESC#", pscRMscEntity.getMscDesc());
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", pscRMscEntity.getCustAlphaNo() + ";");
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", pscRMscEntity.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private boolean setPscRMscCustAlpaNo(Connection con, String msc, String custAlphaNo) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.setPscRMscCustAlpaNo");
		sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", custAlphaNo);
		
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private ComBaseProductEntity getProductEntity(Connection con, CreateUserAndMscParms parms) throws SQLException{
		String sqlQueryProductType = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryProductType");
		sqlQueryProductType = StringTool.ReplaceAll(sqlQueryProductType, "#PSC#", parms.getPsc());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sqlQueryProductType);
		rs.next();
		ComBaseProductEntity productEntity = new ComBaseProductEntity();
		productEntity.setProducType(rs.getString("PRODUC_TYPE") == null ? "" : rs.getString("PRODUC_TYPE"));
		productEntity.setProducHead(rs.getString("PRODUC_HEAD") == null ? "" : rs.getString("PRODUC_HEAD"));
		rs.close();
		st.close();
		return productEntity;
	}
	
	private String getMaxMsc(Connection con, CreateUserAndMscParms parms) throws SQLException{
		String sqlQueryMaxMsc = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxMscCode");
		sqlQueryMaxMsc = StringTool.ReplaceAll(sqlQueryMaxMsc, "#PSC#", parms.getPsc());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sqlQueryMaxMsc);
		rs.next();
		String maxMsc = rs.getString("MAX_MSC");
		rs.close();
		st.close();
		return maxMsc;
	}
	
	private ComMscEntity getMscEntity(Connection con, CreateUserAndMscParms parms) throws SQLException{
		String sqlQueryStdMsc = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryStdMsc");
		sqlQueryStdMsc = StringTool.ReplaceAll(sqlQueryStdMsc, "#PSC#", parms.getPsc());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sqlQueryStdMsc);
		rs.next();
		ComMscEntity mscEntity = new ComMscEntity();
		mscEntity.setMsc(rs.getString("MSC") == null ? "" : rs.getString("MSC"));
		mscEntity.setMscDesc(rs.getString("MSC_DESC") == null ? "" : rs.getString("MSC_DESC"));
		rs.close();
		st.close();
		return mscEntity;
	}
	
	private boolean createMscItem(Connection con) throws SQLException{
		Statement st = con.createStatement();
 		String[] items = new String[]{"403002", "403003", "403004", "403005", "403006", "403007"};
		String[] itemCs = new String[]{"40300202", "40300302", "40300402", "40300502", "40300602", "40300702"};
		int i = 0;
		for(String item : items){
			String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscItem");
			sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
			sql = StringTool.ReplaceAll(sql, "#INDEX_SEQ#", String.valueOf(i + 1));
			sql = StringTool.ReplaceAll(sql, "#ITEM#", item);
			sql = StringTool.ReplaceAll(sql, "#ITEM_C#", itemCs[i]);
			sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", stdEntity.getCreateName());
			sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
			sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
			st.executeUpdate(sql);
			i++;
		}
		st.close();
		return true;
	}
	
	private String getModeDesc(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryModeDesc");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		String modeDesc = "";
		if(rs.next()){
			modeDesc = rs.getString("MODEL_DESC");
		}
		rs.close();
		st.close();
		return modeDesc;
	}
	
	private boolean createMscCic(Connection con) throws SQLException{
		cic = getMaxCic(con);
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscStdCic");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#PRODUC_HEAD#", productEntity.getProducHead());
		sql = StringTool.ReplaceAll(sql, "#CIC#", cic);
		sql = StringTool.ReplaceAll(sql, "#PSC#", pscEntity.getPsc());
		sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
		sql = StringTool.ReplaceAll(sql, "#STDSTYLE#", stdEntity.getStdstyle());
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private String getMaxCic(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxCic");
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		rs.next();
		String maxCic = rs.getString("MAX_CIC");
		rs.close();
		st.close();
		return maxCic;
	}
	
	private boolean createMscPic(Connection con) throws SQLException{
		pic = getMaxPic(con);
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscStdPic");
		sql = StringTool.ReplaceAll(sql, "#PIC#", pic);
		sql = StringTool.ReplaceAll(sql, "#PSC#", pscEntity.getPsc());
		sql = StringTool.ReplaceAll(sql, "#STDSTYLE#", stdEntity.getStdstyle());
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
		sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#PRODUC_HEAD#", productEntity.getProducHead());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private String getMaxPic(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxPic");
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		rs.next();
		String maxPic = rs.getString("MAX_PIC");
		rs.close();
		st.close();
		return maxPic;
	}
	
	private boolean createMscDic(Connection con) throws SQLException{
		dic = getMaxDic(con);
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscStdDic");
		sql = StringTool.ReplaceAll(sql, "#PRODUC_HEAD#", productEntity.getProducHead());
		sql = StringTool.ReplaceAll(sql, "#DIC#", dic);
		sql = StringTool.ReplaceAll(sql, "#PSC#", pscEntity.getPsc());
		sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
		sql = StringTool.ReplaceAll(sql, "#STDSTYLE#", stdEntity.getStdstyle());
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private String getMaxDic(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxDic");
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		rs.next();
		String maxDic = rs.getString("MAX_DIC");
		rs.close();
		return maxDic;
	}
	
	private boolean createMscSic(Connection con) throws SQLException{
		sic = getMaxSic(con);
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscStdSpec");
		sql = StringTool.ReplaceAll(sql, "#PRODUC_HEAD#", productEntity.getProducHead());
		sql = StringTool.ReplaceAll(sql, "#SIC#", sic);
		sql = StringTool.ReplaceAll(sql, "#PSC#", pscEntity.getPsc());
		sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
		sql = StringTool.ReplaceAll(sql, "#STDSTYLE#", stdEntity.getStdstyle());
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#STDMEMO#", "");
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private String getMaxSic(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxSic");
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		rs.next();
		String maxSic = rs.getString("MAX_SIC");
		rs.close();
		st.close();
		return maxSic;
	}
	
	private boolean createMscWic(Connection con) throws SQLException{
		wic = getMaxWic(con);
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscStdWater");
		sql = StringTool.ReplaceAll(sql, "#PRODUC_HEAD#", productEntity.getProducHead());
		sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
		sql = StringTool.ReplaceAll(sql, "#WIC#", wic);
		sql = StringTool.ReplaceAll(sql, "#PSC#", pscEntity.getPsc());
		sql = StringTool.ReplaceAll(sql, "#STDSTYLE#", stdEntity.getStdstyle());
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		sql = StringTool.ReplaceAll(sql, "#MIN_D#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
		sql = StringTool.ReplaceAll(sql, "#MAX_D#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
		sql = StringTool.ReplaceAll(sql, "#MIN_H#", parms.getHeight());
		sql = StringTool.ReplaceAll(sql, "#MAX_H#", parms.getHeight());
		sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
		sql = StringTool.ReplaceAll(sql, "#SPEC_JG#", parms.getSpecCode().equals("") ? "C000000" : parms.getSpecCode());
		sql = StringTool.ReplaceAll(sql, "#SPEC_JG_DESC#", parms.getSpecCode().equals("") ? "-1" : parms.getSpecName());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private String getMaxWic(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxWic");
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		rs.next();
		String maxWic = rs.getString("MAX_WIC");
		rs.close();
		st.close();
		return maxWic;
	}
	
	private boolean createMscGic(Connection con) throws SQLException{
		gic = getMaxGic(con);
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.inserStdProcess");
		sql = StringTool.ReplaceAll(sql, "#GIC#", gic);
		sql = StringTool.ReplaceAll(sql, "#PSC#", pscEntity.getPsc());
		sql = StringTool.ReplaceAll(sql, "#MSC#", maxMsc);
		sql = StringTool.ReplaceAll(sql, "#STDSTYLE#", stdEntity.getStdstyle());
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", parms.getCreateName());
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", "1");
		sql = StringTool.ReplaceAll(sql, "#MEMO#", "");
		sql = StringTool.ReplaceAll(sql, "#PRODUC_HEAD#", productEntity.getProducHead());
		Statement st = con.createStatement();
		st.execute(sql);
		st.close();
		return true;
	}
	
	private String getMaxGic(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.queryMaxGic");
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		rs.next();
		String maxGic = rs.getString("MAX_GIC");
		rs.close();
		st.close();
		return maxGic;
	}
	
	private ArrayList<SlmCustChemObject> getSaleCustChem(Connection con) throws SQLException{
		ArrayList<SlmCustChemObject> list = new ArrayList<SlmCustChemObject>();
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustChem");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNoChem());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		while(rs.next())
		{
			SlmCustChemObject slmCustChemObj = new SlmCustChemObject();
			slmCustChemObj.setChemCode(rs.getString("CHEM_CODE") == null ? "" : rs.getString("CHEM_CODE"));
			slmCustChemObj.setChemFormula(rs.getString("CHEM_FORMULA") == null ? "" : rs.getString("CHEM_FORMULA"));
			slmCustChemObj.setChemName(rs.getString("CHEM_NAME") == null ? "" : rs.getString("CHEM_NAME"));
			slmCustChemObj.setChemType(rs.getString("CHEM_TYPE") == null ? "" : rs.getString("CHEM_TYPE"));
			slmCustChemObj.setCic(rs.getString("CIC") == null ? "" : rs.getString("CIC"));
			slmCustChemObj.setComplexType(rs.getString("COMPLEX_TYPE") == null ? "0" : rs.getString("COMPLEX_TYPE"));
			slmCustChemObj.setCreateName(rs.getString("CREATE_NAME") == null ? "" : rs.getString("CREATE_NAME"));
			slmCustChemObj.setCustAlphaNo(rs.getString("CUST_ALPHA_NO") == null ? "" : rs.getString("CUST_ALPHA_NO"));
			slmCustChemObj.setDeleteName(rs.getString("DELETE_NAME") == null ? "" : rs.getString("DELETE_NAME"));
			slmCustChemObj.setEleCode(rs.getString("ELE_CODE") == null ? "" : rs.getString("ELE_CODE"));
			slmCustChemObj.setEleMax(rs.getString("ELE_MAX") == null ? "" : rs.getString("ELE_MAX"));
			slmCustChemObj.setEleMaxSign(rs.getString("ELE_MAX_SIGN") == null ? "" : rs.getString("ELE_MAX_SIGN"));
			slmCustChemObj.setEleMin(rs.getString("ELE_MIN") == null ? "" : rs.getString("ELE_MIN"));
			slmCustChemObj.setEleMinSign(rs.getString("ELE_MIN_SIGN") == null ? "" : rs.getString("ELE_MIN_SIGN"));
			slmCustChemObj.setEleName(rs.getString("ELE_NAME") == null ? "" : rs.getString("ELE_NAME"));
			slmCustChemObj.setIndexSeq(rs.getString("INDEX_SEQ") == null ? "" : rs.getString("INDEX_SEQ"));
			slmCustChemObj.setIscheck(rs.getString("ISCHECK") == null ? "0" : rs.getString("ISCHECK"));
			slmCustChemObj.setIsjudge(rs.getString("ISJUDGE") == null ? "0" : rs.getString("ISJUDGE"));
			slmCustChemObj.setIsquote(rs.getString("ISQUOTE") == null ? "0" : rs.getString("ISQUOTE"));
			slmCustChemObj.setModelCode(rs.getString("MODEL_CODE") == null ? "" : rs.getString("MODEL_CODE"));
			slmCustChemObj.setModelDesc(rs.getString("MODEL_DESC") == null ? "" : rs.getString("MODEL_DESC"));
			slmCustChemObj.setRepCode(rs.getString("REP_CODE") == null ? "" : rs.getString("REP_CODE"));
			slmCustChemObj.setRepMax(rs.getString("REP_MAX") == null ? "" : rs.getString("REP_MAX"));
			slmCustChemObj.setRepMaxSign(rs.getString("REP_MAX_SIGN") == null ? "" : rs.getString("REP_MAX_SIGN"));
			slmCustChemObj.setRepMin(rs.getString("REP_MIN") == null ? "" : rs.getString("REP_MIN"));
			slmCustChemObj.setRepMinSign(rs.getString("REP_MIN_SIGN") == null ? "" : rs.getString("REP_MIN_SIGN"));
			slmCustChemObj.setRepName(rs.getString("REP_NAME") == null ? "" : rs.getString("REP_NAME"));
			slmCustChemObj.setRepVal(rs.getString("REP_VAL") == null ? "" : rs.getString("REP_VAL"));
			slmCustChemObj.setSizeCode(rs.getString("SIZE_CODE") == null ? "" : rs.getString("SIZE_CODE"));
			slmCustChemObj.setSizeCode2(rs.getString("SIZE_CODE2") == null ? "" : rs.getString("SIZE_CODE2"));
			slmCustChemObj.setSizeMax(rs.getString("SIZE_MAX") == null ? "" : rs.getString("SIZE_MAX"));
			slmCustChemObj.setSizeMax2(rs.getString("SIZE_MAX2") == null ? "" : rs.getString("SIZE_MAX2"));
			slmCustChemObj.setSizeMaxSign(rs.getString("SIZE_MAX_SIGN") == null ? "" : rs.getString("SIZE_MAX_SIGN"));
			slmCustChemObj.setSizeMaxSign2(rs.getString("SIZE_MAX_SIGN2") == null ? "" : rs.getString("SIZE_MAX_SIGN2"));
			slmCustChemObj.setSizeMin(rs.getString("SIZE_MIN") == null ? "" : rs.getString("SIZE_MIN"));
			slmCustChemObj.setSizeMin2(rs.getString("SIZE_MIN2") == null ? "" : rs.getString("SIZE_MIN2"));
			slmCustChemObj.setSizeMinSign(rs.getString("SIZE_MIN_SIGN") == null ? "" : rs.getString("SIZE_MIN_SIGN"));
			slmCustChemObj.setSizeMinSign2(rs.getString("SIZE_MIN_SIGN2") == null ? "" : rs.getString("SIZE_MIN_SIGN2"));
			slmCustChemObj.setSizeName(rs.getString("SIZE_NAME") == null ? "" : rs.getString("SIZE_NAME"));
			slmCustChemObj.setSizeName2(rs.getString("SIZE_NAME2") == null ? "" : rs.getString("SIZE_NAME2"));
			slmCustChemObj.setSpecJg(rs.getString("SPEC_JG") == null ? "" : rs.getString("SPEC_JG"));
			slmCustChemObj.setSpecJgDesc(rs.getString("SPEC_JG_DESC") == null ? "" : rs.getString("SPEC_JG_DESC"));
			slmCustChemObj.setStdmax(rs.getString("STDMAX") == null ? "" : rs.getString("STDMAX"));
			slmCustChemObj.setStdmaxSign(rs.getString("STDMAX_SIGN") == null ? "" : rs.getString("STDMAX_SIGN"));
			slmCustChemObj.setStdmemo(rs.getString("STDMEMO") == null ? "" : rs.getString("STDMEMO"));
			slmCustChemObj.setStdmin(rs.getString("STDMIN") == null ? "" : rs.getString("STDMIN"));
			slmCustChemObj.setStdminSign(rs.getString("STDMIN_SIGN") == null ? "" : rs.getString("STDMIN_SIGN"));
			slmCustChemObj.setStdtarget(rs.getString("STDTARGET") == null ? "" : rs.getString("STDTARGET"));
			slmCustChemObj.setUpdateName(rs.getString("UPDATE_NAME") == null ? "" : rs.getString("UPDATE_NAME"));
			slmCustChemObj.setValidflag(rs.getString("VALIDFLAG") == null ? "" : rs.getString("VALIDFLAG"));
			list.add(slmCustChemObj);
		}
		
		rs.close();
		st.close();
		return list;
	}
	
	private String getBaseNameByBaseCode(String baseCode, Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.getBaseNameByBaseCode");
		sql = StringTool.ReplaceAll(sql, "#BASECODE#", baseCode);
		ArrayList<GenericEntity> listBaseName = EntityTool.getEntitysBySqlNoClsCon(sql, con, GenericEntity.class);
		
		return listBaseName.get(0).getValue();
	}
	
	private <T> ArrayList<T> ConvertHashTabToEntity(ArrayList<Object> list, Class<T> cls){
		ArrayList<T> list2 = new ArrayList<T>();
		for(Object obj : list){
			JSONObject jsObj = JSONObject.fromObject(obj);
			@SuppressWarnings("unchecked")
			T tobj = (T)JSONObject.toBean(jsObj, cls);
			list2.add(tobj);
		}
		
		return list2;
	}
	
	private boolean createMscChem(String cic, ArrayList<Object> insrtChemData, Connection con) throws SQLException{
		
		ArrayList<SlmCustChemObject> slmCustChemList;
		if(cic.equals("")){
			slmCustChemList = getSaleCustChem(con);
		}else{
			slmCustChemList = ConvertHashTabToEntity(insrtChemData, SlmCustChemObject.class);
		}
		String dimaterCode = "400301";
		String dimaterName = getBaseNameByBaseCode(dimaterCode, con);
		String heightCode = "400302";
		String heightName = getBaseNameByBaseCode(heightCode, con);
		Statement st = con.createStatement();
		for(SlmCustChemObject slmCustChemObj : slmCustChemList){
			String sqlGetMaxCic = CoreXmlSqlParsersFactory.getSql("QualityMsc.getMaxCic");
			sqlGetMaxCic = StringTool.ReplaceAll(sqlGetMaxCic, "#CIC#", this.cic);
			String indexSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxCic, con, GenericEntity.class).get(0).getMaxValue();
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscChem");
		sql = sql.replaceAll("#REP_CODE#", slmCustChemObj.getRepCode().replaceAll("'", "''"));
		sql = sql.replaceAll("#REP_NAME#", slmCustChemObj.getRepName().replaceAll("'", "''"));
		sql = sql.replaceAll("#REP_MIN_SIGN#", slmCustChemObj.getRepMinSign().replaceAll("'", "''"));
		sql = sql.replaceAll("#REP_MIN#", slmCustChemObj.getRepMin().replaceAll("'", "''"));
		sql = sql.replaceAll("#REP_MAX_SIGN#", slmCustChemObj.getRepMaxSign().replaceAll("'", "''"));
		sql = sql.replaceAll("#REP_MAX#", slmCustChemObj.getRepMax().replaceAll("'", "''"));
		sql = sql.replaceAll("#REP_VAL#", slmCustChemObj.getRepVal().replaceAll("'", "''"));
		sql = sql.replaceAll("#COMPLEX_TYPE#", slmCustChemObj.getComplexType().replaceAll("'", "''"));
		sql = sql.replaceAll("#STDMIN_SIGN#", slmCustChemObj.getStdminSign().replaceAll("'", "''"));
		sql = sql.replaceAll("#STDMIN#", slmCustChemObj.getStdmin().replaceAll("'", "''"));
		sql = sql.replaceAll("#STDMAX_SIGN#", slmCustChemObj.getStdmaxSign().replaceAll("'", "''"));
		sql = sql.replaceAll("#STDMAX#", slmCustChemObj.getStdmax().replaceAll("'", "''"));
		sql = sql.replaceAll("#STDTARGET#", slmCustChemObj.getStdtarget().replaceAll("'", "''"));
		sql = sql.replaceAll("#MODEL_CODE#", slmCustChemObj.getModelCode().replaceAll("'", "''"));
		sql = sql.replaceAll("#MODEL_DESC#", slmCustChemObj.getModelDesc().replaceAll("'", "''"));
		sql = sql.replaceAll("#STDMEMO#", slmCustChemObj.getStdmemo().replaceAll("'", "''"));
		sql = sql.replaceAll("#ELE_CODE#", slmCustChemObj.getEleCode().replaceAll("'", "''"));
		sql = sql.replaceAll("#ELE_NAME#", slmCustChemObj.getEleName().replaceAll("'", "''"));
		sql = sql.replaceAll("#ELE_MIN_SIGN#", slmCustChemObj.getEleMinSign().replaceAll("'", "''"));
		sql = sql.replaceAll("#ELE_MIN#", slmCustChemObj.getEleMin().replaceAll("'", "''"));
		sql = sql.replaceAll("#ELE_MAX_SIGN#", slmCustChemObj.getEleMaxSign().replaceAll("'", "''"));
		sql = sql.replaceAll("#ELE_MAX#", slmCustChemObj.getEleMax().replaceAll("'", "''"));
		sql = sql.replaceAll("#SIZE_CODE2#", dimaterCode);
		sql = sql.replaceAll("#SIZE_NAME2#", dimaterName);
		sql = sql.replaceAll("#SIZE_MIN_SIGN2#", ">=");
		sql = sql.replaceAll("#SIZE_MIN2#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
		sql = sql.replaceAll("#SIZE_MAX_SIGN2#", "<=");
		sql = sql.replaceAll("#SIZE_MAX2#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
		sql = sql.replaceAll("#SIZE_CODE#", parms.getHeight().equals("") ? "" : heightCode);
		sql = sql.replaceAll("#SIZE_NAME#", parms.getHeight().equals("") ? "" : heightName);
		sql = sql.replaceAll("#SIZE_MIN_SIGN#", parms.getHeight().equals("") ? "" : ">=");
		sql = sql.replaceAll("#SIZE_MIN#", parms.getHeight());
		sql = sql.replaceAll("#SIZE_MAX_SIGN#", parms.getHeight().equals("") ? "" : "<=");
		sql = sql.replaceAll("#SIZE_MAX#", parms.getHeight());
		sql = sql.replaceAll("#SPEC_JG#", parms.getSpecCode().equals("") ? "C000000" : parms.getSpecCode());
		sql = sql.replaceAll("#SPEC_JG_DESC#", parms.getSpecCode().equals("") ? "-1" : parms.getSpecName());
		sql = sql.replaceAll("#CREATE_NAME#", parms.getCreateName());
		sql = sql.replaceAll("#UPDATE_NAME#", slmCustChemObj.getUpdateName().replaceAll("'", "''"));
		sql = sql.replaceAll("#DELETE_NAME#", slmCustChemObj.getDeleteName().replaceAll("'", "''"));
		sql = sql.replaceAll("#VALIDFLAG#", slmCustChemObj.getValidflag().replaceAll("'", "''"));
		sql = sql.replaceAll("#CIC#", this.cic.replaceAll("'", "''"));
		sql = sql.replaceAll("#INDEX_SEQ#", indexSeq);
		sql = sql.replaceAll("#CHEM_CODE#", slmCustChemObj.getChemCode().replaceAll("'", "''"));
		sql = sql.replaceAll("#CHEM_NAME#", slmCustChemObj.getChemName().replaceAll("'", "''"));
		sql = sql.replaceAll("#CHEM_TYPE#", slmCustChemObj.getChemType().replaceAll("'", "''"));
		sql = sql.replaceAll("#CHEM_FORMULA#", slmCustChemObj.getChemFormula().replaceAll("'", "''"));
		sql = sql.replaceAll("#ISCHECK#", slmCustChemObj.getIscheck().replaceAll("'", "''"));
		sql = sql.replaceAll("#ISJUDGE#", slmCustChemObj.getIsjudge().replaceAll("'", "''"));
		sql = sql.replaceAll("#ISQUOTE#", slmCustChemObj.getIsquote().replaceAll("'", "''"));
		
		st.executeUpdate(sql);
		}
		st.close();
		return true;
	}
	
	private boolean setModelToChem(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.setModeToChem");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#CIC#", cic);
		sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", parms.getCreateName());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private ArrayList<SlmCustPhyObject> getSaleCustPhy(Connection con) throws SQLException{
		ArrayList<SlmCustPhyObject> list = new ArrayList<SlmCustPhyObject>();
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustPhy");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNoPhy());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		
		while(rs.next())
		{
			SlmCustPhyObject slmCustPhyObj = new SlmCustPhyObject();
			slmCustPhyObj.setAddcondition(rs.getString("ADDCONDITION") == null ? "" : rs.getString("ADDCONDITION"));
			slmCustPhyObj.setAddpercent(rs.getString("ADDPERCENT") == null ? "" : rs.getString("ADDPERCENT"));
			slmCustPhyObj.setAddstdconCode(rs.getString("ADDSTDCON_CODE") == null ? "" : rs.getString("ADDSTDCON_CODE"));
			slmCustPhyObj.setAddstdMax(rs.getString("ADDSTD_MAX") == null ? "" : rs.getString("ADDSTD_MAX"));
			slmCustPhyObj.setAddstdMaxSign(rs.getString("ADDSTD_MAX_SIGN") == null ? "" : rs.getString("ADDSTD_MAX_SIGN"));
			slmCustPhyObj.setAddstdMin(rs.getString("ADDSTD_MIN") == null ? "" : rs.getString("ADDSTD_MIN"));
			slmCustPhyObj.setAddstdMinSign(rs.getString("ADDSTD_MIN_SIGN") == null ? "" : rs.getString("ADDSTD_MIN_SIGN"));
			slmCustPhyObj.setCreateName(rs.getString("CREATE_NAME") == null ? "" : rs.getString("CREATE_NAME"));
			slmCustPhyObj.setCustAlphaNo(rs.getString("CUST_ALPHA_NO") == null ?  "" : rs.getString("CUST_ALPHA_NO"));
			slmCustPhyObj.setDeleteName(rs.getString("DELETE_NAME") == null ? "" : rs.getString("DELETE_NAME"));
			slmCustPhyObj.setDeliverystate(rs.getString("DELIVERYSTATE") == null ? "" : rs.getString("DELIVERYSTATE"));
			slmCustPhyObj.setGroupSeq(rs.getString("GROUP_SEQ") == null ? "" : rs.getString("GROUP_SEQ"));
			slmCustPhyObj.setIndexSeq(rs.getString("INDEX_SEQ") == null ? "" : rs.getString("INDEX_SEQ"));
			slmCustPhyObj.setIscheck(rs.getString("ISCHECK") == null ? "0" : rs.getString("ISCHECK"));
			slmCustPhyObj.setIsjudge(rs.getString("ISJUDGE") == null ? "0" : rs.getString("ISJUDGE"));
			slmCustPhyObj.setIsquote(rs.getString("ISQUOTE") == null ? "0" : rs.getString("ISQUOTE"));
			slmCustPhyObj.setItemCodeF(rs.getString("ITEM_CODE_F") == null ? "" : rs.getString("ITEM_CODE_F"));
			slmCustPhyObj.setItemCodeS(rs.getString("ITEM_CODE_S") == null ? "" : rs.getString("ITEM_CODE_S"));
			slmCustPhyObj.setItemCodeW(rs.getString("ITEM_CODE_W") == null ? "" : rs.getString("ITEM_CODE_W"));
			slmCustPhyObj.setItemNameF(rs.getString("ITEM_NAME_F") == null ? "" : rs.getString("ITEM_NAME_F"));
			slmCustPhyObj.setItemNameS(rs.getString("ITEM_NAME_S") == null ? "" : rs.getString("ITEM_NAME_S"));
			slmCustPhyObj.setItemNameW(rs.getString("ITEM_NAME_W") == null ? "" : rs.getString("ITEM_NAME_W"));
			slmCustPhyObj.setJudgeBasis(rs.getString("JUDGE_BASIS") == null ? "D" : rs.getString("JUDGE_BASIS"));
			slmCustPhyObj.setModelCode(rs.getString("MODEL_CODE") == null ? "" : rs.getString("MODEL_CODE"));
			slmCustPhyObj.setModelDesc(rs.getString("MODEL_DESC") == null ? "" : rs.getString("MODEL_DESC"));
			slmCustPhyObj.setPhyCode(rs.getString("PHY_CODE") == null ? "" : rs.getString("PHY_CODE"));
			slmCustPhyObj.setPhyCodeMax(rs.getString("PHY_CODE_MAX") == null ? "" : rs.getString("PHY_CODE_MAX"));
			slmCustPhyObj.setPhyCodeMin(rs.getString("PHY_CODE_MIN") == null ? "" : rs.getString("PHY_CODE_MIN"));
			slmCustPhyObj.setPhyFormula(rs.getString("PHY_FORMULA") == null ? "" : rs.getString("PHY_FORMULA"));
			slmCustPhyObj.setPhyName(rs.getString("PHY_NAME") == null ? "" : rs.getString("PHY_NAME"));
			slmCustPhyObj.setPhyNameMax(rs.getString("PHY_NAME_MAX") == null ? "" : rs.getString("PHY_NAME_MAX"));
			slmCustPhyObj.setPhyNameMin(rs.getString("PHY_NAME_MIN") == null ? "" : rs.getString("PHY_NAME_MIN"));
			slmCustPhyObj.setPhyType(rs.getString("PHY_TYPE") == null ? "" : rs.getString("PHY_TYPE"));
			slmCustPhyObj.setPic(rs.getString("PIC") == null ? "" : rs.getString("PIC"));
			slmCustPhyObj.setResultCount(rs.getString("RESULT_COUNT") == null ? "" : rs.getString("RESULT_COUNT"));
			slmCustPhyObj.setSizeCode(rs.getString("SIZE_CODE") == null ? "" : rs.getString("SIZE_CODE"));
			slmCustPhyObj.setSizeCode2(rs.getString("SIZE_CODE2") == null ? "" : rs.getString("SIZE_CODE2"));
			slmCustPhyObj.setSizeMax(rs.getString("SIZE_MAX") == null ? "" : rs.getString("SIZE_MAX"));
			slmCustPhyObj.setSizeMax2(rs.getString("SIZE_MAX2") == null ? "" : rs.getString("SIZE_MAX2"));
			slmCustPhyObj.setSizeMaxSign(rs.getString("SIZE_MAX_SIGN") == null ? "" : rs.getString("SIZE_MAX_SIGN"));
			slmCustPhyObj.setSizeMaxSign2(rs.getString("SIZE_MAX_SIGN2") == null ? "" : rs.getString("SIZE_MAX_SIGN2"));
			slmCustPhyObj.setSizeMin(rs.getString("SIZE_MIN") == null ? "" : rs.getString("SIZE_MIN"));
			slmCustPhyObj.setSizeMin2(rs.getString("SIZE_MIN2") == null ? "" : rs.getString("SIZE_MIN2"));
			slmCustPhyObj.setSizeMinSign(rs.getString("SIZE_MIN_SIGN") == null ? "" : rs.getString("SIZE_MIN_SIGN"));
			slmCustPhyObj.setSizeMinSign2(rs.getString("SIZE_MIN_SIGN2") == null ? "" : rs.getString("SIZE_MIN_SIGN2"));
			slmCustPhyObj.setSizeName(rs.getString("SIZE_NAME") == null ? "" : rs.getString("SIZE_NAME"));
			slmCustPhyObj.setSizeName2(rs.getString("SIZE_NAME2") == null ? "" : rs.getString("SIZE_NAME2"));
			slmCustPhyObj.setSpecJg(rs.getString("SPEC_JG") == null ? "" : rs.getString("SPEC_JG"));
			slmCustPhyObj.setSpecJgDesc(rs.getString("SPEC_JG_DESC") == null ? "" : rs.getString("SPEC_JG_DESC"));
			slmCustPhyObj.setStdmax(rs.getString("STDMAX") == null ? "" : rs.getString("STDMAX"));
			slmCustPhyObj.setStdmaxSign(rs.getString("STDMAX_SIGN") == null ? "" : rs.getString("STDMAX_SIGN"));
			slmCustPhyObj.setStdmemo(rs.getString("STDMEMO") == null ? "" : rs.getString("STDMEMO"));
			slmCustPhyObj.setStdmin(rs.getString("STDMIN") == null ? "" : rs.getString("STDMIN"));
			slmCustPhyObj.setStdminSign(rs.getString("STDMIN_SIGN") == null ? "" : rs.getString("STDMIN_SIGN"));
			slmCustPhyObj.setUpdateName(rs.getString("UPDATE_NAME") == null ? "" : rs.getString("UPDATE_NAME"));
			slmCustPhyObj.setValidflag(rs.getString("VALIDFLAG") == null ? "" : rs.getString("VALIDFLAG"));
			slmCustPhyObj.setStdmin2(rs.getString("STDMIN_SIGN2") == null ? "" : rs.getString("STDMIN_SIGN2"));
			slmCustPhyObj.setStdminSign2(rs.getString("STDMIN2") == null ? "" : rs.getString("STDMIN2"));
			slmCustPhyObj.setStdmax2(rs.getString("STDMAX2") == null ? "" : rs.getString("STDMAX2"));
			slmCustPhyObj.setStdmaxSign2(rs.getString("STDMAX_SIGN2") == null ? "" : rs.getString("STDMAX_SIGN2"));
			slmCustPhyObj.setStdChoose(rs.getString("STD_CHOOSE") == null ? "" : rs.getString("STD_CHOOSE"));
			slmCustPhyObj.setGuid(rs.getString("GUID") == null ? "" : rs.getString("GUID"));
			list.add(slmCustPhyObj);
		}
		rs.close();
		st.close();
		return list;
	}
	
	private boolean createMscPhy(String pic, ArrayList<Object> insrtPhyData, Connection con) throws SQLException{
		ArrayList<SlmCustPhyObject> slmCustPhyList;
		if(pic.equals("")){
			slmCustPhyList = getSaleCustPhy(con);
		}else{
			slmCustPhyList = ConvertHashTabToEntity(insrtPhyData, SlmCustPhyObject.class);
		}
		String dimaterCode = "400301";
		String dimaterName = getBaseNameByBaseCode(dimaterCode, con);
		String heightCode = "400302";
		String heightName = getBaseNameByBaseCode(heightCode, con);
		Statement st = con.createStatement();
		for(SlmCustPhyObject slmCustPhyObj : slmCustPhyList){
			String sqlGetMaxPic = CoreXmlSqlParsersFactory.getSql("QualityMsc.getMaxPic");
			sqlGetMaxPic = StringTool.ReplaceAll(sqlGetMaxPic, "#PIC#", this.pic);
			String indexSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxPic, con, GenericEntity.class).get(0).getMaxValue();
			String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscPhy");
			sql = sql.replaceAll("#ADDCONDITION#", slmCustPhyObj.getAddcondition().replaceAll("'", "''"));
			sql = sql.replaceAll("#ADDSTDCON_CODE#", slmCustPhyObj.getAddstdconCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#ADDSTD_MIN_SIGN#", slmCustPhyObj.getAddstdMinSign().replaceAll("'", "''"));
			sql = sql.replaceAll("#ADDSTD_MIN#", slmCustPhyObj.getAddstdMin().replaceAll("'", "''"));
			sql = sql.replaceAll("#ADDSTD_MAX_SIGN#", slmCustPhyObj.getAddstdMaxSign().replaceAll("'", "''"));
			sql = sql.replaceAll("#ADDSTD_MAX#", slmCustPhyObj.getAddstdMax().replaceAll("'", "''"));
			sql = sql.replaceAll("#ADDPERCENT#", slmCustPhyObj.getAddpercent().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMIN_SIGN2#", slmCustPhyObj.getStdminSign2().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMIN2#", slmCustPhyObj.getStdmin2().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMAX_SIGN2#", slmCustPhyObj.getStdmaxSign2().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMAX2#", slmCustPhyObj.getStdmax2().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_CHOOSE#", slmCustPhyObj.getStdChoose().replaceAll("'", "''"));
			sql = sql.replaceAll("#PIC#", this.pic.replaceAll("'", "''"));
			sql = sql.replaceAll("#INDEX_SEQ#", indexSeq);
			sql = sql.replaceAll("#PHY_CODE_MAX#", slmCustPhyObj.getPhyCodeMax().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_NAME_MAX#", slmCustPhyObj.getPhyNameMax().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_CODE_MIN#", slmCustPhyObj.getPhyCodeMin().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_NAME_MIN#", slmCustPhyObj.getPhyNameMin().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_CODE#", slmCustPhyObj.getPhyCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_NAME#", slmCustPhyObj.getPhyName().replaceAll("'", "''"));
			sql = sql.replaceAll("#ITEM_CODE_F#", slmCustPhyObj.getItemCodeF().replaceAll("'", "''"));
			sql = sql.replaceAll("#ITEM_NAME_F#", slmCustPhyObj.getItemNameF().replaceAll("'", "''"));
			sql = sql.replaceAll("#ITEM_CODE_W#", slmCustPhyObj.getItemCodeW().replaceAll("'", "''"));
			sql = sql.replaceAll("#ITEM_NAME_W#", slmCustPhyObj.getItemNameW().replaceAll("'", "''"));
			sql = sql.replaceAll("#ITEM_CODE_S#", slmCustPhyObj.getItemCodeS().replaceAll("'", "''"));
			sql = sql.replaceAll("#ITEM_NAME_S#", slmCustPhyObj.getItemNameS().replaceAll("'", "''"));
			sql = sql.replaceAll("#GROUP_SEQ#", slmCustPhyObj.getGroupSeq());
			sql = sql.replaceAll("#RESULT_COUNT#", slmCustPhyObj.getResultCount().replaceAll("'", "''"));
			sql = sql.replaceAll("#ISCHECK#", slmCustPhyObj.getIscheck().replaceAll("'", "''"));
			sql = sql.replaceAll("#ISJUDGE#", slmCustPhyObj.getIsjudge().replaceAll("'", "''"));
			sql = sql.replaceAll("#ISQUOTE#", slmCustPhyObj.getIsquote().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_TYPE#", slmCustPhyObj.getPhyType().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_FORMULA#", slmCustPhyObj.getPhyFormula().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMIN_SIGN#", slmCustPhyObj.getStdminSign().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMIN#", slmCustPhyObj.getStdmin().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMAX_SIGN#", slmCustPhyObj.getStdmaxSign().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMAX#", slmCustPhyObj.getStdmax().replaceAll("'", "''"));
			sql = sql.replaceAll("#JUDGE_BASIS#", slmCustPhyObj.getJudgeBasis().replaceAll("'", "''"));
			sql = sql.replaceAll("#DELIVERYSTATE#", slmCustPhyObj.getDeliverystate().replaceAll("'", "''"));
			sql = sql.replaceAll("#MODEL_CODE#", slmCustPhyObj.getModelCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#MODEL_DESC#", slmCustPhyObj.getModelDesc().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMEMO#", slmCustPhyObj.getStdmemo().replaceAll("'", "''"));
			sql = sql.replaceAll("#SIZE_CODE2#", dimaterCode);
			sql = sql.replaceAll("#SIZE_NAME2#", dimaterName);
			sql = sql.replaceAll("#SIZE_MIN_SIGN2#", ">=");
			sql = sql.replaceAll("#SIZE_MIN2#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
			sql = sql.replaceAll("#SIZE_MAX_SIGN2#", "<=");
			sql = sql.replaceAll("#SIZE_MAX2#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
			sql = sql.replaceAll("#SIZE_CODE#", parms.getHeight().equals("") ? "" : heightCode);
			sql = sql.replaceAll("#SIZE_NAME#", parms.getHeight().equals("") ? "" : heightName);
			sql = sql.replaceAll("#SIZE_MIN_SIGN#", parms.getHeight().equals("") ? "" : ">=");
			sql = sql.replaceAll("#SIZE_MIN#", parms.getHeight());
			sql = sql.replaceAll("#SIZE_MAX_SIGN#", parms.getHeight().equals("") ? "" : "<=");
			sql = sql.replaceAll("#SIZE_MAX#", parms.getHeight());
			sql = sql.replaceAll("#SPEC_JG#", parms.getSpecCode().equals("") ? "C000000" : parms.getSpecCode());
			sql = sql.replaceAll("#SPEC_JG_DESC#", parms.getSpecCode().equals("") ? "-1" : parms.getSpecName());
			sql = sql.replaceAll("#CREATE_NAME#", parms.getCreateName());
			sql = sql.replaceAll("#UPDATE_NAME#", slmCustPhyObj.getUpdateName().replaceAll("'", "''"));
			sql = sql.replaceAll("#DELETE_NAME#", slmCustPhyObj.getDeleteName().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALIDFLAG#", slmCustPhyObj.getValidflag().replaceAll("'", "''"));
			sql = sql.replaceAll("#GUID#", slmCustPhyObj.getGuid().replaceAll("'", "''"));
			st.executeUpdate(sql);
		}
		st.close();
		return true;
	}
	
	private boolean setModelToPhy(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.setModeToPhy");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#PIC#", pic);
		sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", parms.getCreateName());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private ArrayList<SlmCustDetectionObject> getSaleCustDetection(Connection con) throws SQLException{
		ArrayList<SlmCustDetectionObject> list = new ArrayList<SlmCustDetectionObject>();
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustDetection");
		sql = sql.replaceAll("#CUST_ALPHA_NO#", parms.getCustAlphaNoDetection());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		while(rs.next()){
			SlmCustDetectionObject slmCustDetectionObj = new SlmCustDetectionObject();
			slmCustDetectionObj.setCoverage(rs.getString("COVERAGE") == null ? "" : rs.getString("COVERAGE"));
			slmCustDetectionObj.setCreateName(rs.getString("CREATE_NAME") == null ? "" : rs.getString("CREATE_NAME"));
			slmCustDetectionObj.setCustAlphaNo(rs.getString("CUST_ALPHA_NO") == null ? "" : rs.getString("CUST_ALPHA_NO"));
			slmCustDetectionObj.setDeleteName(rs.getString("DELETE_NAME") == null ? "" : rs.getString("CUST_ALPHA_NO"));
			slmCustDetectionObj.setDescRate(rs.getString("DESC_RATE") == null ? "" : rs.getString("DESC_RATE"));
			slmCustDetectionObj.setDescVal(rs.getString("DESC_VAL") == null ? "" : rs.getString("DESC_VAL"));
			slmCustDetectionObj.setDic(rs.getString("DIC") == null ? "" : rs.getString("DIC"));
			slmCustDetectionObj.setGrooveDir(rs.getString("GROOVE_DIR") == null ? "" : rs.getString("GROOVE_DIR"));
			slmCustDetectionObj.setGroovePos(rs.getString("GROOVE_POS") == null ? "/" : rs.getString("GROOVE_POS"));
			slmCustDetectionObj.setGroupSeq(rs.getString("GROUP_SEQ") == null ? "" : rs.getString("GROUP_SEQ"));
			slmCustDetectionObj.setLvCode(rs.getString("LV_CODE") == null ? "" : rs.getString("LV_CODE"));
			slmCustDetectionObj.setLvDesc(rs.getString("LV_DESC") == null ? "" : rs.getString("LV_DESC"));
			slmCustDetectionObj.setMemo(rs.getString("MEMO") == null ? "" : rs.getString("MEMO"));
			slmCustDetectionObj.setPhyCode(rs.getString("PHY_CODE") == null ? "" : rs.getString("PHY_CODE"));
			slmCustDetectionObj.setPhyName(rs.getString("PHY_NAME") == null ? "" : rs.getString("PHY_NAME"));
			slmCustDetectionObj.setPositionCode(rs.getString("POSITION_CODE") == null ? "" : rs.getString("POSITION_CODE"));
			slmCustDetectionObj.setPositionDesc(rs.getString("POSITION_DESC") == null ? "" : rs.getString("POSITION_DESC"));
			slmCustDetectionObj.setRate(rs.getString("RATE") == null ? "" : rs.getString("RATE"));
			slmCustDetectionObj.setStdDesc(rs.getString("STD_DESC") == null ? "" : rs.getString("STD_DESC"));
			slmCustDetectionObj.setUpdateName(rs.getString("UPDATE_NAME") == null ? "" : rs.getString("UPDATE_NAME"));
			slmCustDetectionObj.setValidflag(rs.getString("VALIDFLAG") == null ? "" : rs.getString("VALIDFLAG"));
			slmCustDetectionObj.setXh(rs.getString("XH") == null ? "" : rs.getString("XH"));
			list.add(slmCustDetectionObj);
		}
		rs.close();
		st.close();
		return list;
	}
	
	private boolean createMsDetection(String dic, ArrayList<Object> insrtDetectionData, Connection con) throws SQLException{
		ArrayList<SlmCustDetectionObject> slmCustDetectionList;
		if(dic.equals("")){
			slmCustDetectionList = getSaleCustDetection(con);
		}else{
			slmCustDetectionList = ConvertHashTabToEntity(insrtDetectionData, SlmCustDetectionObject.class);
		}
		Statement st = con.createStatement();
		for(SlmCustDetectionObject slmCustDetectionObj : slmCustDetectionList){
			String sqlGetMaxDic = CoreXmlSqlParsersFactory.getSql("QualityMsc.getMaxDic");
			sqlGetMaxDic = StringTool.ReplaceAll(sqlGetMaxDic, "#DIC#", this.dic);
			String indexSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxDic, con, GenericEntity.class).get(0).getMaxValue();
			String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscDetection");
			sql = sql.replaceAll("#RATE#", slmCustDetectionObj.getRate().replaceAll("'", "''"));
			sql = sql.replaceAll("#DESC_RATE#", slmCustDetectionObj.getDescRate().replaceAll("'", "''"));
			sql = sql.replaceAll("#DESC_VAL#", slmCustDetectionObj.getDescVal().replaceAll("'", "''"));
			sql = sql.replaceAll("#GROUP_SEQ#", slmCustDetectionObj.getGroupSeq().replaceAll("'", "''"));
			sql = sql.replaceAll("#DIC#", this.dic.replaceAll("'", "''"));
			sql = sql.replaceAll("#XH#", indexSeq);
			sql = sql.replaceAll("#PHY_CODE#", slmCustDetectionObj.getPhyCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#PHY_NAME#", slmCustDetectionObj.getPhyName().replaceAll("'", "''"));
			sql = sql.replaceAll("#POSITION_CODE#", slmCustDetectionObj.getPositionCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#POSITION_DESC#", slmCustDetectionObj.getPositionDesc().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_DESC#", slmCustDetectionObj.getStdDesc().replaceAll("'", "''"));
			sql = sql.replaceAll("#LV_CODE#", slmCustDetectionObj.getLvCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#GROOVE_POS#", slmCustDetectionObj.getGroovePos().replaceAll("'", "''"));
			sql = sql.replaceAll("#GROOVE_DIR#", slmCustDetectionObj.getGrooveDir().replaceAll("'", "''"));
			sql = sql.replaceAll("#LV_DESC#", slmCustDetectionObj.getLvDesc().replaceAll("'", "''"));
			sql = sql.replaceAll("#COVERAGE#", slmCustDetectionObj.getCoverage().replaceAll("'", "''"));
			sql = sql.replaceAll("#CREATE_NAME#", parms.getCreateName());
			sql = sql.replaceAll("#UPDATE_NAME#", slmCustDetectionObj.getUpdateName().replaceAll("'", "''"));
			sql = sql.replaceAll("#DELETE_NAME#", slmCustDetectionObj.getDeleteName().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALIDFLAG#", slmCustDetectionObj.getValidflag().replaceAll("'", "''"));
			sql = sql.replaceAll("#MIN_D#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
			sql = sql.replaceAll("#MAX_D#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
			sql = sql.replaceAll("#MIN_H#", parms.getHeight());
			sql = sql.replaceAll("#MAX_H#", parms.getHeight());
			sql = sql.replaceAll("#MEMO#", slmCustDetectionObj.getMemo().replaceAll("'", "''"));
			st.executeUpdate(sql);
		}
		st.close();
		return true;
	}
	
	private boolean setModelToDetection(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.setModeToDetection");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#DIC#", dic);
		sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", parms.getCreateName());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private ArrayList<SlmCustSpecObject> getSaleCustSpec(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustSpec");
		sql = sql.replaceAll("#CUST_ALPHA_NO#", parms.getCustAlphaNoSpec());
		ArrayList<SlmCustSpecObject> listCustSpec = EntityTool.getEntitysBySqlNoClsCon(sql, con, SlmCustSpecObject.class);
		return listCustSpec;
	}
	
	private boolean createMscSpec(String sic, ArrayList<Object> insrtSpecData, Connection con) throws SQLException{
		ArrayList<SlmCustSpecObject> slmCustSpecList;
		if(sic.equals("")){
			slmCustSpecList = getSaleCustSpec(con);
		}else{
			slmCustSpecList = ConvertHashTabToEntity(insrtSpecData, SlmCustSpecObject.class);
		}
		String dimaterCode = "400301";
		String dimaterName = getBaseNameByBaseCode(dimaterCode, con);
		String heightCode = "400302";
		String heightName = getBaseNameByBaseCode(heightCode, con);
		Statement st = con.createStatement();
		for(SlmCustSpecObject slmCustSpecObj : slmCustSpecList){
			String sqlGetMaxSic = CoreXmlSqlParsersFactory.getSql("QualityMsc.getMaxSic");
			sqlGetMaxSic = StringTool.ReplaceAll(sqlGetMaxSic, "#SIC#", this.sic);
			String indexSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxSic, con, GenericEntity.class).get(0).getMaxValue();
			String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscSpec");
			sql = sql.replaceAll("#SIC#", this.sic);
			sql = sql.replaceAll("#INDEX_SEQ#", indexSeq);
			sql = sql.replaceAll("#BIAS_CODE#", slmCustSpecObj.getBiasCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#BIAS_NAME#", slmCustSpecObj.getBiasName().replaceAll("'", "''"));
			sql = sql.replaceAll("#LV#", slmCustSpecObj.getLv().replaceAll("'", "''"));
			sql = sql.replaceAll("#BIAS_CODE_Z#", dimaterCode);
			sql = sql.replaceAll("#BIAS_NAME_Z#", dimaterName);
			sql = sql.replaceAll("#ZMIN_SIGN#", ">=");
			sql = sql.replaceAll("#ZMIN#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
			sql = sql.replaceAll("#ZMAX_SIGN#", "<=");
			sql = sql.replaceAll("#ZMAX#", parms.getDimater().equals("") ? "-1" : parms.getDimater());
			sql = sql.replaceAll("#BIAS_CODE_C#", parms.getHeight().equals("") ? "" : heightCode);
			sql = sql.replaceAll("#BIAS_NAME_C#", parms.getHeight().equals("") ? "" : heightName);
			sql = sql.replaceAll("#CMIN_SIGN#", parms.getHeight().equals("") ? "" : ">=");
			sql = sql.replaceAll("#CMIN#", parms.getHeight());
			sql = sql.replaceAll("#CMAX_SIGN#", parms.getHeight().equals("") ? "" : "<=");
			sql = sql.replaceAll("#CMAX#", parms.getHeight());
			sql = sql.replaceAll("#BIAS_CODE_S#", "");
			sql = sql.replaceAll("#BIAS_NAME_S#", "");
			sql = sql.replaceAll("#SMIN_SIGN#", "");
			sql = sql.replaceAll("#SMIN#", "");
			sql = sql.replaceAll("#SMAX_SIGN#", "");
			sql = sql.replaceAll("#SMAX#", "");
			sql = sql.replaceAll("#ISCHECK#", slmCustSpecObj.getIscheck().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MIN_VAL#", slmCustSpecObj.getStdMinVal().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MAX_VAL#", slmCustSpecObj.getStdMaxVal().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MIN_IN#", slmCustSpecObj.getStdMinIn().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MAX_IN#", slmCustSpecObj.getStdMaxIn().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MIN_PERCENT#", slmCustSpecObj.getStdMinPercent().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MAX_PERCENT#", slmCustSpecObj.getStdMaxPercent().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MIN_FORMULA#", slmCustSpecObj.getStdMinFormula().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MAX_FORMULA#", slmCustSpecObj.getStdMaxFormula().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MIN_FORMULA_V#", slmCustSpecObj.getStdMinFormulaV().replaceAll("'", "''"));
			sql = sql.replaceAll("#STD_MAX_FORMULA_V#", slmCustSpecObj.getStdMaxFormulaV().replaceAll("'", "''"));
			sql = sql.replaceAll("#STDMEMO#", slmCustSpecObj.getStdmemo().replaceAll("'", "''"));
			sql = sql.replaceAll("#CREATE_NAME#", parms.getCreateName());
			sql = sql.replaceAll("#UPDATE_NAME#", slmCustSpecObj.getUpdateName().replaceAll("'", "''"));
			sql = sql.replaceAll("#DELETE_NAME#", slmCustSpecObj.getDeleteName().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALIDFLAG#", slmCustSpecObj.getValidflag());
			st.executeUpdate(sql);
		}
		st.close();
		return true;
	}
	
	private boolean setModelToSpec(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.setModeToSpec");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#SIC#", sic);
		sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", parms.getCreateName());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private ArrayList<SlmCustWaterObject> getSaleCustWater(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustWater");
		sql = sql.replaceAll("#CUST_ALPHA_NO#", parms.getCustAlphaNoWater());
		ArrayList<SlmCustWaterObject> list = EntityTool.getEntitysBySqlNoClsCon(sql, con, SlmCustWaterObject.class);
		
		return list;
	}
	
	private boolean createMscWater(String wic, ArrayList<Object> insrtWaterData, Connection con) throws SQLException{
		ArrayList<SlmCustWaterObject> slmCustWaterList;
		if(wic.equals("")){
			slmCustWaterList = getSaleCustWater(con);
		}else{
			slmCustWaterList = ConvertHashTabToEntity(insrtWaterData, SlmCustWaterObject.class);
		}
		Statement st = con.createStatement();
		for(SlmCustWaterObject slmCustWaterObj : slmCustWaterList){
			String sqlGetMaxWic = CoreXmlSqlParsersFactory.getSql("QualityMsc.getMaxWic");
			sqlGetMaxWic = StringTool.ReplaceAll(sqlGetMaxWic, "#WIC#", this.wic);
			String indexSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxWic, con, GenericEntity.class).get(0).getMaxValue();
			String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscWater");
			sql = sql.replaceAll("#GET_MAXVALUE#", slmCustWaterObj.getGetMaxvalue().replaceAll("'", "''"));
			sql = sql.replaceAll("#GET_MINVALUE#", slmCustWaterObj.getGetMinvalue().replaceAll("'", "''"));
			sql = sql.replaceAll("#WIC#", this.wic.replaceAll("'", "''"));
			sql = sql.replaceAll("#XH#", indexSeq);
			sql = sql.replaceAll("#PRESSURE_Y#", slmCustWaterObj.getPressureY().replaceAll("'", "''"));
			sql = sql.replaceAll("#PRESSURE#", slmCustWaterObj.getPressure().replaceAll("'", "''"));
			sql = sql.replaceAll("#FORMULA#", slmCustWaterObj.getFormula().replaceAll("'", "''"));
			sql = sql.replaceAll("#SAVE_TIME#", slmCustWaterObj.getSaveTime().replaceAll("'", "''"));
			sql = sql.replaceAll("#CREATE_NAME#", parms.getCreateName());
			sql = sql.replaceAll("#UPDATE_NAME#", slmCustWaterObj.getUpdateName().replaceAll("'", "''"));
			sql = sql.replaceAll("#DELETE_NAME#", slmCustWaterObj.getDeleteName().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALIDFLAG#", slmCustWaterObj.getValidflag().replaceAll("'", "''"));
			sql = sql.replaceAll("#MEMO#", "".replaceAll("'", "''"));
			st.executeUpdate(sql);
		}
		st.close();
		return true;
	}
	
	private boolean setModelToWater(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.setModeToWater");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#WIC#", wic);
		sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", parms.getCreateName());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private ArrayList<SlmCustProcessEntity> getSaleCustProcess(Connection con) throws SQLException{
		ArrayList<SlmCustProcessEntity> list = new ArrayList<SlmCustProcessEntity>();
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustProcess");
		sql = sql.replaceAll("#CUST_ALPHA_NO#", parms.getCustAlphaNoChem());
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		while(rs.next()){
			SlmCustProcessEntity slmCustProcessObj = new SlmCustProcessEntity();
			slmCustProcessObj.setCreateName(rs.getString("CREATE_NAME") == null ? "" : rs.getString("CREATE_NAME"));
			slmCustProcessObj.setCustAlphaNo(rs.getString("CUST_ALPHA_NO") == null ? "" : rs.getString("CUST_ALPHA_NO"));
			slmCustProcessObj.setDeleteName(rs.getString("DELETE_NAME") == null ? "" : rs.getString("DELETE_NAME"));
			slmCustProcessObj.setGic(rs.getString("GIC") == null ? "" : rs.getString("GIC"));
			slmCustProcessObj.setGroupSeq(rs.getString("GROUP_SEQ") == null ? "" : rs.getString("GROUP_SEQ"));
			slmCustProcessObj.setProcessCdoe(rs.getString("PROCESS_CDOE") == null ? "" : rs.getString("PROCESS_CDOE"));
			slmCustProcessObj.setProcessCdoeC(rs.getString("PROCESS_CDOE_C") == null ? "" : rs.getString("PROCESS_CDOE_C"));
			slmCustProcessObj.setProcessDesc(rs.getString("PROCESS_DESC") == null ? "" : rs.getString("PROCESS_DESC"));
			slmCustProcessObj.setProcessDescC(rs.getString("PROCESS_DESC_C") == null ? "" : rs.getString("PROCESS_DESC_C"));
			slmCustProcessObj.setStationCode(rs.getString("STATION_CODE") == null ? "" : rs.getString("STATION_CODE"));
			slmCustProcessObj.setStationDesc(rs.getString("STATION_DESC") == null ? "" : rs.getString("STATION_DESC"));
			slmCustProcessObj.setUpdateName(rs.getString("UPDATE_NAME") == null ? "" : rs.getString("UPDATE_NAME"));
			slmCustProcessObj.setValidflag(rs.getString("VALIDFLAG") == null ? "" : rs.getString("VALIDFLAG"));
			slmCustProcessObj.setValueMemo(rs.getString("VALUE_MEMO") == null ? "" : rs.getString("VALUE_MEMO"));
			slmCustProcessObj.setValueNum(rs.getString("VALUE_NUM") == null ? "" : rs.getString("VALUE_NUM"));
			slmCustProcessObj.setValueText(rs.getString("VALUE_TEXT") == null ? "" : rs.getString("VALUE_TEXT"));
			slmCustProcessObj.setXh(rs.getString("XH") == null ? "" : rs.getString("XH"));
			list.add(slmCustProcessObj);
		}
		rs.close();
		st.close();
		return list;
	}
	
	private boolean createMscProcess(String gic, ArrayList<Object> insrtProcessData, Connection con) throws SQLException{
		Statement st = con.createStatement();
		ArrayList<SlmCustProcessEntity> slmCustProcessList;
		if(gic.equals("")){
			slmCustProcessList = getSaleCustProcess(con);
		}else{
			slmCustProcessList = ConvertHashTabToEntity(insrtProcessData, SlmCustProcessEntity.class);
		}
		for(SlmCustProcessEntity slmCustProcessEntity : slmCustProcessList){
			String sqlGetMaxGic = CoreXmlSqlParsersFactory.getSql("QualityMsc.getMaxGic");
			sqlGetMaxGic = StringTool.ReplaceAll(sqlGetMaxGic, "#GIC#", this.gic);
			String indexSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxGic, con, GenericEntity.class).get(0).getMaxValue();
			String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.insertMscProcess");
			sql = sql.replaceAll("#GIC#", this.gic.replaceAll("'", "''"));
			sql = sql.replaceAll("#XH#", indexSeq);
			sql = sql.replaceAll("#STATION_CODE#", slmCustProcessEntity.getStationCode().replaceAll("'", "''"));
			sql = sql.replaceAll("#STATION_DESC#", slmCustProcessEntity.getStationDesc().replaceAll("'", "''"));
			sql = sql.replaceAll("#PROCESS_CDOE#", slmCustProcessEntity.getProcessCdoe().replaceAll("'", "''"));
			sql = sql.replaceAll("#PROCESS_DESC#", slmCustProcessEntity.getProcessDesc().replaceAll("'", "''"));
			sql = sql.replaceAll("#PROCESS_CDOE_C#", slmCustProcessEntity.getProcessCdoeC().replaceAll("'", "''"));
			sql = sql.replaceAll("#PROCESS_DESC_C#", slmCustProcessEntity.getProcessDescC().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALUE_TEXT#", slmCustProcessEntity.getValueText().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALUE_NUM#", slmCustProcessEntity.getValueNum().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALUE_MEMO#", slmCustProcessEntity.getValueMemo().replaceAll("'", "''"));
			sql = sql.replaceAll("#GROUP_SEQ#", slmCustProcessEntity.getGroupSeq().replaceAll("'", "''"));
			sql = sql.replaceAll("#CREATE_NAME#", parms.getCreateName());
			sql = sql.replaceAll("#UPDATE_NAME#", slmCustProcessEntity.getUpdateName().replaceAll("'", "''"));
			sql = sql.replaceAll("#DELETE_NAME#", slmCustProcessEntity.getDeleteName().replaceAll("'", "''"));
			sql = sql.replaceAll("#VALIDFLAG#", slmCustProcessEntity.getValidflag().replaceAll("'", "''"));
			sql = sql.replaceAll("#MEMO#", "".replaceAll("'", "''"));
			st.executeUpdate(sql);
		}
		st.close();
		return true;
	}
	
	private boolean setModelToProcess(Connection con) throws SQLException{
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.setModeToProcess");
		sql = StringTool.ReplaceAll(sql, "#MODEL_CODE#", parms.getModel());
		sql = StringTool.ReplaceAll(sql, "#MODEL_DESC#", modeDesc);
		sql = StringTool.ReplaceAll(sql, "#GIC#", gic);
		sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", parms.getCreateName());
		Statement st = con.createStatement();
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private boolean updateCustAlphaState(Connection con) throws SQLException{
		Statement st = con.createStatement();
		CoreOrderSpecialInfo specialInfo = new CoreOrderSpecialInfo();
		SlmCustAlphaEntity custAlphaEntity = new SlmCustAlphaEntity();
		custAlphaEntity.setCustAlphaNo(parms.getCustAlphaNoChem());
		custAlphaEntity.setCreateName(parms.getCreateName());
		custAlphaEntity.setCustAlphaSts("S");
		custAlphaEntity.setReviewFRs("");
		String sql = specialInfo.getUpdateCustAlphaStateSql(custAlphaEntity);
		st.executeUpdate(sql);
		st.close();
		return true;
	}
	
	private SlmOrdDesignDeptEntity getDesignDept(Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.getDesignDeptByOrdLnPk");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", parms.getOrdLnPk());
		ArrayList<SlmOrdDesignDeptEntity> listDesignDept = EntityTool.getEntitysBySqlNoClsCon(sql, con, SlmOrdDesignDeptEntity.class);
		
		return listDesignDept.get(0);
	}
	
	private int getSaleCustChemCnt(Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustChemCnt");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNo());
		ArrayList<GenericEntity> listCustChem = EntityTool.getEntitysBySqlNoClsCon(sql, con, GenericEntity.class);
		
		return Integer.parseInt(listCustChem.get(0).getCount());
	}
	
	private int getSaleCustPhyCnt(Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustPhyCnt");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNo());
		ArrayList<GenericEntity> listCustPhy = EntityTool.getEntitysBySqlNoClsCon(sql, con, GenericEntity.class);
		
		return Integer.parseInt(listCustPhy.get(0).getCount());
	}
	
	private int getSaleCustSpecCnt(Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustSpecCnt");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNo());
		ArrayList<GenericEntity> listCustSpec = EntityTool.getEntitysBySqlNoClsCon(sql, con, GenericEntity.class);
		
		return Integer.parseInt(listCustSpec.get(0).getCount());
	}
	
	private int getSaleCustDetectionCnt(Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustDetectionCnt");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNo());
		ArrayList<GenericEntity> listCustDetection = EntityTool.getEntitysBySqlNoClsCon(sql, con, GenericEntity.class);
		
		return Integer.parseInt(listCustDetection.get(0).getCount());
	}
	
	private int getSaleCustWaterCnt(Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustWaterCnt");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNo());
		ArrayList<GenericEntity> listCustWater = EntityTool.getEntitysBySqlNoClsCon(sql, con, GenericEntity.class);
		
		return Integer.parseInt(listCustWater.get(0).getCount());
	}
	
	private int getSaleCustProcessCnt(Connection con){
		String sql = CoreXmlSqlParsersFactory.getSql("QualityMsc.querySaleCustProcessCnt");
		sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", parms.getCustAlphaNo());
		ArrayList<GenericEntity> listCustProcess = EntityTool.getEntitysBySqlNoClsCon(sql, con, GenericEntity.class);
		
		return Integer.parseInt(listCustProcess.get(0).getCount());
	}
}
