package com.kingdee.shr.compensation.util.integrate;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONObject;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.util.EASResource;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.hr.base.HRBillStateEnum;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.base.syssetting.app.filter.HRFilterUtils;
import com.kingdee.shr.compensation.app.integrate.BatchSubmitSchemeBillDataSource;
import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillFactory;
import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillInfo;
import com.kingdee.shr.compensation.app.integrate.CalSubmitItemDataType;
import com.kingdee.shr.compensation.app.integrate.DateTypeEnum;
import com.kingdee.shr.compensation.integrate.dto.CalShemeSubmitItemDTO;
import com.kingdee.shr.compensation.resource.ResourceConstant;
import com.kingdee.shr.compensation.util.CmpDateUtil;
import com.kingdee.shr.compensation.util.CmpStrUtil;

public class CmpIntegrateUtilsNew {
	
	private static Logger logger = Logger.getLogger(CmpIntegrateUtilsNew.class);
	
	
	
	/**
	 * 重载更新分录审批状态
	 * 
	 * @param ctx
	 * @param billId
	 * @param stateEnum
	 * @throws BOSException
	 * @throws EASBizException
	 */
	public static void updateEntryBillState(Context ctx, String billId, HRBillStateEnum stateEnum,
			String billEntryTable) throws BOSException, EASBizException {
		BatchSubmitShemeBillInfo info = BatchSubmitShemeBillFactory.getLocalInstance(ctx)
				.getBatchSubmitShemeBillInfo("where id = '" + billId + "'");

		String billEntryTableName = billEntryTable;
		if (StringUtils.isEmpty(billEntryTableName)) {
			Map<String, Object> map = CmpIntegrateUtilsNew.getBillColumnListAndBillEntryTableName(ctx,
					info.getSubmitScheme().getId().toString());
			billEntryTableName = map.get("fBillEntryTableName").toString(); // 方案对应的动态表名
		}
		// 更新分录状态
		String sqlTemplate = "UPDATE %s SET FBillState = ? WHERE FBILLID = ?";
		String sql = String.format(sqlTemplate, billEntryTableName);

		DbUtil.execute(ctx, sql, new Object[] {stateEnum.getValue(), info.getId().toString()});
	}
	
	
	
	/**
	 * 指定业务组织下，当前用户可使用且数据权限分配的薪酬项目
	 * @throws EASBizException 
	 */
	public static String getUsableItemByHro(Context ctx, String hrOrgUnit,boolean isDisatribute)  {
		StringBuffer personCmpItemPerm = new StringBuffer();
		personCmpItemPerm.append("select FBaseInfoId from T_HR_SCalSubmitItemRelHR  where T_HR_SCalSubmitItemRelHR.FHrOrgUseId ='");
		personCmpItemPerm.append(hrOrgUnit).append("'");//可使用
		if(isDisatribute){
			personCmpItemPerm.append(" and FState=100 ");
		}
		return personCmpItemPerm.toString();
	}
	
	
	
	/**
	 * 判断提报方案是否存在 未提交 审批中 未审批 已审批
	 * @param schemeId
	 * @return
	 */
	public static boolean checkSubmitSchemeIsUsingBill(	Context ctx,String schemeId){
		boolean flag = false ;
		if (StringUtils.isEmpty(schemeId)) {
			return flag ;
		}
		String sql  = "Select top 1 fid  from T_HR_SBatchSubmitShemeBill where fbillstate in (0,1,2)  and FSubmitSchemeID = ? " ;
		try {
			IRowSet rs = DbUtil.executeQuery(ctx, sql, new Object[]{schemeId});
			if (rs.size()>0) {
				flag =  true;
			}
		} catch (BOSException e) {
			logger.error(e);
		}
		return flag ;
	}
	
	/**
	 * 判断提报方案是否存在 未提交 审批中 未审批 已审批
	 * @param schemeId
	 * @return
	 */
	public static boolean checkSubmitBillEntryIsExists(	Context ctx,String  billEntryTableName ,String billId){
		boolean flag = false ;
		if (StringUtils.isEmpty(billId)) {
			return flag ;
		}
		String sql  = "Select top 1 fid  from "+billEntryTableName+" where fbillId = ? " ;
		try {
			IRowSet rs = DbUtil.executeQuery(ctx, sql, new Object[]{billId});
			if (rs.size()>0) {
				flag =  true;
			}
		} catch (BOSException e) {
			logger.error(e);
		}
		return flag ;
	}
	
	/**
	 * 判断提报方案是否存在  审批中 未审批
	 * @param schemeId
	 * @return
	 */
	public static boolean checkSubmitSchemeIsUsedBill(Context ctx,String schemeId){
		boolean flag = false ;
		if (StringUtils.isEmpty(schemeId)) {
			return flag ;
		}
		String sql  = "Select top 1 fid  from T_HR_SBatchSubmitShemeBill where fbillstate in (1,2)  and FSubmitSchemeID = ? " ;
		try {
			IRowSet rs = DbUtil.executeQuery(ctx, sql, new Object[]{schemeId});
			if (rs.size()>0) {
				flag =  true;
			}
		} catch (BOSException e) {
			logger.error(e);
		}
		return flag ;
	}
	
	
	/**
	 * 判断提报方案是否存在 未提交 审批中 未审批
	 * @param schemeId
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static Map checkSubmitSchemesIsUsingBill(Context ctx,List<String> list){
		Map<String ,Boolean > map = new HashMap<String ,Boolean>();
		String sql  = "Select distinct FSubmitSchemeID from T_HR_SBatchSubmitShemeBill where fbillstate in (0,1,2) "
				+ " and FSubmitSchemeID in( "+CmpStrUtil.convertListToString(list)+") " ;
		Set<String> snSet = new HashSet<String>();
		try {
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			while (rs.next()) {
				String submitSchemeID = rs.getString("FSubmitSchemeID");
				snSet.add(submitSchemeID);
			}
			for( String submitSchemeID: list){
				map.put(submitSchemeID, snSet.contains(submitSchemeID));
			}
		} catch (Exception e) {
			logger.error(e);
		}
		return map ;
	}
	
	
	/**
	 * 
	 * 根据方案id 获取方案提报单分录的提报项目列
	 * @param schemeId
	 * @return
	 * @throws BOSException 
	 * 
	 */
	
