package com.steering.pss.qcm;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import CoreFS.Util.StringUtils;
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.comm.tools.TransctionTool;
import com.steering.pss.qcm.model.*;
import com.steering.pss.sale.order.model.CraftOrdDesignEntity;
import com.steering.pss.sale.order.model.MscGradeRSpecEntity;

import java.sql.Connection;
import java.util.ArrayList;

/**
 * 冶金规范
 * @author Cx
 */
public class CoreFrmProPSCMSC2 extends DBCommon {

    /**
     * 查询产品规范
     * @param list 参数
     * @return 平台对象
     */
    public CoreReturnObject queryComPsc(ArrayList<String> list) {
    	 String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryCom_Psc2");
    	 sql = StringTool.ReplaceAll(sql, "#PRODUCCODE#", list.get(0));
    	 sql = StringTool.ReplaceAll(sql, "#STD_NAME#", list.get(1));
    	 sql = StringTool.ReplaceAll(sql, "#STEELNAME#", list.get(2));
    	 sql = StringTool.ReplaceAll(sql, "#PSC#", list.get(3));
    	 sql = StringTool.ReplaceAll(sql, "#MSC#", list.get(4));
    	 sql = StringTool.ReplaceAll(sql, "#UNIT_DESC#", list.get(5));
    	 sql = StringTool.ReplaceAll(sql, "#USE_DESC#", list.get(6));
         return this.getData(sql);
    }

    /**
     * 根据产品规范码查询冶金规范
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryComMsc(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.queryCom_Msc", list.toArray());
    }

    /**
     * 加载Alpha
     * @return ojb
     */
    public CoreReturnObject loadAlpha() {
        return getDataBySqlID("CoreFrmProPSCMSC2.loadAlpha");
    }

    /**
     * 加载Msc
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject loadMsc(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.loadMsc", list.toArray());
    }

    /**
     * 查询客户
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryClient(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.QueryClient", list.toArray());
    }

    /**
     * 查询MSC所属的标准名称和标准协会（用于树形结构）
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryStd_Name_Style(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.QueryStd_Name_Style", list
                .toArray());
    }

    /**
     * 查询冶金规范项目
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryComMscItem(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.queryCom_Msc_Item", list
                .toArray());
    }

    /**
     * 查询最大的冶金规范编码
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMaxMscCode(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.queryMaxMscCode", list
                .toArray());
    }
    
    /**
     * 查询最大的冶金规范编码
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMaxMscCode2(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.queryMaxMscCode2", list
                .toArray());
    }
    
    /**
     * 查询最大的Alpha冶金规范编码
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscAlphaCode(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.queryMaxMscAlphaCode", list
                .toArray());
    }
    
    /**
     * 查询最大的Alpha冶金规范编码
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscAlphaCode2(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC2.queryMaxMscAlphaCode2", list
                .toArray());
    }
    
    /**
     * 是否完整的MSC
     * @param msc
     * @return
     */
    public CoreReturnObject isCompleteMsc(String msc){
        String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.isCompleteMsc");
        sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
        return this.getData(sql);
    }
    
    /**
     * 是否完整的MSC
     * @param msc
     * @return
     */
    public CoreReturnObject isCompleteMsc2(String msc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.isCompleteMsc2");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
        return this.getData(sql);
    }

    /**
     * 查询服务器时间
     * @return obj
     */
    public CoreReturnObject queryServerDate() {
        return getDataBySqlID("CoreFrmProPSCMSC2.queryServerDate");
    }
    
