/*
* Created on 2008-06-13
* Copyright (c) 2001-2008 泛微软件
* 泛微协同商务系统，版权所有。
* 
*/

package com.engine.custom.archives.workflow.biz.requestForm;

import com.engine.workflow.biz.requestForm.WfToDocBiz;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;
import weaver.workflow.request.RequestManager;
import weaver.workflow.workflow.WorkflowComInfo;

import java.util.HashMap;
import java.util.Map;

/**

 * Description: 更新文档属性页基本类
 * @author 方观生
 * @date 2008-6-13
 * 备注：该类目前只考虑表单而没有考虑单据。
 */

public class RequestDocPropManagerCus extends BaseBean {

	public static Logger log = LoggerFactory.getLogger("Archives");

	//private RecordSet rs;//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量
	//private RecordSet rsTwo;//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量
	private char flag = Util.getSeparator();
	
    private WorkflowComInfo workflowComInfo;

    private WfToDocBizCus wfToDocBiz;
	/**
	 * 构造函数
	 */
	public RequestDocPropManagerCus() {

		//rs = new RecordSet();//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量		
		//rsTwo = new RecordSet();//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量     
		
		try {
			workflowComInfo=new WorkflowComInfo();
		} catch (Exception ex) {
		}
	}

	public RequestDocPropManagerCus(WfToDocBizCus wfToDocBiz) {

		this.wfToDocBiz = wfToDocBiz;
		try {
			workflowComInfo=new WorkflowComInfo();
		} catch (Exception ex) {
		}
	}
	/**
	 * 更改文档属性页数据。
	 * 
	 * @param requestManager RequestManager对象
	 *
	 * @param docIds 文档id
	 * 
	 */	
	public void changeDocProp(RequestManager requestManager,String docIds)  throws Exception{
	    RecordSet rs = new RecordSet();//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量
	    RecordSet rsTwo = new RecordSet();//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量
	    
		int requestId=requestManager.getRequestid();
		int workflowId=requestManager.getWorkflowid();
		int creater=requestManager.getCreater();

		//创建人分部
		int subCompanyId = 0;
		try {
			ResourceComInfo resourceComInfo = new ResourceComInfo();
			subCompanyId = Util.getIntValue(resourceComInfo.getSubCompanyID("" + creater), 0);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		//安全性检查
		if(requestId<=0
		  ||workflowId<=0				
		  ||docIds==null
		  ||docIds.trim().equals("")
		  ){
			return ;
		}
		
		String requestName=Util.null2String(requestManager.getRequestname());		
//		//2、根据workflowId获取创建文档字段、确定文件存放目录的字段
//		RequestDoc requestDoc=new RequestDoc();
//		ArrayList flowDoc=requestDoc.getDocFiled(""+workflowId);
//		if(flowDoc==null||flowDoc.size()==0){
//			return ;
//		}
//writeLog("2");
//		int flowDocField=Util.getIntValue((String)flowDoc.get(1),-1);//创建文档字段
//		int flowDocCatField=Util.getIntValue((String)flowDoc.get(3),-1);// 确定文件存放目录的字段
//		//创建文档字段必须选择
//		if(flowDocField<=0){
//			return ;
//		}

    	int formId=Util.getIntValue(workflowComInfo.getFormId(""+workflowId),0);
	    String isBill=Util.null2String(workflowComInfo.getIsBill(""+workflowId));
	    if(!isBill.equals("1")){
		    isBill="0";
	    }		
		
//		//3、由创建文档字段、确定文件存放目录的字段获取文档id，确定文件存放目录的字段值。
//		String flowDocFieldName=null;
//		String flowDocCatFieldName=null;
//		
//		String tableName="workflow_form";
//		String sql=null;
//		if(isBill.equals("1")){
//			rs.executeSql("select tablename from workflow_bill where id = " + formId); // 查询工作流单据表的信息
//			if (rs.next()){
//				tableName = Util.null2String(rs.getString("tablename"));          // 获得单据的主表
//			}
//	   		sql="select a.fieldname from workflow_billfield a where a.id="+flowDocField ;
//	    }else{
//	   		sql="select a.fieldname from workflow_formdict a where a.id="+flowDocField ;
//	   	}
//		rs.executeSql(sql);
//		if(rs.next()){
//			flowDocFieldName=Util.null2String(rs.getString(1));
//		}
//		
//		if(isBill.equals("1")){
//	   		sql="select a.fieldname from workflow_billfield a where a.id="+flowDocCatField ;
//	    }else{
//	   		sql="select a.fieldname from workflow_formdict a where a.id="+flowDocCatField ;
//	   	}		
//		rs.executeSql(sql);
//		if(rs.next()){
//			flowDocCatFieldName=Util.null2String(rs.getString(1));
//		}
//		
//		int docId=0;
//		int selectItemId=-1;
//		if(flowDocCatFieldName!=null&&!flowDocCatFieldName.trim().equals("")){
//			sql="select "+flowDocFieldName+","+flowDocCatFieldName+" from "+tableName+" where requestId="+requestId;
//		}else{
//			sql="select "+flowDocFieldName+",-1 from "+tableName+" where requestId="+requestId;
//		}		
//		rs.executeSql(sql);
//		if(rs.next()){
//			docId=Util.getIntValue(rs.getString(1),-1);
//			selectItemId=Util.getIntValue(rs.getString(2),-1);			
//		}					
//		if(docId<=0||(","+docIds+",").indexOf(","+docId+",")<0){
//			return ;
//		}
		//存文文档优化-根据选择框值设置存放目录
		String wfdocpathfieldvalue = "";  //表单中存放目录的选择框字段值
		String wfdocpathtype = "";
		String wfdocpathfieldid = "";
		String isAccordToSubCom = "";
		if (wfToDocBiz!=null){
			wfdocpathtype = Util.null2String(wfToDocBiz.getWfdocpathtype());
			if (wfdocpathtype.equals("2")){
				wfdocpathfieldvalue = Util.null2String(wfToDocBiz.getWfdocpathfieldvalue());
				wfdocpathfieldid = Util.null2String(wfToDocBiz.getWfdocpathfieldid());
				isAccordToSubCom = Util.null2String(wfToDocBiz.getIsAccordToSubCom());
			}
		}

		//4、根据文档id获取文档所在的子目录
		int docId=Util.getIntValue(docIds,0);
		int secCategoryId=-1;
		rs.executeSql("select secCategory from DocDetail where id="+docId);
		if(rs.next()){
			secCategoryId=Util.getIntValue(rs.getString("secCategory"),-1);		
		}
		if(secCategoryId<=0){
			return ;
		}

		//5、根据workflowId、selectItemId、secCategoryId获取docPropId
		int docPropId=-1;
		if (wfdocpathtype.equals("2")&&!wfdocpathfieldvalue.equals("")){
			String sql = "select id from WorkflowToDocProp where workflowId=? and secCategoryId= ? and selectitemid =? and selectfieldid =? ";
			if(isAccordToSubCom.equals("2"))
				sql = sql+ " objid="+subCompanyId;
			rs.executeQuery(sql,workflowId,secCategoryId,wfdocpathfieldvalue,wfdocpathfieldid);
			if(rs.next()){
				docPropId=Util.getIntValue(rs.getString("id"),-1);
			}
		}else {
			rs.executeSql("select id from WorkflowToDocProp where workflowId="+workflowId+" and secCategoryId="+secCategoryId +" and selectitemid is null");
			if(rs.next()){
				docPropId=Util.getIntValue(rs.getString("id"),-1);
			}
		}
		

		
		if(docPropId<=0){
			return ;
		}
		
		//6、根据docPropId获取WorkflowToDocPropDetail中数据，workflowFieldId要求大于0
		int docPropFieldId=-1;
		int workflowFieldId=-1;
		String workflowFieldName=null;
		String strDocPropFieldId="";
		String strWorkflowFieldName="";
		
		Map workflowFieldIdByDocPropFieldIdMap=new HashMap();
		rs.executeSql("select docPropFieldId,workflowFieldId from WorkflowToDocPropDetail where docPropId="+docPropId+" and (workflowFieldId>=0 or workflowFieldId=-3 or workflowFieldId=-99) order by id asc");
		while(rs.next()){
			docPropFieldId=Util.getIntValue(rs.getString("docPropFieldId"),-1);
			workflowFieldId=Util.getIntValue(rs.getString("workflowFieldId"),-1);
			workflowFieldIdByDocPropFieldIdMap.put(""+docPropFieldId,""+workflowFieldId);
			strDocPropFieldId+=","+docPropFieldId;
		}
		
		if(strDocPropFieldId.equals("")){
			return ;
		}
		strDocPropFieldId=strDocPropFieldId.substring(1);
		
		Map mainFieldValueMap=this.getValueOfField(requestManager,workflowId);
		String workflowFieldValue=null;
		String workflowFieldShowName=null;		
		
		//7、获得DocDetail、cus_fielddata的更新语句。
		boolean isEditCustomData=false;
        rs.executeSql("select id from cus_fielddata where scope='DocCustomFieldBySecCategory' and scopeid=" + secCategoryId
                + " and id=" + docId);
        if (rs.next()) {
        	isEditCustomData=true;
        }
        
        String docDetailSql="update DocDetail set ";
        String docDetailSetStr="";
        
        String cusFieldDataSql=null;
        if(isEditCustomData){
        	cusFieldDataSql="update cus_fielddata set ";
        }else{
        	cusFieldDataSql="insert into cus_fielddata";
        }
        String cusFieldDataSetStr="";
        
        String cusFieldDataNameStr="";
        String cusFieldDataValueStr="";
        
        int docPropertyId=-1;
        int docPropertyType=-1;
        int fieldId=-1;
        String fieldDbType= null;

        String fieldHtmlType=null;
        String type=null;        
        Map cusFieldValueMap=new HashMap();        
        int fieldLength=0;
        
        rs.executeSql("select id as fieldId,fieldDbType,fieldHtmlType,type from cus_formdict");
        while(rs.next()){
        	fieldId=Util.getIntValue(rs.getString("fieldId"),-1);
        	fieldDbType=Util.null2String(rs.getString("fieldDbType"));
        	fieldHtmlType=Util.null2String(rs.getString("fieldHtmlType"));
        	type=Util.null2String(rs.getString("type"));
        	
        	cusFieldValueMap.put("fieldDbType"+fieldId,""+fieldDbType);
        	cusFieldValueMap.put("fieldHtmlType"+fieldId,""+fieldHtmlType);
        	cusFieldValueMap.put("type"+fieldId,""+type);        	
        }
        
        StringBuffer sb=new StringBuffer();

        sb.append(" select id as docPropertyId,type as docPropertyType,fieldId ")
          .append("   from DocSecCategoryDocProperty")
          .append("  where secCategoryId=").append(secCategoryId)
          .append("    and id in(").append(strDocPropFieldId).append(") ")
          .append("  order by viewIndex ")
        ;        
        rs.executeSql(sb.toString());
        while(rs.next()){
        	docPropertyId=Util.getIntValue(rs.getString("docPropertyId"),-1);
        	docPropertyType=Util.getIntValue(rs.getString("docPropertyType"),-1);
        	fieldId=Util.getIntValue(rs.getString("fieldId"),-1);
        	fieldDbType=Util.null2String((String)cusFieldValueMap.get("fieldDbType"+fieldId));
        	fieldHtmlType=Util.null2String((String)cusFieldValueMap.get("fieldHtmlType"+fieldId));       	
        	
        	workflowFieldId=Util.getIntValue((String)workflowFieldIdByDocPropFieldIdMap.get(""+docPropertyId),0);
        	if (workflowFieldId==-99)//requestid
				workflowFieldValue = requestId+"";
			else
				workflowFieldValue=Util.null2String((String)mainFieldValueMap.get("field"+workflowFieldId));
        	
        	if(docPropertyType==1&&docDetailSetStr.indexOf(",docSubject=")<0&&!workflowFieldValue.trim().equals("")){//文档标题,docSubject,varchar(200)
        		docDetailSetStr += ",docSubject='"+interceptString(workflowFieldValue,200)+"'";
        	}else if(docPropertyType==2&&docDetailSetStr.indexOf(",docCode=")<0){//文档编号,docCode,varchar(200)
        		docDetailSetStr += ",docCode='"+interceptString(workflowFieldValue,200)+"'";       		
        	}else if(docPropertyType==3&&docDetailSetStr.indexOf(",docPublishType=")<0){//发布,docPublishType,char(1)
        		docDetailSetStr += ",docPublishType='"+interceptString(workflowFieldValue,1)+"'";          		
        	}else if(docPropertyType==4&&docDetailSetStr.indexOf(",docedition=")<0){//文档版本,docedition,int
        		docDetailSetStr += ",docedition="+Util.getIntValue(workflowFieldValue,-1);         		
        	}else if(docPropertyType==5&&docDetailSetStr.indexOf(",docStatus=")<0){//文档状态,docStatus,int
        		docDetailSetStr += ",docStatus="+Util.getIntValue(workflowFieldValue,-1);          		
        	}else if(docPropertyType==9&&docDetailSetStr.indexOf(",docDepartmentId=")<0){//部门,docDepartmentId,int
        		docDetailSetStr += ",docDepartmentId="+Util.getIntValue(workflowFieldValue,-1);         		
        	}else if(docPropertyType==12&&docDetailSetStr.indexOf(",keyword=")<0){//关键字,keyword,varchar(255)
        		docDetailSetStr += ",keyword='"+interceptString(workflowFieldValue,255)+"'";            		
        	}else if(docPropertyType==19&&docDetailSetStr.indexOf(",mainDoc=")<0){//主文档,mainDoc,int
        		docDetailSetStr += ",mainDoc="+Util.getIntValue(workflowFieldValue,docId);         		
        	}else if(docPropertyType==21&&docDetailSetStr.indexOf(",ownerId=")<0){//文档所有者,ownerId,int
        		docDetailSetStr += ",ownerId="+Util.getIntValue(workflowFieldValue,-1);         		
        	}else if(docPropertyType==22&&docDetailSetStr.indexOf(",invalidationDate=")<0){//失效时间,invalidationDate,char(10)
        		docDetailSetStr += ",invalidationDate='"+interceptString(workflowFieldValue,10)+"'";          		
        	}else if(docPropertyType==25&&docDetailSetStr.indexOf(",canPrintedNum=")<0){//可打印份数,canPrintedNum,int
        		docDetailSetStr += ",canPrintedNum="+Util.getIntValue(workflowFieldValue,0);            		
        	}else if(docPropertyType==0){//自定义字段
				String cusfieldname="";
                rsTwo.executeSql("select fieldname from cus_formdict where id="+fieldId);
				if(rsTwo.next()){
				cusfieldname=Util.null2String(rsTwo.getString("fieldname"));
				}
        		if(isEditCustomData&&cusFieldDataSetStr.indexOf(",field" + fieldId + "=")<0){
        			cusFieldDataSetStr += ",field" + fieldId + "=";
                    if (fieldDbType.startsWith("text") || fieldDbType.startsWith("char")
                            || fieldDbType.startsWith("varchar")|| fieldDbType.startsWith("browser")) {
                		if(fieldDbType.indexOf("(")>=0&&fieldDbType.indexOf(")")>fieldDbType.indexOf("(")+1){
                			fieldLength=Util.getIntValue(fieldDbType.substring(fieldDbType.indexOf("(")+1,fieldDbType.indexOf(")")),0);
                		}
                		if(fieldLength>0){
                			cusFieldDataSetStr += "'" + interceptString(workflowFieldValue,fieldLength) + "'";
                		}else{
                			cusFieldDataSetStr += "'" + workflowFieldValue + "'";
                		}
                    } else {
                    	if(fieldHtmlType.equals("5")){
                    		workflowFieldShowName=(String)mainFieldValueMap.get("fieldShowName"+workflowFieldId);
                    		workflowFieldValue=this.getNewSelectValue(workflowFieldShowName,workflowFieldValue,fieldId);
                    	}
                    	if(fieldHtmlType.equals("1")){
                    		cusFieldDataSetStr += Util.getDoubleValue(workflowFieldValue,0);
                    	}else{
                    		cusFieldDataSetStr += Util.getIntValue(workflowFieldValue,0);
                    	}  
                    }        			
        		}else if((cusFieldDataNameStr+",").indexOf("," + cusfieldname+",")<0){
        			cusFieldDataNameStr += "," + cusfieldname;
                    if (fieldDbType.startsWith("text") || fieldDbType.startsWith("char")
                            || fieldDbType.startsWith("varchar")|| fieldDbType.startsWith("browser")) {
                		if(fieldDbType.indexOf("(")>=0&&fieldDbType.indexOf(")")>fieldDbType.indexOf("(")+1){
                			fieldLength=Util.getIntValue(fieldDbType.substring(fieldDbType.indexOf("(")+1,fieldDbType.indexOf(")")),0);
                		}
                		if(fieldLength>0){
                        	cusFieldDataValueStr += ",'" + interceptString(workflowFieldValue,fieldLength) + "'";
                		}else{
                        	cusFieldDataValueStr += ",'" + workflowFieldValue + "'";
                		}
                    } else {
                    	if(fieldHtmlType.equals("5")){
                    		workflowFieldShowName=(String)mainFieldValueMap.get("fieldShowName"+workflowFieldId);
                    		workflowFieldValue=this.getNewSelectValue(workflowFieldShowName,workflowFieldValue,fieldId);
                    	}
                    	if(fieldHtmlType.equals("1")){
                    		cusFieldDataValueStr += "," +Util.getDoubleValue(workflowFieldValue,0);
                    	}else{
                    		cusFieldDataValueStr += "," +Util.getIntValue(workflowFieldValue,0);
                    	}                    	
                        
                    }       			
        		}
        	}
        }
        
        if (!docDetailSetStr.equals("")) {
        	docDetailSetStr = docDetailSetStr.substring(1);
        	docDetailSql += docDetailSetStr + " where id=" + docId;
//writeLog("docDetailSql:"+docDetailSql);
        	rs.executeSql(docDetailSql);
        }
        
        if(isEditCustomData){
            if (!cusFieldDataSetStr.equals("")) {
            	cusFieldDataSetStr = cusFieldDataSetStr.substring(1);
                cusFieldDataSql += cusFieldDataSetStr + " where scope='DocCustomFieldBySecCategory' and scopeid=" + secCategoryId + " and id=" + docId;
                rs.executeSql(cusFieldDataSql);
            }
        }else{
            if (!cusFieldDataNameStr.equals("")) {
            	cusFieldDataNameStr = cusFieldDataNameStr.substring(1);
            	cusFieldDataValueStr = cusFieldDataValueStr.substring(1);

                cusFieldDataSql += "(scope,scopeid,id," + cusFieldDataNameStr + ") values('DocCustomFieldBySecCategory'," + secCategoryId + "," + docId
                        + "," + cusFieldDataValueStr + ")";           
                rs.executeSql(cusFieldDataSql);
            }       	
        }
        
	}
	
	  /**
	   * 截取不大于指定字节长度的字符串
	   * @param initString 初始字符串
	   * @param byteLength 指定字节长度
	   * @return String 不大于指定字节长度的字符串
	   */  
	private static String interceptString(String initString,int byteLength) {
		try{
			
			int counterOfDoubleByte = 0;
			byte[] b = initString.getBytes("UTF-8");
			  if(b.length <= byteLength)
			    return initString;
			  for(int i = 0; i < byteLength; i++){
			    if(b[i] < 0)
			      counterOfDoubleByte++;
			  }

			  if(counterOfDoubleByte % 2 == 0)
			    return new String(b, 0, byteLength, "UTF-8");
			  else
			    return new String(b, 0, byteLength - 1, "UTF-8");
			
		}catch(Exception ex){
			return "";
		}
	}
	
    /**
	 * 获得指定工作流程某个请求所有主字段的值。
	 * 
	 * @param mainRequest 主请求
	 * @param workflowId 工作流id
	 * 
	 * @return Map  关键字为 field加字段id 值为字段值、
	 *              关键字为 fieldHtmlType加字段id 值为表现形式、
	 *              关键字为 type加字段id  值为字段类型
	 *              关键字为 fieldShowName加字段id  职位字段显示名称
	 */	
	private Map getValueOfField(RequestManager mainRequest,int workflowId){
	    RecordSet rs = new RecordSet();//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量
	    RecordSet rsTwo = new RecordSet();//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量
	    
		Map mainFieldValueMap=new HashMap();

		//获取字段值
		//根据主流程的id获得相关信息
		String formId="";
		String isBill="";
		rs.executeSql(" select formId,isBill from workflow_base where id="+workflowId);
		if(rs.next()){
			formId=rs.getString(1);
			isBill=rs.getString(2);
		}
	    if(!"1".equals(isBill)){
		    isBill="0";
	    }		
		int requestId=mainRequest.getRequestid();
		
		mainFieldValueMap.put("field-2",""+requestId);
		mainFieldValueMap.put("field-3",mainRequest.getRequestname());
		mainFieldValueMap.put("field-4",mainRequest.getRequestlevel());
		mainFieldValueMap.put("field-5",mainRequest.getMessageType());			
		
		//获得主流程人力资源相关字段的值和页面类型、详细类型
		String fieldId="";//字段id
		String fieldName="";//字段名称		
		String fieldValue="";//字段值
		String fieldHtmlType="";//页面类型
		String type="";//详细类型
		//String billId="0";
		String tableName="workflow_form";
		
        Map tempmap=new HashMap();
        String fieldnames="";        
        int cols=0;        
        String sql="";
        
		if("0".equals(isBill)){//如果不为单据，即为表单
			sql="select b.id,b.fieldName,b.fieldHtmlType,b.type from workflow_formfield a,workflow_formdict b where a.fieldId=b.id and  (a.isdetail<>'1' or a.isdetail is null) and  a.formId="+formId;			
		}else{//否则为单据
			//rs.executeSql(" select tableName from workflow_bill where id="+billId);
			rs.executeSql(" select tableName from workflow_bill where id="+formId);			
			if(rs.next()){
				tableName=Util.null2String(rs.getString("tableName"));
			}
			//sql="select id,fieldName,fieldHtmlType,type from workflow_billfield where (viewtype is null or viewtype<>1) and billId="+fieldId;
			sql="select id,fieldName,fieldHtmlType,type from workflow_billfield where (viewtype is null or viewtype<>1) and billId="+formId;			
		}
        rs.executeSql(sql);
		while(rs.next()){
			fieldId=Util.null2String(rs.getString("id"));			
            fieldName=Util.null2String(rs.getString("fieldName"));
			fieldHtmlType=Util.null2String(rs.getString("fieldHtmlType"));
			type=Util.null2String(rs.getString("type"));
			
            if(!fieldName.equals("")){
                if(fieldnames.equals("")){
                    fieldnames=fieldName;
                }else{
                    fieldnames+=","+fieldName;
                }
                tempmap.put("col"+cols,fieldId);
                cols++;
            }
            
            mainFieldValueMap.put("fieldHtmlType"+fieldId,fieldHtmlType);
            mainFieldValueMap.put("type"+fieldId,type);           
        }
		
		if(fieldnames.equals("")||tableName.equals("")){
			return mainFieldValueMap;
		}
		
		String fieldShowName="";
		
		sql="select "+fieldnames+" from "+tableName+" where requestid= "+requestId;
        rs.executeSql(sql);
		while(rs.next()){
            for(int i=0;i<cols;i++){
            	fieldValue=Util.null2String(rs.getString(i+1));
                //mainFieldValueMap.put("field"+tempmap.get("col"+i),fieldValue);
            	fieldId=Util.null2String((String)tempmap.get("col"+i));
            	fieldHtmlType=Util.null2String((String)mainFieldValueMap.get("fieldHtmlType"+fieldId));
            	
            	if(fieldHtmlType.equals("5")&&!"".equals(fieldValue)){
            		rsTwo.executeSql("  select selectName from workflow_selectitem where fieldId="+fieldId+" and isBill="+isBill+" and selectValue="+fieldValue);
            		if(rsTwo.next()){
            			fieldShowName=Util.null2String(rsTwo.getString("selectName"));
                    	mainFieldValueMap.put("fieldShowName"+fieldId,fieldShowName);           			
            		}
            	}
            	
            	mainFieldValueMap.put("field"+fieldId,fieldValue);
            }
        }
			
		return mainFieldValueMap;
	}

    /**
	 * 获得新的下拉框的值
	 * 
	 * @param workflowFieldShowName 表单下拉框显示值
	 * @param workflowFieldValue 表单下拉框字段值
	 * @param fieldId 文档属性页字段id
	 * 
	 * @return String  新的下拉框的值
	 */		
	private  String getNewSelectValue(String workflowFieldShowName, String workflowFieldValue,int fieldId) {
	    RecordSet rsTwo = new RecordSet();//277481: [90]集成中心－解决代码质量问题修复--操作数据库的对象不能作为成员变量
		try{
			String newSelectValue="";
			workflowFieldShowName=Util.null2String(workflowFieldShowName);
			rsTwo.executeSql("select selectValue from cus_selectitem where fieldId="+fieldId+" and selectName='"+Util.toHtml100(workflowFieldShowName)+"'");
			if(rsTwo.next()){
				newSelectValue=Util.null2String(rsTwo.getString("selectValue"));
			}
			if(newSelectValue.equals("")){
				newSelectValue=workflowFieldValue;
			}
			return newSelectValue;
		}catch(Exception ex){
			return workflowFieldValue;
		}
	}	
}