	@SuppressWarnings("rawtypes")
	public static Map<String,List> assembleSubmitSchemeColModel(Context ctx,String schemeId, Integer dataSource) throws BOSException{
		Map<String,List> map = new HashMap<String,List>();
		List<String> colNames = new ArrayList<String>();
		List<Map<String, Object>> colModel = new ArrayList<Map<String, Object>>();
		if (StringUtils.isEmpty(schemeId)) {
			return map ;
		}
		
		String language = ctx.getLocale().getLanguage();
		
		String  sql = "Select e.FSubmitTarget, e.FIsEnableSubmitElement,e.FEFFECTDATEDISPLAY , m.fieldSn,m.fdataType,m.fname_"+ language +" MNAME,t.FIsRequired ,m.FDataDot,m.FDataLength, "
				+ " M.FDATETYPE,M.FFILTERFIELD,B.FENTITYNAME,B.FNAME_"+ language +" BNAME,B.FUSEUIPK, B.FMAINTAINUIPK  "
				+ " from  T_HR_SCalSubmitScheme e "
				+ " inner join  T_HR_SCalSubmitSchemeItem t on t.FCalSubmitSchemeID = e.fid "
				+ " inner join T_HR_SCalSubmitItem m on  m.fid = t.FCalSubmitItemID "
				+ " left join  T_BS_SHRBasicItem b on m.FFilterField = b.fid "
				+ " where e.fid = '"+schemeId+"' order by  FSortSn";
//		String  sql = "Select m.FNumber,e.FSubmitTarget,e.FIsEnableSubmitElement,e.FEFFECTDATEDISPLAY , m.fieldSn,m.fdataType,m.fname_"+ language +" MNAME,t.FIsRequired ,m.FDataDot,m.FDataLength, "
//				+ " M.FDATETYPE,M.FFILTERFIELD,B.FNAME_"+ language +" BNAME, B.FUipk FMAINTAINUIPK,b.FISBASIC  "
//				+ " from  T_HR_SCalSubmitScheme e "
//				+ " inner join  T_HR_SCalSubmitSchemeItem t on t.FCalSubmitSchemeID = e.fid "
//				+ " inner join T_HR_SCalSubmitItem m on  m.fid = t.FCalSubmitItemID "
//				+ " left join  T_HR_SCalSchemeItemForF7 b on m.FFilterField = b.fid "
////				+ " where e.fid = '"+schemeId+"' and m.FNumber != 'AwardName' and t.FIsShow = 1 order by  FSortSn";
//				+ " where e.fid = '"+schemeId+"'  order by  t.FSortSn asc ";
		try {
			String  submitTarget = "" ,dataType = ""; //提报对象 01 person  02 org
			int dateType = 0;// 日期类型
			int effectDateDisplay = 0;
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			boolean  f7Flag = true,isEnableSubmitElement = false;
			while (rs.next()) {
				//=====组装提报对象
			    submitTarget = rs.getString("FSubmitTarget");
			    effectDateDisplay = rs.getInt("FEFFECTDATEDISPLAY");
			    isEnableSubmitElement = rs.getBoolean("FIsEnableSubmitElement");
			    dataType = rs.getString("fdataType");// 0 数值 1 字符串
				//提报对象列
				if (f7Flag) {
					f7Flag = false;
					Map<String, Object> gridMainKeyIdMap = new HashMap<String, Object>();
					Map<String, Object> adminOrgUnitGridMainKeyIdMap = new HashMap<String, Object>();
					Map<String, Object> positionGridMainKeyIdMap = new HashMap<String, Object>();
					Map<String, Object> cmpEmpORGridMainKeyIdMap = new HashMap<String, Object>();
					Map<String, Object> gridIdMap = new HashMap<String, Object>();
					// 组装ID前端基础属性
					assembleColModelId(gridIdMap);
					colNames.add("id");
					colModel.add(gridIdMap);
					//==== 组装F7
					if ("02".equals(submitTarget)) {
						assembleColModelF7(gridMainKeyIdMap, "orgUnit", "提报组织", true);
						gridMainKeyIdMap.put(ColModelAttributeConstants.editoptions, assembleColModelF7("提报组织", "com.kingdee.eas.basedata.org.app.AdminOrgUnit.F7", true));
						gridMainKeyIdMap.put(ColModelAttributeConstants.sortable, true);
						colNames.add("提报组织");  //colNames.add("提报组织");
						colModel.add(gridMainKeyIdMap);
					}else{
						Map<String, Object> gridPersonNumberMap = new HashMap<String, Object>();
						gridPersonNumberMap.put(ColModelAttributeConstants.name, "number");
						gridPersonNumberMap.put(ColModelAttributeConstants.label, "员工编码");
						gridPersonNumberMap.put(ColModelAttributeConstants.frozen, false);
						gridPersonNumberMap.put(ColModelAttributeConstants.width, 90);
						gridPersonNumberMap.put(ColModelAttributeConstants.align, "left");
						gridPersonNumberMap.put(ColModelAttributeConstants.key, true);
						gridPersonNumberMap.put(ColModelAttributeConstants.hidden, false);
						gridPersonNumberMap.put(ColModelAttributeConstants.editable, false);				
						gridPersonNumberMap.put(ColModelAttributeConstants.sorttype, "string");
						gridPersonNumberMap.put(ColModelAttributeConstants.classes, "disabled");
						gridPersonNumberMap.put(ColModelAttributeConstants.edittype, "shrtext");
						gridPersonNumberMap.put(ColModelAttributeConstants.sortable, true);
						
						
						colNames.add("员工编码"); // colNames.add("员工编码");
						colModel.add(gridPersonNumberMap);
						
						String CmpEmpORelF7Uipk = "com.kingdee.shr.compensation.app.integrate.CmpEmpORelation.F7";
						// 3表示来源为团队提报的
						if (BatchSubmitSchemeBillDataSource.TEAM_SUBMIT_VALUE == dataSource) {
							CmpEmpORelF7Uipk = "com.kingdee.shr.compensation.app.integrate.stores.CmpEmpORelation.F7";
						} 
						assembleColModelF7(gridMainKeyIdMap, "person", "员工姓名", true);
						gridMainKeyIdMap.put(ColModelAttributeConstants.editoptions, assembleColModelF7("员工姓名", CmpEmpORelF7Uipk,true));
						colNames.add("员工姓名"); // colNames.add("员工姓名");
						colModel.add(gridMainKeyIdMap);
						
						//行政组织
						assembleColModelF7NotEdit(adminOrgUnitGridMainKeyIdMap, "adminOrgUnit", "所属行政组织");
						adminOrgUnitGridMainKeyIdMap.put(ColModelAttributeConstants.sortable, true);

//						gridMainKeyIdMap.put(ColModelAttributeConstants.editoptions, assembleColModelF7("姓名", "shr.person.HRAndAdminOrg.F7"));
						colNames.add("所属行政组织");  //colNames.add("所属行政组织");
						colModel.add(adminOrgUnitGridMainKeyIdMap);
						
						//职位
						assembleColModelF7NotEdit(positionGridMainKeyIdMap, "position", "职位");
						positionGridMainKeyIdMap.put(ColModelAttributeConstants.sortable, true);

						colNames.add("职位");  //colNames.add("职位");
						colModel.add(positionGridMainKeyIdMap);
						
						//发薪任职id
						assembleColModelF7Hidden(cmpEmpORGridMainKeyIdMap, "cmpEmpORelation", "发薪任职");
						colNames.add("发薪任职"); // colNames.add("发薪任职");
						colModel.add(cmpEmpORGridMainKeyIdMap);
						
						
						//=====虚拟id 用于编辑保存
						Map<String, Object> gridPersonIdMap = new HashMap<String, Object>();
						gridPersonIdMap.put(ColModelAttributeConstants.name, "tempId");
						gridPersonIdMap.put(ColModelAttributeConstants.label, "员工或者组织临时id");
						gridPersonIdMap.put(ColModelAttributeConstants.frozen, false);
						gridPersonIdMap.put(ColModelAttributeConstants.width, 90);
						gridPersonIdMap.put(ColModelAttributeConstants.align, "left");
						gridPersonIdMap.put(ColModelAttributeConstants.key, true);
						gridPersonIdMap.put(ColModelAttributeConstants.hidden, true);
						gridPersonIdMap.put(ColModelAttributeConstants.editable, false);				
						gridPersonIdMap.put(ColModelAttributeConstants.sorttype, "string");
						gridPersonIdMap.put(ColModelAttributeConstants.classes, "disabled");
						gridPersonIdMap.put(ColModelAttributeConstants.edittype, "shrtext");
						colNames.add("tempId");
						colModel.add(gridPersonIdMap);
					}
					// 申报要素，如果提报方案上选了启用申报要素，则申报要素必填
					if(isEnableSubmitElement){
						Map<String, Object> gridSubmitElementMap = new HashMap<String, Object>();
						assembleColModelF7(gridSubmitElementMap, "submitElement", "申报要素", true);
						gridSubmitElementMap.put(ColModelAttributeConstants.editoptions, assembleColModelF7("申报要素", "com.kingdee.shr.compensation.app.integrate.SubmitElement.SubmitBillEntry.F7",true));
						colNames.add("申报要素"); // colNames.add("申报要素");
						colModel.add(gridSubmitElementMap);
					}
					
					
					// 币别
					Map<String, Object> gridCurrencyMap = new HashMap<String, Object>();
					assembleColModelF7(gridCurrencyMap, "currency", "币别", true);
					gridCurrencyMap.put(ColModelAttributeConstants.editoptions, assembleColModelF7("币别", "com.kingdee.eas.basedata.assistant.app.Currency.CMP.F7",true));
					colNames.add("币别");   // colNames.add("币别");
					colModel.add(gridCurrencyMap);
					
					//日期控件
					//8.6sp1日期控件
					Map<String, Object> gridPersonNumberMap = new HashMap<String, Object>();
					gridPersonNumberMap.put(ColModelAttributeConstants.name, "effectDay");
					gridPersonNumberMap.put(ColModelAttributeConstants.label, "发生日期");
					gridPersonNumberMap.put(ColModelAttributeConstants.frozen, false);
					gridPersonNumberMap.put(ColModelAttributeConstants.width, 100);
					gridPersonNumberMap.put(ColModelAttributeConstants.align, "left");
					gridPersonNumberMap.put(ColModelAttributeConstants.key, true);
					gridPersonNumberMap.put(ColModelAttributeConstants.hidden, false);
					gridPersonNumberMap.put(ColModelAttributeConstants.editable, true);				
					gridPersonNumberMap.put(ColModelAttributeConstants.sorttype, "date");
					gridPersonNumberMap.put(ColModelAttributeConstants.sortable, false);
//					gridPersonNumberMap.put(ColModelAttributeConstants.formatter, "datepicker");    8.5sp1
//					gridPersonNumberMap.put(ColModelAttributeConstants.edittype, "shrdatepicker");
					gridPersonNumberMap.put(ColModelAttributeConstants.formatter, "shrDateTimePicker");
					gridPersonNumberMap.put(ColModelAttributeConstants.edittype, "shrDateTimePicker");
					gridPersonNumberMap.put(ColModelAttributeConstants.classes, "required");
					
					StringBuffer datapickerjsonBuffer = new StringBuffer();
					datapickerjsonBuffer.append("{");
					datapickerjsonBuffer.append("\"datepickerjson\":");
					datapickerjsonBuffer.append("{");
					datapickerjsonBuffer.append("\"id\":\"dp_autoSize\",");
					datapickerjsonBuffer.append("\"name\":\"dp_autoSize\",");
					datapickerjsonBuffer.append("\"minuteStep\":\"\",");
					datapickerjsonBuffer.append("\"showTimeZoneForCtrl\":false,");
					datapickerjsonBuffer.append("\"isAutoTimeZoneTrans\":false,");
					datapickerjsonBuffer.append("\"isShowUTC\":false,");
					datapickerjsonBuffer.append("\"isReadonlyUTC\":true,");
					datapickerjsonBuffer.append("\"isRemoveSeconds\":true,");
					
					if(DateTypeEnum.YYYYMM_VALUE == effectDateDisplay){
						datapickerjsonBuffer.append("\"isRemoveDay\":true,");
					}else if(DateTypeEnum.YYYYMMDD_VALUE == effectDateDisplay){
						datapickerjsonBuffer.append("\"isRemoveDay\":false,");
					}else{
						datapickerjsonBuffer.append("\"isRemoveDay\":true,");
					}
					
					datapickerjsonBuffer.append("\"ctrlType\":\"Date\"");
					datapickerjsonBuffer.append("},");
					datapickerjsonBuffer.append("\"validateJson\":");
					datapickerjsonBuffer.append("{");
					datapickerjsonBuffer.append("\"errMsg\":\"\",");
					datapickerjsonBuffer.append("\"rules\":\"required:true\",");
					datapickerjsonBuffer.append("\"validatetrigger\":\"focus keyup datachange\"");
					datapickerjsonBuffer.append("}");
					datapickerjsonBuffer.append("}");
					gridPersonNumberMap.put(ColModelAttributeConstants.editoptions, JSONObject.parseObject(datapickerjsonBuffer.toString()));
					colNames.add("发生日期");  // colNames.add("发生日期");
					colModel.add(gridPersonNumberMap);
				}
				
				//=====组装提报项目
			    dataType = rs.getString("fdataType");// 0 数值 1 字符串2日期类型3F7过滤
			    int isRequired = rs.getInt("FIsRequired"); // 1 必填
			    int fDataDot = rs.getInt("FDataDot"); // 1 精度
			    int fDataLength = rs.getInt("FDataLength"); // 1 字符长度
			    if ("0".equals(dataType)) {
			    	// 0 数值
			    	Map<String, Object> schemeMap = new HashMap<String, Object>();
			    	schemeMap.put(ColModelAttributeConstants.name, "S"+rs.getString("fieldSn"));
					schemeMap.put(ColModelAttributeConstants.label, rs.getString("MNAME"));
					schemeMap.put(ColModelAttributeConstants.frozen, false);
					schemeMap.put(ColModelAttributeConstants.width, 90);
					schemeMap.put(ColModelAttributeConstants.align, "left");
					schemeMap.put(ColModelAttributeConstants.key, false);
					schemeMap.put(ColModelAttributeConstants.editable, true);				
					schemeMap.put(ColModelAttributeConstants.sorttype, "bigdecimal");
//					schemeMap.put(ColModelAttributeConstants.sortable, true);
					//先不排序
					schemeMap.put(ColModelAttributeConstants.sortable, false);
					schemeMap.put(ColModelAttributeConstants.formatter, "numberfield");
					schemeMap.put(ColModelAttributeConstants.edittype, "numberfield");
					JSONObject editoptions = JSONObject.parseObject("{ \"inputJson\": { \"id\": \"txt_money\", \"name\": \"money\", \"<formatTy></formatTy>pe\": \"number\" }}");
					
					//添加必填校验
					if(isRequired == 1) {
						schemeMap.put(ColModelAttributeConstants.classes, "required");
						editoptions.put("validateJson", JSONObject.parseObject("{ \"errMsg\": \"\", \"rules\": \"required:true\", \"validatetrigger\": \"focus keyup datachange\" }"));
					}
					
					//添加精度
					JSONObject inputJson = editoptions.getJSONObject("inputJson");
					inputJson.put("decimalPrecision", fDataDot);
					//添加长度
					inputJson.put("maxlength", fDataLength);
					
					
					schemeMap.put(ColModelAttributeConstants.editoptions,editoptions);
					colModel.add(schemeMap);
					colNames.add(rs.getString("MNAME"));
				}else if(CalSubmitItemDataType.STRING_VALUE.equals(dataType)) {
					
					Map<String, Object> schemeMap = new HashMap<String, Object>();
					schemeMap.put(ColModelAttributeConstants.name, "S"+rs.getString("fieldSn"));
					schemeMap.put(ColModelAttributeConstants.label, rs.getString("MNAME"));
					schemeMap.put(ColModelAttributeConstants.frozen, false);
					schemeMap.put(ColModelAttributeConstants.width, 90);
					schemeMap.put(ColModelAttributeConstants.align, "left");
					schemeMap.put(ColModelAttributeConstants.key, false);
					schemeMap.put(ColModelAttributeConstants.editable, true);				
					schemeMap.put(ColModelAttributeConstants.sorttype, "string");
//					schemeMap.put(ColModelAttributeConstants.sortable, true);
					schemeMap.put(ColModelAttributeConstants.sortable, false);
					JSONObject editoptions = JSONObject.parseObject("{ \"inputJson\": {  } }");
					if(isRequired == 1) {
						schemeMap.put(ColModelAttributeConstants.classes, "required");
						editoptions.put("validateJson", JSONObject.parseObject("{ \"errMsg\": \"\", \"rules\": \"required:true\", \"validatetrigger\": \"focus keyup datachange\" }"));
					}else{
						editoptions.put("validateJson", JSONObject.parseObject("{ \"errMsg\": \"\", \"rules\": \"required:false\", \"validatetrigger\": \"focus keyup datachange\" }"));
					}
					
					
					//添加精度
					JSONObject inputJson = editoptions.getJSONObject("inputJson");
					inputJson.put("decimalPrecision", fDataDot);
					//添加长度
					inputJson.put("maxlength", fDataLength);
					schemeMap.put(ColModelAttributeConstants.editoptions, editoptions);
					schemeMap.put(ColModelAttributeConstants.edittype, "shrtext");				
					colModel.add(schemeMap);
					colNames.add(rs.getString("MNAME"));
				}else if(CalSubmitItemDataType.DATE_VALUE.equals(dataType)){//日期类型
					dateType = rs.getInt("FDATETYPE");
					
					Map<String, Object> schemeMap = new HashMap<String, Object>();
					schemeMap.put(ColModelAttributeConstants.name, "S"+rs.getString("fieldSn"));
					schemeMap.put(ColModelAttributeConstants.label, rs.getString("MNAME"));
					schemeMap.put(ColModelAttributeConstants.frozen, false);
					schemeMap.put(ColModelAttributeConstants.width, 100);
					schemeMap.put(ColModelAttributeConstants.align, "left");
					schemeMap.put(ColModelAttributeConstants.key, true);
					schemeMap.put(ColModelAttributeConstants.hidden, false);
					schemeMap.put(ColModelAttributeConstants.editable, true);				
					schemeMap.put(ColModelAttributeConstants.sorttype, "date");
					schemeMap.put(ColModelAttributeConstants.sortable, false);
//					gridPersonNumberMap.put(ColModelAttributeConstants.formatter, "datepicker");    8.5sp1
//					gridPersonNumberMap.put(ColModelAttributeConstants.edittype, "shrdatepicker");
					schemeMap.put(ColModelAttributeConstants.formatter, "shrDateTimePicker");
					schemeMap.put(ColModelAttributeConstants.edittype, "shrDateTimePicker");
					if(isRequired == 1) {
						schemeMap.put(ColModelAttributeConstants.classes, "required");
					}
					StringBuffer datapickerjsonBuffer = new StringBuffer();
					datapickerjsonBuffer.append("{");
					datapickerjsonBuffer.append("\"datepickerjson\":");
					datapickerjsonBuffer.append("{");
					datapickerjsonBuffer.append("\"id\":\"dp_autoSize\",");
					datapickerjsonBuffer.append("\"name\":\"dp_autoSize\",");
					datapickerjsonBuffer.append("\"minuteStep\":\"\",");
					datapickerjsonBuffer.append("\"showTimeZoneForCtrl\":false,");
					datapickerjsonBuffer.append("\"isAutoTimeZoneTrans\":false,");
					datapickerjsonBuffer.append("\"isShowUTC\":false,");
					datapickerjsonBuffer.append("\"isReadonlyUTC\":true,");
					datapickerjsonBuffer.append("\"isRemoveSeconds\":true,");
					if(DateTypeEnum.YYYYMM_VALUE == dateType){
						datapickerjsonBuffer.append("\"isRemoveDay\":true,");
					}else if(DateTypeEnum.YYYYMMDD_VALUE == dateType){
						datapickerjsonBuffer.append("\"isRemoveDay\":false,");
					}else{
						datapickerjsonBuffer.append("\"isRemoveDay\":false,");
					}
					datapickerjsonBuffer.append("\"ctrlType\":\"Date\"");
					datapickerjsonBuffer.append("},");
					datapickerjsonBuffer.append("\"validateJson\":");
					datapickerjsonBuffer.append("{");
					datapickerjsonBuffer.append("\"errMsg\":\"\",");
					if(isRequired == 1){
						datapickerjsonBuffer.append("\"rules\":\"required:true\",");
					}else{
						datapickerjsonBuffer.append("\"rules\":\"required:false\",");
					}
					datapickerjsonBuffer.append("\"validatetrigger\":\"focus keyup datachange\"");
					datapickerjsonBuffer.append("}");
					datapickerjsonBuffer.append("}");
					schemeMap.put(ColModelAttributeConstants.editoptions, JSONObject.parseObject(datapickerjsonBuffer.toString()));
					colNames.add(rs.getString("MNAME"));
					colModel.add(schemeMap);
				}else if(CalSubmitItemDataType.F7_VALUE.equals(dataType)){
					
					Map<String, Object> schemeMap = new HashMap<String, Object>();
					assembleColModelF7(schemeMap, "S"+rs.getString("fieldSn"), rs.getString("MNAME"), isRequired == 1);
					Map<String, Object> editoptions = assembleColModelF7(rs.getString("BNAME"), rs.getString("FMAINTAINUIPK"), isRequired == 1,"");
//					Map<String, Object> f7Json = (Map<String, Object>) editoptions.get("f7Json");   //F7的过滤使用可维护，由于可使用查询可能会很慢，如果需要调整为可使用，则调整uipk获取可使用的即可，并且调整displayFormat和submitFormat
//					f7Json.put("displayFormat", "{BaseInfo.name}");
//					f7Json.put("submitFormat", "{BaseInfo.id}");
					schemeMap.put(ColModelAttributeConstants.editoptions, editoptions);
					colNames.add(rs.getString("MNAME"));
					colModel.add(schemeMap);
				}
			}
			
			// 描述
			Map<String, Object> gridDescriptionMap = new HashMap<String, Object>();
			gridDescriptionMap.put(ColModelAttributeConstants.name, "description");
			gridDescriptionMap.put(ColModelAttributeConstants.label, "备注");
			gridDescriptionMap.put(ColModelAttributeConstants.frozen, false);
			gridDescriptionMap.put(ColModelAttributeConstants.width, 90);
			gridDescriptionMap.put(ColModelAttributeConstants.align, "left");
			gridDescriptionMap.put(ColModelAttributeConstants.key, false);
			gridDescriptionMap.put(ColModelAttributeConstants.editable, true);				
			gridDescriptionMap.put(ColModelAttributeConstants.sortable, false);
			gridDescriptionMap.put(ColModelAttributeConstants.formatter, "shrMultiLangBox");
			gridDescriptionMap.put(ColModelAttributeConstants.edittype, "shrMultiLangBox");
			JSONObject editoptions = JSONObject.parseObject("{ \"inputJson\": {  } }");
			
			//添加精度
			JSONObject inputJson = editoptions.getJSONObject("inputJson");
			//添加长度
			inputJson.put("maxlength", 255);
			gridDescriptionMap.put(ColModelAttributeConstants.editoptions, editoptions);
			colNames.add("备注"); // colNames.add("备注");
			colModel.add(gridDescriptionMap);

			
		} catch (Exception e) {
			throw new BOSException("获取提报方案的提报项目列出错！"); // "获取提报方案的提报项目列出错！"
		}
		map.put("colNames", colNames);
		map.put("colModel", colModel);
		return map ;
	}
	
	
	/**
     *  组装ID前端基础属性
     * @param gridIdMap
     * @param name
     * @param label
     * @return
     * @throws BOSException
     */
	public static Map<String, Object>  assembleColModelId(Map<String, Object> gridIdMap){
    	gridIdMap.put(ColModelAttributeConstants.name, "id");
		gridIdMap.put(ColModelAttributeConstants.label, "id");
		gridIdMap.put(ColModelAttributeConstants.frozen, false);
		gridIdMap.put(ColModelAttributeConstants.width, 90);
		gridIdMap.put(ColModelAttributeConstants.align, "left");
		gridIdMap.put(ColModelAttributeConstants.key, true);
		gridIdMap.put(ColModelAttributeConstants.hidden, true);
		gridIdMap.put(ColModelAttributeConstants.editable, false);				
		gridIdMap.put(ColModelAttributeConstants.sorttype, "");
		gridIdMap.put(ColModelAttributeConstants.sortable, false);
		gridIdMap.put(ColModelAttributeConstants.classes, "disabled");
	   return gridIdMap;
	}
	
	
   /**
    * 组装F7前端editoptions属性
    * @param name
    * @param uipk
    * @param isRequired
    * @return
    */
	public static Map<String, Object>  assembleColModelF7(String name , String uipk, boolean isRequired){
	
			//=====组装F7
	        Map<String, Object> resultMap = new HashMap<String, Object>();
	        Map<String, Object> f7JsonMap = new HashMap<String, Object>();
	        Map<String, Object> validateJsonMap = new HashMap<String, Object>();
	        // ======subWidgetOptions属性
			Map<String, Object> uipkMap = new HashMap<String, Object>();
			uipkMap.put(ColModelAttributeConstants.title, name);
			uipkMap.put(ColModelAttributeConstants.uipk, uipk);
			uipkMap.put(ColModelAttributeConstants.query, "");
			uipkMap.put(ColModelAttributeConstants.filter, "");
			uipkMap.put(ColModelAttributeConstants.multiselect, false);
			uipkMap.put(ColModelAttributeConstants.isTree, false);
			uipkMap.put(ColModelAttributeConstants.treeUrl, "");				
			uipkMap.put(ColModelAttributeConstants.isContainLowerOrg, false);
			uipkMap.put(ColModelAttributeConstants.isAdminOrg, false);
//			uipkMap.put(ColModelAttributeConstants.isEnableExpFilter, true); 
			
			f7JsonMap.put("subWidgetOptions", uipkMap);
			// =====其他属性
			f7JsonMap.put(ColModelAttributeConstants.subWidgetName, "shrPromptGrid");
			f7JsonMap.put(ColModelAttributeConstants.searchFields, "");
			f7JsonMap.put(ColModelAttributeConstants.isHROrg, false);
			f7JsonMap.put(ColModelAttributeConstants.isAdminOrg, false);
			f7JsonMap.put(ColModelAttributeConstants.searchLikePattern,  "any");
			resultMap.put("f7Json", f7JsonMap);
			//======validateJsonMap 
			validateJsonMap.put(ColModelAttributeConstants.errMsg, "");
			if(isRequired){
				validateJsonMap.put(ColModelAttributeConstants.rules, "required:true");
			}
			validateJsonMap.put(ColModelAttributeConstants.validatetrigger, "focus keyup datachange");
			resultMap.put("validateJson", validateJsonMap);
	        return resultMap;
	}
	