    /**
     * 是否存在Alpha
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject isExistAlpha(ArrayList<String> list){
        return getDataBySqlID("CoreFrmProPSCMSC2.isExistAlpha", list.toArray());
    }
    
    /**
     * 查询品名类型
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryProductType(ArrayList<String> list){
        return getDataBySqlID("CoreFrmProPSCMSC2.queryProductType", list.toArray());
    }

    /**
     * 新增产品规范与冶金规范关系
     * @param list 冶金规范和产品规范关系表参数
     * @param list2 冶金规范表参数
     * @param list3 冶金规范项目表参数
     * @param list4 复制参数
     * @return obj
     */
    public CoreReturnObject insertComPscRMsc(ArrayList<String> list,
            ArrayList<String> list2, ArrayList<String> list4) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        if (list.size() > 0) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreFrmProPSCMSC2.insertCom_Psc_R_Msc"));
            parmlist.add(list.toArray());
        }
        if (list2.size() > 0) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreFrmProPSCMSC.insertMsc"));
            parmlist.add(list2.toArray());
        }
        
        if (list4.size() > 0) {
            // sqllist.add(CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.copyMscData"));
            // parmlist.add(list4.toArray());
        }
        return getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist,
                parmlist);
    }

    /**
     * 更新冶金规范
     * @param list 冶金规范表参数
     * @param list2 冶金规范项目表参数
     * @param list3 复制参数
     * @return
     */
    public CoreReturnObject updateMsc(ArrayList<String> list, ArrayList<String> list3) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        if (list.size() > 0) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreFrmProPSCMSC.updateMsc"));
            parmlist.add(list.toArray());
        }
        if (list3.size() > 0) {
            // sqllist.add(CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.copyMscData"));
            // parmlist.add(list3.toArray());
        }
        return getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist,
                parmlist);
    }

    /**
     * 作废或者恢复冶金规范
     * @param list 冶金规范表参数
     * @param list2 冶金规范项目表参数
     * @return obj
     */
    public CoreReturnObject deleteOrResumeMsc(ArrayList<String> list,  ArrayList<String> list3) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        if (list.size() > 0) {
        	String validflag2 = "";
        	String validflag = list.get(0);
        	if(validflag.equals("A")){
        		validflag2 = "1";
        	}
        	else if(validflag.equals("B")){
        		validflag2 = "2";
        	}
        	else if(validflag.equals("C")){
        		validflag2 = "3";
        	}
        	else if(validflag.equals("D")){
        		validflag2 = "0";
        	}
        	
        	String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreFrmProPSCMSC.deleteOrResumeMsc");
        	sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", validflag);
        	sql = StringTool.ReplaceAll(sql, "#VALIDFLAG2#", validflag2);
        	sql = StringTool.ReplaceAll(sql, "#MSC#", list.get(1));
        	sql = StringTool.ReplaceAll(sql, "#NAME#", list.get(2));
        	sql = StringTool.ReplaceAll(sql, "#DELETE_NAME#", list.get(2));
        	sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", list.get(2));
        	sql = StringTool.ReplaceAll(sql, "#ACTION_TYPE#", list.get(3));
            sqllist.add(sql);
            parmlist.add(new Object[]{});
        }
        
        if(list3.size() > 0){
        	sqllist.add(CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.updateMscMemo"));
        	parmlist.add(list3.toArray());
        }
        return getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist,
                parmlist);
    }
    
    /**
     * 更新内控状态位。
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject updateMscNkFlg(ArrayList<String> list){
    	CoreReturnObject obj = new CoreReturnObject();
    	if(list.size() == 0){
    		obj.setResult(1);
    		return obj;
    	}
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.updateMscNkFlg");
    	sql = StringTool.ReplaceAll(sql, "#VALIDFLAG_NK#", list.get(0));
    	sql = StringTool.ReplaceAll(sql, "#AUDIT_NAME_NK#", list.get(1));
    	sql = StringTool.ReplaceAll(sql, "#AUDIT_TIME#", list.get(2));
    	sql = StringTool.ReplaceAll(sql, "#REMARK_NK#", list.get(3));
    	sql = StringTool.ReplaceAll(sql, "#MSC#", list.get(4));
    	
    	String sqlUpdateBackLogNkFlg = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.updateBackLogNkFlg");
    	sqlUpdateBackLogNkFlg = StringTool.ReplaceAll(sqlUpdateBackLogNkFlg, "#VALIDFLAG_NK#", list.get(0));
    	sqlUpdateBackLogNkFlg = StringTool.ReplaceAll(sqlUpdateBackLogNkFlg, "#UPDATE_NAME#", list.get(1));
    	sqlUpdateBackLogNkFlg = StringTool.ReplaceAll(sqlUpdateBackLogNkFlg, "#MSC#", list.get(4));
    	ArrayList<String> sqllist = new ArrayList<String>();
    	sqllist.add(sql);
    	sqllist.add(sqlUpdateBackLogNkFlg);
    	obj = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    	return obj;
    }
    
    /**
     * 是否可以作废MSC
     * @param msc MSC
     * @return obj
     */
    public CoreReturnObject isDeleteMsc(String msc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.isDeleteMsc");
    	sql = sql.replaceAll("MSC:", msc);
    	return this.getData(sql);
    }

    /**
     * 查询冶金规范产线
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscBackLog(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMscBackLog", list
                .toArray());
    }

    /**
     * 查询最大冶金规范产线号
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMaxMscBackLogPline(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMaxMscBackLogPline", list
                .toArray());
    }

    /**
     * 新增冶金规范产线（包括产线下面的所有业务，是整个事务新增）
     * @param list1 冶金规范产线表参数
     * @param list2 冶金规范工序表参数
     * @param list3 冶金规范工序点参数
     * @return obj
     */
    public CoreReturnObject insertMscBackLog(ArrayList<String> list1,
            ArrayList<ArrayList<String>> list2,
            ArrayList<ArrayList<String>> list3) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sql1 = CoreXmlSqlParsersFactory
                .getSql("CoreFrmProPSCMSC.insertMscBackLog");
        String sqlDeleteProcess = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteBaseProcess");
        String sql2 = CoreXmlSqlParsersFactory
                .getSql("CoreFrmProPSCMSC.insertMscProcess");
        String sqlDeleteStation = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteMscStation");
        String sql3 = CoreXmlSqlParsersFactory
                .getSql("CoreFrmProPSCMSC.insertMsc_Station");
        String sql4 = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.copyMustStation");
        sqllist.add(sql1);
        parmlist.add(list1.toArray());

        if(list2.size() > 0){
            sqllist.add(sqlDeleteProcess);
            parmlist.add(new Object[]{list1.get(0), list1.get(1)});
        }
        for (int i = 0; i < list2.size(); i++) {
            sqllist.add(sql2);
            parmlist.add(list2.get(i).toArray());
            
            if(list2.get(i).get(0).equals("DELETE")){
            	sqllist.add(sqlDeleteStation);
            	parmlist.add(new Object[]{list2.get(i).get(1), list2.get(i).get(2), list2.get(i).get(5)});
            }
        }

        String tempProcessCode = "";
        for (int i = 0; i < list3.size(); i++) {
        	String processCode = list3.get(i).get(4);
        	if(processCode.equals(tempProcessCode) == false)
        	{
	        	sqllist.add(sqlDeleteStation);
	            parmlist.add(new Object[]{list3.get(i).get(1), list3.get(i).get(2), list3.get(i).get(4)} );
	            tempProcessCode = processCode;
        	}
        	
            if(list3.get(i).size() == 6){
                sqllist.add(sql4);
            }
            else {
                sqllist.add(sql3);
            }            
            parmlist.add(list3.get(i).toArray());
        }
        CoreReturnObject cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist,
                parmlist);
        
        if(list2.size() > 0){
            String sqlDelMscStdCraft = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteMscStdCraft");
            sqlDelMscStdCraft = StringTool.ReplaceAll(sqlDelMscStdCraft, "#MSC#", list1.get(0));
            sqlDelMscStdCraft = StringTool.ReplaceAll(sqlDelMscStdCraft, "#MSC_PLINE#", list1.get(1));
            this.setData(sqlDelMscStdCraft);
        }
        
        return cro;
    }
   

    /**
     * 更新冶金规范产线（包括产线下面的所有业务，是整个事务新增
     * @param list1 冶金规范产线表参数
     * @param list2 冶金规范工序表参数
     * @param list3 冶金规范工序点参数
     * @return obj
     */
    public CoreReturnObject updateMscBackLog(ArrayList<String> list1,
            ArrayList<ArrayList<String>> list2,
            ArrayList<ArrayList<String>> list3, String ordLnPk) {
    	String sqlIsExistDesignPlControl = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.isExistSlmOrdDesignPlControl");
    	sqlIsExistDesignPlControl = StringTool.ReplaceAll(sqlIsExistDesignPlControl, "#MSC#", list1.get(6));
    	sqlIsExistDesignPlControl = StringTool.ReplaceAll(sqlIsExistDesignPlControl, "#MSC_PLINE#", list1.get(7));
    	sqlIsExistDesignPlControl = StringTool.ReplaceAll(sqlIsExistDesignPlControl, "#ORD_LN_PK#", ordLnPk);
    	Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    	ArrayList<GenericEntity> isExistSlmOrdDesignPlControl = EntityTool.getEntitysBySql(
    			sqlIsExistDesignPlControl, con, GenericEntity.class);
    	if(Integer.parseInt(isExistSlmOrdDesignPlControl.get(0).getCount()) > 0){
    		boolean result = canUpdateBackLog(list2, list3, ordLnPk);
    		if(!result){
    			CoreReturnObject cro = new CoreReturnObject();
    			cro.setV_errCode(-1);
    			cro.setV_errMsg("该制程已列入MPS，不能修改工序和工序点！");
    			return cro;
    		}
    	}
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sql1 = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.updateMscBackLog");
        String sqlDeleteProcess = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteBaseProcess");
        String sql2 = CoreXmlSqlParsersFactory
                .getSql("CoreFrmProPSCMSC.insertMscProcess");
        String sqlDeleteStation = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteMscStation");
        String sql3 = CoreXmlSqlParsersFactory
                .getSql("CoreFrmProPSCMSC.insertMsc_Station");
        sqllist.add(sql1);
        parmlist.add(list1.toArray());

        if(list2.size() > 0){
        	sqllist.add(sqlDeleteProcess);
            parmlist.add(new Object[]{list1.get(6), list1.get(7)} );
        }
        for (int i = 0; i < list2.size(); i++) {
            sqllist.add(sql2);
            parmlist.add(list2.get(i).toArray());
            
            if(list2.get(i).get(0).equals("DELETE")){
            	sqllist.add(sqlDeleteStation);
            	parmlist.add(new Object[]{list2.get(i).get(1), list2.get(i).get(2), list2.get(i).get(5)});
            }
        }

        String tempProcessCode = "";
        for (int i = 0; i < list3.size(); i++) {
        	String processCode = list3.get(i).get(4);
        	if(processCode.equals(tempProcessCode) == false)
        	{
	        	sqllist.add(sqlDeleteStation);
	            parmlist.add(new Object[]{list3.get(i).get(1), list3.get(i).get(2), list3.get(i).get(4)} );
	            tempProcessCode = processCode;
        	}
            sqllist.add(sql3);
            parmlist.add(list3.get(i).toArray());
        }
        
        CoreReturnObject cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist,
                parmlist);
        
        if(list2.size() > 0){
            String sqlDelMscStdCraft = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteMscStdCraft");
            sqlDelMscStdCraft = StringTool.ReplaceAll(sqlDelMscStdCraft, "#MSC#", list1.get(6));
            sqlDelMscStdCraft = StringTool.ReplaceAll(sqlDelMscStdCraft, "#MSC_PLINE#", list1.get(7));
            this.setData(sqlDelMscStdCraft);
        }
        
        return cro;
    }
    
    /**
     * 修改工艺文件路径
     * @param msc
     * @param mscPline
     * @param craftPath
     * @return
     */
    public CoreReturnObject updateCraftPath(String msc, String mscPline, String craftPath){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.updateCraftPath");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	sql = StringTool.ReplaceAll(sql, "#MSC_PLINE#", mscPline);
    	sql = StringTool.ReplaceAll(sql, "#CRAFT_PATH#", craftPath);
    	return this.setData(sql);
    }
    
    /**
     * 是否可以修改制程
     * @param list2
     * @param list3
     * @return
     */
    public boolean canUpdateBackLog(ArrayList<ArrayList<String>> list2,
            ArrayList<ArrayList<String>> list3, String ordLnPk){
    	if(list2.size() == 0){
    		return false;
    	}
    	Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    	String sqlComMscProcessTotalCnt = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.comMscProcessTotalCnt");
    	sqlComMscProcessTotalCnt = StringTool.ReplaceAll(sqlComMscProcessTotalCnt, "#MSC#", list2.get(0).get(1));
    	sqlComMscProcessTotalCnt = StringTool.ReplaceAll(sqlComMscProcessTotalCnt, "#MSC_PLINE#", list2.get(0).get(2));
    	ArrayList<GenericEntity> processTotalCntList = EntityTool.getEntitysBySql(sqlComMscProcessTotalCnt, con, GenericEntity.class);
    	int list2Cnt = 0;
    	for(int i = 0; i < list2.size(); i++){
    		if(!list2.get(i).get(0).equals("DELETE")){
    			list2Cnt++;
    		}
    	}
    	if(Integer.parseInt(processTotalCntList.get(0).getCount()) != list2Cnt){
    		return false;
    	}
    	for(int i = 0; i < list2.size(); i++){
    		if(list2.get(i).get(0).equals("DELETE")) continue;
    		String sqlIsSameComMscProcess = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.isSameComMscProcess");
    		sqlIsSameComMscProcess = StringTool.ReplaceAll(sqlIsSameComMscProcess, "#MSC#", list2.get(i).get(1));
    		sqlIsSameComMscProcess = StringTool.ReplaceAll(sqlIsSameComMscProcess, "#MSC_PLINE#", list2.get(i).get(2));
    		sqlIsSameComMscProcess = StringTool.ReplaceAll(sqlIsSameComMscProcess, "#PROCESS_CODE#", list2.get(i).get(5));
    		sqlIsSameComMscProcess = StringTool.ReplaceAll(sqlIsSameComMscProcess, "#BACKLOG_SEQ#", list2.get(i).get(3));
    		sqlIsSameComMscProcess = StringTool.ReplaceAll(sqlIsSameComMscProcess, "#PROCESS_CODE_C#", list2.get(i).get(20));
    		con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    		ArrayList<GenericEntity> isSameList = EntityTool.getEntitysBySql(sqlComMscProcessTotalCnt, con, GenericEntity.class);
        	if(Integer.parseInt(isSameList.get(0).getCount()) == 0){
        		return false;
        	}
    	}
    	
    	con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    	ArrayList<String> list3Process = new ArrayList<String>();
    	String strProcess = "''";
    	int list3Cnt = 0;
    	for(int i = 0; i < list3.size(); i++){
    		if(!list3Process.contains(list3.get(i).get(4))){
    			list3Process.add(list3.get(i).get(4));
    			strProcess += ", '"+ list3.get(i).get(4) +"'";
    		}
    		if(!list3.get(i).get(0).equals("DELETE")){
    			list3Cnt++;
    		}
    	}
    	
    	String sqlComMscStationTotalCnt = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.comMscStationTotalCnt");
    	sqlComMscStationTotalCnt = StringTool.ReplaceAll(sqlComMscStationTotalCnt, "#MSC#", list2.get(0).get(1));
    	sqlComMscStationTotalCnt = StringTool.ReplaceAll(sqlComMscStationTotalCnt, "#MSC_PLINE#", list2.get(0).get(2));
    	sqlComMscStationTotalCnt = sqlComMscStationTotalCnt.replaceAll("PROCESS_CODE", strProcess);
    	ArrayList<GenericEntity> stationTotalCntList = EntityTool.getEntitysBySql(sqlComMscProcessTotalCnt, con, GenericEntity.class);
    	if(Integer.parseInt(stationTotalCntList.get(0).getCount()) != list3Cnt){
    		return false;
    	}
    	for(int i = 0; i < list3.size(); i++){
    		if(list3.get(i).get(0).equals("DELETE")) continue;
    		String sqlIsSameComMscStation = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.isSameComMscStation");
    		sqlIsSameComMscStation = StringTool.ReplaceAll(sqlIsSameComMscStation, "#MSC#", list3.get(i).get(1));
    		sqlIsSameComMscStation = StringTool.ReplaceAll(sqlIsSameComMscStation, "#MSC_PLINE#", list3.get(i).get(2));
    		sqlIsSameComMscStation = StringTool.ReplaceAll(sqlIsSameComMscStation, "#PROCESS_CODE#", list3.get(i).get(4));
    		sqlIsSameComMscStation = StringTool.ReplaceAll(sqlIsSameComMscStation, "#STATION_CODE#", list3.get(i).get(6));
    		sqlIsSameComMscStation = StringTool.ReplaceAll(sqlIsSameComMscStation, "#RETURN_RESULT#", list3.get(i).get(12));
    		sqlIsSameComMscStation = StringTool.ReplaceAll(sqlIsSameComMscStation, "#SEND_CHECKPLAN#", list3.get(i).get(13));
    		sqlIsSameComMscStation = StringTool.ReplaceAll(sqlIsSameComMscStation, "#PROCESS_SEQ#", list3.get(i).get(15));
    		con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    		ArrayList<GenericEntity> isSameList = EntityTool.getEntitysBySql(sqlIsSameComMscStation, con, GenericEntity.class);
        	if(Integer.parseInt(isSameList.get(0).getCount()) == 0){
        		return false;
        	}
    	}
    	
    	return true;
    }

    /**
     * 作废或者恢复冶金规范产线
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject deleteOrResumeMscBackLog(ArrayList<String> list) {
        return setDataBySqlID("CoreFrmProPSCMSC.deleteOrResumeMscBackLog", list
                .toArray());
    }
    
    /**
     * 制程下面是否存在工序
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject isExistProcess(ArrayList<String> list){
        return getDataBySqlID("CoreFrmProPSCMSC.isExistProcess", list.toArray());
    }
    
    /**
     * 制程下面是否存在钢种
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject isExistGrade(ArrayList<String> list){
        return getDataBySqlID("CoreFrmProPSCMSC.isExistGrade", list.toArray());
    }

    /**
     * 查询工序基础
     * @return obj
     */
    public CoreReturnObject queryBaseProcess() {
        return getDataBySqlID("CoreFrmProPSCMSC.queryBaseProcess");
    }
    
    /**
     * 查询工序基础
     * @return obj
     */
    public CoreReturnObject queryBaseProcess2() {
        return getDataBySqlID("CoreFrmProPSCMSC.queryBaseProcess2");
    }

    /**
     * 查询工序基础
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscProcess(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMscProcess", list
                .toArray());
    }

    /**
     * 查询工序基础（用于树形结构）
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscProcess2(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMscProcess2", list
                .toArray());
    }

    /**
     * 查询最大的工序基础表seq
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMaxMscProBkLog_seq(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMaxMscProBkLog_seq", list
                .toArray());
    }

    /**
     * 查询工序点
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryBaseStation(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryBase_Station", list
                .toArray());
    }

    /**
     * 查询工序点
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscStation(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMsc_Station", list
                .toArray());
    }
    
    /**
     * 查询指定工序点类型的数目
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject querySttnTypeCnt(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMscStationTypeCount", list
                .toArray());
    }

    /**
     * 查询工序点（用于树形结构）
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscStation2(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMsc_Station2", list
                .toArray());
    }

    /**
     * 查询钢种
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryGrade(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryGrade", list.toArray());
    }
    
    /**
     * 查询钢种下的规格
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryGradeRSpec(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryGradeRSpec", list.toArray());
    }

    /**
     * 查询接箍
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryJG(ArrayList<String> list) {
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.queryJG");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", list.get(0));
    	sql = StringTool.ReplaceAll(sql, "#PSC#", list.get(1));
    	sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", list.get(2));
    	sql = StringTool.ReplaceAll(sql, "#MSC2#", list.get(3));
        return this.getData(sql);
    }
    
    /**
     * 保存图片路径到MSC
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject saveMscImg(ArrayList<String> list){
        return setDataBySqlID("CoreFrmProPSCMSC.saveMscImg", list.toArray());
    }
    
    /**
     * 查询MSC中的图片
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscImg(ArrayList<String> list) {
        return getDataBySqlID("CoreFrmProPSCMSC.queryMscImg", list.toArray());
    }
    
    /**
     * 查询二级工序
     * @return obj
     */
    public CoreReturnObject queryProcessC(){
        return getDataBySqlID("CoreFrmProPSCMSC.queryProcessC");
    }
    
    /**
     * 保存接箍和冶金规范关系表中的3个附加要求
     * @param list 保存参数
     * @return obj
     */
    public CoreReturnObject saveMscRJg(ArrayList<String> list){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.saveMscRJg");
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_DETECTION#", list.get(0));
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_BONDERIZING#", list.get(1));
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_COPPER#", list.get(2));
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_BLAST#", list.get(3));
    	sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", list.get(4));
    	sql = StringTool.ReplaceAll(sql, "#MEMO#", list.get(5));
    	sql = StringTool.ReplaceAll(sql, "#TORQUE_UNIT#", list.get(6));
    	sql = StringTool.ReplaceAll(sql, "#TORQUE_MAX#", list.get(7));
    	sql = StringTool.ReplaceAll(sql, "#TORQUE_MIN#", list.get(8));
    	sql = StringTool.ReplaceAll(sql, "#TORQUE_BEST#", list.get(9));
    	sql = StringTool.ReplaceAll(sql, "#POINT_MAX#", list.get(10));
    	sql = StringTool.ReplaceAll(sql, "#POINT_MIN#", list.get(11));
    	sql = StringTool.ReplaceAll(sql, "#M_STD_NO#", list.get(12));
    	sql = StringTool.ReplaceAll(sql, "#W_STD_NO#", list.get(13));
    	sql = StringTool.ReplaceAll(sql, "#M_PRINT_NO#", list.get(14));
    	sql = StringTool.ReplaceAll(sql, "#W_PRINT_NO#", list.get(15));
    	sql = StringTool.ReplaceAll(sql, "#FILE_PATH#", list.get(16));
    	sql = StringTool.ReplaceAll(sql, "#JG_MEMO#", list.get(17));
    	sql = StringTool.ReplaceAll(sql, "#MSC#", list.get(18));
    	sql = StringTool.ReplaceAll(sql, "#KEY_JG#", list.get(19));
    	return this.setData(sql);
    }
    
    /**
     * updateJgPath
     * @param list 保存参数
     * @return obj
     */
    public CoreReturnObject updateJgPath(ArrayList<String> list){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC.updateJgPath");
    	b.Fill(new String[]{ list.get(0), list.get(1), list.get(2), list.get(3) });
    	return this.setData(b.toString());
    }
    
    /**
     * 查询PSC中的科室
     * @param psc psc
     * @return obj
     */
    public CoreReturnObject queryUnitCodeByPsc(String psc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.queryUnitCodeByPsc");
    	sql = StringTool.ReplaceAll(sql, "#PSC#", psc);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询是否存在标准MSC
     * @param psc psc
     * @return obj
     */
    public CoreReturnObject queryIsExistStdMsc(String psc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.queryIsExistStdMsc");
    	sql = StringTool.ReplaceAll(sql, "#PSC#", psc);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询MSC
     * @param msc MSC
     * @return OBJ
     */
    public CoreReturnObject getPscByMsc(String msc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.getPscByMsc");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询制程
     * @param msc
     * @return obj
     */
    public CoreReturnObject getBackLog(String msc, String ordLnPk, String isCraft){
    	String sql = "";
    	if(isCraft.equals("True")){
    		sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.getCraftOrdDesignMscPl");
    	}else{
    		sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.getMscBackLogByMscMscPline");
    	}
    	sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	return this.getData(sql);
    }
    
    /**
     * 新增质量设计制程
     * @param listJSON
     * @param ordLnPk
     * @param designKey
     * @return obj
     */
    public CoreReturnObject setDesignMscPl(ArrayList<String> listJSON, String ordLnPk,
    		String designKey, String isCraft){
    	ArrayList<String> sqllist = new ArrayList<String>();
    	String sqlGetDesignMscPl = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.getCraftDesign");
    	sqlGetDesignMscPl = StringTool.ReplaceAll(sqlGetDesignMscPl, "#ORD_LN_PK#", ordLnPk);
    	Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    	ArrayList<CraftOrdDesignEntity> craftOrdDesignList = EntityTool.getEntitysBySql(sqlGetDesignMscPl, con, CraftOrdDesignEntity.class);
    	if(isCraft.equals("True")){
    		String sqlDeleteMscPl = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteCraftDesignMscPl");
    		sqlDeleteMscPl = StringTool.ReplaceAll(sqlDeleteMscPl, "#DESGIN_KEY#", craftOrdDesignList.get(0).getDesginKey());
    		sqllist.add(sqlDeleteMscPl);
        	for(String strJSON : listJSON){
        		MscBacklogEntity mscBacklog = EntityTool.getEntityByJSONStr(strJSON, MscBacklogEntity.class);
        		String sqlInsertMscPl = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.insertCraftDesingMscPl");
        		sqlInsertMscPl = EntityTool.fillSqlByEntity(sqlInsertMscPl, mscBacklog);
        		sqlInsertMscPl = StringTool.ReplaceAll(sqlInsertMscPl, "#DESGIN_KEY#", craftOrdDesignList.get(0).getDesginKey());
        		sqlInsertMscPl = StringTool.ReplaceAll(sqlInsertMscPl, "#ORD_LN_PK#", ordLnPk);
        		sqllist.add(sqlInsertMscPl);
        	}
    	}else{
    		String sqlDeleteMscPl2 = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteDesignMscPl2");
        	sqlDeleteMscPl2 = StringTool.ReplaceAll(sqlDeleteMscPl2, "#ORD_LN_PK#", ordLnPk);
        	sqllist.add(sqlDeleteMscPl2);
        	
    		String sqlDeleteMscPl = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.deleteDesignMscPl");
    		sqlDeleteMscPl = StringTool.ReplaceAll(sqlDeleteMscPl, "#DESGIN_KEY#", designKey);
    		sqllist.add(sqlDeleteMscPl);
        	for(String strJSON : listJSON){
        		MscBacklogEntity mscBacklog = EntityTool.getEntityByJSONStr(strJSON, MscBacklogEntity.class);
        		String sqlInsertMscPl = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.insertDesignMscPl");
        		sqlInsertMscPl = EntityTool.fillSqlByEntity(sqlInsertMscPl, mscBacklog);
        		sqlInsertMscPl = StringTool.ReplaceAll(sqlInsertMscPl, "#DESGIN_KEY#", designKey);
        		sqlInsertMscPl = StringTool.ReplaceAll(sqlInsertMscPl, "#ORD_LN_PK#", ordLnPk);
        		sqllist.add(sqlInsertMscPl);
        	}
    	}
    	
    	return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }
    
    /**
     * 查询附件图片
     * @param msc
     * @return obj
     */
    public CoreReturnObject getMscFjImg(String msc){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC.getMscFjImg");
    	b.Fill(new String[]{ msc });
    	return this.getData(b.toString());
    }
    
    /**
     * 查询附件图片
     * @param msc
     * @return obj
     */
    public CoreReturnObject getCraftFjImg(String ordLnPk){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC.getCraftFjImg");
    	b.Fill(new String[]{ ordLnPk });
    	return this.getData(b.toString());
    }
    
    /**
     * 设定附件图片
     * @param fileImg
     * @param ordLnPk
     * @return
     */
    public CoreReturnObject setCraftFjImg(String fileImg, String ordLnPk){
    	ArrayList<String> sqllist = new ArrayList<String>();
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC.deleteCraftFjImg");
    	b.Fill(new String[]{ ordLnPk });
    	sqllist.add(b.toString());
    	b = new SqlBuilder("CoreFrmProPSCMSC.insertCraftFjImg");
    	b.Fill(new String[]{ ordLnPk, fileImg });
    	sqllist.add(b.toString());
    	
    	return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }
    
    /**
     * 通过MSC查询MSC表
     * @param msc
     * @return obj
     */
    public CoreReturnObject getComMscByMsc(String msc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.getComMscByMsc");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	
    	return this.getData(sql);
    }
    
    /**
     * 获取标准类型
     * @param msc
     * @return obj
     */
    public CoreReturnObject getStdStyle(String psc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.getStdStyle");
    	sql = StringTool.ReplaceAll(sql, "#PSC#", psc);
    	
    	return this.getData(sql);
    }
    
    /**
     * 复制制程。
     * @param msc
     * @return
     */
    public CoreReturnObject CopyBackLog(String msc, String userName){
        return CopyBackLog(msc,userName,"");
    }
    public CoreReturnObject CopyBackLog(String msc, String userName,String CopyMsc){
        return CopyBackLog(msc,userName,"","");
    }
    public CoreReturnObject CopyBackLog(String msc, String userName,String CopyMsc,String copyMscPline){
    	TransctionTool transction = new TransctionTool();
    	Connection con = transction.getCon();
    	boolean result = false;
    	try{
	    	String sqlGetStdMsc = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryComMsc");
	    	sqlGetStdMsc = StringTool.ReplaceAll(sqlGetStdMsc, "#MSC#", msc);
	    	ArrayList<MscEntity> listMscEntity = EntityTool.getEntitysBySqlNoClsCon(sqlGetStdMsc, con, MscEntity.class);
	    	if(!StringUtils.isEmpty(CopyMsc) && listMscEntity != null && listMscEntity.size() > 0){
                listMscEntity.get(0).setMscSeq(CopyMsc);
            }
	    	//复制制程
	    	String sqlGetBackLog = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryMscBackLog");
	    	sqlGetBackLog = StringTool.ReplaceAll(sqlGetBackLog, "#MSC#", listMscEntity.get(0).getMscSeq());
	    	if(!StringUtils.isEmpty(copyMscPline)){
                sqlGetBackLog += " AND MSC_PLINE = '" +copyMscPline+ "'";
            }
	    	ArrayList<MscBacklogEntity> listMscBackLogEntitySrc = EntityTool.getEntitysBySqlNoClsCon(sqlGetBackLog, con, MscBacklogEntity.class);
	    	for(MscBacklogEntity mscBackLogEntitySrc : listMscBackLogEntitySrc){
	    		String sqlInsertMscBackLog = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.insertMscBackLog");
	    		mscBackLogEntitySrc.setMsc(msc);
	    		mscBackLogEntitySrc.setMemo("复制生成");
	    		mscBackLogEntitySrc.setCreateName(userName);
	    		mscBackLogEntitySrc.setValidflag("0");
	    		sqlInsertMscBackLog = EntityTool.fillSqlByEntity(sqlInsertMscBackLog, mscBackLogEntitySrc);
	    		result = transction.ExcuteTransction(sqlInsertMscBackLog);
	    		if(result == false){
	    			return transction.rollBack();
	    		}
	    	}
	    	
	    	//复制工序
	    	String sqlGetMscProcess = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryMscProcess");
			sqlGetMscProcess = StringTool.ReplaceAll(sqlGetMscProcess, "#MSC#", listMscEntity.get(0).getMscSeq());
            if(!StringUtils.isEmpty(copyMscPline)){
                sqlGetMscProcess += " AND MSC_PLINE = '" +copyMscPline+ "'";
            }
			ArrayList<MscProcessEntity> listMscProcessEntitySrc = EntityTool.getEntitysBySqlNoClsCon(sqlGetMscProcess, con, MscProcessEntity.class);
			for(MscProcessEntity mscProcessEntitySrc : listMscProcessEntitySrc){
				String sqlInsertMscProcess = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.insertMscProcess");
				mscProcessEntitySrc.setMsc(msc);
//				mscProcessEntitySrc.setMemo("复制生成");
				mscProcessEntitySrc.setCreateName(userName);
				sqlInsertMscProcess = EntityTool.fillSqlByEntity(sqlInsertMscProcess, mscProcessEntitySrc);
				result = transction.ExcuteTransction(sqlInsertMscProcess);
				if(result == false){
					return transction.rollBack();
				}
			}
			
			//复制工序点
			String sqlGetMscStation = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryMscStation");
			sqlGetMscStation = StringTool.ReplaceAll(sqlGetMscStation, "#MSC#", listMscEntity.get(0).getMscSeq());
            if(!StringUtils.isEmpty(copyMscPline)){
                sqlGetMscStation += " AND MSC_PLINE = '" +copyMscPline+ "'";
            }
			ArrayList<MscStationEntity> listMscStationEntitySrc = EntityTool.getEntitysBySqlNoClsCon(sqlGetMscStation, con, MscStationEntity.class);
			for(MscStationEntity mscStationEntitySrc : listMscStationEntitySrc){
				String sqlInsertMscStation = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.insertMscStation");
				mscStationEntitySrc.setMsc(msc);
				mscStationEntitySrc.setMemo("复制生成");
				mscStationEntitySrc.setCreateName(userName);
				sqlInsertMscStation = EntityTool.fillSqlByEntity(sqlInsertMscStation, mscStationEntitySrc);
				result = transction.ExcuteTransction(sqlInsertMscStation);
				if(result == false){
					return transction.rollBack();
				}
			}
			
			//复制钢种
			String sqlGetMscGrade = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryMscGrade");
			sqlGetMscGrade = StringTool.ReplaceAll(sqlGetMscGrade, "#MSC#", listMscEntity.get(0).getMscSeq());
            if(!StringUtils.isEmpty(copyMscPline)){
                sqlGetMscGrade += " AND MSC_PLINE = '" +copyMscPline+ "'";
            }
			ArrayList<MscGradeEntity> listMscGradeEntitySrc = EntityTool.getEntitysBySqlNoClsCon(sqlGetMscGrade, con, MscGradeEntity.class);
			for(MscGradeEntity mscGradeEntitySrc : listMscGradeEntitySrc){
				String sqlInsertMscGrade = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.insertMscGrade");
				mscGradeEntitySrc.setMsc(msc);

				mscGradeEntitySrc.setMemo("复制生成");
				mscGradeEntitySrc.setCreateName(userName);
				sqlInsertMscGrade = EntityTool.fillSqlByEntity(sqlInsertMscGrade, mscGradeEntitySrc);
				result = transction.ExcuteTransction(sqlInsertMscGrade);
				if(result == false){
					return transction.rollBack();
				}
			}
			
			//复制钢种与规格关系
			String sqlGetMscGradeRSpec = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryMscGradeRSpec");
			sqlGetMscGradeRSpec = StringTool.ReplaceAll(sqlGetMscGradeRSpec, "#MSC#", listMscEntity.get(0).getMscSeq());
            if(!StringUtils.isEmpty(copyMscPline)){
                sqlGetMscGradeRSpec += " AND MSC_PLINE = '" +copyMscPline+ "'";
            }
			ArrayList<MscGradeRSpecEntity> listMscGradeRSpecEntitySrc = EntityTool.getEntitysBySqlNoClsCon(sqlGetMscGradeRSpec, con, MscGradeRSpecEntity.class);
			for(MscGradeRSpecEntity mscGradeEntitySrc : listMscGradeRSpecEntitySrc){
				String sqlInsertMscGradeRSpec = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.insertMscGradeRSpec");
				mscGradeEntitySrc.setMsc(msc);
				mscGradeEntitySrc.setMemo("复制生成");
				mscGradeEntitySrc.setCreateName(userName);
				sqlInsertMscGradeRSpec = EntityTool.fillSqlByEntity(sqlInsertMscGradeRSpec, mscGradeEntitySrc);
				result = transction.ExcuteTransction(sqlInsertMscGradeRSpec);
				if(result == false){
					return transction.rollBack();
				}
			}
			
			//复制工艺参数
			String sqlGetMscStdCraft = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryMscStdCraft");
			sqlGetMscStdCraft = StringTool.ReplaceAll(sqlGetMscStdCraft, "#MSC#", listMscEntity.get(0).getMscSeq());
            if(!StringUtils.isEmpty(copyMscPline)){
                sqlGetMscStdCraft += " AND MSC_PLINE = '" +copyMscPline+ "'";
            }
			ArrayList<MscStdCraftEntity> listMscStdCraftSrc = EntityTool.getEntitysBySqlNoClsCon(sqlGetMscStdCraft, con, MscStdCraftEntity.class);
	    	for(MscStdCraftEntity mscStdCraftEntitySrc : listMscStdCraftSrc){
	    		String sqlInsertMscStdCraft = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.insertMscStdCraft");
	    		mscStdCraftEntitySrc.setMsc(msc);
	    		mscStdCraftEntitySrc.setMemo("复制生成");
	    		mscStdCraftEntitySrc.setCreateName(userName);
	    		sqlInsertMscStdCraft = EntityTool.fillSqlByEntity(sqlInsertMscStdCraft, mscStdCraftEntitySrc);
	    		result = transction.ExcuteTransction(sqlInsertMscStdCraft);
	    		if(result == false){
	    			return transction.rollBack();
	    		}
	    	}
    	}
    	catch(Exception ex){
    		CoreReturnObject cro = transction.rollBack();
    		cro.SetErrInfo(ex.getMessage());
    		return cro;
    	}
    	return transction.commit();
    }
    
    /**
     * 是否存在制程
     * @param msc
     * @return
     */
    public CoreReturnObject queryExistBackLog(String msc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryExistBackLog");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	return this.getData(sql);
    }

    
    /**
     * 根据主键查询制程
     * @param msc
     * @param mscPline
     * @return
     */
    public CoreReturnObject queryComMscBacklogByPk(String msc, String mscPline){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryComMscBacklogByPk");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	sql = StringTool.ReplaceAll(sql, "#MSC_PLINE#", mscPline);
    	return this.getData(sql);
    }
    
    /**
     * 通过主键查询二级工序
     * @param processCodeC
     * @return
     */
    public CoreReturnObject queryComBaseProcessCByPk(String processCodeC){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.queryComBaseProcessCByPk");
    	sql = StringTool.ReplaceAll(sql, "#PROCESS_CDOE_C#", processCodeC);
    	return this.getData(sql);
    }
    
    /**
     * 接箍和冶金规范管理关系数目
     * @param processCodeC
     * @return
     */
    public CoreReturnObject getMscRJgCnt(String codeJg, String detection, String bonderizing,
    		String copper, String blast, String orderSpecialDesc, String alphaCode, String keyJg, String msc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.getMscRJgCnt");
    	sql = StringTool.ReplaceAll(sql, "#CODE_JG#", codeJg);
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_DETECTION#", detection);
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_BONDERIZING#", bonderizing);
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_COPPER#", copper);
    	sql = StringTool.ReplaceAll(sql, "#DEMAND_BLAST#", blast);
    	sql = StringTool.ReplaceAll(sql, "#ORDER_SPECIAL_DESC#", orderSpecialDesc);
    	sql = StringTool.ReplaceAll(sql, "#ALPHA_CODE#", alphaCode);
    	sql = StringTool.ReplaceAll(sql, "#KEY_JG#", keyJg);
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	return this.getData(sql);
    }
    
    /**
     * 查询制程描述
     * @param backLogDesc
     * @param msc
     * @return
     */
    public CoreReturnObject getBackLogDescCnt(String backLogDesc, String msc, String strAction, String mscPline){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.getBackLogDescCnt");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	sql = StringTool.ReplaceAll(sql, "#WHOLE_BACKLOG_DESC#", backLogDesc);
    	sql = StringTool.ReplaceAll(sql, "#STR_ACTION#", strAction);
    	sql = StringTool.ReplaceAll(sql, "#MSC_PLINE#", mscPline);
    	return this.getData(sql);
    }
    
    /**
     * 查询bom数目
     * @param msc
     * @param mscPline
     * @return
     */
    public CoreReturnObject getDesignBomCnt(String msc, String mscPline){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.getDesignBomCnt");
    	sql = StringTool.ReplaceAll(sql, "#MSC#", msc);
    	sql = StringTool.ReplaceAll(sql, "#MSC_PLINE#", mscPline);
    	return this.getData(sql);
    }
    
    /**
     * 通过主键查询冶金规范基础数据
     * @return
     */
    public CoreReturnObject getComMscByPk(String msc){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC2.getComMscByPk");
    	Object[] parms = new Object[]{msc};
    	return this.getData(sql, parms);
    }
    
    /**
     * 通过主键查询合同行
     * @param ordLnPk
     * @return
     */
    public CoreReturnObject getSlmOrderLineByPk(String ordLnPk){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC2.getSlmOrderLineByPk");
    	b.Fill(new String[]{ordLnPk});
    	return this.getData(b.toString());
    }
    
    /**
     * 通过主键查询合同行
     * @param ordLnPk
     * @return
     */
    public CoreReturnObject getComMsc0(String psc){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC2.getComMsc0");
    	b.Fill(new String[]{psc});
    	return this.getData(b.toString());
    }
    
    /**
     * 是否存在制程
     * @return
     */
    public CoreReturnObject isExistsBackLog(String msc, String mscPline, String wholeBackLogDesc){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC2.isExistsBackLog");
    	b.Fill(new String[]{msc, mscPline, wholeBackLogDesc});
    	return this.getData(b.toString());
    }
    
    
    /**
     * 修改工序贴图
     * @param parm
     * @return
     */
    public CoreReturnObject updateProcessFile(String[] parm){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC2.updateProcessFile");
    	b.Fill(parm);
    	return this.setData(b.toString());
    }
    
    /**
     * 删除制程向下的钢种
     * @param msc
     * @param mscPline
     * @param grade
     * @return
     */
    public CoreReturnObject deletePlineGrade(String msc, String mscPline, String grade){
    	SqlBuilder b = new SqlBuilder("CoreFrmProPSCMSC2.deletePlineGrade");
    	b.Fill(new String[]{ msc, mscPline, grade });
    	
    	return this.setData(b.toString());
    }
}
