package nc.ui.iufo.report.publish.nccloud;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.swing.BorderFactory;
import javax.swing.JTree;
import javax.swing.SwingConstants;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import com.ufida.iufo.pub.tools.AppDebug;
import com.ufida.zior.comp.layout.SimpleGridLayout;

import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.itf.iufo.publish.IRepPublishService;
import nc.pub.iufo.publish.IButtonGroupVo;
import nc.pub.iufo.publish.RepPublishParam;
import nc.pub.iufo.publish.RepPublishTypeEnum;
import nc.pub.iufo.publish.RepPublishUtil;
import nc.pub.iufo.publish.WebRepPublishParam;
import nc.ui.iufo.report.publish.FuncSelectPanel;
import nc.ui.iufo.report.publish.MenuSelectStep;
import nc.ui.iufo.report.publish.RepPublishUtilClient;
import nc.ui.pub.beans.UIComboBox;
import nc.ui.pub.beans.UILabel;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.beans.UIRadioButton;
import nc.ui.pub.beans.UIScrollPane;
import nc.ui.pub.beans.UITextField;
import nc.ui.pub.beans.UITree;
import nc.ui.pub.beans.wizard.WizardModel;
import nc.ui.pub.print.TreeModuleVoNC;
import nc.ui.sf.functree.FuncTreeCellRender;
import nc.ui.uap.funcreg.model.DefaultSortTreeModel;
import nc.vo.bd.pub.NODE_TYPE;
import nc.vo.ml.MultiLangContext;
import nc.vo.org.orgmodel.OrgTypeVO;
import nc.vo.org.util.OrgTypeManager;
import nc.vo.platform.workbench.AppPageVO;
import nc.vo.platform.workbench.AppParamVO;
import nc.vo.platform.workbench.AppRegisterVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.sm.funcreg.FunRegisterConst;
import nc.vo.sm.funcreg.FuncRegisterVO;
import nc.vo.sm.funcreg.ModuleVO;
import nc.vo.sm.funcreg.ParamRegVO;

public class WebAppSelectPanel extends UIPanel implements ActionListener{
	
	private static final long serialVersionUID = 1L;

	private UIPanel pnCenter = null;

	private UIPanel pnNodeType = null;

	FuncTreeEventHandler eventHandler = new FuncTreeEventHandler();

	private UILabel labelFuncCode = null;
	
	private UIPanel pnFuncCode = null;
	
	private UILabel labelPageIndex = null;

	private UITextField tfPageIndex = null;

	private UIScrollPane pnFuncTree = null;

	private UITextField tfFuncCode = null;

	private UILabel labelNodeName = null;

	private UILabel labelOrgType = null;

	private UITextField tfNodeName = null;

	private UITree treeFunc = null;

	private UIRadioButton radioBnNew = null;

	private UIRadioButton radioBnOverwrite = null;

	private UIRadioButton radioBnAppend = null;

	private UIRadioButton radioBnDelete = null;

	private UIComboBox comboBoxOrgType = null;
	
	private RepPublishTypeEnum publisType = null;
	/** 需要发布的报表id*/
	private String[] aryRepIds = null;

	private WizardModel wizardModel = null;

	private NODE_TYPE nodeType = null;
	/** 选中的报表名称*/
	private String defName = null;

	private List<String> pubFuncids;

	private boolean isFirst = true;
	
	private static String defaultPageUrl = "/nccloud/resources/uap/report/default/simple/index.html";

	class FuncTreeEventHandler implements TreeSelectionListener
	{
		public void valueChanged(TreeSelectionEvent e)
		{
			if (e.getSource() == WebAppSelectPanel.this.getTreeFunc())
				connEtoC1(e);
		}
	}

	public WebAppSelectPanel(String[] aryRepIds, NODE_TYPE nodeType,String defName)
	{
		this.aryRepIds = aryRepIds;
		this.defName = defName;
		this.nodeType = nodeType;
		initUI();
	}
	
	public void initUI()
	{
		try
		{
			setName("ReportNodePanel");
			setLayout(new BorderLayout());
			setSize(680, 500);
			add(getPnNodeType(), BorderLayout.NORTH);
			add(getPnCenter(), BorderLayout.CENTER);
			initConnections();
			getRadioBnNew().setSelected(true);
			setPublisType(RepPublishTypeEnum.NEW);
		} catch (java.lang.Throwable ivjExc)
		{
			handleException(ivjExc);
		}

	}
	
	protected NODE_TYPE getNodeType(){
		return this.nodeType;
	}

	protected final String[] getAryRepIds(){
		return this.aryRepIds;
	}

	/**
	 *
	 * @param arg1
	 *            TreeSelectionEvent
	 */
	private void connEtoC1(TreeSelectionEvent arg1)
	{
		try
		{
			this.treeFunc_ValueChanged(arg1);
		} catch (java.lang.Throwable ivjExc)
		{
			handleException(ivjExc);
		}
	}