	/**
	    * 组装F7前端editoptions属性
	    * @param name
	    * @param uipk
	    * @param isRequired
	    * @return
	    */
		public static Map<String, Object>  assembleColModelF7(String name , String uipk, boolean isRequired, String filter){
		
				//=====组装F7
		        Map<String, Object> resultMap = new HashMap<String, Object>();
		        Map<String, Object> f7JsonMap = new HashMap<String, Object>();
		        Map<String, Object> validateJsonMap = new HashMap<String, Object>();
		        // ======subWidgetOptions属性
				Map<String, Object> uipkMap = new HashMap<String, Object>();
				uipkMap.put(ColModelAttributeConstants.title, name);
				uipkMap.put(ColModelAttributeConstants.uipk, uipk);
				uipkMap.put(ColModelAttributeConstants.query, "");
				uipkMap.put(ColModelAttributeConstants.filter, filter);
				uipkMap.put(ColModelAttributeConstants.multiselect, false);
				uipkMap.put(ColModelAttributeConstants.isTree, false);
				uipkMap.put(ColModelAttributeConstants.treeUrl, "");				
				uipkMap.put(ColModelAttributeConstants.isContainLowerOrg, false);
				uipkMap.put(ColModelAttributeConstants.isAdminOrg, false);
				f7JsonMap.put("subWidgetOptions", uipkMap);
				// =====其他属性
				f7JsonMap.put(ColModelAttributeConstants.subWidgetName, "shrPromptGrid");
				f7JsonMap.put(ColModelAttributeConstants.searchFields, "");
				f7JsonMap.put(ColModelAttributeConstants.isHROrg, false);
				f7JsonMap.put(ColModelAttributeConstants.isAdminOrg, false);
				f7JsonMap.put(ColModelAttributeConstants.searchLikePattern,  "any");
				resultMap.put("f7Json", f7JsonMap);
				//======validateJsonMap 
				validateJsonMap.put(ColModelAttributeConstants.errMsg, "");
				if(isRequired){
					validateJsonMap.put(ColModelAttributeConstants.rules, "required:true");
				}
				validateJsonMap.put(ColModelAttributeConstants.validatetrigger, "focus keyup datachange");
				resultMap.put("validateJson", validateJsonMap);
		        return resultMap;
		}
	
