package com.steering.pss.qcm;

import net.sf.json.JSONObject;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.StringTool;
import com.steering.pss.qcm.model.ComMscGradeEntity;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.qcm.model.MscBacklogEntity;
import com.steering.pss.qcm.model.MscEntity;
import com.steering.pss.qcm.model.MscItemEntity;
import com.steering.pss.qcm.model.MscProcessEntity;
import com.steering.pss.qcm.model.MscStationEntity;
import com.steering.pss.qcm.model.PscEntity;
import com.steering.pss.qcm.model.PscObject;

public class MscManage extends DBCommon {

	/**
	 * 查询产品规范码
	 * @param strJSON 参数
	 * @return obj
	 */
	public CoreReturnObject queryPsc(String strJSON){
		JSONObject obj = JSONObject.fromObject(strJSON);
		PscEntity pscObj = (PscEntity)JSONObject.toBean(obj, PscEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryPsc");
		sql = EntityTool.fillSqlByEntity(sql, pscObj);
		
		return this.getData(sql);
	}
	
	/**
	 * 查询冶金规范码
	 * @param strJSON 参数
	 * @return obj
	 */
	public CoreReturnObject queryMsc(String strJSON){
		JSONObject obj = JSONObject.fromObject(strJSON);
		MscEntity mscObj = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMsc");
		sql = EntityTool.fillSqlByEntity(sql, mscObj);
		return this.getData(sql);
	}
	
	/**
	 * 查询接箍
	 * @param strJSON 参数
	 * @return obj
	 */
	public CoreReturnObject queryMscJg(String strJSON){
		JSONObject obj = JSONObject.fromObject(strJSON);
		MscEntity mscObj = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryJG");
		sql = EntityTool.fillSqlByEntity(sql, mscObj);
		return this.getData(sql);
	}
	
	/**
	 * 新增MSC
	 * @param strMscJSON 冶金规范参数
	 * @param strMscItemJSON 冶金规范项目参数
	 * @return obj
	 */
	public CoreReturnObject insertMsc(String strMscJSON){
		ArrayList<String> sqllist = new ArrayList<String>();
		JSONObject mscObj = JSONObject.fromObject(strMscJSON);
		MscEntity mscEntity = (MscEntity)JSONObject.toBean(mscObj, MscEntity.class);
		String sqlInsertMsc = CoreXmlSqlParsersFactory.getSql("MscManage.insertMsc");
		sqlInsertMsc = EntityTool.fillSqlByEntity(sqlInsertMsc, mscEntity);
		
		if(strMscJSON.equals("") == false){
			sqllist.add(sqlInsertMsc);
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
     * 更新冶金规范
     * @param list 冶金规范表参数
     * @param list2 冶金规范项目表参数
     * @param list3 复制参数
     * @return
     */
    public CoreReturnObject updateMsc(String strMscJSON) {
    	ArrayList<String> sqllist = new ArrayList<String>();
		JSONObject mscObj = JSONObject.fromObject(strMscJSON);
		MscEntity mscEntity = (MscEntity)JSONObject.toBean(mscObj, MscEntity.class);
		
		String sqlUpdateMsc = CoreXmlSqlParsersFactory.getSql("MscManage.updateMsc");
		sqlUpdateMsc = EntityTool.fillSqlByEntity(sqlUpdateMsc, mscEntity);
		if(strMscJSON.equals("") == false){
			sqllist.add(sqlUpdateMsc);
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }
	
	/**
     * 是否存在Alpha
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject isExistAlpha(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
		MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("MscManage.isExistAlpha");
		sql = EntityTool.fillSqlByEntity(sql, mscEntity);
		
        return this.getData(sql);
    }
    
    /**
     * 是否完整的MSC
     * @param msc
     * @return
     */
    public CoreReturnObject isCompleteMsc(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
		MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("MscManage.isCompleteMsc");
		sql = EntityTool.fillSqlByEntity(sql, mscEntity);
		
        return this.getData(sql);
    }
    
    /**
     * 是否完整的MSC
     * @param msc
     * @return
     */
    public CoreReturnObject isCompleteMsc2(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
		MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("MscManage.isCompleteMsc2");
		sql = EntityTool.fillSqlByEntity(sql, mscEntity);
		
        return this.getData(sql);
    }
    
    /**
     * 作废或者恢复冶金规范
     * @param list 冶金规范表参数
     * @param list2 冶金规范项目表参数
     * @return obj
     */
    public CoreReturnObject updateMscState(String strMscJSON, String actionType) {
        JSONObject obj = JSONObject.fromObject(strMscJSON);
        MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
    	String validflag2 = "";
    	String validflag = mscEntity.getValidflag();
    	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("MscManage.updateMscState");
    	sql = EntityTool.fillSqlByEntity(sql, mscEntity);
    	sql = StringTool.ReplaceAll(sql, "#VALIDFLAG2#", validflag2);
    	sql = StringTool.ReplaceAll(sql, "#ACTION_TYPE#", actionType);
        
        return this.setData(sql);
    }
    
    /**
     * 更新内控状态位。
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject updateMscNkState(String strMscJSON, String actionType){
    	JSONObject obj = JSONObject.fromObject(strMscJSON);
        MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
        
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.updateMscNkState");
    	sql = EntityTool.fillSqlByEntity(sql, mscEntity);
    	sql = StringTool.ReplaceAll(sql, "#ACTION_TYPE#", actionType);
    	
    	String sqlUpdateBackLogNkFlg = CoreXmlSqlParsersFactory.getSql("MscManage.updateBackLogNkState");
    	sqlUpdateBackLogNkFlg = EntityTool.fillSqlByEntity(sqlUpdateBackLogNkFlg, mscEntity);
    	ArrayList<String> sqllist = new ArrayList<String>();
    	sqllist.add(sql);
    	sqllist.add(sqlUpdateBackLogNkFlg);
    	return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }
    
    /**
     * 加载Alpha
     * @return ojb
     */
    public CoreReturnObject loadAlpha() {
        return getDataBySqlID("CoreFrmProPSCMSC2.loadAlpha");
    }
    
    /**
     * 加载Msc
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject loadMsc(String strMscJSON) {
    	JSONObject obj = JSONObject.fromObject(strMscJSON);
        MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.loadMsc");
        sql = EntityTool.fillSqlByEntity(sql, mscEntity);
        return getData(sql);
    }
    
    /**
     * 查询冶金规范产线
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMscBackLog(String strBackLogJSON) {
    	JSONObject obj = JSONObject.fromObject(strBackLogJSON);
        MscBacklogEntity mscBackLogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscBackLog");
        sql = EntityTool.fillSqlByEntity(sql, mscBackLogEntity);
        return getData(sql);
    }
    
    /**
     * 查询最大冶金规范产线号
     * @param strBackLogJSON 参数
     * @return obj
     */
    public CoreReturnObject queryMaxMscBackLogPline(String strBackLogJSON) {
    	JSONObject obj = JSONObject.fromObject(strBackLogJSON);
        MscBacklogEntity mscBackLogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMaxBackLogPline");
        sql = EntityTool.fillSqlByEntity(sql, mscBackLogEntity);
        return getData(sql);
    }
    
    /**
     * 新增冶金规范产线（包括产线下面的所有业务，是整个事务新增）
     * @param strBackLogJSON 冶金规范产线表参数
     * @param listProcessJSON 冶金规范工序表参数
     * @param listStationJSON 冶金规范工序点参数
     * @return obj
     */
    public CoreReturnObject saveMscBackLog(String strBackLogJSON, ArrayList<String> listProcessJSON,
    		ArrayList<String> listStationJSON, ArrayList<String> listMustStationJSON, 
    		ArrayList<String> listProcessJSONNoChk, String strAction) {
    	ArrayList<String> sqllist = new ArrayList<String>();
    	JSONObject obj = JSONObject.fromObject(strBackLogJSON);
        MscBacklogEntity mscBackLogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
        String sqlSaveBackLog = "";
        //全程工序路径。
        String[] strsWholeBackLog = getWholeBackLog(listProcessJSON);
        mscBackLogEntity.setWholeBacklog(strsWholeBackLog[0]);
    	mscBackLogEntity.setWholeBacklogDesc(strsWholeBackLog[1]);
        if(strAction.equals("Add"))
        {
        	String sqlGetMaxMscPline = CoreXmlSqlParsersFactory.getSql("MscManage.queryMaxBackLogPline");
        	sqlGetMaxMscPline = EntityTool.fillSqlByEntity(sqlGetMaxMscPline, mscBackLogEntity);
        	Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
        	ArrayList<GenericEntity> maxMscPlineList = EntityTool.getEntitysBySql(sqlGetMaxMscPline, con, GenericEntity.class);
        	mscBackLogEntity.setMscPline(maxMscPlineList.get(0).getMaxValue());
        	sqlSaveBackLog = CoreXmlSqlParsersFactory.getSql("MscManage.insertMscBackLog");
        	sqlSaveBackLog = EntityTool.fillSqlByEntity(sqlSaveBackLog, mscBackLogEntity);
        	
        }
        else{
        	sqlSaveBackLog = CoreXmlSqlParsersFactory.getSql("MscManage.updateMscBackLog");
        	sqlSaveBackLog = EntityTool.fillSqlByEntity(sqlSaveBackLog, mscBackLogEntity);
        }
        sqllist.add(sqlSaveBackLog);
        String sqlDeleteProcess = CoreXmlSqlParsersFactory.getSql("MscManage.deleteMscProcess");
        sqlDeleteProcess = EntityTool.fillSqlByEntity(sqlDeleteProcess, mscBackLogEntity);
        sqllist.add(sqlDeleteProcess);
        
        
        for(int i = 0; i < listProcessJSON.size(); i++){
        	String sqlInsertProcess = CoreXmlSqlParsersFactory.getSql("MscManage.insertMscProcess");
        	String strProcessJSON = listProcessJSON.get(i);
        	JSONObject processObj = JSONObject.fromObject(strProcessJSON);
            MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(processObj, MscProcessEntity.class);
            mscProcessEntity.setMscPline(mscBackLogEntity.getMscPline());
            sqlInsertProcess = EntityTool.fillSqlByEntity(sqlInsertProcess, mscProcessEntity);
	        sqllist.add(sqlInsertProcess);
        }
        
        for(int i = 0; i < listProcessJSONNoChk.size(); i++){
        	String sqlDeleteStation = CoreXmlSqlParsersFactory.getSql("MscManage.deleteMscStation");
        	String strProcessJSONNoChk = listProcessJSONNoChk.get(i);
        	JSONObject processObj = JSONObject.fromObject(strProcessJSONNoChk);
            MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(processObj, MscProcessEntity.class);
            sqlDeleteStation = EntityTool.fillSqlByEntity(sqlDeleteStation, mscProcessEntity);
            sqllist.add(sqlDeleteStation);
        }
        
        String tempProcessCode = "";
        for(int i = 0; i < listStationJSON.size(); i++){
        	String sqlDeleteStation = CoreXmlSqlParsersFactory.getSql("MscManage.deleteMscStation");
            String sqlInsertStation = CoreXmlSqlParsersFactory.getSql("MscManage.insertMscStation");
        	String strStationJSON = listStationJSON.get(i);
        	JSONObject stationObj = JSONObject.fromObject(strStationJSON);
            MscStationEntity mscStationEntity = (MscStationEntity)JSONObject.toBean(stationObj, MscStationEntity.class);
            mscStationEntity.setMscPline(mscBackLogEntity.getMscPline());
            mscStationEntity.setChoose(mscStationEntity.getChoose().equals("True") ? "1" : "0");
            mscStationEntity.setReturnResult(mscStationEntity.getReturnResult().equals("True") ? "1" : "0");
            mscStationEntity.setSendCheckplan(mscStationEntity.getSendCheckplan().equals("True") ? "1" : "0");
            if(mscStationEntity.getProcessCode().equals(tempProcessCode) == false){
            	sqlDeleteStation = EntityTool.fillSqlByEntity(sqlDeleteStation, mscStationEntity);
		        tempProcessCode = mscStationEntity.getProcessCode();
		        sqllist.add(sqlDeleteStation);
            }
            sqlInsertStation = EntityTool.fillSqlByEntity(sqlInsertStation, mscStationEntity);
            sqllist.add(sqlInsertStation);
        }
        
        for(int i = 0; i < listMustStationJSON.size(); i++){
        	String sqlCopyMustStation = CoreXmlSqlParsersFactory.getSql("MscManage.copyMustStation");
        	String strProcessJSON = listMustStationJSON.get(i);
        	JSONObject processObj = JSONObject.fromObject(strProcessJSON);
            MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(processObj, MscProcessEntity.class);
            mscProcessEntity.setMscPline(mscBackLogEntity.getMscPline());
            sqlCopyMustStation = EntityTool.fillSqlByEntity(sqlCopyMustStation, mscProcessEntity);
            sqllist.add(sqlCopyMustStation);
        }
        
        CoreReturnObject cro = getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
        cro.setResult(mscBackLogEntity.getMscPline());
        return cro;
    }
    
    private String[] getWholeBackLog(ArrayList<String> listProcessJSON){
    	String[] strs = new String[]{"", ""};
    	for(int i = 0; i < listProcessJSON.size(); i++){
        	String strProcessJSON = listProcessJSON.get(i);
        	JSONObject processObj = JSONObject.fromObject(strProcessJSON);
            MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(processObj, MscProcessEntity.class);
            strs[0] += strs[0].equals("") ? mscProcessEntity.getProcessCode() : ("-" + mscProcessEntity.getProcessCode());
            strs[1] += strs[1].equals("") ? mscProcessEntity.getProcessDesc() : ("-" + mscProcessEntity.getProcessDesc());
        }
    	
    	return strs;
    }
    
    /**
     * 查询最大冶金规范产线号
     * @param strBackLogJSON 参数
     * @return obj
     */
    public CoreReturnObject queryMaxMscPline(String strBackLogJSON) {
    	JSONObject obj = JSONObject.fromObject(strBackLogJSON);
        MscBacklogEntity mscBackLogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMaxMscPline");
        sql = EntityTool.fillSqlByEntity(sql, mscBackLogEntity);
        return this.getData(sql);
    }
    
    /**
     * 作废或者恢复冶金规范产线
     * @param strBackLogJSON 参数
     * @return obj
     */
    public CoreReturnObject updateBackLogState(String strBackLogJSON) {
    	JSONObject obj = JSONObject.fromObject(strBackLogJSON);
        MscBacklogEntity mscBackLogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.updateBackLogState");
        sql = EntityTool.fillSqlByEntity(sql, mscBackLogEntity);
        return this.setData(sql);
    }
    
    /**
     * 制程下面是否存在工序
     * @param strBackLogJSON 参数
     * @return obj
     */
    public CoreReturnObject isExistProcess(String strBackLogJSON){
    	JSONObject obj = JSONObject.fromObject(strBackLogJSON);
        MscBacklogEntity mscBackLogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.isExistProcess");
        sql = EntityTool.fillSqlByEntity(sql, mscBackLogEntity);
        
        return this.getData(sql);
    }
    
    /**
     * 制程下面是否存在钢种
     * @param strBackLogJSON 参数
     * @return obj
     */
    public CoreReturnObject isExistGrade(String strBackLogJSON){
    	JSONObject obj = JSONObject.fromObject(strBackLogJSON);
        MscBacklogEntity mscBackLogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.isExistGrade");
        sql = EntityTool.fillSqlByEntity(sql, mscBackLogEntity);
        return this.getData(sql);
    }
    
    /**
     * 查询工序下的工序点个数
     * @param strProcessJSON 参数
     * @return obj
     */
    public CoreReturnObject queryMscStationCnt(String strProcessJSON) {
    	JSONObject obj = JSONObject.fromObject(strProcessJSON);
        MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(obj, MscProcessEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscStationCnt");
        sql = EntityTool.fillSqlByEntity(sql, mscProcessEntity);
        return this.getData(sql);
    }
    
    /**
     * 查询冶金工序
     * @param strProcessJSON 参数
     * @return obj
     */
    public CoreReturnObject queryMscProcess(String strProcessJSON){
    	JSONObject obj = JSONObject.fromObject(strProcessJSON);
        MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(obj, MscProcessEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscProcess");
        sql = EntityTool.fillSqlByEntity(sql, mscProcessEntity);
        
        return this.getData(sql);
    }
    
    /**
     * 查询冶金工序2 
     * @param strProcessJSON 输入参数
     * @return obj
     */
    public CoreReturnObject queryMscProcess2(String strProcessJSON){
    	JSONObject obj = JSONObject.fromObject(strProcessJSON);
        MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(obj, MscProcessEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscProcess2");
        sql = EntityTool.fillSqlByEntity(sql, mscProcessEntity);
        
        return this.getData(sql);
    }
    
    /**
     * 查询冶金工序点
     * @param strStationJSON 实体类输入参数
     * @return obj
     */
    public CoreReturnObject queryMscStation(String strStationJSON){
    	JSONObject obj = JSONObject.fromObject(strStationJSON);
    	MscStationEntity mscStationEntity = (MscStationEntity)JSONObject.toBean(obj, MscStationEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscStation");
    	sql = EntityTool.fillSqlByEntity(sql, mscStationEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询工序点2
     * @param strStationJSON 输入参数
     * @return obj
     */
    public CoreReturnObject queryMscStation2(String strStationJSON){
    	JSONObject obj = JSONObject.fromObject(strStationJSON);
    	MscStationEntity mscStationEntity = (MscStationEntity)JSONObject.toBean(obj, MscStationEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscStation2");
    	sql = EntityTool.fillSqlByEntity(sql, mscStationEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询所有二级工序
     * @return obj
     */
    public CoreReturnObject queryProcessC(){
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryProcessC");
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询所有工序代码
     * @return obj
     */
    public CoreReturnObject queryProcessCode(){
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryProcessCode");
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询钢种
     * @param strGradeJSON 参数
     * @return obj
     */
    public CoreReturnObject queryGrade(String strGradeJSON) {
    	JSONObject obj = JSONObject.fromObject(strGradeJSON);
    	ComMscGradeEntity mscGradeEntity = (ComMscGradeEntity)JSONObject.toBean(obj, ComMscGradeEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryGrade");
    	sql = EntityTool.fillSqlByEntity(sql, mscGradeEntity);
    	
        return this.getData(sql);
    }
    
    /**
     * 查询钢种下的规格
     * @param strGradeJSON 参数
     * @return obj
     */
    public CoreReturnObject queryGradeRSpec(String strGradeJSON) {
    	JSONObject obj = JSONObject.fromObject(strGradeJSON);
    	ComMscGradeEntity mscGradeEntity = (ComMscGradeEntity)JSONObject.toBean(obj, ComMscGradeEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryGradeRSpec");
    	sql = EntityTool.fillSqlByEntity(sql, mscGradeEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询冶金规范项目
     * @return obj
     */
    public CoreReturnObject queryMscItemByMsc(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscItemEntity mscItemEntity = (MscItemEntity)JSONObject.toBean(obj, MscItemEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscItemByMsc");
    	sql = EntityTool.fillSqlByEntity(sql, mscItemEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询冶金规范产线
     * @return obj
     */
    public CoreReturnObject queryMscBacklogByMsc(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscBacklogEntity mscBacklogEntity = (MscBacklogEntity)JSONObject.toBean(obj, MscBacklogEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscBackLogByMsc");
    	sql = EntityTool.fillSqlByEntity(sql, mscBacklogEntity);
    	
    	return this.getData(sql);
    }
    
    
    /**
     * 查询冶金规范工序
     * @return obj
     */
    public CoreReturnObject queryMscProcessByMsc(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscProcessEntity mscProcessEntity = (MscProcessEntity)JSONObject.toBean(obj, MscProcessEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscProcessByMsc");
    	sql = EntityTool.fillSqlByEntity(sql, mscProcessEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询冶金规范工序点
     * @return obj
     */
    public CoreReturnObject queryMscStationByMsc(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscStationEntity mscStationEntity = (MscStationEntity)JSONObject.toBean(obj, MscStationEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryMscStationByMsc");
    	sql = EntityTool.fillSqlByEntity(sql, mscStationEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询是否存在标准MSC
     * @param psc psc
     * @return obj
     */
    public CoreReturnObject queryIsExistStdMsc(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreFrmProPSCMSC.queryIsExistStdMsc");
    	sql = EntityTool.fillSqlByEntity(sql, mscEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询品名类型
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryProductType(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryProductType");
    	sql = EntityTool.fillSqlByEntity(sql, mscEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询PSC中的科室
     * @param psc psc
     * @return obj
     */
    public CoreReturnObject queryUnitCodeByPsc(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryUnitCodeByPsc");
    	sql = EntityTool.fillSqlByEntity(sql, mscEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 冶金规范界面根据冶金规范码查询接箍信息
     * @param list 查询参数
     * @return obj
     */
    public CoreReturnObject queryJgByMsc(String msc) {
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryJgByMsc");
    	sql = StringTool.ReplaceAll(sql, "#MSC#",msc);
        return this.getData(sql);
    }
    
    /**
     * Title: doQuery
     * Description: 查询备料通过接箍码
     * @param codeJg  接箍码
     * @return  平台统一返回对象
     */
    public CoreReturnObject queryBlByJg(String codeJg) {
        Object[] obj = new Object[] { codeJg};
        return this.getDataBySqlID("MscManage.queryBlByJg", obj);  
    }
    
    /**
     * 保存接箍和冶金规范关系表中的3个附加要求
     * @param list 保存参数
     * @return obj
     */
    public CoreReturnObject saveMscRJg(ArrayList<String> list){
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.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, "#MSC#", list.get(6));
    	sql = StringTool.ReplaceAll(sql, "#CODE_JG#", list.get(7));
    	return this.setData(sql);
    }
    
    /**
     * 冶金规范中的备料查询
     * @param list 查询参数
     * @return obj
     */
    public CoreReturnObject queryMscRBlByMsc(String msc){
    	Object[] objs = new Object[]{ msc };
        return this.getDataBySqlID("MscManage.queryMscRBlByMsc", objs);
    }
    
    public CoreReturnObject groupBl(ArrayList<ArrayList<String>> list){
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        for (ArrayList<String> arrayList : list) {
            sqllist.add(CoreXmlSqlParsersFactory.getSql("MscManage.groupBl"));
            parmlist.add(arrayList.toArray());
        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist, parmlist);
    }
    
    /**
     * 通过通途码获取所有客户
     * @param useCode 用途码
     * @return obj
     */
    public CoreReturnObject getClienByUse(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryClient");
    	sql = EntityTool.fillSqlByEntity(sql, mscEntity);
    	
    	return this.getData(sql);
    }
    
    /**
     * 查询冶金规范码所属的标准和协议。
     * @param strJSON 实体类
     * @return obj
     */
    public CoreReturnObject queryStdNameStyle(String strJSON){
    	JSONObject obj = JSONObject.fromObject(strJSON);
    	MscEntity mscEntity = (MscEntity)JSONObject.toBean(obj, MscEntity.class);
    	String sql = CoreXmlSqlParsersFactory.getSql("MscManage.queryStdNameStyle");
    	sql = EntityTool.fillSqlByEntity(sql, mscEntity);
    	
    	return this.getData(sql);
    }
}