	/**
	 * 返回 LabelFuncCode 特性值。
	 *
	 * @return UILabel
	 */
	protected UILabel getPageIndexCode()
	{
		if (labelPageIndex == null)
		{
			try
			{
				labelPageIndex = new UILabel();
				labelPageIndex.setName("LabelPageIndex");
//				labelFuncCode.setText(nc.ui.ml.NCLangRes.getInstance()
//						.getStrByID("10241201", "UPP10241201-001493"));
				labelPageIndex.setText("页面跳转路径");
				labelPageIndex.setToolTipText("开发人员使用，没有则不输");
				labelPageIndex.setForeground(Color.black);
				labelPageIndex.setILabelType(0/** Java默认(自定义) */
				);
//				labelFuncCode.setPreferredSize(new Dimension(120, 22));
//				labelFuncCode.setPreferredSize(new Dimension(150, 22));
				labelPageIndex.setPreferredSize(new Dimension(180, 22));
				labelPageIndex.setHorizontalAlignment(SwingConstants.CENTER);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return labelPageIndex;
	}
	
	/**
	 * 返回 LabelFuncCode 特性值。
	 *
	 * @return UILabel
	 */
	protected UILabel getLabelFuncCode()
	{
		if (labelFuncCode == null)
		{
			try
			{
				labelFuncCode = new UILabel();
				labelFuncCode.setName("LabelFuncCode");
//				labelFuncCode.setText(nc.ui.ml.NCLangRes.getInstance()
//						.getStrByID("10241201", "UPP10241201-001493"));
				labelFuncCode.setText("新增应用节点编码");// 新增应用节点编码
				labelFuncCode.setForeground(Color.black);
				labelFuncCode.setILabelType(0/** Java默认(自定义) */
				);
//				labelFuncCode.setPreferredSize(new Dimension(120, 22));
//				labelFuncCode.setPreferredSize(new Dimension(150, 22));
				labelFuncCode.setPreferredSize(new Dimension(180, 22));
				labelFuncCode.setHorizontalAlignment(SwingConstants.CENTER);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return labelFuncCode;
	}

	/**
	 *
	 * @return UILabel
	 */
	/* 警告：此方法将重新生成。 */
	protected UILabel getLabelNodeName()
	{
		if (labelNodeName == null)
		{
			try
			{
				labelNodeName = new UILabel();
				labelNodeName.setName("LabelNodeName");
				// i18n
//				labelNodeName.setText(nc.ui.ml.NCLangRes.getInstance()
//						.getStrByID("10241201", "UPP10241201-001548"));
				labelNodeName.setText("新增应用节点名称");
				labelNodeName.setForeground(Color.black);
				labelNodeName.setILabelType(0/** Java默认(自定义) */
				);
//				labelNodeName.setPreferredSize(new Dimension(120, 22));
//				labelNodeName.setPreferredSize(new Dimension(150, 22));
				labelNodeName.setPreferredSize(new Dimension(180, 22));
				labelNodeName.setHorizontalAlignment(SwingConstants.CENTER);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return labelNodeName;
	}

	protected UILabel getLabelOrgType()
	{
		if (labelOrgType == null)
		{
			try
			{
				labelOrgType = new UILabel();
				labelOrgType.setName("labelOrgType");
				// i18n
				labelOrgType.setText(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0081")/*@res "组织类型"*/);
				labelOrgType.setForeground(Color.black);
				labelOrgType.setILabelType(0/** Java默认(自定义) */
				);
				labelOrgType.setPreferredSize(new Dimension(120, 22));
				labelOrgType.setHorizontalAlignment(SwingConstants.CENTER);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return labelOrgType;
	}

	protected UITextField getTFNodeName()
	{
		if (tfNodeName == null)
		{
			try
			{
				tfNodeName = new UITextField();
				tfNodeName.setName("TFFuncCode");
				tfNodeName.setPreferredSize(new Dimension(150, 22));
				tfNodeName.setMaxLength(100);
				tfNodeName.setText(defName);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return tfNodeName;
	}

	/**
	 * 返回 PnCenter 特性值。
	 *
	 * @return UIPanel
	 */
	private UIPanel getPnCenter()
	{
		if (pnCenter == null)
		{
			try
			{
				pnCenter = new UIPanel();
				pnCenter.setName("PnCenter");
				pnCenter.setLayout(new BorderLayout(5, 6));
				getPnCenter().add(getPnFuncCode(), "South");
				getPnCenter().add(getSclPnFuncTree(), "Center");
				// 设置边框
//				getPnCenter().setBorder(
//						BorderFactory.createTitledBorder(BorderFactory
//								.createEtchedBorder(), nc.ui.ml.NCLangRes
//								.getInstance().getStrByID("10241201",
//										"UPP10241201-001494")));
				getTreeFunc().revalidate();
				getPnCenter().setBorder(
						BorderFactory.createTitledBorder(BorderFactory
								.createEtchedBorder(),"新增请选择一个应用分类（编码长度为6位，需输入新建应用编码，应用编码长度需大于6位），覆盖和删除请选择一个已存在的应用。"));
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return pnCenter;
	}

	/**
	 * 返回 PnFuncCode 特性值。
	 *
	 * @return UIPanel
	 */
	/* 警告：此方法将重新生成。 */
	protected UIPanel getPnFuncCode()
	{
		if (pnFuncCode == null)
		{
			try
			{
				pnFuncCode = new UIPanel();
				pnFuncCode.setName("PnFuncCode");
				pnFuncCode.setLayout(new SimpleGridLayout(3, 4, 6, 6));

				pnFuncCode.add(getLabelFuncCode());
				pnFuncCode.add(getTFFuncCode());
				pnFuncCode.add(getLabelNodeName());
				pnFuncCode.add(getTFNodeName());
				pnFuncCode.add(getLabelOrgType());
				pnFuncCode.add(getComboBoxOrgType());
				pnFuncCode.add(getPageIndexCode());
				pnFuncCode.add(getTFPageIndex());
				pnFuncCode.add(SimpleGridLayout.createEmptyComponent());
				pnFuncCode.add(SimpleGridLayout.createEmptyComponent());
				pnFuncCode.add(SimpleGridLayout.createEmptyComponent());
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return pnFuncCode;
	}

	/**
	 * 返回 PnNodeType 特性值。
	 *
	 * @return UIPanel
	 */
	protected UIPanel getPnNodeType()
	{
		if (pnNodeType == null)
		{
			try
			{
				pnNodeType = new UIPanel();
				FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
				flow.setHgap(20);
				pnNodeType.setLayout(flow);
				pnNodeType.setName("PnNodeType");
				pnNodeType.add(getRadioBnNew());
				pnNodeType.add(getRadioOverwrite());
				pnNodeType.add(getRadioBnDelete());

				// 设置边框
				pnNodeType.setBorder(BorderFactory.createTitledBorder(
						BorderFactory.createEtchedBorder(), nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0083")/*@res "发布方式"*/));
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return pnNodeType;
	}

	/**
	 * 返回 RadioBnIndependent 特性值。
	 *
	 * @return UIRadioButton
	 */
	/* 警告：此方法将重新生成。 */
	protected UIRadioButton getRadioBnNew()
	{
		if (radioBnNew == null)
		{
			try
			{
				radioBnNew = new UIRadioButton();
				radioBnNew.setName("RadioBnNew");
				// radioBnNew.setPreferredSize(new Dimension(100, 22));
				radioBnNew.setText(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0084")/*@res "新增"*/);
				radioBnNew.setHorizontalAlignment(SwingConstants.CENTER);
				radioBnNew.addActionListener(this);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return radioBnNew;
	}

	protected UIComboBox getComboBoxOrgType()
	{
		if (comboBoxOrgType == null)
		{
			OrgTypeVO[] orgtypevos = getOrgtypevos();
			dealOrgTypesMultil(orgtypevos);//处理组织类型的多语
			comboBoxOrgType = new UIComboBox(orgtypevos);
			comboBoxOrgType.setPreferredSize(new Dimension(165, 22));
		}
		return comboBoxOrgType;
	}

	/**
	 * 查询可作为主组织类型的所有OrgTypeVO（全局、集团、业务单元及各具体类型）
	 * @return
	 */
	@SuppressWarnings("deprecation")
	protected OrgTypeVO[] getOrgtypevos() {
		return OrgTypeManager.getInstance().getAllFuncCodeOrgType();
	}

	/**
	 * 处理组织类型的多语
	 * @param orgtypevos
	 * @author: zhongkm  2011-10-25 下午04:25:14
	 */
	private void dealOrgTypesMultil(OrgTypeVO[] orgtypevos) {

		for(OrgTypeVO orgVo:orgtypevos){
			orgVo.setName(getorgMultilName(orgVo));
		}
	}

	private String getorgMultilName(OrgTypeVO orgVo) {
		int langSeq = MultiLangContext.getInstance().getCurrentLangSeq() ;
		String str = null;
		switch (langSeq) {
		case 1:
			str = orgVo.getName() ;
			break;
		case 2:
			str = orgVo.getName2() ;
			break;
		case 3:
			str = orgVo.getName3() ;
			break;
		case 4:
			str = orgVo.getName4() ;
			break;
		case 5:
			str = orgVo.getName5() ;
			break;
		case 6:
			str = orgVo.getName6() ;
			break;
		default:
			break;
		}
		return str;
	}

	/**
	 * 返回 RadioBnManagement 特性值。
	 *
	 * @return UIRadioButton
	 */
	private UIRadioButton getRadioOverwrite()
	{
		if (radioBnOverwrite == null)
		{
			try
			{
				radioBnOverwrite = new UIRadioButton();
				radioBnOverwrite.setName("RadioBnOverwrite");
				// radioBnOverwrite.setPreferredSize(new Dimension(100, 22));
				radioBnOverwrite.setText(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0085")/*@res "覆盖"*/);
				radioBnOverwrite.setHorizontalAlignment(SwingConstants.CENTER);
				radioBnOverwrite.addActionListener(this);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return radioBnOverwrite;
	}

	/**
	 * 返回 RadioBnTemplet 特性值。
	 *
	 * @return UIRadioButton
	 */
	/* 警告：此方法将重新生成。 */
	private UIRadioButton getRadioBnAppend()
	{
		if (radioBnAppend == null)
		{
			try
			{
				radioBnAppend = new UIRadioButton();
				radioBnAppend.setName("RadioBnAppend");
				// radioBnAppend.setPreferredSize(new Dimension(100, 22));
				radioBnAppend.setText(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0086")/*@res "追加"*/);
				radioBnAppend.setHorizontalAlignment(SwingConstants.CENTER);
				radioBnAppend.addActionListener(this);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return radioBnAppend;
	}

	private UIRadioButton getRadioBnDelete() {
		if(radioBnDelete == null) {
			radioBnDelete = new UIRadioButton();
			radioBnDelete.setName("RadioBnDelete");
			radioBnDelete.setText(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0091")/*@res "删除"*/);
			radioBnDelete.setHorizontalAlignment(SwingConstants.CENTER);
			radioBnDelete.addActionListener(this);
		}
		return radioBnDelete;
	}

	/**
	 * 返回 SclPnFuncTree 特性值。
	 *
	 * @return UIScrollPane
	 */
	/* 警告：此方法将重新生成。 */
	private UIScrollPane getSclPnFuncTree()
	{
		if (pnFuncTree == null)
		{
			try
			{
				pnFuncTree = new UIScrollPane();
				pnFuncTree.setName("SclPnFuncTree");
				getSclPnFuncTree().setViewportView(getTreeFunc());
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return pnFuncTree;
	}

	/**
	 * 返回 TFFuncCode 特性值。
	 *
	 * @return UITextField
	 */
	/* 警告：此方法将重新生成。 */
	protected UITextField getTFPageIndex()
	{
		if (tfPageIndex == null)
		{
			try
			{
				tfPageIndex = new UITextField();
				tfPageIndex.setName("TFPageIndex");
				tfPageIndex.setPreferredSize(new Dimension(165, 22));
				// ivjTFFuncCode.setTextType("TextInt");
				tfPageIndex.setMaxLength(300);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return tfPageIndex;
	}
	
	/**
	 * 返回 TFFuncCode 特性值。
	 *
	 * @return UITextField
	 */
	/* 警告：此方法将重新生成。 */
	protected UITextField getTFFuncCode()
	{
		if (tfFuncCode == null)
		{
			try
			{
				tfFuncCode = new UITextField();
				tfFuncCode.setName("TFFuncCode");
				tfFuncCode.setPreferredSize(new Dimension(165, 22));
				// ivjTFFuncCode.setTextType("TextInt");
				tfFuncCode.setMaxLength(100);
				tfFuncCode.setText(getPredictCode());
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return tfFuncCode;
	}

	/**
	 * 返回 TreeFunc 特性值。
	 *
	 * @return UITree
	 */
	/* 警告：此方法将重新生成。 */
	protected UITree getTreeFunc()
	{
		if (treeFunc == null)
		{
			try
			{
				treeFunc = makeFuncTree(nc.ui.ml.NCLangRes.getInstance()
						.getStrByID("10241201", "UPP10241201-001128"));
				treeFunc.setName("TreeFunc");
				treeFunc.setBounds(0, 0, 78, 72);
				treeFunc.getSelectionModel().setSelectionMode(
						TreeSelectionModel.SINGLE_TREE_SELECTION);
				treeFunc.setSelectionRow(1);
			} catch (java.lang.Throwable ivjExc)
			{
				handleException(ivjExc);
			}
		}
		return treeFunc;
	}

	/**
	 * 每当部件抛出异常时被调用
	 *
	 * @param exception
	 *            java.lang.Throwable
	 * @i18n upp08110600001=--------- 未捕捉到的异常 ---------
	 */
	protected void handleException(java.lang.Throwable exception)
	{

		/* 除去下列各行的注释，以将未捕捉到的异常打印至 stdout。 */
		Logger.error("--------- 未捕捉到的异常 ---------", exception);
	}

	/**
	 * 初始化连接
	 *
	 * @exception java.lang.Exception
	 *                异常说明。
	 */
	/* 警告：此方法将重新生成。 */
	private void initConnections() throws java.lang.Exception
	{
		getTreeFunc().addTreeSelectionListener(eventHandler);
	}

	/**
	 * 树节点改变选取事件响应
	 */
	protected void treeFunc_ValueChanged(TreeSelectionEvent treeSelectionEvent)
	{
		// 获得选中功能VO
		TreePath path = getTreeFunc().getSelectionPath();
		DefaultMutableTreeNode item = null;
		if (path != null)
		{
			item = (DefaultMutableTreeNode) path.getLastPathComponent();
		}
		if (item == null || item.isRoot())
			return;

		Object userObj = item.getUserObject();
//		boolean isParentItem = isParentFunc(userObj);
		if (getRadioBnNew().isSelected())
		{
			boolean canAddApp = canAddApp(userObj);
			enableFuncFld(canAddApp);
			//编码智能提供
			if(canAddApp){//不是子节点
				String code = getPredictCode(item);
				getTFFuncCode().setText(code);;//预置节点编码
				getTFNodeName().setText(defName);
			}else{
				getTFFuncCode().setText(null);
				getTFNodeName().setText(null);
			}
			wizardModel.getPublicActions().getNextAction().setEnabled(
					canAddApp);
			return;
		} else if (getRadioOverwrite().isSelected()
				|| getRadioBnAppend().isSelected() || getRadioBnDelete().isSelected())
		{
			boolean canOverwrite = canOverwriteOrDel(userObj);
//			boolean isParentItem = isParentFunc(userObj);
			enableFuncFld(false);
			if (!canOverwrite)
			{
				getTFFuncCode().setText(null);
				getTFNodeName().setText(null);
			} else
			{
				TreeModuleVoNC treeVo = (TreeModuleVoNC)userObj;
				getTFFuncCode().setText(treeVo.getCode());
				//以后可能要处理多语
				String appName = treeVo.getName();
				
//				FuncRegisterVO funVo = (FuncRegisterVO) userObj;
//				getTFFuncCode().setText(funVo.getFuncode());
//				String funcName = nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getString("funcode",funVo.getFun_name(),funVo.getFuncode()) ;
				// modified by huoqi 20120323 trim需要重新赋值
				appName = appName.trim();
				getTFNodeName().setText(appName);
				//先让可以选，之后自动加
//				getComboBoxOrgType().setEnabled(true);
				//暂时先不加这个，等接口好了之后加
				getComboBoxOrgType().setSelectedItem(OrgTypeManager.getInstance().getOrgTypeByID(treeVo.getOrgTypeCode()));
//				getComboBoxOrgType().setSelectedItem(
//						OrgTypeManager.getInstance().getOrgTypeByID(
//								funVo.getOrgtypecode()));
			}
			wizardModel.getPublicActions().getFinishAction().setEnabled(
					wizardModel.getStepsCount() == 1
							&& canOverwrite
							);
			return;
		}
	}

	/**
	 * 删除菜单选项step
	 */
	private void deleteMenuStep()
	{
		if (wizardModel.getStepsCount() == 2)
			wizardModel.deleteStep(1);
	}

	/**
	 * 增加菜单选项step
	 */
	private void addMenuStep()
	{
		if (wizardModel.getStepsCount() == 1)
			wizardModel.insertStep(new WebMenuSelectStep(defName), 1);
	}

	private boolean isParentFunc(Object userObj)
	{
		if (userObj instanceof ModuleVO)
			return true;
		else if (userObj instanceof FuncRegisterVO
				&& (((FuncRegisterVO) userObj).getFun_property() == null || FunRegisterConst.INEXECUTABLE_FUNC_NODE == ((FuncRegisterVO) userObj)
						.getFun_property()))
		{
			return true;
		}
		return false;
	}
	
	private boolean canAddApp(Object userObj){
		if(userObj instanceof TreeModuleVoNC){
			int codelen = ((TreeModuleVoNC) userObj).getCode().length();
			if(codelen == 6 || codelen == 7){
				return true;
			}
		}
		return false;
	}
	
	private boolean canOverwriteOrDel(Object userObj){
		if(userObj instanceof TreeModuleVoNC){
			if(((TreeModuleVoNC) userObj).getCode().length() > 6 && ((TreeModuleVoNC) userObj).getIsleaf() == UFBoolean.TRUE){
				return true;
			}
		}
		return false;
	}

	/**
	 * 改变功能节点输入框的状态
	 *
	 * @param flag
	 */
	private void enableFuncFld(boolean flag)
	{
		getLabelFuncCode().setEnabled(flag);
		getLabelNodeName().setEnabled(flag);
		getTFFuncCode().setEnabled(flag);
		getTFNodeName().setEnabled(flag);
		getLabelOrgType().setEnabled(flag);
		getComboBoxOrgType().setEnabled(flag);
	}

	/**
	 * 获得功能树（不含被禁用的功能，不含按钮，不含可执行功能节点）
	 */
	private UITree makeFuncTree(String strRoot)
	{

		UITree treeFunc = new UITree(WebRepPublishUtilClient.createApplicationTree());
		// 添加树单元修饰（用于区分有权限按钮与无权限按钮）
		treeFunc.setCellRenderer(new WebAppTreeCellRender());
		// 设置树线型
		treeFunc.putClientProperty("JTree.lineStyle", "Angled");
		// 限制树节点单选
		treeFunc.getSelectionModel().setSelectionMode(
				TreeSelectionModel.SINGLE_TREE_SELECTION);
		return treeFunc;
	}

	private class RepFuncTreeCellRender extends FuncTreeCellRender {
		private static final long serialVersionUID = 1L;
		public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
			Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
			DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
			Object obj = node.getUserObject();
//			if(obj instanceof FuncRegisterVO) {
//				FuncRegisterVO vo = (FuncRegisterVO)obj;
//				if(vo.getClass_name() != null && vo.getClass_name().equals("nc.ui.iufo.freereport.FreeReportFunclet")) {
//					comp.setBackground(Color.RED);
//					comp.setForeground(Color.BLUE);
//					comp.setFont(Font.getFont(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("0502002_0","00502002-0005")/*@res "宋体"*/));
//				}
//			}
			if(obj instanceof TreeModuleVoNC){
				TreeModuleVoNC vo = (TreeModuleVoNC)obj;
				if(vo.getIsleaf() == UFBoolean.TRUE){
					comp.setBackground(Color.RED);
					comp.setForeground(Color.BLUE);
					comp.setFont(Font.getFont(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("0502002_0","00502002-0005")/*@res "宋体"*/));
				}
//				if(vo.get)
			}
			return comp;
		}
	}

	public void reload(boolean onlyRep) {
//		if(onlyRep) {
//			DefaultMutableTreeNode newRoot = new DefaultMutableTreeNode();
//			DefaultMutableTreeNode root = (DefaultMutableTreeNode)(getTreeFunc().getModel()).getRoot();
//			newRoot.setUserObject(root.getUserObject());
//			reloadTree(newRoot, null, null);
//			((DefaultTreeModel)getTreeFunc().getModel()).setRoot(newRoot);
//		} else {
		((DefaultTreeModel)getTreeFunc().getModel()).setRoot((TreeNode)WebRepPublishUtilClient.createApplicationTree().getRoot());

//		}
	}

//	protected boolean reloadTree(DefaultMutableTreeNode newRoot, List<String> allPubFuncids, DefaultMutableTreeNode root) {
//		DefaultTreeModel model = (DefaultTreeModel)getTreeFunc().getModel();
//		boolean isremoveParent = true;
//		boolean isremove = true;
//		if(root == null) {
//			root = (DefaultMutableTreeNode)model.getRoot();
//		}
//		newRoot.setUserObject(root.getUserObject());
//		if(allPubFuncids == null) {
//			allPubFuncids = getAllPubRepFuncids();
//		}
//		if(allPubFuncids == null) {
//			return false;
//		}
//		int len  = model.getChildCount(root);
//		for(int i = 0;i < len;i++) {
//			isremove = true;
//			DefaultMutableTreeNode node = (DefaultMutableTreeNode)model.getChild(root, i);
//			DefaultMutableTreeNode np = new DefaultMutableTreeNode();
//			np.setUserObject(node.getUserObject());
//			if(node.getUserObject() instanceof ModuleVO) {
//				isremove = reloadTree(np, allPubFuncids, node);
//				if(!isremove) {
//					newRoot.add(np);
//					isremoveParent = false;
//				}
//			} else if(node.getUserObject() instanceof FuncRegisterVO) {
//				FuncRegisterVO funcVo = (FuncRegisterVO)node.getUserObject();
//				if(!node.isLeaf()) {
//					isremove = reloadTree(np, allPubFuncids, node);
//					if(!isremove) {
//						newRoot.add(np);
//						isremoveParent = false;
//					}
//				} else {
//					
//				}
//			}
//		}
//		return isremoveParent;
//	}

	protected List<String> getAllPubRepFuncids() {
		if(pubFuncids == null) {
			IRepPublishService funcService = NCLocator.getInstance().lookup(IRepPublishService.class);
			try {
				pubFuncids = funcService.getAllPubRepFuncids();
			} catch (BusinessException e) {
				AppDebug.debug(e);
			}
		}
		return pubFuncids;
	}

	/**
	 * 获得选中对象
	 */
	protected Object getSelFunc()
	{
		TreePath path = getTreeFunc().getSelectionPath();
		DefaultMutableTreeNode item = null;
		if (path != null)
		{
			item = (DefaultMutableTreeNode) path.getLastPathComponent();
		}
		if (item == null || item.isRoot())
			return null;
		Object userObj = item.getUserObject();
		return userObj;
	}

	private String getOwnModule()
	{
		TreePath path = getTreeFunc().getSelectionPath();
		DefaultMutableTreeNode item = null;
		if (path != null)
		{
			item = (DefaultMutableTreeNode) path.getLastPathComponent();
		}
		if (item == null || item.isRoot())
			return null;
		Object userObj = item.getUserObject();
		if (userObj instanceof FuncRegisterVO)
		{
			return ((FuncRegisterVO) userObj).getOwn_module();
		} else if (userObj instanceof ModuleVO)
		{
			return ((ModuleVO) userObj).getModuleid();
		}else if(userObj instanceof TreeModuleVoNC){
			return ((TreeModuleVoNC)userObj).getPid();
		}
		return null;
	}

	/**
	 * 校验
	 */
	protected String checkFuncValid()
	{
		if (isCreateNode())
		{
			// 选中目录，新建功能节点
			String funCode = getNewFuncCode();
			if (funCode == null || funCode.trim().equals(""))
				return nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0092")/*@res "功能编码不能为空"*/;
			// 限制根节点
			// 编码合法性
			// if (!checkFuncode(dirCode, funCode)) {
			// return nc.ui.ml.NCLangRes.getInstance().getStrByID("10241201",
			// "UPP10241201-001124")/* @res "功能编码不合法" */;
			// }
			// 判断功能编码是否已使用
			if (RepPublishUtil.isFuncCodeUsed(funCode))
			{
//				return nc.ui.ml.NCLangRes.getInstance().getStrByID("10241201",
//						"UPP10241201-001125")/* @res "功能编码已被使用" */;
				return nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1413001_0","01413001-0087")/*@res "功能编码已被使用"*//* @res "功能编码已被使用" */;
			}
		}
		return null;
	}

	/**
	 * 获得用户指定的功能编码
	 */
	private String getNewFuncCode()
	{
		return getTFFuncCode().getText();
	}

	/**
	 * 是否新建节点
	 */
	private boolean isCreateNode()
	{
		return getTFFuncCode().isEnabled();
	}

	protected WizardModel getWizardModel()
	{
		return wizardModel;
	}

	protected void setWizardModel(WizardModel wizardModel)
	{
		this.wizardModel = wizardModel;
	}

	/**
	 * 单选按钮控制（用ButtonGroup好象不能全不选）
	 */
	public void actionPerformed(ActionEvent e)
	{
		if (e.getSource() == getRadioBnNew())
		{
			getRadioOverwrite().setSelected(false);
			getRadioBnAppend().setSelected(false);
			getRadioBnDelete().setSelected(false);
			getRadioBnNew().setSelected(true);
			getTFFuncCode().setText(getPredictCode());
			getTFNodeName().setText(defName);
			setPublisType(RepPublishTypeEnum.NEW);
			addMenuStep();
			if(!isFirst) {
				reload(false);
			}
		}
		if (e.getSource() == getRadioOverwrite())
		{
			getRadioBnNew().setSelected(false);
			getRadioBnAppend().setSelected(false);
			getRadioBnDelete().setSelected(false);
			getRadioOverwrite().setSelected(true);
			getTFFuncCode().setText(null);
			getTFNodeName().setText(null);
			setPublisType(RepPublishTypeEnum.OVERWRITE);
			deleteMenuStep();
			reload(true);
			isFirst = false;
			wizardModel.getPublicActions().getFinishAction().setEnabled(false);
		}
		if (e.getSource() == getRadioBnAppend())
		{
			getRadioBnNew().setSelected(false);
			getRadioOverwrite().setSelected(false);
			getRadioBnDelete().setSelected(false);
			getRadioBnAppend().setSelected(true);
			getTFFuncCode().setText(null);
			getTFNodeName().setText(null);
			setPublisType(RepPublishTypeEnum.APPEND);
			deleteMenuStep();
			reload(true);
			isFirst = false;
			wizardModel.getPublicActions().getFinishAction().setEnabled(false);
		}
		if (e.getSource() == getRadioBnDelete()) {
			getRadioBnNew().setSelected(false);
			getRadioOverwrite().setSelected(false);
			getRadioBnAppend().setSelected(false);
			getRadioBnDelete().setSelected(true);
			getTFFuncCode().setText(null);
			getTFNodeName().setText(null);
			setPublisType(RepPublishTypeEnum.DELETE);
			deleteMenuStep();
			reload(true);
			isFirst = false;
			wizardModel.getPublicActions().getFinishAction().setEnabled(false);
		}
		if (e.getSource() == getRadioBnNew()
				|| e.getSource() == getRadioOverwrite()
				|| e.getSource() == getRadioBnAppend()
				|| e.getSource() == getRadioBnDelete()){
			treeFunc_ValueChanged(null);
			changeEnabledInSub();//子类中 可以做些事情
		}
	}


	/** 留出接口供子类使用,使之可以改变界面中的一些可用性
	 *@author: zhongkm  2011-8-18 下午05:44:01
	*/
	protected void changeEnabledInSub() {

	}

	public RepPublishTypeEnum getPublisType()
	{
		return publisType;
	}

	public void setPublisType(RepPublishTypeEnum publisType)
	{
		this.publisType = publisType;
	}

	// /**
	// * 寻找可用功能编码
	// */
	// public String makeNewFunCode(FuncPowerTreeItem item, String parentCode) {
	// String newFunCode = null;
	// try {
	// Hashtable<String,FuncRegisterVO> hashChildCode = new
	// Hashtable<String,FuncRegisterVO>();
	// for (int i = 0; i < item.getChildCount(); i++) {
	// FuncPowerTreeItem childNode = (FuncPowerTreeItem) item.getChildAt(i);
	// if (childNode != null) {
	// FuncRegisterVO childVO = childNode.getFuncRegisterVO();
	// hashChildCode.put(childVO.getFuncode(), childVO);
	// }
	// }
	// // V502+
	// d: for (char c1 = 'A'; c1 < 'Z'; c1++) {
	// for (char c2 = 'A'; c2 < 'Z'; c2++) {
	// newFunCode = parentCode + c1 + c2;
	// if (!hashChildCode.containsKey(newFunCode)) {
	// break d;
	// }
	// }
	// }
	// } catch (Exception e) {
	// Logger.error(e);
	// }
	// if (newFunCode == null) {
	// newFunCode = parentCode + "00";
	// }
	// return newFunCode;
	// }

	/**
	 * 得到发布功能节点的父节点id
	 *
	 * @return
	 */
	private String getFuncParentId()
	{
		Object vo = getSelFunc();
		return vo instanceof FuncRegisterVO ? ((FuncRegisterVO) vo).getCfunid()
				: null;
	}
	
	private String getAppParentId(){
		Object vo = getSelFunc();
		String parentid = null;
		if(vo instanceof TreeModuleVoNC){
			parentid = ((TreeModuleVoNC)vo).getPk();
		}
		return parentid;
	}
	
	/**
	 * 返回组织类型编码
	 *
	 * @return
	 */
	private String getOrgTypeCode()
	{
		return ((OrgTypeVO) getComboBoxOrgType().getSelectdItemValue())
				.getPk_orgtype();
	}

	/**
	 * 构建发布功能节点的vo
	 */
	protected FuncRegisterVO getFuncRegisterVo()
	{
		FuncRegisterVO funcVo = new FuncRegisterVO();
		funcVo.setFun_name(getTFNodeName().getText());
		funcVo.setFuncode(getTFFuncCode().getText());
		funcVo.setOwn_module(getOwnModule());
		funcVo.setParent_id(getFuncParentId());
		funcVo.setFuntype(FunRegisterConst.FUNC_TYPE_BUSINESS);
		funcVo.setFun_property(FunRegisterConst.EXECUTABLE_FUNC_NODE);
		funcVo.setIsenable(UFBoolean.TRUE);
		funcVo.setOrgtypecode(getOrgTypeCode());
		funcVo.setIsbuttonpower(UFBoolean.TRUE);
		return funcVo;
	}
	
	/**
	 * 覆盖和删除时存应用主键即可
	 * @return
	 */
	protected AppRegisterVO getSelApp(){
		TreeModuleVoNC vo = (TreeModuleVoNC)getSelFunc();
		AppRegisterVO appVo = new AppRegisterVO();
		appVo.setPk_appregister(vo.getPk());
		appVo.setCode(vo.getCode());
		appVo.setOrgtypecode(vo.getOrgTypeCode());
		return appVo;
	}
	
	protected AppRegisterVO getAppRegisterVO(){
		AppRegisterVO appVo = new AppRegisterVO();
		appVo.setName(getTFNodeName().getText());
		appVo.setCode(getTFFuncCode().getText());
		appVo.setOwn_module(getOwnModule());
		appVo.setParent_id(getAppParentId());
		appVo.setFuntype(FunRegisterConst.FUNC_TYPE_BUSINESS);
		appVo.setFun_property(FunRegisterConst.EXECUTABLE_FUNC_NODE);
		appVo.setIsenable(UFBoolean.TRUE);
		appVo.setOrgtypecode(getOrgTypeCode());
		return appVo;
		
	}
	
	private AppParamVO getAppParamVo(){
		AppParamVO vo = new AppParamVO();
		vo.setParamname("pk_report");
		vo.setParamvalue(aryRepIds[0]);
		return vo;
	}
	
	private AppPageVO getPageVO(){
		AppPageVO vo = new AppPageVO();
		vo.setPagecode("ReportPage");
		vo.setPagename(getTFNodeName().getText());
		vo.setIsdefault(UFBoolean.TRUE);
		if(getTFPageIndex()!=null){
			if(getTFPageIndex().getText().isEmpty()){
				vo.setPageurl(defaultPageUrl);
			}else{
				vo.setPageurl(getTFPageIndex().getText());
			}
			
		}else{
			vo.setPageurl(defaultPageUrl);
		}
		return vo;
	}
	
	public WebRepPublishParam doWebPublish(){
		//功能ID 功能注册需要的参数
		AppRegisterVO appRegVO = null;
		List<AppParamVO> paraList = new ArrayList<AppParamVO>();
		
		paraList.add(getAppParamVo());
		if(getPublisType().equals(RepPublishTypeEnum.NEW)){//新增
//			funcRegVO = getFuncRegisterVo();
			appRegVO = getAppRegisterVO();
		}else{
//			funcRegVO = (FuncRegisterVO) getSelFunc();
//			appRegVO = (FuncRegisterVO) getSelFunc();
			appRegVO = getSelApp();
		}
		
		AppPageVO pageVo = getPageVO();
		WebRepPublishParam pubParam = new WebRepPublishParam();
		pubParam.setFuncRegVO(appRegVO);
		pubParam.setparaList(paraList);
		pubParam.setPublishType(getPublisType());
		pubParam.setAryRepIds(aryRepIds);
		pubParam.setAppPageVO(pageVo);
//		pubParam.setButtonGroupVos(getButtonGroups(funcRegVO.getCfunid()));
//		pubParam.setPk_casedefine(getCaseDefinePK());//add by liws0,多传一个参数到后台：发布方案的主键

		return pubParam;
	}

	/**
	 * 发布
	 */
	public RepPublishParam doPublish()
	{

		//功能ID 功能注册需要的参数
		FuncRegisterVO funcRegVO = null;
		List<ParamRegVO> paraList = new ArrayList<ParamRegVO>();
		if(getPublisType().equals(RepPublishTypeEnum.NEW)){//新增
			funcRegVO = getFuncRegisterVo();
		}else{
			funcRegVO = (FuncRegisterVO) getSelFunc();
		}
		RepPublishParam pubParam = new RepPublishParam();
		pubParam.setFuncRegVO(funcRegVO);
		pubParam.setparaList(paraList);
		pubParam.setPublishType(getPublisType());
		pubParam.setAryRepIds(aryRepIds);
		pubParam.setButtonGroupVos(getButtonGroups(funcRegVO.getCfunid()));
		pubParam.setPk_casedefine(getCaseDefinePK());//add by liws0,多传一个参数到后台：发布方案的主键

		return pubParam;
		/*FuncRegisterVO funcVo = null;
		try
		{
			String strFuncId = null;
			if (getPublisType().equals(RepPublishTypeEnum.NEW))
			{
				funcVo = getFuncRegisterVo();
				funcVo = RepPublishUtil.insertFunctionRegVO(funcVo);
				strFuncId = funcVo.getCfunid();
				List<ParamRegVO> lstParams = new ArrayList<ParamRegVO>();
				Map<String, String> mapParams = getParams();

				if (mapParams != null && mapParams.size() > 0)
				{
					Iterator<Map.Entry<String, String>> iter = mapParams
							.entrySet().iterator();
					while (iter.hasNext())
					{
						Map.Entry<String, String> paramEntry = iter.next();
						ParamRegVO paramVo = new ParamRegVO();
						paramVo.setParamname(paramEntry.getKey());
						paramVo.setParamvalue(paramEntry.getValue());
						paramVo.setParentid(funcVo.getCfunid());
						lstParams.add(paramVo);
					}
				}

				RepPublishUtil.insertParamVOs(lstParams
						.toArray(new ParamRegVO[0]));
			} else
			{
				strFuncId = ((FuncRegisterVO) getSelFunc()).getCfunid();
			}
			RepPublishUtil.savePublishReport(strFuncId, aryRepIds,
					getPublisType());

		} catch (Exception e)
		{
			AppDebug.debug(e);
			MessageDialog.showErrorDlg(this, "报表发布出错", e.getMessage());

		}
		return funcVo;*/
	}

	/**
	 * @return 子类实现，返回需要的业务活动和按钮信息
	 *@author: zhongkm  2011-8-18 下午03:29:24
	 * @param funid
	*/
	protected List<IButtonGroupVo> getButtonGroups(String funid) {
		return null;
	}

	/**
	 * 子类实现，返回 发布方案的主键
	 * @author liws0
	 * @return
	 */
	protected String getCaseDefinePK(){
		return null;
	}

	/**
	 * @return 根据参数名，参数值，生成对应的参数
	 *@author: zhongkm  2011-8-9 上午11:28:10
	*/
	protected ParamRegVO CreateParamRegVo(String paramName,String paramValue, String parentid) {
		ParamRegVO paramVo = new ParamRegVO();
		paramVo.setParamname(paramName);
		paramVo.setParamvalue(paramValue);
		paramVo.setParentid(parentid);
		return paramVo;
	}

	public void refresh(){
		this.getTFFuncCode().setText("");
		this.getTFNodeName().setText("");
		this.getComboBoxOrgType().setSelectedIndex(0);
	}
	
	private String getPredictCode(){
		TreePath path = getTreeFunc().getSelectionPath();
		DefaultMutableTreeNode item = null;
		if (path != null) {
			item = (DefaultMutableTreeNode) path.getLastPathComponent();
		}
		String code = null;
		if (!(item == null || item.isRoot())){
			Object userObj = item.getUserObject();
			boolean isParentItem = isParentFunc(userObj);
			if(isParentItem){//不是子节点
				code = getPredictCode(item);
			}else{
				return null;
			}
		}
		return code;
	}
	
	/**
	 * 对选中的功能树一个目录节点，获取其所有子节点的编码list
	 */
	private ArrayList<String> getAllChildrenCodes(
			DefaultMutableTreeNode node) {
		ArrayList<String> list = new ArrayList<String>();

		Object next = null;
		Object nextUserObject = null;
		Enumeration<?> e = node.children();
		while (e.hasMoreElements()) {
			next = e.nextElement();
			if (!(next instanceof DefaultMutableTreeNode)) {
				continue;
			}
			nextUserObject = ((DefaultMutableTreeNode) next).getUserObject();
//			if (nextUserObject instanceof ModuleVO) {
//				list.add(((ModuleVO) nextUserObject).getModuleid());
//			} else if (nextUserObject instanceof FuncRegisterVO) {
//				list.add(((FuncRegisterVO) nextUserObject).getFuncode());
//			}
			if(nextUserObject instanceof TreeModuleVoNC){
				list.add(((TreeModuleVoNC)nextUserObject).getCode());
			}
		}
		return list;
	}
	
	
	@SuppressWarnings("unchecked")
	private String getPredictCode(DefaultMutableTreeNode node) {
		if (node == null) {
			return null;
		}
		ArrayList<String> codeList = getAllChildrenCodes(node);

		if (codeList.isEmpty()) {
			Object vo = node.getUserObject();
//			if (vo instanceof ModuleVO) {
//				return ((ModuleVO) vo).getModuleid() + "01";
//			} else if (vo instanceof FuncRegisterVO) {
//				return ((FuncRegisterVO) vo).getFuncode() + "01";
//			}
			return ((TreeModuleVoNC)vo).getCode() + "01";
		}

		ArrayList<Integer> finalList = new ArrayList<Integer>();
		// 先找出出现次数最多的共同前缀
		HashMap<Integer, String> commonMap = new HashMap<Integer, String>();
		ArrayList<String> codeListClone1 = (ArrayList<String>) codeList.clone();
		ArrayList<String> codeListClone2 = (ArrayList<String>) codeList.clone();
		for (int i = 0; i < codeListClone1.size(); i++) {
			String commonString = codeListClone1.get(i).substring(0,
					codeListClone1.get(i).length() - 2);
			int num = 0;
			for (int j = i + 1; j < codeListClone2.size(); j++) {
				if (commonString.equals(codeListClone2.get(j).substring(0,
						codeListClone2.get(j).length() - 2))) {
					codeListClone1.remove(j - num);
					num++;
				}
			}
			commonMap.put(num, commonString);
			codeListClone2 = (ArrayList<String>) codeListClone1.clone();
		}
		ArrayList<Integer> numList = new ArrayList<Integer>();
		Iterator<Integer> iterator = commonMap.keySet().iterator();
		while (iterator.hasNext()) {
			numList.add(iterator.next());
		}
		int maxNum = Collections.max(numList);
		String commonString = commonMap.get(maxNum);

		// 根据出现次数最多的前缀找到以此为前缀的所有id，比较后两位，找出最大值
		for (int i = 0; i < codeList.size(); i++) {
			if (codeList.get(i).startsWith(commonString)) {
				String lastString = codeList.get(i).substring(
						codeList.get(i).length() - 2, codeList.get(i).length());
				// 对后两位暂时只处理数字，字母什么的不处理了~~
				Pattern pattern = Pattern.compile("[0-9]*");
				if (pattern.matcher(lastString).matches()) {
					finalList.add(Integer.parseInt(lastString));
				}
			}
		}

		// 如果finalList为空，则后两位取01算
		if (finalList.isEmpty()) {
			return commonString + "01";
		}
		int finalmax = Collections.max(finalList);
		if (finalmax < 9) {
			return commonString + "0" + String.valueOf(finalmax + 1);
		} else {
			return commonString + String.valueOf(finalmax + 1);
		}
	}

}