    /**
     *  组装F7前端基础属性
     * @param gridMainKeyIdMap
     * @param name
     * @param label
     * @return
     * @throws BOSException
     */
	public static Map<String, Object>  assembleColModelF7(Map<String, Object> gridMainKeyIdMap,String name ,String label, boolean isRequired){
    	gridMainKeyIdMap.put(ColModelAttributeConstants.name, name);
		gridMainKeyIdMap.put(ColModelAttributeConstants.label, label);
		gridMainKeyIdMap.put(ColModelAttributeConstants.frozen, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.width, 120);
		gridMainKeyIdMap.put(ColModelAttributeConstants.align, "left");
		gridMainKeyIdMap.put(ColModelAttributeConstants.key, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.edittype, "promptBox");
		gridMainKeyIdMap.put(ColModelAttributeConstants.editable, true);				
		gridMainKeyIdMap.put(ColModelAttributeConstants.sorttype, "objectvalue");
//		gridMainKeyIdMap.put(ColModelAttributeConstants.sortable, true);
		gridMainKeyIdMap.put(ColModelAttributeConstants.sortable, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.formatter, "promptBox");
		
		if(isRequired){
			gridMainKeyIdMap.put(ColModelAttributeConstants.classes, "required");
		}
	   return gridMainKeyIdMap;
	}
	
	/**
	 *  组装F7前端基础属性不可编辑
	 * @param gridMainKeyIdMap
	 * @param name
	 * @param label
	 * @return
	 * @throws BOSException
	 */
	public static Map<String, Object>  assembleColModelF7NotEdit(Map<String, Object> gridMainKeyIdMap,String name ,String label){
		gridMainKeyIdMap.put(ColModelAttributeConstants.name, name);
		gridMainKeyIdMap.put(ColModelAttributeConstants.label, label);
		gridMainKeyIdMap.put(ColModelAttributeConstants.frozen, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.width, 120);
		gridMainKeyIdMap.put(ColModelAttributeConstants.align, "left");
		gridMainKeyIdMap.put(ColModelAttributeConstants.key, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.edittype, "promptBox");
		gridMainKeyIdMap.put(ColModelAttributeConstants.editable, false);				
		gridMainKeyIdMap.put(ColModelAttributeConstants.sorttype, "objectvalue");
//		gridMainKeyIdMap.put(ColModelAttributeConstants.sortable, true);
		gridMainKeyIdMap.put(ColModelAttributeConstants.sortable, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.formatter, "promptBox");
		gridMainKeyIdMap.put(ColModelAttributeConstants.classes, "disabled");
		return gridMainKeyIdMap;
	}
	
	/**
	 *  组装F7前端基础属性隐藏
	 * @param gridMainKeyIdMap
	 * @param name
	 * @param label
	 * @return
	 * @throws BOSException
	 */
	public static Map<String, Object>  assembleColModelF7Hidden(Map<String, Object> gridMainKeyIdMap,String name ,String label){
		gridMainKeyIdMap.put(ColModelAttributeConstants.name, name);
		gridMainKeyIdMap.put(ColModelAttributeConstants.label, label);
		gridMainKeyIdMap.put(ColModelAttributeConstants.frozen, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.width, 120);
		gridMainKeyIdMap.put(ColModelAttributeConstants.hidden, true);
		gridMainKeyIdMap.put(ColModelAttributeConstants.align, "left");
		gridMainKeyIdMap.put(ColModelAttributeConstants.key, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.edittype, "promptBox");
		gridMainKeyIdMap.put(ColModelAttributeConstants.editable, false);				
		gridMainKeyIdMap.put(ColModelAttributeConstants.sorttype, "objectvalue");
//		gridMainKeyIdMap.put(ColModelAttributeConstants.sortable, true);
		gridMainKeyIdMap.put(ColModelAttributeConstants.sortable, false);
		gridMainKeyIdMap.put(ColModelAttributeConstants.formatter, "promptBox");
		gridMainKeyIdMap.put(ColModelAttributeConstants.classes, "disabled");
		return gridMainKeyIdMap;
	}
	
	
	   public static Map<String, Object> getBillColumnListAndQuerySql(Context ctx, String submitSchemeId, String billID)
			/*      */     throws BOSException
			/*      */   {
			/*  727 */     Map map = new HashMap();
			/*  728 */     List colNames = new ArrayList();
			/*  729 */     Map columnMap = new HashMap();
			/*  730 */     if (StringUtils.isEmpty(submitSchemeId)) {
			/*  731 */       return map;
			/*      */     }
			/*      */ 
			/*  734 */     String language = ctx.getLocale().getLanguage();
			/*      */ 
			/*  736 */     String sql = new StringBuilder().append("Select e.FSubmitTarget,e.FIsEnableSubmitElement , m.fieldSn,m.FDataDot,m.fdataType,m.fname_").append(language).append(" ,n.FBillEntryTableName from  T_HR_SCalSubmitScheme e ").append(" inner join  T_HR_SCalSubmitSchemeItem t on t.FCalSubmitSchemeID = e.fid ").append(" inner join T_HR_SCalSubmitItem m on  m.fid = t.FCalSubmitItemID ").append(" inner join T_HR_SCalShemeTableRelation n on n.FSubmitSchemeID =e.fid  ").append(" where e.fid = '").append(submitSchemeId).append("'  order by FSortSn ").toString();
			/*      */ 
			/*  742 */     StringBuilder sd = new StringBuilder(" select t.fid id ,  t.FEffectDate effectDay , t.FCmpEmpORelationID cmpEmpORelation,");
			/*  743 */     colNames.add("id");
			/*  744 */     colNames.add("effectDay");
			/*      */     try {
			/*  746 */       String submitTarget = ""; String fBillEntryTableName = "";
			/*  747 */       IRowSet rs = DbUtil.executeQuery(ctx, sql);
			/*  748 */       boolean f7Flag = true; boolean personFlag = true; boolean isEnableSubmitElement = false;
			/*  749 */       while (rs.next())
			/*      */       {
			/*  751 */         submitTarget = rs.getString("FSubmitTarget");
			/*  752 */         isEnableSubmitElement = rs.getBoolean("FIsEnableSubmitElement");
			/*      */ 
			/*  754 */         if (f7Flag) {
			/*  755 */           f7Flag = false;
			/*      */ 
			/*  757 */           fBillEntryTableName = rs.getString("FBillEntryTableName");
			/*      */ 
			/*  759 */           if ("02".equals(submitTarget)) {
			/*  760 */             personFlag = false;
			/*  761 */             colNames.add("orgId");
			/*  762 */             colNames.add("name");
			/*  763 */             colNames.add("number");
			/*  764 */             sd.append("n.fid orgId , n.fname_").append(language).append(" name , n.fnumber number ");
			/*      */           } else {
			/*  766 */             colNames.add("personId");
			/*  767 */             colNames.add("name");
			/*  768 */             colNames.add("number");
			/*  769 */             colNames.add("admOrgId");
			/*  770 */             colNames.add("admOrgName");
			/*      */ 
			/*  772 */             colNames.add("positionId");
			/*  773 */             colNames.add("positionName");
			/*  774 */             colNames.add("cmpEmpORelation");
			/*      */ 
			/*  777 */             sd.append(" n.fid personId , n.fname_").append(language).append("  name, n.fnumber number, a.fid admOrgId, a.fname_").append(language).append(" admOrgName, p.fid positionId, p.fname_").append(language).append(" positionName  ");
			/*      */           }
			/*      */         }
			/*  780 */         sd.append(new StringBuilder().append(",S").append(rs.getString("fieldSn")).toString());
			/*      */ 
			/*  782 */         colNames.add(new StringBuilder().append("S").append(rs.getString("fieldSn")).toString());
			/*      */ 
			/*  785 */         if ("0".equals(rs.getString("fdataType")));
			/*  786 */         columnMap.put(new StringBuilder().append("S").append(rs.getString("fieldSn")).toString(), Integer.valueOf(rs.getInt("FDataDot")));
			/*      */       }
			/*      */ 
			/*  789 */       colNames.add("description");
			/*  790 */       if (isEnableSubmitElement) {
			/*  791 */         colNames.add("submitElement");
			/*  792 */         sd.append(", t.FSubmitElementID submitElement,subele.Fname_").append(language).append(" submitElementName ");
			/*      */       }
			/*  794 */       colNames.add("currency");
			/*  795 */       sd.append(",c.fid currency,c.fname_").append(language).append(" currencyName,t.fdescription_l1 description_l1,t.fdescription_l2 description_l2,t.fdescription_l3 description_l3");
			/*      */ 
			/*  797 */       sd.append(new StringBuilder().append(" from   ").append(fBillEntryTableName).append(" ").toString());
			/*  798 */       if (personFlag) {
			/*  799 */         sd.append(" t  inner join t_bd_person n on t.fpersonId = n.fid ");
			/*  800 */         sd.append(" LEFT join T_ORG_Admin a on t.FAdminOrgUnitID = a.fid ");
			/*  801 */         sd.append(" LEFT join T_ORG_Position p on t.FPositionID = p.fid ");
			/*      */       } else {
			/*  803 */         sd.append(" t on b.fid = t.fbillid  inner join T_ORG_Admin  n on t.FOrgUnitID = n.fid ");
			/*      */       }
			/*  805 */       sd.append(" LEFT join T_BD_Currency c on t.fCurrencyID = c.fid ");
			/*  806 */       if (isEnableSubmitElement) {
			/*  807 */         sd.append(" LEFT join T_HR_SSubmitElement subele on t.FSubmitElementID = subele.fid ");
			/*      */       }
			/*      */ 
			/*  810 */       sd.append(new StringBuilder().append(" where t.fbillid = '").append(billID).append("'").toString());
			///*  811 */       sd.append(new StringBuilder().append(" and  b.FSubmitSchemeID = '").append(submitSchemeId).append("' ").toString());
			/*      */ 
			/*  813 */       map.put("querySql", sd.toString());
			/*  814 */       map.put("colNames", colNames);
			/*  815 */       map.put("columnMap", columnMap);
			/*      */     }
			/*      */     catch (Exception e) {
			/*  818 */       throw new BOSException("获取提报方案的提报项目列出错！");
			/*      */     }
			/*  820 */     return map;
			/*      */   }
	
	/**
	 * 
	 * 根据方案id 获取方案提报单分录的提报项目列及对应的分录表名
	 * @param schemeId
	 * @return List
	 * @throws BOSException 
	 */
	public static Map<String, Object>  getBillColumnListAndBillEntryTableName(Context ctx,String submitSchemeId) throws BOSException{
		
		Map<String, Object> map = new HashMap<String, Object>();
		List<String> colNames = new ArrayList<String>();
		List<String> colTypes = new ArrayList<String>();
		if (StringUtils.isEmpty(submitSchemeId)) {
			return map ;
		}
		
		String language = ctx.getLocale().getLanguage();
		
		String  sql = "Select e.FSubmitTarget , m.fieldSn,m.fdataType,m.fname_" + language + " ,n.FBillEntryTableName ,n.FCalShemeTableName ,t.FIsRequired from  T_HR_SCalSubmitScheme e "
				+ " inner join  T_HR_SCalSubmitSchemeItem t on t.FCalSubmitSchemeID = e.fid "
				+ " inner join T_HR_SCalSubmitItem m on  m.fid = t.FCalSubmitItemID "
				+ " inner join T_HR_SCalShemeTableRelation n on n.FSubmitSchemeID =e.fid  "
				+ " where e.fid = '"+submitSchemeId+"'  order by FSortSn ";
		try {
			String fBillEntryTableName = ""; //提报对象 01 person  02 org
			logger.error("CmpIntegrateUtilsNew.getBillColumnListAndBillEntryTableName.sql:"+sql);
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			while (rs.next()) {			
				//=====组装提报项目
				if (StringUtils.isEmpty(fBillEntryTableName)) {
					fBillEntryTableName = rs.getString("FBillEntryTableName");
//					fCalShemeTableName = rs.getString("FCalShemeTableName");
				}
				colNames.add("S"+rs.getString("fieldSn"));
				colTypes.add(rs.getString("fdataType"));
			}	
			map.put("fBillEntryTableName", fBillEntryTableName);
//			map.put("fCalShemeTableName", fCalShemeTableName);
			map.put("colNames", colNames);
			map.put("colTypes", colTypes);
			
		} catch (Exception e) {
			throw new BOSException("获取提报方案的提报项目列出错！"); //"获取提报方案的提报项目列出错！"
		}
		return map ;
	}
	
	/**
	 * 获取插入的列1
	 * @param ctx
	 * @param billEntryTable
	 * @param colNames
	 * @param billId
	 * @return
	 */
	public static String getAssembleField1Sql(Context ctx, String billEntryTable,
			List<String> colNames, String billId) {
		StringBuilder insertCol = new StringBuilder(" insert into ");
		String userId = HRFilterUtils.getCurrentUserId(ctx);
		Date date = new Date();
		insertCol.append(billEntryTable);
		insertCol.append(" (FID ,fparentid ");
		

		/*StringBuilder insertval = new StringBuilder(new StringBuilder().append(
				" values ( ?,'").append(billId).append("', '").append(userId)
				.append("', ").append(CmpDateUtil.toKSqlDate(date)).toString());
		insertval.append(", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ");*/
		for (String schemeItem : colNames) {
			insertCol.append(new StringBuilder().append(",").append(schemeItem)
					.toString());
			//insertval.append(", ? ");
		}
		insertCol.append(" )");
		//insertval.append(" ,?,?,?,?)");
		//insertCol.append(insertval);

		return insertCol.toString();
	}
	
	
	/**
	 * 获取插入的列1
	 * @param ctx
	 * @param billEntryTable
	 * @param colNames
	 * @param billId
	 * @return
	 */
	public static String getAssembleField2Sql(Context ctx, String billEntryTable,
			List<String> colNames, String billId) {
		StringBuilder insertCol = new StringBuilder(" insert into ");
		String userId = HRFilterUtils.getCurrentUserId(ctx);
		Date date = new Date();
		insertCol.append(billEntryTable);
		insertCol.append(" (FID ,fbillid ");
		

		/*StringBuilder insertval = new StringBuilder(new StringBuilder().append(
				" values ( ?,'").append(billId).append("', '").append(userId)
				.append("', ").append(CmpDateUtil.toKSqlDate(date)).toString());
		insertval.append(", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ");*/
		for (String schemeItem : colNames) {
			insertCol.append(new StringBuilder().append(",").append(schemeItem)
					.toString());
			//insertval.append(", ? ");
		}
		insertCol.append(" )");
		//insertval.append(" ,?,?,?,?)");
		//insertCol.append(insertval);

		return insertCol.toString();
	}
	
	

	/**
	 * 获取临时表的fid,billId所有动态字段
	 * @param ctx
	 * @param billEntryTable
	 * @param colNames
	 * @param billId
	 * @return
	 * @throws BOSException 
	 */
	public static List<Map<String,Object>> getAssembleListByCmp(Context ctx, String billEntryTable,
			List<String> colNames, String billId) throws BOSException {
		List<Map<String,Object>> sValuelist= new ArrayList<Map<String,Object>>();
		StringBuilder sql = new StringBuilder(" SELECT ");
		String userId = HRFilterUtils.getCurrentUserId(ctx);
		
		
		sql.append(" FID ,fbillid ");
		

		/*StringBuilder insertval = new StringBuilder(new StringBuilder().append(
				" values ( ?,'").append(billId).append("', '").append(userId)
				.append("', ").append(CmpDateUtil.toKSqlDate(date)).toString());
		insertval.append(", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ");*/
		for (String schemeItem : colNames) {
			sql.append(new StringBuilder().append(",").append(schemeItem)
					.toString());
			//insertval.append(", ? ");
		}
		sql.append(" from ");
		sql.append(billEntryTable);
		sql.append(" where fbillid = '"+billId+"'");
		logger.error("BatchSubmitSchemeBillControllerBeanExt.getAssembleListByCmp.sql:"+sql.toString());
		//insertval.append(" ,?,?,?,?)");
		//insertCol.append(insertval);
		try{
			IRowSet rs = DbUtil.executeQuery(ctx, sql.toString()); 
			String fid = "";
			String fbillid = "";
			while (rs.next()) {		
				Map<String,Object> sValueMap = new HashMap<String,Object>();
				//=====组装提报项目
				fid = rs.getString("FID");
				fbillid = rs.getString("fbillid");
				sValueMap.put("fid", fid);
				sValueMap.put("fbillid", fbillid);
				for (String schemeItem : colNames) {
					sValueMap.put(""+schemeItem, rs.getObject(""+schemeItem));
				}
				sValuelist.add(sValueMap);
						
			}	
			} catch (Exception e) {
				throw new BOSException("获取提报方案的提报项目列出错！"); //"获取提报方案的提报项目列出错！"
			}
		
		
		return sValuelist;
	}
	
	
	/**
	 * 更新提报分录的s字段
	 * @param ctx
	 * @param colNames
	 * @param sValue
	 * @throws BOSException 
	 */
	public static void updateSchemeBillEntryByCmpS(Context ctx,List<String> colNames,Map<String,Object> sValue) throws BOSException{
		logger.error("into updateSchemeBillEntryByCmpS method.colNames.size:"+colNames.size());
		StringBuilder sqlSb = new StringBuilder(" update T_HR_SchemeBillEntry set ");
		Object cmpObje = null;
		//是否免税字符串
		String s81ValueId = "";
		for (String schemeItem : colNames) {		
			cmpObje = sValue.get(""+schemeItem);
			if(cmpObje instanceof String){
				sqlSb.append(" CF"+schemeItem).append("='").append(cmpObje).append("',");
				
				//是否免税特殊处理
				if("S81".equals(schemeItem)){
					if(cmpObje!=null){
						s81ValueId = (String)cmpObje;
					}
				}
				
				
			}else{
				sqlSb.append(" CF"+schemeItem).append("=").append(cmpObje).append(",");
			}
		}
		String sqlSbStr = sqlSb.toString();
		if(sqlSbStr.endsWith(",")) {
			sqlSbStr = sqlSbStr.substring(0, sqlSbStr.length() - 1);
		}
		Object fidObj = sValue.get("fid");
		
		if(fidObj == null){
			logger.error("BatchSubmitSchemeBillControllerBeanExt.updateSchemeBillEntryByCmpS:fidObj为空");
			return;
		}
		String fid= (String)fidObj;
		sqlSbStr = sqlSbStr + " where fid = '"+fid+"'";
		logger.error("BatchSubmitSchemeBillControllerBeanExt.updateSchemeBillEntryByCmpS:sqlSbStr:"+sqlSbStr);
		DbUtil.execute(ctx,sqlSbStr);
		
		//更新分录的是否免税字符串		
		updateSchemeBillEntryCFTaxExemptionStrByEntryFid(ctx,s81ValueId,fid);
	}
	
	
	/**
	 * 更新分录的是否免税字符串
	 * @param ctx
	 * @param s81ValueId
	 * @param fid
	 * @throws BOSException 
	 */
	private static void updateSchemeBillEntryCFTaxExemptionStrByEntryFid(Context ctx,String s81ValueId , String fid) throws BOSException{
		String sql = "update T_HR_SchemeBillEntry set cftaxexemptionstr = (select fname_l1 from CT_CUS_TaxExemption where fid ='"+s81ValueId+"' ) where fid ='"+fid+"'";
		logger.error("BatchSubmitSchemeBillControllerBeanExt.updateSchemeBillEntryCFTaxExemptionStrByEntryFid:sql:"+sql);
		
		DbUtil.execute(ctx,sql);
	}
	
	
	
	/**
	 * 
	 * 根据方案id,dataType获取方案提报单分录在提报项目列及对应的分录表名
	 * @param schemeId
	 * @return List
	 * @throws BOSException 
	 */
	public static Map<String, Object>  getBillColumnListAndBillEntryTableNameByDataType(Context ctx,String submitSchemeId, String dataType) throws BOSException{
		
		Map<String, Object> map = new HashMap<String, Object>();
		List<String> colNames = new ArrayList<String>();
		if (StringUtils.isEmpty(submitSchemeId)) {
			return map ;
		}
		
		String language = ctx.getLocale().getLanguage();
		
		String  sql = "Select e.FSubmitTarget , m.fieldSn,m.fdataType,m.fname_"+language+" ,n.FBillEntryTableName ,n.FCalShemeTableName ,t.FIsRequired from  T_HR_SCalSubmitScheme e "
				+ " inner join  T_HR_SCalSubmitSchemeItem t on t.FCalSubmitSchemeID = e.fid "
				+ " inner join T_HR_SCalSubmitItem m on  m.fid = t.FCalSubmitItemID "
				+ " inner join T_HR_SCalShemeTableRelation n on n.FSubmitSchemeID =e.fid  "
				+ " where e.fid = '"+submitSchemeId+"' and m.fdataType = '"+dataType+"'  order by FSortSn ";
		try {
			String fBillEntryTableName = "" ,fCalShemeTableName = ""; //提报对象 01 person  02 org
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			while (rs.next()) {			
				//=====组装提报项目
				if (StringUtils.isEmpty(fBillEntryTableName)) {
					fBillEntryTableName = rs.getString("FBillEntryTableName");
					fCalShemeTableName = rs.getString("FCalShemeTableName");
				}
				colNames.add("S"+rs.getString("fieldSn"));
			}	
			map.put("fBillEntryTableName", fBillEntryTableName);
			map.put("fCalShemeTableName", fCalShemeTableName);
			map.put("colNames", colNames);
			
		} catch (Exception e) {
			throw new BOSException("获取提报方案的提报项目列出错！"); //"获取提报方案的提报项目列出错！"
		}
		return map ;
	}
	
	/**
	 * 
	 * 根据方案id 获取方案提报单分录的对应的分录表名
	 * @param schemeId
	 * @return List
	 * @throws BOSException 
	 */
	public static String getSchemeEntryTableName(Context ctx,String submitSchemeId) {
		String fBillEntryTableName = "" ; 
		String  sql = "Select n.FBillEntryTableName  from  T_HR_SCalSubmitScheme e "
				+ " inner join T_HR_SCalShemeTableRelation n on n.FSubmitSchemeID =e.fid  "
				+ " where e.fid = '"+submitSchemeId+"'  ";
		try {
			//提报对象 01 person  02 org
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			while (rs.next()) {			
				//=====组装提报项目
				fBillEntryTableName = rs.getString("FBillEntryTableName");		
			}	
		} catch (Exception e) {
			logger.info(e);
		}
		return fBillEntryTableName ;
	}
	
	/**
	 * 
	 * 根据方案id 获取方案提报单分录的对应的分录表名
	 * @param schemeId
	 * @return List
	 * @throws BOSException 
	 */
	public static String getCalShemeTableName(Context ctx,String submitSchemeId) {
		String calShemeTableName = "" ; 
		String  sql = "Select n.FBillEntryTableName  from  T_HR_SCalSubmitScheme e "
				+ " inner join T_HR_SCalShemeTableRelation n on n.FSubmitSchemeID =e.fid  "
				+ " where e.fid = '"+submitSchemeId+"'  ";
		try {
			//提报对象 01 person  02 org
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			while (rs.next()) {			
				//=====组装提报项目
				calShemeTableName = rs.getString("FBillEntryTableName");		
			}	
		} catch (Exception e) {
			logger.info(e);
		}
		return calShemeTableName ;
	}
	
	/**
	 * 删除提报方案关联的动态表及数据
	 * @param schemeId
	 * @return
	 * @throws BOSException 
	 * @throws SQLException 
	 */
	public static boolean deleteSubmitSchemeRelationDate(Context ctx,String schemeId) throws BOSException, SQLException {
		boolean flag = false ;
		if (StringUtils.isEmpty(schemeId)) {
			return flag ;
		}
		String sql = "select FBillEntryTableName , FCalShemeTableName  from T_HR_SCalShemeTableRelation where FSubmitSchemeID = '"+schemeId+"'";
		String  calShemeTableName = "" ,billEntryTableName ="";
		IRowSet list = DbUtil.executeQuery(ctx, sql);
		while (list.next()) {
			billEntryTableName = list.getString("FBillEntryTableName");
			calShemeTableName = list.getString("FCalShemeTableName");
		}
		if (!CmpStrUtil.isEmpty(calShemeTableName)) {
			DbUtil.execute(ctx, "If exists (select * from KSQL_USERTABLES where KSQL_TABNAME ='" + calShemeTableName + "') drop table " + calShemeTableName + "");
			DbUtil.execute(ctx, "If exists (select * from KSQL_USERTABLES where KSQL_TABNAME ='" + billEntryTableName + "') drop table " + billEntryTableName + "");
		}
		DbUtil.execute(ctx, "delete   from T_HR_SCalShemeTableRelation where FSubmitSchemeID = '"+schemeId+"'");		
		return flag ;
	}
	
	/**
	 * 删除提报方案关联的动态表列
	 * @param schemeId
	 * @return
	 * @throws BOSException 
	 * @throws SQLException 
	 */
	public static boolean dropSubmitSchemeEntryTableCol(Context ctx,String schemeId,String itemId) throws BOSException, SQLException {
		boolean flag = false ;
		if (StringUtils.isEmpty(schemeId)) {
			return flag ;
		}
		String sql = "select FBillEntryTableName , FCalShemeTableName  from T_HR_SCalShemeTableRelation where FSubmitSchemeID = '"+schemeId+"'";
		String sqlItem  = "select fieldSn from  T_HR_SCalSubmitItem m "
				+ " inner join  T_HR_SCalSubmitSchemeItem t on m.fid = t.FCalSubmitItemID  where t.fid  = '"+itemId+"'" ;
		String  calShemeTableName = "" ,billEntryTableName ="",col="";
		IRowSet rs = DbUtil.executeQuery(ctx, sql);
		while (rs.next()) {
			billEntryTableName = rs.getString("FBillEntryTableName");
			calShemeTableName = rs.getString("FCalShemeTableName");
		}
		rs = DbUtil.executeQuery(ctx, sqlItem);
		while (rs.next()) {
			col = "S"+rs.getString("fieldSn");
		}
		StringBuilder calShemeTable = new StringBuilder("If  exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='"+col+"' "
				+ " and KSQL_COL_TABNAME='"+calShemeTableName+"')");
		calShemeTable.append("ALTER TABLE "+calShemeTableName+" drop column "+col+" ");
	
		StringBuilder billEntryTable = new StringBuilder("If  exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='"+col+"' "
				+ " and KSQL_COL_TABNAME='"+billEntryTableName+"')");
		billEntryTable.append("ALTER TABLE "+billEntryTableName+" drop column "+col+" ");
		if (!CmpStrUtil.isEmpty(calShemeTableName)) {
			DbUtil.execute(ctx,calShemeTable.toString());
			DbUtil.execute(ctx,billEntryTable.toString());
		}		
		return flag ;
	}
	
	/**
	 * 
	 * 根据方案id 获取方案提报单分录的提报项目列及对应的分录表名
	 * @param schemeId
	 * @return List
	 * @throws BOSException 
	 */
	public static Map<String ,Object>  getRequiredColumns(Context ctx,String submitSchemeId) throws BOSException{
		Map<String ,Object>  map  = new HashMap<String ,Object>();
		//Set集合保存提报项目信息导致提报项目无法排序，只能改成list
		List<Map<String, Object>>  colNames = new ArrayList<Map<String, Object>>();
		if (StringUtils.isEmpty(submitSchemeId)) {
			return map ;
		}
		String language = ctx.getLocale().getLanguage();
		String  sql = "Select e.FSubmitTarget , m.fieldSn,m.fdataType,m.fname_"+language+" MNAME,n.FBillEntryTableName ,n.FCalShemeTableName ,t.FIsRequired"
				+ " from  T_HR_SCalSubmitScheme e "
				+ " inner join  T_HR_SCalSubmitSchemeItem t on t.FCalSubmitSchemeID = e.fid "
				+ " inner join T_HR_SCalSubmitItem m on  m.fid = t.FCalSubmitItemID "
				+ " inner join T_HR_SCalShemeTableRelation n on n.FSubmitSchemeID =e.fid  "
				+ " where e.fid = '"+submitSchemeId+"' order by fieldSn ";
		String submitTarget =null;
		try {
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			while (rs.next()) {		
				Map<String, Object> gridIdMap = new HashMap<String, Object>();
				gridIdMap.put("rename", rs.getString("MNAME"));
				gridIdMap.put("name", "CMP_SMT002."+"S"+rs.getString("fieldSn"));
				gridIdMap.put("label", rs.getString("MNAME"));
				gridIdMap.put("type", "String");
				submitTarget = rs.getString("FSubmitTarget");
				//=====组装提报项目
				colNames.add(gridIdMap);
			}	
			map.put("colNames", colNames);
			map.put("submitTarget", submitTarget);
		} catch (Exception e) {
			throw new BOSException("获取提报方案的提报项目列出错！"); // "获取提报方案的提报项目列出错！"
		}
		return map ;
	}

    /**
     * 获取指定提报方案的动态项目
     * @param ctx
     * @param schemeId
     * @return
     */
    public static List<CalShemeSubmitItemDTO> getDynamicSubmitItemBySchemeId(Context ctx, String schemeId){
        List<CalShemeSubmitItemDTO> calShemeSubmitItemDTOS=new ArrayList<CalShemeSubmitItemDTO>();
        StringBuffer sqlBuffer=new StringBuffer();
        String language = ctx.getLocale().getLanguage();
        sqlBuffer.append(" SELECT E.FID AS SCHEMEID, M.FID as ITEMID,  M.FIELDSN,M.FDATATYPE,M.FNAME_"+language+" AS ITEMNAME,T.FISREQUIRED ,M.FDATADOT,M.FDATALENGTH ");
        sqlBuffer.append(" FROM  T_HR_SCALSUBMITSCHEME E  ");
        sqlBuffer.append(" INNER JOIN  T_HR_SCALSUBMITSCHEMEITEM T ON T.FCALSUBMITSCHEMEID = E.FID  ");
        sqlBuffer.append(" INNER JOIN T_HR_SCALSUBMITITEM M ON  M.FID = T.FCALSUBMITITEMID WHERE E.FID = '");
        sqlBuffer.append(schemeId);
        sqlBuffer.append("' ORDER BY T.FSORTSN");
        try {
            IRowSet rs = DbUtil.executeQuery(ctx, sqlBuffer.toString());
            CalShemeSubmitItemDTO calShemeSubmitItemDTO=null;
            while (rs.next()){
                calShemeSubmitItemDTO=new CalShemeSubmitItemDTO();
                calShemeSubmitItemDTO.setSubmitSchemeId(rs.getString("SCHEMEID"));
                calShemeSubmitItemDTO.setItemId(rs.getString("ITEMID"));
                calShemeSubmitItemDTO.setFieldSn(rs.getInt("FIELDSN"));
                calShemeSubmitItemDTO.setDataType(rs.getString("FDATATYPE"));
                calShemeSubmitItemDTO.setSubmitItemName(rs.getString("ITEMNAME"));
                calShemeSubmitItemDTO.setIsRequired(rs.getInt("FISREQUIRED"));
                calShemeSubmitItemDTO.setDataDot(rs.getInt("FDATADOT"));
                calShemeSubmitItemDTO.setDataLength(rs.getInt("FDATALENGTH"));
                calShemeSubmitItemDTOS.add(calShemeSubmitItemDTO);
            }
        } catch (BOSException e) {
            e.printStackTrace();
            logger.error(e.getMessage(),e);
        } catch (SQLException e) {
            logger.error(e.getMessage(),e);
            e.printStackTrace();
        }
        return calShemeSubmitItemDTOS;
    }
    
    
    
    /**
     * 获取指定提报方案的动态项目
     * @param ctx
     * @param schemeId
     * @return
     */
    public static List<CalShemeSubmitItemDTO> getDynamicSubmitItemBySchemeIdNotCenter(Context ctx, String schemeId){
        List<CalShemeSubmitItemDTO> calShemeSubmitItemDTOS=new ArrayList<CalShemeSubmitItemDTO>();
        StringBuffer sqlBuffer=new StringBuffer();
        String language = ctx.getLocale().getLanguage();
        sqlBuffer.append(" SELECT E.FID AS SCHEMEID, M.FID as ITEMID,  M.FIELDSN,M.FDATATYPE,M.FNAME_"+language+" AS ITEMNAME,"
        		+ "T.FISREQUIRED ,M.FDATADOT,M.FDATALENGTH ");
        sqlBuffer.append(" FROM  T_HR_SCALSUBMITSCHEME E  ");
        sqlBuffer.append(" INNER JOIN  T_HR_SCALSUBMITSCHEMEITEM T ON T.FCALSUBMITSCHEMEID = E.FID  ");
        sqlBuffer.append(" INNER JOIN T_HR_SCALSUBMITITEM M ON  M.FID = T.FCALSUBMITITEMID WHERE E.FID = '");
        sqlBuffer.append(schemeId);
        sqlBuffer.append("'  and M.Fnumber not in('DormFee027','DormFee026')");
        sqlBuffer.append("   AND T.FState=1 ORDER BY T.FSORTSN");
       
        try {
            IRowSet rs = DbUtil.executeQuery(ctx, sqlBuffer.toString());
            CalShemeSubmitItemDTO calShemeSubmitItemDTO=null;
            while (rs.next()){
                calShemeSubmitItemDTO=new CalShemeSubmitItemDTO();
                calShemeSubmitItemDTO.setSubmitSchemeId(rs.getString("SCHEMEID"));
                calShemeSubmitItemDTO.setItemId(rs.getString("ITEMID"));
                calShemeSubmitItemDTO.setFieldSn(rs.getInt("FIELDSN"));
                calShemeSubmitItemDTO.setDataType(rs.getString("FDATATYPE"));
                calShemeSubmitItemDTO.setSubmitItemName(rs.getString("ITEMNAME"));
                calShemeSubmitItemDTO.setIsRequired(rs.getInt("FISREQUIRED"));
                calShemeSubmitItemDTO.setDataDot(rs.getInt("FDATADOT"));
                calShemeSubmitItemDTO.setDataLength(rs.getInt("FDATALENGTH"));
                calShemeSubmitItemDTOS.add(calShemeSubmitItemDTO);
            }
        } catch (BOSException e) {
            e.printStackTrace();
            logger.error(e.getMessage(),e);
        } catch (SQLException e) {
            logger.error(e.getMessage(),e);
            e.printStackTrace();
        }
        return calShemeSubmitItemDTOS;
    }
    
    
    

    
    /**
     * 获取指定提报方案的动态项目排除实缴
     * @param ctx
     * @param schemeId
     * @return
     */
    public static List<CalShemeSubmitItemDTO>  getDynamicSubmitItemBySchemeIdExcludePaid (Context ctx, String schemeId){
        List<CalShemeSubmitItemDTO> calShemeSubmitItemDTOS=new ArrayList<CalShemeSubmitItemDTO>();
        StringBuffer sqlBuffer=new StringBuffer();
        String language = ctx.getLocale().getLanguage();
        sqlBuffer.append(" SELECT E.FID AS SCHEMEID, M.FID as ITEMID,  M.FIELDSN,M.FDATATYPE,M.FNAME_"+language+" AS ITEMNAME,T.FISREQUIRED ,M.FDATADOT,M.FDATALENGTH ");
        sqlBuffer.append(" FROM  T_HR_SCALSUBMITSCHEME E  ");
        sqlBuffer.append(" INNER JOIN  T_HR_SCALSUBMITSCHEMEITEM T ON T.FCALSUBMITSCHEMEID = E.FID  ");
        sqlBuffer.append(" INNER JOIN T_HR_SCALSUBMITITEM M ON  M.FID = T.FCALSUBMITITEMID WHERE E.FID = '");
        sqlBuffer.append(schemeId);
        sqlBuffer.append("' and M.fnumber not in('DormFee026','DormFee027') ORDER BY T.FSORTSN");
        try {
            IRowSet rs = DbUtil.executeQuery(ctx, sqlBuffer.toString());
            CalShemeSubmitItemDTO calShemeSubmitItemDTO=null;
            while (rs.next()){
                calShemeSubmitItemDTO=new CalShemeSubmitItemDTO();
                calShemeSubmitItemDTO.setSubmitSchemeId(rs.getString("SCHEMEID"));
                calShemeSubmitItemDTO.setItemId(rs.getString("ITEMID"));
                calShemeSubmitItemDTO.setFieldSn(rs.getInt("FIELDSN"));
                calShemeSubmitItemDTO.setDataType(rs.getString("FDATATYPE"));
                calShemeSubmitItemDTO.setSubmitItemName(rs.getString("ITEMNAME"));
                calShemeSubmitItemDTO.setIsRequired(rs.getInt("FISREQUIRED"));
                calShemeSubmitItemDTO.setDataDot(rs.getInt("FDATADOT"));
                calShemeSubmitItemDTO.setDataLength(rs.getInt("FDATALENGTH"));
                calShemeSubmitItemDTOS.add(calShemeSubmitItemDTO);
            }
        } catch (BOSException e) {
            e.printStackTrace();
            logger.error(e.getMessage(),e);
        } catch (SQLException e) {
            logger.error(e.getMessage(),e);
            e.printStackTrace();
        }
        return calShemeSubmitItemDTOS;
    }
    
    
    public static Map<String, Integer> getCellLength(Context ctx, String schemeId){
    	Map<String, Integer> map = new HashMap<String, Integer>();
		String  sql = "Select m.fieldSn,m.FDataLength"
				+ " from  T_HR_SCalSubmitScheme e "
				+ " inner join  T_HR_SCalSubmitSchemeItem t on t.FCalSubmitSchemeID = e.fid "
				+ " inner join T_HR_SCalSubmitItem m on  m.fid = t.FCalSubmitItemID "
				+ " where e.fid = '"+schemeId+"' and FDataType = '1' order by  FSortSn";
		try {
			IRowSet rs = DbUtil.executeQuery(ctx, sql);
			while (rs.next()) {
				String fieldSn = String.valueOf(rs.getInt(1));
				Integer dataLength = rs.getInt(2);
				map.put(fieldSn, dataLength);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
    	return map;
    }
}
