/*
 * ExpExcelWriter.java Created on 2017年1月5日 16:14:48 by cdy
 *
 * Copyright (c) 2001-2017 泛微软件, 版权所有.
 */
package weaver.formmode.excel;

import com.api.cube.cache.CustomTreeComInfo;
import com.api.cube.util.CubeCipherUitl;
import com.api.cube.util.CubeUtil;
import com.api.formmode.cache.ModeFormFieldEncryptComInfo;
import com.engine.cube.biz.ShardingActionHelper;
import com.engine.cube.biz.VSqlUtil;
import com.engine.cube.util.AddSeclevelUtil;
import com.engine.cube.util.SaveConditionUtil;
import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.FelEngineImpl;
import com.greenpineyu.fel.context.FelContext;
import com.weaver.formmodel.util.DateHelper;
import com.weaver.formmodel.util.StringHelper;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.dateformat.DateTransformer;
import weaver.dateformat.TimeZoneVar;
import weaver.docs.docs.DocImageManager;
import weaver.file.ExcelParseForPOI;
import weaver.formmode.cache.StringCacheMap;
import weaver.formmode.dao.BaseDao;
import weaver.formmode.data.FieldInfo;
import weaver.formmode.data.ModeDataIDUpdateSingle;
import weaver.formmode.data.ModeDataIdUpdate;
import weaver.formmode.interfaces.ImportFieldTransAction;
import weaver.formmode.interfaces.ImportFieldTransActionPOI;
import weaver.formmode.interfaces.InterfacesUtil;
import weaver.formmode.log.FormmodeLog;
import weaver.formmode.service.FormInfoService;
import weaver.formmode.service.SelectItemPageService;
import weaver.formmode.setup.ModeSetUtil;
import weaver.formmode.tree.CustomTreeData;
import weaver.general.BaseBean;
import weaver.general.SplitPageParaBean;
import weaver.general.SplitPageUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.workflow.browser.Browser;
import weaver.interfaces.workflow.browser.BrowserBean;
import weaver.systeminfo.SystemEnv;
import weaver.conn.ConnectionPool;
import weaver.conn.constant.DBConstant;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


/**
 * Description: CreateExcelServer.java
 *
 * @author dongping
 * @version 1.0 2005-4-21
 */
public class ImpExcelReader extends FormmodeLog implements Runnable {
	private String action;
	private CountDownLatch doneSignal;
	private int start;
	private int end;
	private String threadname;
	private int currentIndex;
	private String key;
	private Sheet sheet;
	Map<String, Object> params;
	private User user;
	private int formid;
	private int modeid;
	private Map<String, List<String>> validateMap;
	private Map IdMap;
	private ArrayList errorRow;
	private Map<String, String> checkMap;
	private String clientaddress;
	private ArrayList errorTable;
	//导入明细表时用
	private FieldInfo FieldInfo;
	private String maintable;
	private Map map;
	private String Errmsg;
	private int sheetIndex;
	/**
	 * 默认共享是否与明细表字段有关,如果有关,则权限重构需等到明细表插入完成才重构,否则可以主表插入一条就重构一条
	 */
	private boolean isdetailright = false;
	private List billList;
	private List rowNumList;
	private HashMap creatoridMap;
	private List<String> addBillIdList;
	private List detailList;
	private List<String> updateList;
	private List<Integer> errorRowList;
	private Hashtable<String, Vector<Integer>> errorDetailMap;
	private Map<String, Boolean> customBrowserMap = new HashMap<String, Boolean>();
	private Map<String, List<Map<String, String>>> treeBaseMap = new HashMap<String, List<Map<String, String>>>();
	private ModeFormFieldEncryptComInfo modeFormFieldEncryptComInfo = new ModeFormFieldEncryptComInfo();
	private Map<String, String> modeVFormMap = new HashMap<String, String>();
	private Map<String, Object> modeLogMap;//记录主表id及对应的viewlogid
	private int realRows;
	private String timezone;
	private ModeDataIDUpdateSingle modeDataIDUpdateSingle = ModeDataIDUpdateSingle.INSTANCE;
	//明细日志信息处理
	private String columnNames_d;
	private Map<String, String> columnFieldids_d = new HashMap<String, String>();

	private List<List<String>> impFieldIds;//记录excel中字段顺序
	private Object fieldTransObject;
	private List<String> fieldtranslist;
	private jxl.Sheet sheetJXL;
	private static final int pageSize = 1000;//1000条查询一次

	public ImpExcelReader() {
		super();
	}

	@SuppressWarnings("unchecked")
	public ImpExcelReader(String action, CountDownLatch doneSignal, int start, int end, int currentIndex,
						  String key, Sheet sheet, Map<String, Object> params, User user, int formid
			, int modeid, Map validateMap, Map IdMap, Map<String, String> checkMap, ArrayList errorRow
			, String clientaddress, String threadname
						  //子表需要的参数
			, FieldInfo FieldInfo,
						  HashMap map, String maintable, String Errmsg, int sheetIndex
			, List billList, HashMap creatoridMap, List<String> addBillIdList, List detailList, List<String> operatelList, List<Integer> errorRowList, Hashtable<String, Vector<Integer>> errorDetailMap, int realRows, List rowNumList, Map<String, Object> modeLogMap, ArrayList errorTable
			, String timezone, boolean isdetailright, List<List<String>> impFieldIds
	) {
		this.action = action;
		this.doneSignal = doneSignal;
		this.start = start;
		this.end = end;
		this.currentIndex = currentIndex;
		this.key = key;
		this.sheet = sheet;
		this.params = params;
		this.user = user;
		this.formid = formid;
		this.modeid = modeid;
		this.validateMap = validateMap;
		this.IdMap = IdMap;
		this.checkMap = checkMap;
		this.clientaddress = clientaddress;
		this.threadname = threadname;
		this.errorTable = errorTable;
		this.FieldInfo = FieldInfo;
		this.map = map;
		this.errorRow = errorRow;
		this.maintable = maintable;
		this.Errmsg = Errmsg;
		this.sheetIndex = sheetIndex;
		this.billList = billList;
		this.creatoridMap = creatoridMap;
		this.addBillIdList = addBillIdList;
		this.detailList = detailList;
		this.updateList = operatelList;
		this.errorRowList = errorRowList;
		this.errorDetailMap = errorDetailMap;
		this.realRows = realRows;
		this.rowNumList = rowNumList;
		this.modeLogMap = modeLogMap;
		this.isdetailright = isdetailright;
		this.timezone = timezone;
		this.impFieldIds = impFieldIds;
		this.fieldTransObject = this.params.get("fieldTransObject");
		if (fieldTransObject != null) {
			fieldtranslist = (List<String>) this.params.get("fieldtranslist");
			sheetJXL = (jxl.Sheet) this.params.get("sheetJXL");
		}
	}

	public void run() {
		this.initDepartAndSubpany();
		if (this.action.equals("importMainData")) {
			importMainData();
		} else if (this.action.equals("importDetailData")) {
			importDetailData();
		}
	}

	private void importDetailData() {
		ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
		try {
			InterfacesUtil InterfacesUtil = new InterfacesUtil();
			RecordSet recordSet = new RecordSet();
			RecordSet rs = new RecordSet();
			String sql = "";
			ArrayList detailTableFields = FieldInfo.getDetailTableFields();
			if (detailTableFields.size() == 0) {
				FieldInfo tempFieldInfo = new FieldInfo();
				tempFieldInfo.setUser(user);
				int isHaveTemplate = 0;
				String templateSql = "select 1 from mode_import_template a where modeid=" + modeid + " and formid=" + formid + " and (exists(select 1 from workflow_billfield b where b.billid=" + formid + " and b.id=a.fieldid) or  a.fieldid in(-1000,-1001,-1002)) ";
				rs.execute(templateSql);
				if (rs.getCounts() > 0) {
					isHaveTemplate = 1;
				}
				if (isHaveTemplate == 1) {
					tempFieldInfo.GetDetailTableFieldToExcelTemplate(formid, 1, user.getLanguage(), modeid);//根据模块导入模板获得明细字段
				} else {
					tempFieldInfo.GetDetailTableFieldToExcel(formid, 1, user.getLanguage());//获得明细字段
				}
				this.FieldInfo = tempFieldInfo;
				detailTableFields = FieldInfo.getDetailTableFields();
			}
			ArrayList detailTableFieldIds = FieldInfo.getDetailTableFieldIds();
			ArrayList detailtablefieldnames = FieldInfo.getDetailDBFieldNames();
			ArrayList detailtablefielddbtypes = FieldInfo.getDetailFieldDBTypes();
			ArrayList detailtablenames = FieldInfo.getDetailTableNames();
			ArrayList detailtablekeys = FieldInfo.getDetailTableKeys();
			ArrayList detailtableqfws = FieldInfo.getDetailQfwses();
			ArrayList detailtablelabelname = FieldInfo.getDetailTableFieldNames();
			ImpExcelUtil impExcelUtil = new ImpExcelUtil();
			impExcelUtil.setModeVFormMap(modeVFormMap);
			String detailtable = "";
			String detailtablekey = "";
			int sheetcount = this.sheetIndex;
			ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
			int subIndex = currentIndex - 1;
			detailtable = Util.null2String((String) detailtablenames.get(subIndex));
			detailtablekey = Util.null2String((String) detailtablekeys.get(subIndex));
			if (detailtablekey.equals("")) {
				detailtablekey = "mainid";
			}
			map.put(detailtable, detailtablekey);

			ArrayList dtlfieldIdsTemp = (ArrayList) detailTableFieldIds.get(subIndex);
			ArrayList dtlfieldsTemp = (ArrayList) detailTableFields.get(subIndex);
			ArrayList dtlfieldnamesTemp = (ArrayList) detailtablefieldnames.get(subIndex);
			ArrayList dtlfielddbtypesTemp = (ArrayList) detailtablefielddbtypes.get(subIndex);
			ArrayList dtlqwfsTemp = (ArrayList) detailtableqfws.get(subIndex);
			ArrayList dtfieldlabelnameTemp = (ArrayList) detailtablelabelname.get(subIndex);

			//excel中的明细表信息
			ArrayList dtlfields = new ArrayList();
			ArrayList dtlFieldIds = new ArrayList();
			ArrayList dtlfieldnames = new ArrayList();
			ArrayList dtlfielddbtypes = new ArrayList();
			ArrayList dtlqwfs = new ArrayList();
			ArrayList dtfieldlabelname = new ArrayList();

			List<String> detailFieldIds = impFieldIds.get(subIndex + 1);//excel中的明细表字段id
			int mainIdCol = detailFieldIds.indexOf("-2001");
			for (int i = 0, len = detailFieldIds.size(); i < len; i++) {
				int fieldId = Util.getIntValue(detailFieldIds.get(i));
				if (fieldId <= 0) {
					continue;
				}
				int index = dtlfieldIdsTemp.indexOf(detailFieldIds.get(i));
				dtlfields.add(dtlfieldsTemp.get(index));
				dtlfieldnames.add(dtlfieldnamesTemp.get(index));
				dtlfielddbtypes.add(dtlfielddbtypesTemp.get(index));
				dtlqwfs.add(dtlqwfsTemp.get(index));
				dtfieldlabelname.add(dtfieldlabelnameTemp.get(index));
				dtlFieldIds.add(fieldId);
			}
			if (dtlfields.size() > 0) {
				FormInfoService formInfoService = new FormInfoService();
				List<Map<String, Object>> needlogFieldList = formInfoService.getNeedlogField_detail(formid, detailtable);
				if (needlogFieldList.size() > 0) {
					for (int i = 0; i < needlogFieldList.size(); i++) {
						Map<String, Object> needlogField = needlogFieldList.get(i);
						String fieldname = Util.null2String(needlogField.get("fieldname"));
						String fieldid = Util.null2String(needlogField.get("id"));
						if (this.columnNames_d == null || this.columnNames_d.equals("")) {
							this.columnNames_d = fieldname;
						} else {
							this.columnNames_d += "," + fieldname;
						}
						this.columnFieldids_d.put(fieldname, fieldid);
					}
				}

				boolean canImport = ImpExcelServer.getProgressCanImport(key);
				int rows = start;
				if (rows == 0) {
					rows = 1;
				}
				if (end >= realRows + 1) {
					end = realRows;
				}

				NumberFormat nf = NumberFormat.getInstance();
				nf.setGroupingUsed(false);
				nf.setMaximumFractionDigits(100);
				List<String> indexList = new ArrayList<String>();
				while (canImport = ImpExcelServer.getProgressCanImport(key) && rows <= end && rows >= start) {
					if (StringCacheMap.containsKey(key + "_cancel")) {
						break;
					}
					rowNumList.add(1);
					if (rowNumList.size() % 20 == 0) {
						ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
					}
					ImpExcelServer.writeProgressMsg(key, MessageFormat.format(SystemEnv.getHtmlLabelName(132242, user.getLanguage()), sheetIndex) + ":" + rowNumList.size() + "/" + (POIUtil.getLastRowNum(sheet) - 1), "0");

					String detailid = Util.null2String(POIUtil.getValue(sheet, rows, mainIdCol)).trim();
					String mainids = Util.null2String(IdMap.get(detailid));
					String[] mainidarr = mainids.split(",");
					for (String _mainid : mainidarr) {
						String sql1 = "";
						String sql2 = "";
						boolean flag = false;
						boolean isnull = true;
						boolean iserrordata = false;
						int mainid = Util.getIntValue(_mainid, 0);
						String Countsql = Util.null2String(IdMap.get(detailid + "sql"));

						Map<String, Map<String, Object>> oldData_detail = new HashMap<String, Map<String, Object>>();
						if (needlogFieldList.size() > 0) {
							oldData_detail = formInfoService.getTableData(detailtable, mainid, this.columnNames_d, "id", "mainid");
						}
						boolean rowCanImport = true;//当前行进行验证，如，设置了导入字段必填，如果值为空则不允许导入当前行
						indexList.clear();
						// 生成插入sql
						for (int k = 0; k < dtlFieldIds.size(); k++) {
							boolean isDepSup = false;    //全路径导入的>处理
							String f = StringHelper.null2String(dtlfields.get(k));
							String[] arr = f.split("_");
							String dhtmltype = "";
							if (arr.length == 4) {
								dhtmltype = arr[3];
								//if(dhtmltype.equals("6")){
								//	continue;
								//}
							}
							String detailFieldId = Util.null2String(dtlFieldIds.get(k));
							int col = detailFieldIds.indexOf(detailFieldId);
							ArrayList tempfields = Util.TokenizerString((String) dtlfields.get(k), "_");
							int type = Util.getIntValue((String) tempfields.get(2));
							int htmltype = Util.getIntValue((String) tempfields.get(3));
							//							Cell cell = sheet.getCell(col, rows);
							String tempvalue = "";
							if ((type == 5 || type == 4 || type == 3) && htmltype == 1) {//浮点数的话避免被四舍五入
								tempvalue = POIUtil.getValue(sheet, rows, col);
							} else {
								tempvalue = Util.null2String(POIUtil.getValue(sheet, rows, col));
								if (type == 1 && htmltype == 1) {//文本
									tempvalue = tempvalue.replaceAll("\\n", "");
									if ("1".equals(modeFormFieldEncryptComInfo.getIsencrypt(detailFieldId))) {
										tempvalue = CubeCipherUitl.encrypt(tempvalue);
									}
									//					        		if(cell.getType() == CellType.NUMBER) {
									//					        			int dindex = tempvalue.indexOf(".");
									//										if(dindex!=-1){//不包含小数点，直接导入
									//											double tempDoubleVal=((NumberCell)cell).getValue();
									//					        	      		tempvalue=nf.format(tempDoubleVal);//避免转换为值的时候变为科学计数法
									//										}
									//					        	     }
								}
								if (htmltype == 3 && (type == 161 || type == 162)) {
									tempvalue = CubeCipherUitl.getBrowserEncryptValueImp(Util.null2String(dtlfielddbtypes.get(k)), tempvalue, type + "");
								}
							}

							tempvalue = StringHelper.convertSpecialChar2Html(tempvalue);
							String tempvalueForIdentify = tempvalue;
							String detailfieldid = Util.null2String((String) tempfields.get(0)).replaceAll("field", "");

							//根据条件来判断是否必填
							String tempCondition = "";
							String tempHead = "";
							String tempFieldName = "";
							boolean validateflag = false;
							for (Map.Entry<String, List<String>> et : validateMap.entrySet()) {
								String key = et.getKey();
								if (detailfieldid.equals(key)) {
									List<String> value = et.getValue();
									if (value.size() == 0) {
										tempHead = Util.null2String(POIUtil.getValue(sheet, 0, col));
										validateflag = true;
										break;
									}
									for (String selectid : value) {
										String[] values = selectid.split(":");
										int temp_index = -1;
										for (int n = 0; n < dtlfields.size(); n++) {
											String tempField = (String) dtlfields.get(n);
											if (tempField.indexOf("field" + values[0]) > -1) {
												temp_index = n;
												break;
											}
										}
										if (Util.null2String(POIUtil.getValue(sheet, rows, temp_index + 1)).equals(values[1])) {
											tempCondition = Util.null2String(POIUtil.getValue(sheet, rows, temp_index + 1));
											tempHead = Util.null2String(POIUtil.getValue(sheet, 0, col));
											tempFieldName = Util.null2String(POIUtil.getValue(sheet, 0, temp_index + 1));
											validateflag = true;
											break;
										}
									}
								}
								if (validateflag) {
									break;
								}
							}


							if (tempvalue.equals("") && validateflag) {
								if (!tempCondition.equals("")) {
									tempCondition = MessageFormat.format(SystemEnv.getHtmlLabelName(132243, user.getLanguage()), tempFieldName, tempCondition, tempHead);
								} else {
									tempCondition = MessageFormat.format(SystemEnv.getHtmlLabelName(132244, user.getLanguage()), tempHead);
								}
								errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + "" + tempCondition);
								if (mainid > 0) {
									errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + "" + tempCondition + "+" + dtfieldlabelname.get(k) +
											"+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable + "+"
											+ SystemEnv.getHtmlLabelName(19325, user.getLanguage()) + dtfieldlabelname.get(k) + tempCondition);
								}
								indexList.add((String) errorRow.get(errorRow.size() - 1)); //获得当前错误提示的idnex
								rowCanImport = false;
							}
							// excel值转换
							if (!tempvalue.equals("")) {
								isnull = false;
								String fieldid = Util.null2String(dtlFieldIds.get(k));
								if (fieldTransObject != null && fieldtranslist.contains(fieldid)) {//调用自定义转换接口
									this.params.put("fieldid", fieldid);
									this.params.put("fieldname", "d" + currentIndex + "_" + dtlfieldnames.get(k));
									if (fieldTransObject instanceof ImportFieldTransAction) {
										ImportFieldTransAction fieldTrans = (ImportFieldTransAction) fieldTransObject;
										tempvalue = fieldTrans.getTransValue(this.params, user, sheetJXL, rows, col);
									} else if (fieldTransObject instanceof ImportFieldTransActionPOI) {
										ImportFieldTransActionPOI fieldTrans = (ImportFieldTransActionPOI) fieldTransObject;
										ExcelParseForPOI excelParse = (ExcelParseForPOI) this.params.get("excelParse");
										tempvalue = fieldTrans.getTransValue(this.params, user, excelParse, (rows + 1), (col + 1));
									}
								} else {
									tempvalue = tempvalue.replace("'", "''");
									if (type == 2 && htmltype == 1) {//整数
										Pattern pattern = Pattern.compile("^(-)?\\d+$");
										Matcher isFlag = pattern.matcher(tempvalue);
										if (!isFlag.matches()) {
											errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(382376, user.getLanguage()));
											if (mainid > 0) {
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) +
														"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
														"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) + "," + SystemEnv.getHtmlLabelName(391252, user.getLanguage()) + "!");
											}
											iserrordata = true;
											tempvalue = "";
										}
									} else if ((type == 3 || type == 4 || type == 5) && htmltype == 1) {//浮点数
										String excelVal = tempvalue;
										tempvalue = tempvalue.replace(",", "");
										Pattern pattern = Pattern.compile("^(-)?(0|([1-9]\\d*))(.\\d+)?$"); //浮点数
										Matcher isFlag = pattern.matcher(tempvalue);
										if (!isFlag.matches()) {
											String errMsg = "";
											if (type == 3) {
												errMsg = SystemEnv.getHtmlLabelName(382377, user.getLanguage());
											} else if (type == 4) {
												errMsg = SystemEnv.getHtmlLabelName(382378, user.getLanguage());
											} else if (type == 5) {
												errMsg = SystemEnv.getHtmlLabelName(382379, user.getLanguage());
											}
											errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + ",“" + excelVal + "”," + errMsg);
											if (mainid > 0) {
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+“" + excelVal + "”+" + errMsg +
														"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
														"+" + detailtable + "+<a style='color:red'>" + excelVal + "</a>:" + errMsg);
											}
											iserrordata = true;
											tempvalue = "";
										}
									} else if (htmltype == 3) {
										//判断是否ID串
										boolean isNumber = false;
										String[] number = tempvalue.split(",");
										if (number != null && number.length > 0) {
											for (String num : number) {
												Pattern pattern = Pattern.compile("^(-)?[1-9][0-9]*$"); //验证正数或负数
												Matcher isNum = pattern.matcher(num.trim());
												if (!isNum.matches()) {//非数字 进行ID获取
													isNumber = false;
													break;
												} else {
													isNumber = true;
												}
											}
										}


										//虚拟表单修改主键后  主键不一定是数字类型  不能用数字类型作为判断   只能检查主键数据中是否存在改数据   zwbo
										if (!isNumber) {
											if (type == 161 || type == 162) { //自定义单选和多选
												//浏览框为虚拟表单  并且修改主键
												Browser browser = ModeCacheManager.getInstance().getBrowserSetMap((String) dtlfielddbtypes.get(k));
												String browser_id = browser.getCustomid();
												if (!StringHelper.isEmpty(browser_id)) {
													boolean isVFrom = false;
													if (customBrowserMap.containsKey(browser_id)) {
														isVFrom = customBrowserMap.get(browser_id);
													} else {
														RecordSet virrs = new RecordSet();
														virrs.execute("select a.formid,b.vprimarykey from mode_custombrowser a,modeformextend b where a.id =" + browser_id + "  AND a.formid=b.formid ");
														if (virrs.next()) {
															isVFrom = true;
														}
														customBrowserMap.put(browser_id, isVFrom);
													}
													if (isVFrom && number.length > 0) {
														BrowserBean browserBean = browser.searchById(number[0].trim());
														if (browserBean.getId() == null) {
															isNumber = false;
														} else {
															isNumber = true;
														}
													}
												}
											}
										}
										//------------------------提取start------------------------------
										if (type == 2 || type == 19 || type == 403) { // 日期
											Cell cell = POIUtil.getCell(sheet, rows, col);
											tempvalue = ImpExcelUtil.getDateOrTime(cell, tempvalue, type);

											if (tempvalue.startsWith("#@ERROR@#")) {
												tempvalue = tempvalue.replace("#@ERROR@#", "");
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
												if (mainid > 0) {
													errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) +
															"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
															"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
												}
												iserrordata = true;
												tempvalue = "";
											}
										} else if (type == 290) {//日期时间
											Cell cell = POIUtil.getCell(sheet, rows, col);
											tempvalue = ImpExcelUtil.getDateTime(cell, tempvalue, type);
											TimeZoneVar.setTimeZone(timezone);
											tempvalue = "".equals(Util.null2String(tempvalue)) ? "" : new DateTransformer().getServerDateTime(tempvalue);
											if (tempvalue != null && tempvalue.indexOf(":") != tempvalue.lastIndexOf(":")) {
												tempvalue = tempvalue.substring(0, tempvalue.lastIndexOf(":"));
											}
											if (tempvalue.startsWith("#@ERROR@#")) {
												tempvalue = tempvalue.replace("#@ERROR@#", "");
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
												if (mainid > 0) {
													errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) +
															"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
															"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
												}
												iserrordata = true;
												tempvalue = "";
											}
										} else if (type == 402) {//年、年是int型，判断值是否是整数
											Pattern pattern = Pattern.compile("^(-)?\\d+$");
											Matcher isFlag = pattern.matcher(tempvalue);
											if (!isFlag.matches()) {
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(382376, user.getLanguage()));
												if (mainid > 0) {
													errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) +
															"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
															"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) + "," + SystemEnv.getHtmlLabelName(391252, user.getLanguage()) + "!");
												}
												iserrordata = true;
												tempvalue = "";
											}
										} else if ((type == 4 || type == 57 || type == 168 || type == 167) && (tempvalue.indexOf(">") > -1 || tempvalue.indexOf(this.sepCharacter) > -1 && this.isDepartAndSubpany)) {//如果部门里面有> 代表逐级导入
											ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
											String temps = "";
											for (int n = 0; n < tempvalues.size(); n++) {
												String temp = Util.null2String(tempvalues.get(n));
												Map<String, String> tempvalueMap = getIdByPathName(1, temp);
												if (Util.null2String(tempvalueMap.get("flag")).equals("0")) {
													temp = tempvalueMap.get("value");
												} else {
													boolean isflag = isDepartAndSubpany;
													if (!isflag) {
														errorRow.add(sheetcount + "," + rows + "," + col + "," + ((String) tempvalueMap.get("orgname")).trim());
														if (mainid > 0) {
															errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalueMap.get("orgname")).trim() +
																	"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																	"+" + detailtable + "+<a style='color:red'>" + temp + "</a>:" + SystemEnv.getHtmlLabelName(391288, user.getLanguage()) + "select id from hrmdepartment where departmentname='" + temp + "'");
														}
													} else {
														isDepSup = true;
													}
												}
												temps += "," + temp;
											}
											if (temps.length() > 0) {
												temps = temps.substring(1);
											}
											if (!isDepSup) {
												tempvalue = temps;
											}
										} else if ((type == 164 || type == 169 || type == 170 || type == 194) && (tempvalue.indexOf(">") > -1 || tempvalue.indexOf(this.sepCharacter) > -1 && this.isDepartAndSubpany)) {//如果分部里面有> 代表逐级导入
											ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
											String temps = "";
											for (int n = 0; n < tempvalues.size(); n++) {
												String temp = Util.null2String(tempvalues.get(n));
												Map<String, String> tempvalueMap = getIdByPathName(0, temp);
												if (Util.null2String(tempvalueMap.get("flag")).equals("0")) {
													temp = tempvalueMap.get("value");
												} else {
													boolean isflag = isDepartAndSubpany;
													if (!isflag) {
														errorRow.add(sheetcount + "," + rows + "," + col + "," + ((String) tempvalueMap.get("orgname")).trim());
														if (mainid > 0) {
															errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalueMap.get("orgname")).trim() +
																	"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																	"+" + detailtable + "+<a style='color:red'>" + temp + "</a>:" + SystemEnv.getHtmlLabelName(391267, user.getLanguage()) + ":select id from HrmSubCompany where  subcompanyname='" + temp + "'");
														}
													} else {
														isDepSup = true;
													}
												}
												temps += "," + temp;
											}
											if (temps.length() > 0) {
												temps = temps.substring(1);
											}
											if (!isDepSup) {
												tempvalue = temps;
											}
										} else if ((type == 1 || type == 17 || type == 165 || type == 166) && tempvalue.indexOf(">") > -1) {//如果人员里面有> 代表逐级导入
											ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
											String temps = "";
											for (int n = 0; n < tempvalues.size(); n++) {
												String temp = Util.null2String(tempvalues.get(n));
												Map<String, String> tempvalueMap = getIdByPathName(2, temp);
												if (Util.null2String(tempvalueMap.get("flag")).equals("0")) {
													temp = tempvalueMap.get("value");
												} else {
													errorRow.add(sheetcount + "," + rows + "," + col + "," + ((String) tempvalueMap.get("orgname")).trim());
													if (mainid > 0) {
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalueMap.get("orgname")).trim() +
																"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																"+<a style='color:red'>" + temp + "</a>:" + SystemEnv.getHtmlLabelName(391270, user.getLanguage()) + "select id from hrmresource where lastname='" + temp + "' and departmentid=0");
													}
												}
												temps += "," + temp;
											}
											if (temps.length() > 0) {
												temps = temps.substring(1);
											}
											tempvalue = temps;
										} else if (type == 224 || type == 225 || type == 226 || type == 227) {
											tempvalue = tempvalue;
										} else if ((type == 4 || type == 57) || (type == 164 || type == 194)) { //虚拟部门
											String flagStr = "";
											String keyname = "";
											String tablename = "";
											String keynameall = "";//支持全称导入
											if ((type == 4 || type == 57)) {
												if (tempvalue.toLowerCase().startsWith("virtual_")) {
													flagStr = "virtual_";
													if (tempvalue.startsWith("VIRTUAL_")) {
														flagStr = "VIRTUAL_";
													}
													keyname = "departmentmark";
													keynameall = "departmentname";
													tablename = "HrmDepartmentVirtual";
												} else if (tempvalue.startsWith("-")) {
													keyname = "id";
													tablename = "HrmDepartmentVirtual";
												} else if (tempvalue.startsWith("deptcode_")) {
													tablename = "HrmDepartment";
													keyname = "departmentcode";
													if (tempvalue.indexOf("deptcode_") != -1) {
														tempvalue = tempvalue.replace("deptcode_", "");
													} else {
														tempvalue = tempvalue.substring(9);
													}
												} else {
													keyname = "departmentmark";
													tablename = "HrmDepartment";
													if (isNumber) {
														keyname = "id";
													} else {
														keynameall = "departmentname";
													}
												}
											} else if ((type == 164 || type == 194)) {
												if (tempvalue.toLowerCase().startsWith("virtual_")) {
													flagStr = "virtual_";
													if (tempvalue.startsWith("VIRTUAL_")) {
														flagStr = "VIRTUAL_";
													}
													//分部要优先简称导入
													keyname = "subcompanydesc";
													keynameall = "subcompanyname";
													tablename = "hrmsubcompanyvirtual";
												} else if (tempvalue.startsWith("-")) {
													keyname = "id";
													tablename = "hrmsubcompanyvirtual";
												} else {
													keyname = "subcompanydesc";
													tablename = "hrmsubcompany";
													if (isNumber) {
														keyname = "id";
													} else {
														keynameall = "subcompanyname";
													}
												}
											}
											//部门及分部封存，人员离职过滤
											String hrmFilterCondiction = "";
											if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompany".equalsIgnoreCase(tablename.toLowerCase())
													|| "HrmDepartmentVirtual".equalsIgnoreCase(tablename.toLowerCase()) ||
													"hrmsubcompanyvirtual".equalsIgnoreCase(tablename.toLowerCase())) {
												hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='' )";
											}

											ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");

											ArrayList tempvalueForIdentifys = Util.TokenizerString(tempvalueForIdentify, ",");
											tempvalue = "";
											String values = "";
											for (int n = 0; n < tempvalues.size(); n++) {
												if (!((String) tempvalues.get(n)).trim().toLowerCase().startsWith(flagStr))
													continue;
												values += ",'" + ((String) tempvalues.get(n)).trim().replace(flagStr, "") + "'";
											}
											if (!StringHelper.isEmpty(values)) {
												values = values.substring(1);
												for (int n = 0; n < tempvalues.size(); n++) {
													rs = new RecordSet();
													String value = ((String) tempvalues.get(n)).trim().replace(flagStr, "");
													value = checkDepartAndSubpany(value);
													//添加判断value 是不是id 或者编号

													String valueForIdentify = ((String) tempvalueForIdentifys.get(n)).trim().replace(flagStr, "");
													if (isNumberOrCode(valueForIdentify)) {
														hrmFilterCondiction = "";
													}
													if (!"".equals(keynameall)) {
														sql = "select id," + keynameall + " as showname from " + tablename + "  where " + keynameall + " ='" + value + "'  " + hrmFilterCondiction + " order by id desc";
														rs.executeSql(sql);
													}
													if (rs.getCounts() <= 0) {
														sql = "select id," + keyname + " as showname from " + tablename + "  where " + keyname + " ='" + value + "'  " + hrmFilterCondiction + " order by id desc";
														rs.executeSql(sql);
													}
													if (!rs.next()) {//判断是否为多语言
														if (!"".equals(keynameall)) {
															String tempSqlTemp = "select id," + keynameall + " as showname from " + tablename +
																	" where (" + keynameall + " like '%" + "`~`7 " + value + "`~`" + "%' or " + keynameall + " like '%" + "`~`8 " + value + "`~`" + "%' or " + keynameall + " like '%" + "`~`9 " + value + "`~`" + "%')"
																	+ hrmFilterCondiction + " order by id desc";
															rs.execute(tempSqlTemp);
														}
														if (rs.getCounts() <= 0) {
															String tempSqlTemp = "select id," + keyname + " as showname from " + tablename +
																	" where (" + keyname + " like '%" + "`~`7 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`8 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`9 " + value + "`~`" + "%')"
																	+ hrmFilterCondiction + " order by id desc";
															rs.execute(tempSqlTemp);
														}
													}
													rs.beforFirst();
													boolean isExists = false;
													while (rs.next()) {
														String showname = rs.getString("showname");
														showname = Util.formatMultiLang(showname, user.getLanguage() + "");
														String tempValue = (String) tempvalues.get(n);
														tempValue = checkDepartAndSubpany(tempValue.trim());
														String shownameNew = (flagStr + showname).replace("'", "''");
														if (shownameNew.equals(tempValue)) {
															tempvalue += "," + rs.getString(1);
															isExists = true;
															break;
														}
													}
													if (!isExists) {
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + ((String) tempvalues.get(n)).trim());
														if (mainid > 0) {
															errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalues.get(n)).trim() +
																	"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																	"+" + detailtable + "+<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391271, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
														}
														iserrordata = true;
													}
												}
												if (tempvalue.startsWith(",")) {
													tempvalue = tempvalue.substring(1);
												}
											}
										} else if (type == 161 || type == 162) {
											if (!isNumber) {//不是数字
												if (type == 161) { // 自定义单选
													Browser browser = ModeCacheManager.getInstance().getBrowserSetMap((String) dtlfielddbtypes.get(k));
													Map<String, String> browserMap = ModeCacheManager.getInstance().getIdByNames((String) dtlfielddbtypes.get(k), tempvalue, user.getLanguage());
													if (browserMap.containsKey("ids")) {
														tempvalue = browserMap.get("ids");
													} else {
														//解决浏览框名称为整数，判断有误情况
														String realTempvalue = analyzeNameValue(tempvalue);
														Map resultmap = analyzeIdValue(realTempvalue);
														BrowserBean BrowserBean = null;
														if (!("").equals(resultmap.get("id"))) {
															BrowserBean = browser.searchById(resultmap.get("id").toString().replace("''", "'"));
														} else {
															BrowserBean = browser.searchForImport(resultmap.get("name").toString().replace("''", "'"), user);
														}
														if (null == BrowserBean) {
															BrowserBean = browser.searchById(realTempvalue.replace("''", "'"));
														}
														if (BrowserBean != null) {
															String val = BrowserBean.getId();
															String browserSql = browser.getSearchByName();
															if (val == null) {
																tempvalue = CubeCipherUitl.decrypt(tempvalue);
																errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue.replace(",", "，"));
																if (mainid > 0) {
																	errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue.replace(",", "，") +
																			"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																			"+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()) + "<a style='color:red'>" + tempvalue.replace(",", "，") + "</a>" + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
																}
																iserrordata = true;
																tempvalue = "";
															} else {
																tempvalue = val;
															}
														} else {
															if (mainid > 0) {
																tempvalue = CubeCipherUitl.decrypt(tempvalue);
																errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue.replace(",", "，"));
																errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue.replace(",", "，") +
																		"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																		"+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()));
																iserrordata = true;
																//															writeErrorRow();
															}
															tempvalue = "";
														}
													}
												} else if (type == 162) { // 自定义多选
													Browser browser = ModeCacheManager.getInstance().getBrowserSetMap((String) dtlfielddbtypes.get(k));
													Map<String, String> browserMap = ModeCacheManager.getInstance().getIdByNames((String) dtlfielddbtypes.get(k), tempvalue, user.getLanguage());
													if (browserMap.containsKey("ids")) {
														tempvalue = browserMap.get("ids");
													} else {
														//解决浏览框名称为整数，判断有误情况
														String realTempvalue = analyzeNameValue(tempvalue);
														Map resultmap = analyzeIdValue(realTempvalue);
														BrowserBean BrowserBean = null;
														if (!("").equals(resultmap.get("id"))) {
															BrowserBean = browser.searchById2(resultmap.get("id").toString().replace("''", "'"));
														} else {
															BrowserBean = browser.searchForImport2(resultmap.get("name").toString().replace("''", "'"), user);
														}
														if (null == BrowserBean) {
															BrowserBean = browser.searchById(realTempvalue.replace("''", "'"));
														}
														if (BrowserBean != null) {
															String tempvaluenew = BrowserBean.getId();
															if (tempvaluenew.indexOf("null") > -1) {
																BrowserBean = browser.searchById2(tempvalue);
															}
														}
														if (BrowserBean != null) {
															String name = BrowserBean.getName();
															String browserSql = browser.getSearchByName();
															if (browserSql == null || browserSql.equals("")) {
																browserSql = SystemEnv.getHtmlLabelName(500319, user.getLanguage());
															}
															if (name.startsWith("#@ERROR@#")) {
																String old_val = name.replace("#@ERROR@#", "");
																old_val = CubeCipherUitl.decrypt(old_val);
																errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + old_val);
																if (mainid > 0) {
																	errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + old_val + "+" + dtfieldlabelname.get(k) +
																			"+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																			"+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()) + "<a style='color:red'>" + old_val + "</a>" + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
																}
																iserrordata = true;
																tempvalue = "";
															} else {
																String old_val = tempvalue;
																tempvalue = BrowserBean.getId();
																if (tempvalue.indexOf("null") > -1) {
																	tempvalue = CubeCipherUitl.decrypt(tempvalue);
																	errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + old_val);
																	if (mainid > 0) {
																		errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + old_val + "+" + dtfieldlabelname.get(k) +
																				"+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																				"+" + SystemEnv.getHtmlLabelName(391274, user.getLanguage()) + "<a style='color:red'>" + tempvalue + "</a><br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
																	}
																	iserrordata = true;
																	tempvalue = "";
																}
															}
														} else {
															if (mainid > 0) {
																tempvalue = CubeCipherUitl.decrypt(tempvalue);
																errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
																errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
																		"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																		"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()));
																iserrordata = true;
																//															writeErrorRow();
															}
															tempvalue = "";
														}
													}
												}
											} else { //是数字
												Browser browser = ModeCacheManager.getInstance().getBrowserSetMap((String) dtlfielddbtypes.get(k));
												int r = ModeCacheManager.getInstance().isContainBrowserIds((String) dtlfielddbtypes.get(k), tempvalue, user.getLanguage());
												if (r == -1) {//没有缓存
													if (number != null && number.length > 0) {
														for (String num : number) {
															BrowserBean browserBean = browser.searchById(num.trim());
															String browserSql = browser.getSearchByName();
															if (browserBean == null || browserBean.getId() == null) {
																errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
																if (mainid > 0) {
																	errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
																			"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																			"+" + detailtable + "+<a style='color:red'>" + tempvalue + "</a><br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
																}
																iserrordata = true;
																tempvalue = "";
																break;
															}
														}
													}
												} else if (r == 0) {//存在未找到
													String browserSql = ModeCacheManager.getInstance().getBrowserSql((String) dtlfielddbtypes.get(k), tempvalue, user.getLanguage());
													errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
													if (mainid > 0) {
														errorTable.add(sheetcount + "+" + (col + 1) + "+" + (col + 1) + "+" + tempvalue +
																"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																"+" + detailtable + "+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()) + "<a style='color:red'>" + tempvalue + "</a><br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
													}
													iserrordata = true;
													tempvalue = "";
													break;
												}


											}
										} else if (type == 256 || type == 257) {
											String tempIdStr = "";
											if (!tempvalue.isEmpty()) {
												String fielddbtype = (String) dtlfielddbtypes.get(k);
												CustomTreeComInfo comInfo = new CustomTreeComInfo();
												boolean showlevel = "1".equals(comInfo.get(CustomTreeComInfo.showlevel, fielddbtype));
												String levelsplitchar = comInfo.get(CustomTreeComInfo.levelsplitchar, fielddbtype);
												List<Map<String, String>> list = new ArrayList<Map<String, String>>();
												List<Map<String, String>> listBak = new ArrayList<Map<String, String>>();
												if (treeBaseMap.containsKey(fielddbtype)) {
													list = treeBaseMap.get(fielddbtype);
													listBak = treeBaseMap.get("showfield");
												} else {
													String treeSetSql = "select id,sourcefrom,sourceid,tablename,tablekey,showfield,supnode,datacondition,tablesup,supnodefield,nodefield from mode_customtreedetail where mainid=" + fielddbtype;
													recordSet.execute(treeSetSql);
													while (recordSet.next()) {
														Map<String, String> setMap = new HashMap<String, String>();
														Map<String, String> setMapBak = new HashMap<String, String>();
														String nodeid = recordSet.getString("id");//节点id
														String tablename = recordSet.getString("tablename");//表名
														String tablekey = recordSet.getString("tablekey");//主键字段
														String showfield = recordSet.getString("showfield");//显示名称字段
														String datacondition = recordSet.getString("datacondition").trim();//数据显示条件
														String sourcefrom = recordSet.getString("sourcefrom");
														String sourceid = recordSet.getString("sourceid");
														String supnode = recordSet.getString("supnode");
														String tablesup = recordSet.getString("tablesup");
														String supnodefield = recordSet.getString("supnodefield");
														String nodefield = recordSet.getString("nodefield");
														setMap.put("nodeid", nodeid);
														setMap.put("tablename", tablename);
														setMap.put("tablekey", tablekey);
														setMap.put("showfield", showfield);
														setMap.put("datacondition", datacondition);
														setMap.put("sourcefrom", sourcefrom);
														setMap.put("sourceid", sourceid);
														setMap.put("supnode", supnode);
														setMap.put("tablesup", tablesup);
														setMap.put("supnodefield", supnodefield);
														setMap.put("nodefield", nodefield);
														setMapBak.put("showfield", showfield);
														list.add(setMap);
														listBak.add(setMapBak);
													}
													treeBaseMap.put(fielddbtype, list);
													treeBaseMap.put("showfield", listBak);
												}

												String[] nameArray = null;
												if (type == 257) {
													if (tempvalue.indexOf("DH{") != -1) {//批量导入自定义多选时，如果选项中有英文逗号，批量导入时用DH{}包裹
														String[] tempNumber = tempvalue.split(",");//数组格式：{"xxxx","DH{XXXX","XXXX"?(也许有),"xxx}"},其中DH{}中间包裹的值是自定义多选的一个选项
														List<String> list1 = new ArrayList<String>();
														int m = 0;
														int j = 0;
														while (m < tempNumber.length) {
															if (tempNumber[m].indexOf("DH{") != -1) {
																list1.add(tempNumber[m].substring(3, tempNumber[m].length()) + ",");
																m++;
																boolean flag1 = false;
																while (!flag1) {//判断数组中是否含有
																	if (tempNumber[m].indexOf("}") != -1) {
																		list1.add(list1.get(j) + tempNumber[m].substring(0, tempNumber[m].length() - 1));
																		list1.remove(j);
																		m++;
																		j++;
																		flag1 = true;
																	} else {
																		list1.add(list1.get(j) + tempNumber[m] + ",");
																		list1.remove(j);
																		m++;
																	}
																}
															} else {
																list1.add(tempNumber[m]);
																m++;
																j++;
															}
														}
														nameArray = list1.toArray(new String[list1.size()]);
													} else {
														nameArray = tempvalue.split(",");
													}
												} else {//type=256
													nameArray = tempvalue.split("weaver_ecology");
												}

												for (int m = 0; m < nameArray.length; m++) {
													String tempName = nameArray[m];
													String tempid = "";
													String tempSql = "";
													if (!tempName.isEmpty()) {
														tempName = tempName.trim();
														//解决浏览框名称为整数，判断有误情况
														String realTempvalue = analyzeNameValue(tempName);
														if (realTempvalue.startsWith("tree_")) {
															String[] valuearr = realTempvalue.split("_");
															if (valuearr.length == 3) {
																for (int n = 0; n < list.size(); n++) {
																	Map<String, String> setMap = list.get(n);
																	if (setMap.get("nodeid").equals(valuearr[1])) {
																		setMap.put("showfield", "id");
																	} else {
																		continue;
																	}
																	Map<String, Object> value = impExcelUtil.getTreeValue("", "", setMap, valuearr[2]);
																	tempSql = Util.null2String(value.get("sql"));
																	if (value.size()>0 && listBak.get(0).size()>0){
																		setMap.put("showfield", listBak.get(0).get("showfield"));
																	}

																	if (!"".equals(Util.null2String(value.get("id")))) {
																		if (!tempIdStr.equals("")) {
																			tempIdStr += ",";
																		}
																		tempid = Util.null2String(value.get("id"));
																		tempIdStr += Util.null2String(value.get("id"));
																		break;
																	}
																}
															}
														} else if (showlevel && realTempvalue.indexOf(levelsplitchar) > 0) {
															Map<String, Object> value = impExcelUtil.importTreeDataAllLevel(list, levelsplitchar, realTempvalue);
															if (!tempIdStr.equals("")) {
																tempIdStr += ",";
															}
															tempid = Util.null2String(value.get("id"));
															tempIdStr += Util.null2String(value.get("id"));
															tempSql = Util.null2String(value.get("sql"));
														} else {
															for (int n = 0; n < list.size(); n++) {
																Map<String, String> setMap = list.get(n);
																Map<String, Object> value = impExcelUtil.getTreeValue("", "", setMap, realTempvalue);
																tempSql = Util.null2String(value.get("sql"));

																if (!"".equals(Util.null2String(value.get("id")))) {
																	if (!tempIdStr.equals("")) {
																		tempIdStr += ",";
																	}
																	tempid = Util.null2String(value.get("id"));
																	tempIdStr += Util.null2String(value.get("id"));
																	break;
																}
															}
														}
														if (tempid.equals("")) {
															errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempName);
															if (mainid > 0) {
																errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempName +
																		"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																		"+" + detailtable + "+" + tempName + SystemEnv.getHtmlLabelName(391276, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + tempSql);
															}
															iserrordata = true;
															tempIdStr = "";
														}
													}
												}

											}
											tempvalue = tempIdStr.replace("'", "''");
										} else {
											if (!isNumber) {
												rs.executeSql("select tablename,columname,keycolumname from workflow_browserurl where id=" + type);
												if (rs.next()) {
													ArrayList tempvalues = null;
													if (type == 1) {//如果是单人力不分割
														tempvalues = new ArrayList();
														tempvalues.add(tempvalue);
													} else {
														tempvalues = Util.TokenizerString(tempvalue, ",");
													}
													tempvalue = "";
													String keyname = Util.null2String(rs.getString("keycolumname"));
													String tablename = Util.null2String(rs.getString("tablename"));
													String columname = Util.null2String(rs.getString("columname"));
													String columnameCopy = columname;
													String[] realProjectName = CubeUtil.getRealProjectName(tablename, columname);
													tablename = realProjectName[0];
													columname = realProjectName[1];
													columnameCopy = columname;
													String columnameall = "";
													if (tablename.toLowerCase().equals("hrmdepartment") || tablename.toLowerCase().equals("hrmdepartmentallview")) {
														columname = "departmentmark";
														columnameall = "departmentname";
													} else if (tablename.toLowerCase().equals("hrmsubcompanyallview")) {
														columnameall = columname;//分部优先简称
														columname = "subcompanydesc";
													}
													//部门及分部封存，人员离职过滤
													String hrmFilterCondiction = "";
													if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompanyallview".equalsIgnoreCase(tablename.toLowerCase())) {
														hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='' )";
													} else if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
														hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
													} else if ("crm_customerinfo".equalsIgnoreCase(tablename)) {
														hrmFilterCondiction = " and deleted=0";
													}
													if ((!keyname.equals("") && !tablename.equals("") && !columname.equals("")) || isDepSup) {
														for (int n = 0; n < tempvalues.size(); n++) {
															columname = columnameCopy;
															rs = new RecordSet();
															if (SystemEnv.getHtmlLabelName(16139, user.getLanguage()).equals(Util.null2String(tempvalues.get(n)).trim())) {//系统管理员
																if (tempvalue.equals("")) {
																	tempvalue = "1";
																} else {
																	tempvalue += "," + "1";
																}
																continue;
															}
															String importValue = Util.null2String(tempvalues.get(n)).trim();
															String keyValue = importValue;
															if ("hrmresource".equalsIgnoreCase(tablename.toLowerCase()) && importValue.toLowerCase().startsWith("workcode_")) {
																keyValue = keyValue.substring(9);
																columname = "workcode";
															} else if ("hrmdepartment".equalsIgnoreCase(tablename.toLowerCase()) && importValue.toLowerCase().startsWith("deptcode_")) {
																keyValue = keyValue.substring(9);
																columname = "departmentcode";
															} else if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
																if (importValue.startsWith("LZRY_")) {
																	keyValue = keyValue.substring(5);
																	hrmFilterCondiction = "";//包含LZRY_ 就可以导入所有类型的人员
																} else {
																	hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
																}
															} else {
																//解决浏览框名称为整数，判断有误情况
																keyValue = analyzeNameValue(keyValue);
															}
															if (type == 164 || type == 169 || type == 170 || type == 194 || type == 167 || type == 168 || isDepSup) {
																keyValue = checkDepartAndSubpany(keyValue);
															}
															//添加判断value 是不是id 或者编号
															if (isNumberOrCode(importValue)) {
																hrmFilterCondiction = "";
															}
															if (!"".equals(keyValue)) {
																if (!"".equals(columnameall)) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where " + columnameall + " ='" + keyValue
																			+ "' " + hrmFilterCondiction + " order by " + keyname + " desc";
																	rs.executeSql(sql);
																}
																if (rs.getCounts() <= 0) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where " + columname + " ='" + keyValue
																			+ "' " + hrmFilterCondiction + " order by " + keyname + " desc";
																	rs.executeSql(sql);
																}
																if (rs.next()) {
																	if (tempvalue.equals("")) {
																		tempvalue = rs.getString(1);
																	} else {
																		tempvalue += "," + rs.getString(1);
																	}
																} else { //先判断下是否是多语言结构
																	if (!"".equals(columnameall)) {
																		sql = "select " + keyname + " from " + tablename
																				+ " where (" + columnameall + " like '%" + "`~`7 " + keyValue + "`~`" + "%' or " + columnameall + " like '%" + "`~`8 " + keyValue + "`~`" + "%' or " + columnameall + " like '%" + "`~`9 " + keyValue + "`~`" + "%')"
																				+ " order by " + keyname + " desc";
																		rs.executeSql(sql);
																	}
																	if (rs.getCounts() <= 0) {
																		sql = "select " + keyname + " from " + tablename
																				+ " where (" + columname + " like '%" + "`~`7 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`8 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`9 " + keyValue + "`~`" + "%')"
																				+ " order by " + keyname + " desc";
																		rs.executeSql(sql);
																	}
																	if (rs.next()) {
																		if (tempvalue.equals("")) {
																			tempvalue = rs.getString(1);
																		} else {
																			tempvalue += "," + rs.getString(1);
																		}
																	} else {
																		if (mainid > 0) {
																			sql = "select " + keyname + " from " + tablename
																					+ " where (" + columname + " like '%" + "`~`7 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`8 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`9 " + keyValue + "`~`" + "%' or " + columname + "='" + keyValue + "')"
																					+ " order by " + keyname + " desc";
																			errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + importValue);
																			errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + importValue +
																					"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																					"+" + detailtable + "+<a style='color:red'>" + importValue + "</a>:" + SystemEnv.getHtmlLabelName(391277, user.getLanguage()) + sql);
																			iserrordata = true;
																		}
																	}
																}
															} else {
																if (mainid > 0) {
																	errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + importValue);
																	errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + importValue +
																			"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																			"+<a style='color:red'>" + importValue + "</a>:" + SystemEnv.getHtmlLabelName(391278, user.getLanguage()) + keyValue + "," + SystemEnv.getHtmlLabelName(382055, user.getLanguage()));
																	iserrordata = true;
																}
															}
														}
													}
												} else {
													tempvalue = "";
												}
											} else {//浏览按钮ID导入验证
												rs.executeSql("select tablename,columname,keycolumname from workflow_browserurl where id=" + type);
												if (rs.next()) {
													ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
													tempvalue = "";
													String keyname = Util.null2String(rs.getString("keycolumname"));
													String tablename = Util.null2String(rs.getString("tablename"));
													String columname = Util.null2String(rs.getString("columname"));
													String[] realProjectName = CubeUtil.getRealProjectName(tablename, columname);
													tablename = realProjectName[0];
													columname = realProjectName[1];
													if (tablename.toLowerCase().equals("hrmdepartment")) {
														columname = "departmentname";
													}
													//部门及分部封存，人员离职过滤
													String hrmFilterCondiction = "";
													if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompanyallview".equalsIgnoreCase(tablename.toLowerCase())) {
														hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='')";
													} else if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
														hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
													} else if ("crm_customerinfo".equalsIgnoreCase(tablename)) {
														hrmFilterCondiction = " and deleted=0";
													}
													if (!keyname.equals("") && !tablename.equals("") && !columname.equals("")) {
														for (int n = 0; n < tempvalues.size(); n++) {
															String importValue = Util.null2String(tempvalues.get(n)).trim();
															if ("1".equals(Util.null2String(tempvalues.get(n)).trim())) {
																if (tempvalue.equals("")) {
																	tempvalue = "1";
																} else {
																	tempvalue += "," + "1";
																}
																continue;
															}
															//添加判断value 是不是id 或者编号
															if (isNumberOrCode(((String) tempvalues.get(n)).trim())) {
																hrmFilterCondiction = "";
															}
															if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
																if (importValue.startsWith("LZRY_")) {
																	importValue = importValue.substring(5);
																	hrmFilterCondiction = "";//包含LZRY_ 就可以导入所有类型的人员
																} else {
																	hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
																}
															}
															sql = "select " + keyname + " from " + tablename
																	+ " where " + keyname + " ='" + importValue
																	+ "' " + hrmFilterCondiction + " order by " + keyname + " desc";
															rs.executeSql(sql);
															if (rs.next()) {
																if (tempvalue.equals("")) {
																	tempvalue = rs.getString(1);
																} else {
																	tempvalue += "," + rs.getString(1);
																}
															} else {
																if (mainid > 0) {
																	errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + ((String) tempvalues.get(n)).trim());
																	errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalues.get(n)).trim() +
																			"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
																			"+<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391271, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
																	iserrordata = true;
																	//																	writeErrorRow();
																}
															}
														}
													}
												} else {
													tempvalue = "";
												}
											}
										}
										if (isDepSup) { //虚拟部门
											String flagStr = "";
											String keyname = "";
											String tablename = "";
											if ((type == 4 || type == 57)) {
												if (tempvalue.toLowerCase().startsWith("virtual_")) {
													flagStr = "virtual_";
													if (tempvalue.startsWith("VIRTUAL_")) {
														flagStr = "VIRTUAL_";
													}
													keyname = "departmentname";
													tablename = "HrmDepartmentVirtual";
												} else if (tempvalue.startsWith("-")) {
													keyname = "id";
													tablename = "HrmDepartmentVirtual";
												} else if (tempvalue.startsWith("deptcode_")) {
													tablename = "HrmDepartment";
													keyname = "departmentcode";
													if (tempvalue.indexOf("deptcode_") != -1) {
														tempvalue = tempvalue.replace("deptcode_", "");
													} else {
														tempvalue = tempvalue.substring(9);
													}
												} else {
													keyname = "departmentname";
													tablename = "HrmDepartment";
													if (isNumber) {
														keyname = "id";
													}
												}
											} else if ((type == 164 || type == 194)) {
												if (tempvalue.toLowerCase().startsWith("virtual_")) {
													flagStr = "virtual_";
													if (tempvalue.startsWith("VIRTUAL_")) {
														flagStr = "VIRTUAL_";
													}
													keyname = "subcompanyname";
													tablename = "hrmsubcompanyvirtual";
												} else if (tempvalue.startsWith("-")) {
													keyname = "id";
													tablename = "hrmsubcompanyvirtual";
												} else {
													keyname = "subcompanyname";
													tablename = "hrmsubcompany";
													if (isNumber) {
														keyname = "id";
													}
												}
											}
											//部门及分部封存，人员离职过滤
											String hrmFilterCondiction = "";
											if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompany".equalsIgnoreCase(tablename.toLowerCase())
													|| "HrmDepartmentVirtual".equalsIgnoreCase(tablename.toLowerCase()) ||
													"hrmsubcompanyvirtual".equalsIgnoreCase(tablename.toLowerCase())) {
												hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='' )";
											}

											ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
											tempvalue = "";
											String values = "";
											for (int n = 0; n < tempvalues.size(); n++) {
												if (!((String) tempvalues.get(n)).trim().toLowerCase().startsWith(flagStr))
													continue;
												values += ",'" + ((String) tempvalues.get(n)).trim().replace(flagStr, "") + "'";
											}
											if (!StringHelper.isEmpty(values)) {
												values = values.substring(1);
												for (int n = 0; n < tempvalues.size(); n++) {
													String value = ((String) tempvalues.get(n)).trim().replace(flagStr, "");
													value = checkDepartAndSubpany(value);
													//添加判断value 是不是id 或者编号
													if (isNumberOrCode(value)) {
														hrmFilterCondiction = "";
													}
													sql = "select id," + keyname + " as showname from " + tablename + "  where " + keyname + " ='" + value + "'  " + hrmFilterCondiction + " order by id desc";
													rs.executeSql(sql);
													if (!rs.next()) {//判断是否为多语言
														String tempSqlTemp = "select id," + keyname + " as showname from " + tablename +
																" where (" + keyname + " like '%" + "`~`7 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`8 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`9 " + value + "`~`" + "%')"
																+ hrmFilterCondiction + " order by id desc";
														rs.execute(tempSqlTemp);
													}
													rs.beforFirst();
													boolean isExists = false;
													while (rs.next()) {
														String showname = rs.getString("showname");
														showname = Util.formatMultiLang(showname, user.getLanguage() + "");
														String tempValue = (String) tempvalues.get(n);
														tempValue = checkDepartAndSubpany(tempValue.trim());
														String shownameNew = (flagStr + showname).replace("'", "''");
														if (shownameNew.equals(tempValue)) {
															tempvalue += "," + rs.getString(1);
															isExists = true;
															break;
														}
													}
													if (!isExists) {
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + ((String) tempvalues.get(n)).trim());
														if (mainid > 0) {
															errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalues.get(n)).trim() +
																	"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																	"+" + detailtable + "+<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391271, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
														}
														iserrordata = true;
													}
												}
												if (tempvalue.startsWith(",")) {
													tempvalue = tempvalue.substring(1);
												}
											}
										}
										//------------------------提取end------------------------------

									} else if (htmltype == 4) {
										if (tempvalue.equals("1") || tempvalue.toLowerCase().trim().equals(SystemEnv.getHtmlLabelName(163, user.getLanguage()).toLowerCase().trim())) {
											tempvalue = "1";
										} else if (tempvalue.equals("0") || tempvalue.toLowerCase().trim().equals(SystemEnv.getHtmlLabelName(161, user.getLanguage()).toLowerCase().trim())) {
											tempvalue = "0";
										} else {
											if (mainid > 0) {
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
														"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) + "+" + detailtable +
														"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391252, user.getLanguage()));
												iserrordata = true;
												//												writeErrorRow();
											}
											tempvalue = "";
										}
									} else if (htmltype == 5) {
										if (type == 2) {
											ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
											tempvalue = "";
											for (int i = 0; i < tempvalues.size(); i++) {
												sql = "select selectvalue from workflow_selectitem where (selectname='" + ((String) tempvalues.get(i)).trim() + "' or  selectname like '%`~`7 " + ((String) tempvalues.get(i)).trim() + "`~`%' or selectname like '%`~`8 " + ((String) tempvalues.get(i)).trim() + "`~`%' or selectname like '%`~`9 " + ((String) tempvalues.get(i)).trim() + "`~`%') and fieldid=" + ((String) tempfields.get(0)).substring(5) + " and (cancel is null  or cancel = 0)";
												rs.executeSql(sql);
												if (rs.next()) {
													if (tempvalue.equals("")) {
														tempvalue = rs.getString(1);
													} else {
														tempvalue += "," + rs.getString(1);
													}
												} else {
													if (mainid > 0) {
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalues.get(i));
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalues.get(i) +
																"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																"+" + detailtable + "+<a style='color:red'>" + tempvalues.get(i) + "</a>:" + SystemEnv.getHtmlLabelName(391279, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
														iserrordata = true;
													}
												}
											}
										} else {
											List<String> selectvalueList = ModeCacheManager.getInstance().getSelectValByName(((String) tempfields.get(0)).substring(5), tempvalue, user.getLanguage());
											if (selectvalueList.size() == 1) {
												tempvalue = selectvalueList.get(0);
											} else {
												sql = "select selectvalue from workflow_selectitem where (selectname='" + tempvalue + "' or selectname like '%`~`7 " + tempvalue + "`~`%' or selectname like '%`~`8 " + tempvalue + "`~`%' or selectname like '%`~`9 " + tempvalue + "`~`%') and fieldid=" + ((String) tempfields.get(0)).substring(5) + " and (cancel is null  or cancel = 0)";
												rs.executeSql(sql);
												if (rs.next()) {
													tempvalue = rs.getString(1);
												} else {
													if (mainid > 0) {
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
																"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
																"+" + detailtable + "+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391279, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
														iserrordata = true;
													}
													tempvalue = "";
												}
											}
										}
									} else if (htmltype == 6) {
										StringBuffer value = new StringBuffer();
										String[] tempvalues = tempvalue.split(",");
										for (String val : tempvalues) {
											Map<String, String> map = doImportForFileOrImg(val, type);
											if (map.containsKey("errorStr") && !StringHelper.isEmpty(map.get("errorStr"))) {
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + val);
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + val +
														"+" + dtfieldlabelname.get(k) + "+" + dtlfieldnames.get(k) + "+" + dtlfielddbtypes.get(k) +
														"+" + detailtable + "+<a style='color:red'>" + val + "</a>:" + map.get("errorStr") + "<br/>");
												iserrordata = true;
											} else if (!StringHelper.isEmpty(map.get("value"))) {
												value.append(",").append(map.get("value"));
											}
										}
										String valuetemp = value.toString();
										if (!StringHelper.isEmpty(valuetemp) && valuetemp.startsWith(",")) {
											valuetemp = valuetemp.substring(1);
										}
										tempvalue = valuetemp;
									}
									if (type != 1 && htmltype != 1) {//文本
										tempvalue = Util.toHtmltextarea(tempvalue);
									}
									tempvalue = InterfacesUtil.getSubStringValue(((String) dtlfielddbtypes.get(k)).toLowerCase(), tempvalue);
									if ("5".equals(type + "") && htmltype == 1) {
										int qfws = Util.getIntValue(Util.null2String(dtlqwfs.get(k)), 0);
										//QC:311928 ,如果输入自带分号，那么先去掉分号，转换为double
										if (tempvalue != null && tempvalue.indexOf(",") != -1) {
											tempvalue = tempvalue.replace(",", "");
										}
										tempvalue = Util.toDecimalDigits(tempvalue, qfws);
										tempvalue = Util.milfloatFormat(tempvalue);
									} else if (type == 3 && htmltype == 1) {
										String fielddbtype = Util.null2String(dtlfielddbtypes.get(k));
										int digitsIndex = fielddbtype.indexOf(",");
										int decimaldigits_t = 0;
										if (digitsIndex > -1) {
											decimaldigits_t = Util.getIntValue(fielddbtype.substring(digitsIndex + 1, fielddbtype.length() - 1), 2);
										} else {
											decimaldigits_t = 2;
										}
										if (tempvalue.indexOf(",") != -1) {
											tempvalue = tempvalue.replace(",", "");
										}
										tempvalue = Util.toDecimalDigits(tempvalue + "", decimaldigits_t);
									}
								}
							}
							if (!tempvalue.equals("")) {
								if (sql1.equals("")) {
									sql1 = "insert into " + detailtable + "(";
									sql2 = " values(";
									sql1 += detailtablekey;
									sql2 += mainid;
									sql1 += "," + dtlfieldnames.get(k);
									if (((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("int") != -1
											|| ((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("number") != -1
											|| ((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("decimal") != -1
											|| ((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("browser.") != -1) {
										sql2 += ",'" + tempvalue + "'";
										//valueList.add(tempvalue);
									} else {
										sql2 += ",'" + tempvalue + "'";
										//valueList.add(tempvalue);
									}
								} else {
									sql1 += "," + dtlfieldnames.get(k);
									if (((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("int") != -1
											|| ((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("number") != -1
											|| ((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("decimal") != -1
											|| ((String) dtlfielddbtypes.get(k)).toLowerCase().indexOf("browser.") != -1) {
										sql2 += ",'" + tempvalue + "'";
										//valueList.add(tempvalue);
									} else {
										sql2 += ",'" + tempvalue + "'";
										//valueList.add(tempvalue);
									}
								}
							}
						}

						if (!isnull) {
							if (mainid <= 0) {
								errorRow.add(sheetcount + "," + (rows + 1) + ",1,mainid	" + detailid + "	");
								if (Countsql.equals("")) {
									Countsql = SystemEnv.getHtmlLabelName(500098, user.getLanguage());
								}
								errorTable.add(sheetcount + "+" + (rows + 1) + "+1+mainid	" + detailid + "	" + "+" + detailtable + "+" + Countsql);
								Vector<Integer> d;
								if (errorDetailMap.containsKey(sheetIndex + "")) {
									d = errorDetailMap.get(sheetIndex + "");
								} else {
									d = new Vector<Integer>();
								}
								d.add(rows);
								errorDetailMap.put(sheetIndex + "", d);
								iserrordata = true;
								//								writeErrorRow();
							}
						}

						if (!sql1.equals("") && mainid > 0) {
							sql1 += ")";
							sql2 += ")";
							try {
								if (rowCanImport) {
									flag = rs.executeSql(sql1 + sql2);
								}
								if (flag) {
									detailList.add(mainid);
									// 进行列的计算.
									getColCalStr(formid, -1, maintable, map, mainid, 1, detailtable);
									//记录明细日志
									if (needlogFieldList.size() > 0) {
										Map<String, Map<String, Object>> nowData_detail = formInfoService.getTableData(detailtable, mainid, this.columnNames_d, "id", "mainid");
										Set<String> intersectionKey = new HashSet<String>();
										String[] columnsArray = this.columnNames_d.split(",");
										for (String detaildataid : nowData_detail.keySet()) {
											if (oldData_detail.containsKey(detaildataid)) {//编辑的明细数据
												Map<String, Object> od = oldData_detail.get(detaildataid);
												Map<String, Object> nd = nowData_detail.get(detaildataid);
												for (String column : columnsArray) {
													String fieldvalue = Util.null2String(nd.get(column));
													String prefieldvalue = Util.null2String(od.get(column));
													if (!prefieldvalue.equals(fieldvalue)) {
														String detailtable1 = detailtable;
														rs.executeUpdate("insert into ModeLogFieldDetail(viewlogid,fieldid,fieldvalue,prefieldvalue,modeid,detaildataid,operateType,detailtable) values(?,?,?,?,?,?,?,?)", this.modeLogMap.get(mainid + ""),
																this.columnFieldids_d.get(column), fieldvalue, prefieldvalue, this.modeid, detaildataid, "EDIT", detailtable);
													}
												}
												intersectionKey.add(detaildataid);
											} else {//新增的明细数据
												Map<String, Object> nd = nowData_detail.get(detaildataid);
												for (String column : columnsArray) {
													String fieldvalue = Util.null2String(nd.get(column));

													rs.executeUpdate("insert into ModeLogFieldDetail(viewlogid,fieldid,fieldvalue,modeid,detaildataid,operateType,detailtable) values(?,?,?,?,?,?,?)", this.modeLogMap.get(mainid + ""),
															this.columnFieldids_d.get(column), fieldvalue, this.modeid, detaildataid, "ADD", detailtable);
												}
											}
										}
										for (String detaildataid : oldData_detail.keySet()) {
											if (!intersectionKey.contains(detaildataid)) {//被删除的明细数据
												Map<String, Object> od = oldData_detail.get(detaildataid);
												for (String column : columnsArray) {
													String prefieldvalue = Util.null2String(od.get(column));
													rs.executeUpdate("insert into ModeLogFieldDetail(viewlogid,fieldid,prefieldvalue,modeid,detaildataid,operateType,detailtable) values(?,?,?,?,?,?,?)", this.modeLogMap.get(mainid + ""),
															this.columnFieldids_d.get(column), prefieldvalue, this.modeid, detaildataid, "DEL", detailtable);
												}
											}
										}
									}
								} else {
									writeLog(sql1 + sql2);
								}
							} catch (Exception e) {
								writeLog(e);
								errorRow.add(sheetcount + "," + (rows + 1));
								//								writeErrorRow();
							}
						}

						if ((!isnull && (!flag)) || iserrordata) {
							errorRow.add(sheetcount + "," + (rows + 1));
							//							writeErrorRow();
						}

						if (isnull) {
							canImport = false;
							ImpExcelServer.setProgressCanImport(key, false, MessageFormat.format(SystemEnv.getHtmlLabelName(132245, user.getLanguage()), sheetIndex, rows));
							if (!rowCanImport) {
								errorRow.removeAll(indexList);
								errorTable.removeAll(indexList);
							}
						}
					}
					rows++;
				}
				sheetcount++;
			}
		} catch (Exception e) {
			writeLog("导入明细异常 modeId=" + modeid + " formid=" + formid + " Exception : " + e);
			writeLog(e);
			Errmsg = SystemEnv.getHtmlLabelName(27593, user.getLanguage()) + e.getMessage() + "!\\n";
		} finally {
			doneSignal.countDown();
		}
	}

	private void importMainData() {
		try {
			ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
			RecordSet rs = new RecordSet();
			InterfacesUtil InterfacesUtil = new InterfacesUtil();
			String sql = "";
			int importtype = Util.getIntValue(Util.null2String(params.get("importtype")), 0);//1 追加，2覆盖,3更新
			int updateadddata = Util.getIntValue(Util.null2String(params.get("updateadddata")), 0);//importtype==3的时候
			String keyField = Util.null2String(Util.null2String(params.get("keyfield"))).toLowerCase();//重复验证字段
			String conditionfield = Util.null2String(Util.null2String(params.get("conditionfield"))).toLowerCase();//条件验证字段
			String conditionfielddbType = "";//条件验证字段 数据库类型
			boolean isImportedWithIgnoringError = Util.getIntValue(Util.null2String(params.get("isImportedWithIgnoringError"))) == 1 ? true : false;
			// 添加数据ID 创建人 创建日期时间字段 导入
			boolean ismainKeyid = false;
			if (importtype == 3 && "dataid".equals(conditionfield)) {//3更新 并且 条件字段是数据ID
				ismainKeyid = true;
			}
			boolean isHaveModedatastatus = false;
			if (new ModeSetUtil().isHaveModedatastatusByformid(formid)) {
				isHaveModedatastatus = true;
			}
			ArrayList fieldIdListTemp = new ArrayList();
			ArrayList fieldTypeListTemp = new ArrayList();
			ArrayList fieldDbTypeListTemp = new ArrayList();
			ArrayList fieldHtmlTypeListTemp = new ArrayList();
			ArrayList fieldNameListTemp = new ArrayList();
			ArrayList fieldLabelListTemp = new ArrayList();
			ArrayList fieldLabelNameListTemp = new ArrayList();
			ArrayList qfwsListTemp = new ArrayList();
			ImpExcelUtil impExcelUtil = new ImpExcelUtil();
			impExcelUtil.setModeVFormMap(modeVFormMap);
			int isHaveTemplate = 0;
			String templateSql = "select 1 from mode_import_template a where modeid=" + modeid + " and formid=" + formid + " and (exists(select 1 from workflow_billfield b where b.billid=" + formid + " and b.id=a.fieldid) or  a.fieldid in(-1000,-1001,-1002)) ";
			rs.execute(templateSql);
			if (rs.getCounts() > 0) {
				isHaveTemplate = 1;
			}
			if (isHaveTemplate == 1) {
				sql = "select  b.id,fieldlabel,fieldhtmltype,type,fielddbtype,fieldname,qfws,childfieldid,m.dsporder,1 as needExcel from  workflow_billfield b join mode_import_template m on b.id=m.fieldId and m.modeid=" + modeid + " and m.formId='" + formid + "' where fieldhtmltype<> 7  and billid=" + formid + " and viewtype=0 order by m.dsporder,b.id";
			} else {
				sql = "select  id,fieldlabel,fieldhtmltype,type,fielddbtype,fieldname,qfws,childfieldid,dsporder,needExcel from  workflow_billfield b left join ModeFormFieldExtend m on b.id=m.fieldId  and m.formId='" + formid + "' where fieldhtmltype<> 7  and billid=" + formid + " and viewtype=0 order by dsporder,id";
			}
			rs.execute(sql);
			ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
			while (rs.next()) {
				String needExcel = Util.null2String(rs.getString("needExcel"));
				if ("0".equals(needExcel)) {
					continue;
				}

				String fieldid = Util.null2String(rs.getString("id"));
				String fieldtype = Util.null2String(rs.getString("type"));
				String fielddbtype = Util.null2String(rs.getString("fielddbtype"));
				String fieldhtmltype = Util.null2String(rs.getString("fieldhtmltype"));
				String fieldname = Util.null2String(rs.getString("fieldname"));
				String labelname = Util.null2String(SystemEnv.getHtmlLabelName(rs.getInt("fieldlabel"), user.getLanguage()));
				String fieldlabelname = labelname;
				String qfws = Util.null2String(rs.getString("qfws"));

				fieldIdListTemp.add(fieldid);
				fieldTypeListTemp.add(fieldtype);
				fieldDbTypeListTemp.add(fielddbtype);
				fieldHtmlTypeListTemp.add(fieldhtmltype);
				fieldNameListTemp.add(fieldname);
				fieldLabelListTemp.add(labelname);
				fieldLabelNameListTemp.add(fieldlabelname);
				qfwsListTemp.add(qfws);
			}

			ArrayList fieldIdList = new ArrayList();
			ArrayList fieldTypeList = new ArrayList();
			ArrayList fieldDbTypeList = new ArrayList();
			ArrayList fieldHtmlTypeList = new ArrayList();
			ArrayList fieldNameList = new ArrayList();
			ArrayList fieldLabelList = new ArrayList();
			ArrayList fieldLabelNameList = new ArrayList();
			ArrayList qfwsList = new ArrayList();
			List<String> mainFieldIds = impFieldIds.get(0);//excel中的主表字段id
			for (int i = 0, len = mainFieldIds.size(); i < len; i++) {
				int fieldId = Util.getIntValue(mainFieldIds.get(i));
				if (fieldId <= 0) {
					continue;
				}
				int index = fieldIdListTemp.indexOf(mainFieldIds.get(i));
				fieldIdList.add(fieldIdListTemp.get(index));
				fieldTypeList.add(fieldTypeListTemp.get(index));
				fieldDbTypeList.add(fieldDbTypeListTemp.get(index));
				fieldHtmlTypeList.add(fieldHtmlTypeListTemp.get(index));
				fieldNameList.add(fieldNameListTemp.get(index));
				fieldLabelList.add(fieldLabelListTemp.get(index));
				fieldLabelNameList.add(fieldLabelNameListTemp.get(index));
				qfwsList.add(qfwsListTemp.get(index));
			}

			String maintablename = "";
			sql = "select * from workflow_bill where id = " + formid;
			rs.executeSql(sql);
			while (rs.next()) {
				maintablename = Util.null2String(rs.getString("tablename"));
			}
			new ModeDataIdUpdate().updateModifyInfo(maintablename);
			//看数据库是否有重复数据  组合验证每个组合的字段名为一个key(如wb1,wb2),所有的数据库值存到改key对应的map中
			Map<String, Map<String, String>> keyMap = new HashMap<String, Map<String, String>>();
			Map<String, Map<String, String>> keyMapExcel = new HashMap<String, Map<String, String>>();//看excel中是否有重复数据
			Map<String, String> conditionFieldMap = new HashMap<String, String>();//条件字段在数据库中的值
			List<String> keyFields = this.getKeyFields(keyField);
			// 草稿字段不参与验证
			String sqlwherebytemp = " where formmodeid=" + modeid + " ";
			if (new ModeSetUtil().isHaveModedatastatus(formid)) {
				sqlwherebytemp += " and modedatastatus <> 1 ";
			}
			setDataBaseValue(keyField, maintablename, keyMap, sqlwherebytemp);
			if (!"".equals(conditionfield)) {
				int totalPage = 1;
				SplitPageUtil spu = new SplitPageUtil();
				SplitPageParaBean spp = new SplitPageParaBean();
				String primarykey = "id";
				String vdatasource = "";
				String backfield = "";
				String sqlfrom = "";
				String sqlwhere = "1=1";
				//创建临时表
				Boolean iscreatetemptab=IsCreateTempTab(conditionfield,fieldNameList,fieldTypeList,fieldHtmlTypeList);
				if(iscreatetemptab){
					//获取excel更新条件字段  datas进行批量插入
					int rowsy=0;
					if(start!=0){
						 rowsy =start;
					}else{
						 rowsy =start+1;
					}
					List<List> datas = new ArrayList<List>();
					while(rowsy < end && rowsy >= start){
						List<String> data = new ArrayList<>();
						if(conditionfield.equals("dataid")){
							String tempvalue = POIUtil.getValue(sheet, rowsy, 1);					
							data.add(tempvalue);						
						}else{
							for (int k = 0; k < fieldNameList.size(); k++) {
								String fieldid = Util.null2String((String) fieldIdList.get(k));
								String fieldname = Util.null2String((String) fieldNameList.get(k));
								String fieldtype = Util.null2String((String)fieldTypeList.get(k));
								String fieldhtmltype = Util.null2String((String)fieldHtmlTypeList.get(k));
								int col = mainFieldIds.indexOf(fieldid);
								String tempvalue = POIUtil.getValue(sheet, rowsy, col);
								if (conditionfield.equals(fieldname)&&!"".equals(tempvalue)&&"1".equals(fieldhtmltype)&&"1".equals(fieldtype)) {
									data.add(tempvalue);
								}
							}
						}

						rowsy++;
						datas.add(data);
					}
	 
					RecordSet rsSet = new RecordSet();
					rsSet.executeBatchSql("insert into M_"+modeid+"_"+user.getUID()+"("+conditionfield+") values (?)",datas);
				}
				
				
				if (conditionfield.equals("dataid")) {
					backfield = "b.id,a.dataid " ;
					primarykey= "b.id";
					sqlfrom = "M_"+modeid+"_"+user.getUID()+" a, "+maintablename + " b ";
					sqlwhere = "a.dataid = b.id";
					spp.setBackFields(backfield);// t1.id,t1.formmodeid
					spp.setDistinct(false);//false
					spp.setPrimaryKey(primarykey);//t1.id
					spp.setSqlFrom(sqlfrom);//
					spp.setSqlWhere(sqlwhere);
					spp.setCountColumns(primarykey);    //统计项
					spp.setPoolname(vdatasource);//""
					spp.setIsPrintExecuteSql(false);
					spu.setSpp(spp);
					String countSql = spu.getCountSql();
					rs.executeSql(countSql);
					if (rs.next()) {
						int total = Util.getIntValue(rs.getString(1), 0);
						totalPage = (total - 1) / pageSize + 1;
					}
					for (int i = 1; i <= totalPage; i++) {
						rs = spu.getCurrentPageRs(i, pageSize);
						while (rs.next()) {
							String id = Util.null2String(rs.getString("id"));
							if (conditionFieldMap.containsKey(id)) {
								conditionFieldMap.put(id, conditionFieldMap.get(id) + "," + id);
							} else {
								conditionFieldMap.put(id, id);
							}
						}
					}
				} else {
					boolean issingletext =IsSingleText(conditionfield,fieldNameList,fieldTypeList,fieldHtmlTypeList);
					if(issingletext){
						backfield = "b.id,a." + conditionfield;
						primarykey ="b.id";
						sqlfrom = "M_"+modeid+"_"+user.getUID()+" a,"+maintablename+" b";
						sqlwhere = "a."+conditionfield+" = b."+conditionfield;
						spp.setBackFields(backfield);// t1.id,t1.formmodeid
						spp.setDistinct(false);//false
						spp.setPrimaryKey(primarykey);//t1.id
						spp.setSqlFrom(sqlfrom);//
						spp.setSqlWhere(sqlwhere);
						spp.setCountColumns(primarykey);    //统计项
						spp.setPoolname(vdatasource);//""
						spp.setIsPrintExecuteSql(false);
						spu.setSpp(spp);
					}else{
						backfield = "id," + conditionfield;
						sqlfrom = maintablename;
						spp.setBackFields(backfield);// t1.id,t1.formmodeid
						spp.setDistinct(false);//false
						spp.setPrimaryKey(primarykey);//t1.id
						spp.setSqlFrom(sqlfrom);//
						spp.setSqlWhere(sqlwhere);
						spp.setCountColumns(primarykey);    //统计项
						spp.setPoolname(vdatasource);//""
						spp.setIsPrintExecuteSql(false);
						spu.setSpp(spp);
					}

					String countSql = spu.getCountSql();
					rs.executeSql(countSql);
					if (rs.next()) {
						int total = Util.getIntValue(rs.getString(1), 0);
						totalPage = (total - 1) / pageSize + 1;
					}
					for (int i = 1; i <= totalPage; i++) {
						rs = spu.getCurrentPageRs(i, pageSize);
						while (rs.next()) {
							String value = Util.null2String(rs.getString(conditionfield));
							value = value.replace("\'", "''");
							String id = Util.null2String(rs.getString("id"));
							if (conditionFieldMap.containsKey(value)) {
								conditionFieldMap.put(value, conditionFieldMap.get(value) + "," + id);
							} else {
								conditionFieldMap.put(value, id);
							}
						}
					}
				}
			}

			int sheetcount = 1;//sheet1 主表数据
			int rows = start;

			ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
			FormInfoService formInfoService = new FormInfoService();
			List<Map<String, Object>> needlogFieldList = formInfoService.getNeedlogField(formid);
			String columnNames = "";
			String tableName = "";
			if (needlogFieldList.size() > 0) {
				for (int i = 0; i < needlogFieldList.size(); i++) {
					Map<String, Object> needlogField = needlogFieldList.get(i);
					String fieldname = Util.null2String(needlogField.get("fieldname"));
					String detailtable = Util.null2String(needlogField.get("detailtable"));
					if (!detailtable.equals("")) {
						continue;
					}
					columnNames += fieldname;
					if (i != (needlogFieldList.size() - 1)) {
						columnNames += ",";
					}
				}
				rs.executeSql("select tablename from workflow_bill where id = " + formid);
				if (rs.next()) {
					tableName = rs.getString("tablename");
				}
			}

			//如果当某一行的所有数据都为空，则导入终止
			boolean canImport = ImpExcelServer.getProgressCanImport(key);
			RecordSet recordSet = new RecordSet();
			List<String> indexList = new ArrayList<String>();
			if (rows == 0) {
				rows = 1;
			}

			int idCol = mainFieldIds.indexOf("-2000");

			NumberFormat nf = NumberFormat.getInstance();
			nf.setGroupingUsed(false);
			nf.setMaximumFractionDigits(100);
			//表头下的具体内容
			while (canImport = ImpExcelServer.getProgressCanImport(key) && rows < end && rows >= start) {
				if (StringCacheMap.containsKey(key + "_cancel")) {
					break;
				}
				rowNumList.add(1);
				if (rowNumList.size() % 20 == 0) {
					ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
				}
				ExpExcelUtil.refreshImpUserState(user.getUID(), key);//刷新导入状态
				ImpExcelServer.writeProgressMsg(key, SystemEnv.getHtmlLabelName(132246, user.getLanguage()) + ":" + rowNumList.size() + "/" + (POIUtil.getLastRowNum(sheet) - 1), "0");
				String updatesql = " update " + maintablename + " set ";
				String tempdatesql = updatesql;
				boolean flag = false;
				String flagMsg = "";
				boolean isnull = true;
				boolean iserrordata = false;
				String conditionFieldValue = "";//条件字段的值

				//id列
				String id = Util.null2String(POIUtil.getValue(sheet, rows, idCol)).trim();
				if (!"".equals(id)) {
					isnull = false;
				}
				String mainKeyValue = "";
				boolean rowCanImport = true;//当前行进行验证，如，设置了导入字段必填，如果值为空则不允许导入当前行
				indexList.clear();
				// 生成插入sql
				int k = 0;
				Map<String, Map<String, String>> rowdatainfosMap = new HashMap<String, Map<String, String>>();
				boolean allisnull = false;
				for (; k < fieldNameList.size(); k++) {
					boolean isDepSup = false;    //全路径导入的>处理
					String fieldid = Util.null2String((String) fieldIdList.get(k));
					String fieldtype = Util.null2String((String) fieldTypeList.get(k));
					String fielddbtype = Util.null2String((String) fieldDbTypeList.get(k));
					String fieldhtmltype = Util.null2String((String) fieldHtmlTypeList.get(k));
					String fieldname = Util.null2String((String) fieldNameList.get(k));
					String fieldlabel = Util.null2String((String) fieldLabelList.get(k));
					String fieldlabelname = Util.null2String((String) fieldLabelNameList.get(k));
					if (conditionfield.equals(fieldname)) {
						conditionfielddbType = fielddbtype;
					}//获得重复验证字段的 数据库属性
					int qfws = Util.getIntValue((String) qfwsList.get(k), 0);
					int col = mainFieldIds.indexOf(fieldid);
//			        Cell cell = sheet.getCell(col, rows);
					String tempvalue = POIUtil.getValue(sheet, rows, col);
					tempvalue = tempvalue.trim();//去除两头的空格防止导入重复校验出错
					if (!Util.null2String(tempvalue).trim().equals("")) {
						allisnull = true;
					}
					String tempvalueForIdentify = tempvalue;
//			        if((fieldtype.equals("5")||fieldtype.equals("4")||fieldtype.equals("3"))&&fieldhtmltype.equals("1")){//浮点数的话避免被四舍五入
//						try {
//							if(cell instanceof NumberCell){
//								NumberCell numberCell = (NumberCell)cell;
//								Double numberValue = numberCell.getValue();
//								tempvalue=nf.format(numberValue);//避免转换为值的时候变为科学计数法
//							}else{
//								tempvalue = Util.null2String(cell.getContents()).trim();
//							}
//						} catch (Exception e) {
//							tempvalue = Util.null2String(cell.getContents()).trim();
//							rs.writeLog(e);
//						}
//			        }else if(fieldtype.equals("2")&&fieldhtmltype.equals("1")){//整数
//						try {
//							tempvalue = Util.null2String(cell.getContents()).trim();
//						} catch (Exception e) {
//							tempvalue = Util.null2String(cell.getContents()).trim();
//							rs.writeLog(e);
//						}
//					}else{
//						tempvalue = Util.null2String(cell.getContents());
					if ("1".equals(fieldtype) && "1".equals(fieldhtmltype)) {//文本
						tempvalue = tempvalue.replaceAll("\\n", "");
						if ("1".equals(modeFormFieldEncryptComInfo.getIsencrypt(fieldid))) {
							tempvalue = CubeCipherUitl.encrypt(tempvalue);
						}
//							if(cell.getType() == CellType.NUMBER) {
//								int dindex = tempvalue.indexOf(".");
//								if(dindex!=-1){//不包含小数点，直接导入
//									double tempDoubleVal=((NumberCell)cell).getValue();
//			        	      		tempvalue=nf.format(tempDoubleVal);//避免转换为值的时候变为科学计数法
//								}
//			        	     }
					}
					if ("3".equals(fieldhtmltype) && ("161".equals(fieldtype) || "162".equals(fieldtype))) {
						tempvalue = CubeCipherUitl.getBrowserEncryptValueImp(fielddbtype, tempvalue, fieldtype);
					}

					String tempString = tempvalue;
					if ("2".equals(fieldtype) && "2".equals(fieldhtmltype) && !StringHelper.isEmpty(tempvalue)) {
						String[] tempFieldValue = tempvalue.split("<p>|</p>|<script>initFlashVideo\\(\\);</script>|<br>");
						for (int i = 0; i < tempFieldValue.length; i++) {
							String temp = tempFieldValue[i].replaceAll("<", "&lt;");
							temp = temp.replaceAll(">", "&gt;");
							tempString = tempString.replace(tempFieldValue[i], temp);
						}
						if (!tempString.isEmpty()) {
							tempString = "<p>" + tempString.replaceAll("\n", "</p>\n<p>") + "</p>";
						}
						tempString = tempString.replaceAll("&#39;", "'");
						tempString = tempString.replaceAll("<br>", "");
						//String reg="[\u0000-\u001f|\ufffd|囧|]";
						tempString = tempString.replaceAll(" ", "&nbsp;");
						tempvalue = tempString;
					}
//			        }
					//判断tempvalue中的值是不是"null"
					Boolean isNullValue = false;
					String oldtempvalue = tempvalue;
					tempvalue = StringHelper.convertSpecialChar2Html(tempvalue);
					if (importtype == 3) {//更新才做NULL值导入
						String[] tmpv = tempvalue.split(",");
						tempvalue = "";
						for (int i = 0; i < tmpv.length; i++) {
							tmpv[i] = CubeCipherUitl.decrypt(tmpv[i]);
							if (i != tmpv.length - 1) {
								tempvalue += tmpv[i] + ",";
							} else {
								tempvalue += tmpv[i];
							}
						}
						isNullValue = "null".equalsIgnoreCase(tempvalue) ? true : false;
						oldtempvalue = "null".equalsIgnoreCase(tempvalue) ? null : tempvalue;
						tempvalue = StringHelper.convertSpecialChar2Html(oldtempvalue);
					}
					int type = Util.getIntValue(fieldtype);
					int htmltype = Util.getIntValue(fieldhtmltype);
					String checkvalue = tempvalue;
					boolean iserrortime = false;
					boolean iserrordatatime = false;
					if (htmltype == 3) {
						if (type == 2 || type == 19) { // 日期
							Cell cell = POIUtil.getCell(sheet, rows, col);
							checkvalue = ImpExcelUtil.getDateOrTime(cell, checkvalue, type);
							if (checkvalue.startsWith("#@ERROR@#")) {
								checkvalue = checkvalue.replace("#@ERROR@#", "");
								errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + checkvalue + "," + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
								errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + checkvalue + "+" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) +
										"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
										"+<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
								IdMap.put(id + "sql", "<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(391280, user.getLanguage()));
								iserrordata = true;
								checkvalue = "";
								iserrortime = true;
							}
						} else if (type == 290) {//日期时间
							Cell cell = POIUtil.getCell(sheet, rows, col);
							checkvalue = ImpExcelUtil.getDateTime(cell, checkvalue, type);
							if (checkvalue.startsWith("#@ERROR@#")) {
								checkvalue = checkvalue.replace("#@ERROR@#", "");
								errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + checkvalue + "," + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
								errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + checkvalue + "+" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) +
										"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
										"+<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
								IdMap.put(id + "sql", "<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(391281, user.getLanguage()));
								iserrordata = true;
								checkvalue = "";
								iserrordatatime = true;
							}
						}
					}

					if (!checkDataByExpression(fieldid, checkvalue)) {
						errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + SystemEnv.getHtmlLabelName(132247, user.getLanguage()));
						errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + checkvalue + "+" + SystemEnv.getHtmlLabelName(132247, user.getLanguage()) +
								"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
								"+<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(132247, user.getLanguage()));
						IdMap.put(id + "sql", "<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(391282, user.getLanguage()));
						indexList.add((String) errorRow.get(errorRow.size() - 1)); //获得当前错误提示的idnex
						updatesql = tempdatesql;
						rowCanImport = false;
					}

					// excel值转换
					//根据条件来判断是否必填
					String tempCondition = "";
					String tempHead = "";
					String tempFieldName = "";
					boolean validateflag = false;
					for (Map.Entry<String, List<String>> et : validateMap.entrySet()) {
						String key = et.getKey();
						if (fieldid.equals(key)) {
							List<String> value = et.getValue();
							if (value.size() == 0) {
								tempHead = Util.null2String(POIUtil.getValue(sheet, 0, col));
								validateflag = true;
								break;
							}
							for (String selectid : value) {
								String[] values = selectid.split(":");
								int index = mainFieldIds.indexOf(values[0]);
								tempCondition = Util.null2String(POIUtil.getValue(sheet, rows, index));
								if ((tempCondition).equals(values[1])) {
									tempHead = Util.null2String(POIUtil.getValue(sheet, 0, col));
									tempFieldName = Util.null2String(POIUtil.getValue(sheet, 0, index));
									validateflag = true;
									break;
								}
							}
						}
						if (validateflag) {
							break;
						}
					}

					if ("".equals(tempvalue) && validateflag) {
						if (!"".equals(tempCondition)) {
							tempCondition = MessageFormat.format(SystemEnv.getHtmlLabelName(132243, user.getLanguage()), tempFieldName, tempCondition, tempHead);
						} else {
							tempCondition = MessageFormat.format(SystemEnv.getHtmlLabelName(132244, user.getLanguage()), tempHead);
						}
						errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + "" + tempCondition);
						errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + "" + tempCondition + "+" + fieldlabelname +
								"+" + fieldname + "+" + fielddbtype + "+" + maintablename + "+" + SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + fieldlabelname + SystemEnv.getHtmlLabelName(391283, user.getLanguage()));
						IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + fieldlabelname + SystemEnv.getHtmlLabelName(391284, user.getLanguage()));
						indexList.add((String) errorRow.get(errorRow.size() - 1)); //获得当前错误提示的idnex
						updatesql = tempdatesql;
						rowCanImport = false;
					}


					if (!tempvalue.equals("") || isNullValue) {
						isnull = false;
						if (fieldTransObject != null && fieldtranslist.contains(fieldid)) {//调用自定义转换接口
							this.params.put("fieldid", fieldid);
							this.params.put("fieldname", fieldname);
							if (fieldTransObject instanceof ImportFieldTransAction) {
								ImportFieldTransAction fieldTrans = (ImportFieldTransAction) fieldTransObject;
								tempvalue = fieldTrans.getTransValue(this.params, user, sheetJXL, rows, col);
							} else if (fieldTransObject instanceof ImportFieldTransActionPOI) {
								ImportFieldTransActionPOI fieldTrans = (ImportFieldTransActionPOI) fieldTransObject;
								ExcelParseForPOI excelParse = (ExcelParseForPOI) this.params.get("excelParse");
								tempvalue = fieldTrans.getTransValue(this.params, user, excelParse, (rows + 1), (col + 1));
							}
						} else {
							tempvalue = tempvalue.replace("'", "''");
							if (type == 2 && htmltype == 1) {//整数
								Pattern pattern = Pattern.compile("^(-)?\\d+$");
								Matcher isFlag = pattern.matcher(tempvalue);
								if (!isFlag.matches() && !isNullValue) {
									errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(382376, user.getLanguage()));
									errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) +
											"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
											"+<font style='color:red'>" + tempvalue + "</font>:" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) + "," + SystemEnv.getHtmlLabelName(391252, user.getLanguage()) + "!");
									IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391285, user.getLanguage()));
									iserrordata = true;
									tempvalue = "";
								}
							} else if (htmltype == 2 && type == 2 && importtype == 3 && tempvalue.equalsIgnoreCase("<p>null</p>")) {
								tempvalue = "";
								isNullValue = true;
							} else if ((type == 3 || type == 4 || type == 5) && htmltype == 1) {//浮点数
								String excelVal = tempvalue;
								tempvalue = tempvalue.replace(",", "");
								Pattern pattern = Pattern.compile("^(-)?(0|([1-9]\\d*))(.\\d+)?$"); //浮点数
								Matcher isFlag = pattern.matcher(tempvalue);
								if (!isFlag.matches() && !isNullValue) {
									String errMsg = "";
									if (type == 3) {
										errMsg = SystemEnv.getHtmlLabelName(382377, user.getLanguage());
									} else if (type == 4) {
										errMsg = SystemEnv.getHtmlLabelName(382378, user.getLanguage());
									} else if (type == 5) {
										errMsg = SystemEnv.getHtmlLabelName(382379, user.getLanguage());
									}
									errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + ",“" + excelVal + "”," + errMsg);
									errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+“" + excelVal + "”+" + errMsg + "+" + fieldlabelname +
											"+" + fieldname + "+" + fielddbtype + "+" + maintablename + "+<a style='color:red'>" + excelVal + "</a>:" + errMsg);
									IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + fieldlabelname + "," + errMsg + "！" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
									iserrordata = true;
									tempvalue = "";
								}
							} else if (htmltype == 3) {
								//浏览按钮多支持 主键导入
								//判断是否ID串
								boolean isNumber = false;
								String[] number = null;
								if (type == 161) {
									number = tempvalue.split("weaver_ecology");
								} else {
									if (type != 1) {
										if (tempvalue.indexOf("DH{") != -1) {//批量导入自定义多选时，如果选项中有英文逗号，批量导入时用DH{}包裹
											String[] tempNumber = tempvalue.split(",");//数组格式：{"xxxx","DH{XXXX","XXXX"?(也许有),"xxx}"},其中DH{}中间包裹的值是自定义多选的一个选项
											List<String> list = new ArrayList<String>();
											int i = 0;
											int j = 0;
											while (i < tempNumber.length) {
												if (tempNumber[i].indexOf("DH{") != -1) {
													list.add(tempNumber[i].substring(3, tempNumber[i].length()) + ",");
													i++;
													boolean flag1 = false;
													while (!flag1) {//判断数组中是否含有
														if (tempNumber[i].indexOf("}") != -1) {
															list.add(list.get(j) + tempNumber[i].substring(0, tempNumber[i].length() - 1));
															list.remove(j);
															i++;
															j++;
															flag1 = true;
														} else {
															list.add(list.get(j) + tempNumber[i] + ",");
															list.remove(j);
															i++;
														}
													}
												} else {
													list.add(tempNumber[i]);
													i++;
													j++;
												}
											}
											number = list.toArray(new String[list.size()]);
										} else {
											number = tempvalue.split(",");
										}
									} else {
										number = new String[]{tempvalue};
									}
								}
								if (number != null && number.length > 0) {
									for (String num : number) {
										Pattern pattern = Pattern.compile("^(-)?[1-9][0-9]*$"); //验证正数或负数
										Matcher isNum = pattern.matcher(num.trim());
										if (!isNum.matches()) {//非数字 进行ID获取
											isNumber = false;
											break;
										} else {
											isNumber = true;
										}
									}
								}

								//虚拟表单修改主键后  主键不一定是数字类型  不能用数字类型作为判断   只能检查主键数据中是否存在改数据   zwbo
								if (!isNumber) {
									if (type == 161 || type == 162) { //自定义单选和多选
										//浏览框为虚拟表单  并且修改主键
										String pkname = "";
										Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(fielddbtype);
										String browser_id = browser.getCustomid();
										if (!StringHelper.isEmpty(browser_id)) {
											boolean isVFrom = false;
											if (customBrowserMap.containsKey(browser_id)) {
												isVFrom = customBrowserMap.get(browser_id);
											} else {
												RecordSet virrs = new RecordSet();
												virrs.execute("select a.formid,b.vprimarykey from mode_custombrowser a,modeformextend b where a.id =" + browser_id + "  AND a.formid=b.formid ");
												if (virrs.next()) {
													isVFrom = true;
												}
												customBrowserMap.put(browser_id, isVFrom);
											}
											if (isVFrom && number.length > 0) {
												BrowserBean browserBean = browser.searchById(number[0].trim());
												if (browserBean.getId() == null) {
													isNumber = false;
												} else {
													isNumber = true;
												}
											}
										}
									}
								}
								//---------------------------提取start-----------------------------
								if (type == 2 || type == 19 || type == 403) { // 时间
									if (!iserrortime) {
//										tempvalue = Util.null2String(cell.getContents());
										Cell cell = POIUtil.getCell(sheet, rows, col);
										tempvalue = ImpExcelUtil.getDateOrTime(cell, tempvalue, type);
										if (tempvalue.startsWith("#@ERROR@#")) {
											tempvalue = tempvalue.replace("#@ERROR@#", "");
											errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
											errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) +
													"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
													"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
											IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391280, user.getLanguage()));
											iserrordata = true;
											tempvalue = "";
										}
									}
									oldtempvalue = tempvalue;
								} else if (type == 290) {//日期时间
									if (!iserrordatatime) {
//										tempvalue = Util.null2String(cell.getContents());
										Cell cell = POIUtil.getCell(sheet, rows, col);
										tempvalue = ImpExcelUtil.getDateTime(cell, tempvalue, type);
										TimeZoneVar.setTimeZone(timezone);
										tempvalue = "".equals(Util.null2String(tempvalue)) ? "" : new DateTransformer().getServerDateTime(tempvalue);
										if (tempvalue != null && tempvalue.indexOf(":") != tempvalue.lastIndexOf(":")) {
											tempvalue = tempvalue.substring(0, tempvalue.lastIndexOf(":"));
										}
										if (tempvalue.startsWith("#@ERROR@#")) {
											tempvalue = tempvalue.replace("#@ERROR@#", "");
											errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
											errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) +
													"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
													"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
											IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391281, user.getLanguage()));
											iserrordata = true;
											tempvalue = "";
										}
									}
									oldtempvalue = tempvalue;
								} else if (type == 402) {//年、年是int型，判断值是否是整数
									Pattern pattern = Pattern.compile("^(-)?\\d+$");
									Matcher isFlag = pattern.matcher(tempvalue);
									if (!isFlag.matches() && !isNullValue) {
										errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue + "," + SystemEnv.getHtmlLabelName(382376, user.getLanguage()));
										errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue + "+" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) +
												"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
												"+<font style='color:red'>" + tempvalue + "</font>:" + SystemEnv.getHtmlLabelName(382376, user.getLanguage()) + "," + SystemEnv.getHtmlLabelName(391252, user.getLanguage()) + "!");
										IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391285, user.getLanguage()));
										iserrordata = true;
										tempvalue = "";
									}
								} else if ((type == 4 || type == 57 || type == 168 || type == 167) && (tempvalue.indexOf(">") > -1 || tempvalue.indexOf(this.sepCharacter) > -1 && this.isDepartAndSubpany)) {//如果部门里面有> 代表逐级导入
									ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
									String temps = "";
									for (int n = 0; n < tempvalues.size(); n++) {
										String temp = Util.null2String(tempvalues.get(n));
										Map<String, String> tempvalueMap = getIdByPathName(1, temp);
										if (Util.null2String(tempvalueMap.get("flag")).equals("0")) {
											temp = tempvalueMap.get("value");
										} else {
											boolean isflag = isDepartAndSubpany;
											if (!isflag) {
												errorRow.add(sheetcount + "," + rows + "," + col + "," + ((String) tempvalueMap.get("orgname")).trim());
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalueMap.get("orgname")).trim() +
														"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
														"+<a style='color:red'>" + temp + "</a>:" + SystemEnv.getHtmlLabelName(391288, user.getLanguage()) + "select id from hrmdepartment where departmentname='" + temp + "'");
												IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + ((String) tempvalueMap.get("orgname")).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391287, user.getLanguage()));
											} else {
												isDepSup = true;
											}

										}
										temps += "," + temp;
									}
									if (temps.length() > 0) {
										temps = temps.substring(1);
									}
									if (!isDepSup) {
										tempvalue = temps;
									}
								} else if ((type == 164 || type == 169 || type == 170 || type == 194) && tempvalue.indexOf(">") > -1) { //如果分部里面有> 代表逐级导入
									ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
									String temps = "";
									for (int n = 0; n < tempvalues.size(); n++) {
										String temp = Util.null2String(tempvalues.get(n));
										Map<String, String> tempvalueMap = getIdByPathName(0, temp);
										if (Util.null2String(tempvalueMap.get("flag")).equals("0")) {
											temp = tempvalueMap.get("value");
										} else {
											boolean isflag = isDepartAndSubpany;
											if (isflag) {
												isDepSup = true;
											} else {
												errorRow.add(sheetcount + "," + rows + "," + col + "," + ((String) tempvalueMap.get("orgname")).trim());
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalueMap.get("orgname")).trim() +
														"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
														"+<a style='color:red'>" + temp + "</a>:" + SystemEnv.getHtmlLabelName(391267, user.getLanguage()) + "select id from HrmSubCompany where subcompanyname='" + temp + "'");
												IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "- <a style='color:red'>" + ((String) tempvalueMap.get("orgname")).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391289, user.getLanguage()));
											}
										}
										temps += "," + temp;
									}
									if (temps.length() > 0) {
										temps = temps.substring(1);
									}
									if (!isDepSup) {
										tempvalue = temps;
									}
								} else if ((type == 1 || type == 17 || type == 165 || type == 166) && (tempvalue.indexOf(">") > -1 || tempvalue.indexOf(this.sepCharacter) > -1 && this.isDepartAndSubpany)) { //如果人员里面有> 代表逐级导入
									ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
									String temps = "";
									for (int n = 0; n < tempvalues.size(); n++) {
										String temp = Util.null2String(tempvalues.get(n));
										Map<String, String> tempvalueMap = getIdByPathName(2, temp);
										if (Util.null2String(tempvalueMap.get("flag")).equals("0")) {
											temp = tempvalueMap.get("value");
										} else {
											errorRow.add(sheetcount + "," + rows + "," + col + "," + ((String) tempvalueMap.get("orgname")).trim());
											errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalueMap.get("orgname")).trim() +
													"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
													"+<a style='color:red'>" + temp + "</a>:" + SystemEnv.getHtmlLabelName(391270, user.getLanguage()) + "select id from hrmresource where lastname='" + temp + "' and departmentid=0");
											IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + ((String) tempvalueMap.get("orgname")).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391290, user.getLanguage()));
										}
										temps += "," + temp;
									}
									if (temps.length() > 0) {
										temps = temps.substring(1);
									}
									tempvalue = temps;
								} else if (type == 224 || type == 225 || type == 226 || type == 227) {
									oldtempvalue = tempvalue;
								} else if ((type == 4 || type == 57) || (type == 164 || type == 194)) { //虚拟部门   虚拟分部
									String flagStr = "";
									String keyname = "";
									String tablename = "";
									String keynameall = "";//支持全称导入
									if ((type == 4 || type == 57)) {
										if (tempvalue.toLowerCase().startsWith("virtual_")) {
											flagStr = "virtual_";
											if (tempvalue.startsWith("VIRTUAL_")) {
												flagStr = "VIRTUAL_";
											}
											keyname = "departmentmark";
											keynameall = "departmentname";
											tablename = "HrmDepartmentVirtual";
										} else if (tempvalue.startsWith("-")) {
											keyname = "id";
											tablename = "HrmDepartmentVirtual";
										} else if (tempvalue.startsWith("deptcode_")) {
											tablename = "HrmDepartment";
											keyname = "departmentcode";
											if (tempvalue.indexOf("deptcode_") != -1) {
												tempvalue = tempvalue.replace("deptcode_", "");
											} else {
												tempvalue = tempvalue.substring(9);
											}
										} else {
											tablename = "HrmDepartment";
											keyname = "departmentmark";
											if (isNumber) {
												keyname = "id";
											} else {
												keynameall = "departmentname";
											}
										}
									} else if ((type == 164 || type == 194)) {
										if (tempvalue.toLowerCase().startsWith("virtual_")) {
											flagStr = "virtual_";
											if (tempvalue.startsWith("VIRTUAL_")) {
												flagStr = "VIRTUAL_";
											}
											keyname = "subcompanydesc";
											keynameall = "subcompanyname";
											tablename = "hrmsubcompanyvirtual";
										} else if (tempvalue.startsWith("-")) {
											keyname = "id";
											tablename = "hrmsubcompanyvirtual";
										} else {
											tablename = "hrmsubcompany";
											keyname = "subcompanydesc";
											if (isNumber) {
												keyname = "id";
											} else {
												keynameall = "subcompanyname";
											}
										}
									}
									//部门及分部封存，人员离职过滤
									String hrmFilterCondiction = "";
									if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompany".equalsIgnoreCase(tablename.toLowerCase())
											|| "HrmDepartmentVirtual".equalsIgnoreCase(tablename.toLowerCase()) ||
											"hrmsubcompanyvirtual".equalsIgnoreCase(tablename.toLowerCase())) {
										hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='')";
									}

									ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");

									ArrayList tempvalueForIdentifys = Util.TokenizerString(tempvalueForIdentify, ",");
									tempvalue = "";
									String values = "";
									for (int n = 0; n < tempvalues.size(); n++) {
										if (!((String) tempvalues.get(n)).trim().toLowerCase().startsWith(flagStr))
											continue;
										values += ",'" + ((String) tempvalues.get(n)).trim().replace(flagStr, "") + "'";
									}
									if (!StringHelper.isEmpty(values)) {
										values = values.substring(1);

										for (int n = 0; n < tempvalues.size(); n++) {
											rs = new RecordSet();
											String value = ((String) tempvalues.get(n)).trim().replace(flagStr, "");
											value = checkDepartAndSubpany(value);
											//添加判断value 是不是id 或者编号
											String identifyValue = ((String) tempvalueForIdentifys.get(n)).trim().replace(flagStr, "");
											if (isNumberOrCode(identifyValue)) {
												hrmFilterCondiction = "";
											}
											if (!"".equals(keynameall)) {
												sql = "select id," + keynameall + " as showname from " + tablename + "  where " + keynameall + " = '" + value + "'  " + hrmFilterCondiction + " order by id desc";
												rs.executeSql(sql);
											}
											if (rs.getCounts() <= 0) {
												sql = "select id," + keyname + " as showname from " + tablename + "  where " + keyname + " = '" + value + "'  " + hrmFilterCondiction + " order by id desc";
												rs.executeSql(sql);
											}
											if (!rs.next()) {//判断是否为多语言
												if (!"".equals(keynameall)) {
													String tempSqlTemp = "select id," + keynameall + " as showname from " + tablename +
															" where (" + keynameall + " like '%" + "`~`7 " + value + "`~`" + "%' or " + keynameall + " like '%" + "`~`8 " + value + "`~`" + "%' or " + keynameall + " like '%" + "`~`9 " + value + "`~`" + "%')"
															+ hrmFilterCondiction + " order by id desc";
													rs.execute(tempSqlTemp);
												}
												if (rs.getCounts() <= 0) {
													String tempSqlTemp = "select id," + keyname + " as showname from " + tablename +
															" where (" + keyname + " like '%" + "`~`7 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`8 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`9 " + value + "`~`" + "%')"
															+ hrmFilterCondiction + " order by id desc";
													rs.execute(tempSqlTemp);
												}
											}
											rs.beforFirst();
											boolean isExists = false;
											while (rs.next()) {
												String showname = rs.getString("showname");
												showname = Util.formatMultiLang(showname, user.getLanguage() + "");
												String tempValue = (String) tempvalues.get(n);
												tempValue = checkDepartAndSubpany(tempValue.trim());
												String shownameNew = (flagStr + showname).replace("'", "''");
												if (shownameNew.equals(tempValue)) {
													tempvalue += "," + rs.getString(1);
													isExists = true;
													break;
												}
											}
											if (!isExists) {
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + ((String) tempvalues.get(n)).trim());
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalues.get(n)).trim() +
														"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
														"+<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391271, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
												IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(127576, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql + "<br/>" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
												iserrordata = true;
											}
										}
										if (tempvalue.startsWith(",")) {
											tempvalue = tempvalue.substring(1);
										}
									}
								} else if (!isNullValue && (type == 161 || type == 162)) {
									if (!isNumber) {
										if (type == 161) { // 自定义单选
											Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(fielddbtype);
											Map<String, String> browserMap = ModeCacheManager.getInstance().getIdByNames(fielddbtype, tempvalue, user.getLanguage());
											if (browserMap.containsKey("ids")) {
												tempvalue = browserMap.get("ids");
											} else {
												//解决浏览框名称为整数，判断有误情况
												String realTempvalue = analyzeNameValue(tempvalue);
												Map resultmap = analyzeIdValue(realTempvalue);
												BrowserBean BrowserBean = null;
												if (!("").equals(resultmap.get("id"))) {
													BrowserBean = browser.searchById(resultmap.get("id").toString().replace("''", "'"));
												} else {
													BrowserBean = browser.searchForImport(resultmap.get("name").toString().replace("''", "'"), user);
												}
												if (null == BrowserBean) {
													BrowserBean = browser.searchById(realTempvalue.replace("''", "'"));
												}
												if (BrowserBean != null) {
													String val = BrowserBean.getId();
													String browserSql = browser.getSearchByName();
													if (val == null) {
														tempvalue = CubeCipherUitl.decrypt(tempvalue);
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue.replace(",", "，"));
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue.replace(",", "，") +
																"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
																"+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()) + "<a style='color:red'>" + tempvalue.replace(",", "，") + "</a><br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
														IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue.replace(",", "，") + "</a>" + SystemEnv.getHtmlLabelName(391291, user.getLanguage()) + ":<br/>" + browserSql);
														iserrordata = true;
														tempvalue = "";
													} else {
														tempvalue = val;
													}
												} else {
													tempvalue = CubeCipherUitl.decrypt(tempvalue);
													errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue.replace(",", "，"));
													errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue.replace(",", "，") +
															"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename + "+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()));
													IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue.replace(",", "，") + "</a>:" + SystemEnv.getHtmlLabelName(391293, user.getLanguage()));
													iserrordata = true;
													tempvalue = "";
												}
											}
										} else if (type == 162) { // 自定义多选
											Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(fielddbtype);
											Map<String, String> browserMap = ModeCacheManager.getInstance().getIdByNames(fielddbtype, tempvalue, user.getLanguage());
											if (browserMap.containsKey("ids")) {
												tempvalue = browserMap.get("ids");
											} else {
												//解决浏览框名称为整数，判断有误情况
												String realTempvalue = analyzeNameValue(tempvalue);
												Map resultmap = analyzeIdValue(realTempvalue);
												BrowserBean BrowserBean = null;
												if (!("").equals(resultmap.get("id"))) {
													BrowserBean = browser.searchById2(resultmap.get("id").toString().replace("''", "'"));
												} else {
													BrowserBean = browser.searchForImport2(resultmap.get("name").toString().replace("''", "'"), user);
												}
												if (BrowserBean != null) {
													String tempvaluenew = BrowserBean.getId();
													if (tempvaluenew.indexOf("null") > -1 || StringHelper.isEmpty(tempvalue)) {
														BrowserBean = browser.searchById2(tempvalue);
													}
												}
												if (BrowserBean != null) {
													String browserSql = browser.getSearchByName();
													if (browserSql == null || browserSql.equals("")) {
														browserSql = SystemEnv.getHtmlLabelName(500319, user.getLanguage());
													}
													String[] tempvalues = tempvalue.split(",");
													String old_val = "";
													for (String string : tempvalues) {
														old_val += "," + CubeCipherUitl.decrypt(string);
													}
													if (old_val.startsWith(",")) {
														old_val = old_val.substring(1, old_val.length());
													}
													tempvalue = BrowserBean.getId();
													if (tempvalue.indexOf("null") > -1 || StringHelper.isEmpty(tempvalue)) {
														tempvalue = CubeCipherUitl.decrypt(tempvalue);
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + old_val);
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + old_val +
																"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
																"+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()) + "<a style='color:red'>" + old_val + "</a><br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
														IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + old_val + "</a>" + SystemEnv.getHtmlLabelName(391291, user.getLanguage()) + ":" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
														iserrordata = true;
														tempvalue = "";
													}
												} else {
													tempvalue = CubeCipherUitl.decrypt(tempvalue);
													errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
													errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
															"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename + "+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()));
													IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391293, user.getLanguage()));
													iserrordata = true;
													tempvalue = "";
												}
											}
										}
									} else {
										Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(fielddbtype);
										if (number != null && number.length > 0) {
											int r = ModeCacheManager.getInstance().isContainBrowserIds(fielddbtype, tempvalue, user.getLanguage());
											if (r == -1) { //没有缓存
												for (String num : number) {
													BrowserBean browserBean = browser.searchById(num.trim());
													String browserSql = browser.getSearchByName();
													if (browserBean == null || browserBean.getId() == null) {
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
																"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
																"+<a style='color:red'>" + tempvalue + "</a><br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
														IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a><br>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
														iserrordata = true;
														tempvalue = "";
														break;
													}
												}
											} else if (r == 0) {//存在未找到
												String browserSql = ModeCacheManager.getInstance().getBrowserSql(fielddbtype, tempvalue, user.getLanguage());
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
														"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename + "+" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()) + "!<a style='color:red'>" + tempvalue + "</a><br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
												IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + ":" + SystemEnv.getHtmlLabelName(391272, user.getLanguage()) + "!" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()) + ":<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + browserSql);
												iserrordata = true;
												tempvalue = "";
												break;
											}
										}
									}
								} else if (!isNullValue && (type == 256 || type == 257)) {
									String tempIdStr = "";
									if (!tempvalue.isEmpty()) {
										CustomTreeComInfo comInfo = new CustomTreeComInfo();
										boolean showlevel = "1".equals(comInfo.get(CustomTreeComInfo.showlevel, fielddbtype));
										String levelsplitchar = comInfo.get(CustomTreeComInfo.levelsplitchar, fielddbtype);
										List<Map<String, String>> list = new ArrayList<Map<String, String>>();
										List<Map<String, String>> listBak = new ArrayList<Map<String, String>>();
										if (treeBaseMap.containsKey(fielddbtype)) {
											list = treeBaseMap.get(fielddbtype);
											listBak = treeBaseMap.get("showfield");
										} else {
											String treeSetSql = "select id,sourcefrom,sourceid,tablename,tablekey,showfield,supnode,datacondition,tablesup,supnodefield,nodefield from mode_customtreedetail where mainid=" + fielddbtype;
											recordSet.execute(treeSetSql);
											while (recordSet.next()) {
												Map<String, String> setMap = new HashMap<String, String>();
												Map<String, String> setMapBak = new HashMap<String, String>();
												String nodeid = recordSet.getString("id");//节点id
												String tablename = recordSet.getString("tablename");//表名
												String tablekey = recordSet.getString("tablekey");//主键字段
												String showfield = recordSet.getString("showfield");//显示名称字段
												String datacondition = recordSet.getString("datacondition").trim();//数据显示条件
												//解析树形浏览框 显示条件 的动态参数
												CustomTreeData customTreeData = new CustomTreeData();
												customTreeData.setUser(user);
												datacondition = customTreeData.replaceParam(datacondition);
												datacondition = "1=1";
												String sourcefrom = recordSet.getString("sourcefrom");
												String sourceid = recordSet.getString("sourceid");
												String supnode = recordSet.getString("supnode");
												String tablesup = recordSet.getString("tablesup");
												String supnodefield = recordSet.getString("supnodefield");
												String nodefield = recordSet.getString("nodefield");
												setMap.put("nodeid", nodeid);
												setMap.put("tablename", tablename);
												setMap.put("tablekey", tablekey);
												setMap.put("showfield", showfield);
												setMap.put("datacondition", datacondition);
												setMap.put("sourcefrom", sourcefrom);
												setMap.put("sourceid", sourceid);
												setMap.put("supnode", supnode);
												setMap.put("tablesup", tablesup);
												setMap.put("supnodefield", supnodefield);
												setMap.put("nodefield", nodefield);
												setMapBak.put("showfield", showfield);
												list.add(setMap);
												listBak.add(setMapBak);
											}
											treeBaseMap.put(fielddbtype, list);
											treeBaseMap.put("showfield", listBak);
										}
										String[] nameArray = null;
										if (type == 257) {
											//nameArray = tempvalue.split(",");
											if (tempvalue.indexOf("DH{") != -1) {//批量导入自定义多选或树多选时，如果选项中有英文逗号，批量导入时用DH{}包裹
												String[] tempNumber = tempvalue.split(",");//数组格式：{"xxxx","DH{XXXX","XXXX"?(也许有),"xxx}"},其中DH{}中间包裹的值是自定义多选的一个选项
												List<String> list1 = new ArrayList<String>();
												int i = 0;
												int j = 0;
												while (i < tempNumber.length) {
													if (tempNumber[i].indexOf("DH{") != -1) {
														list1.add(tempNumber[i].substring(3, tempNumber[i].length()) + ",");
														i++;
														boolean flag1 = false;
														while (!flag1) {//判断数组中是否含有
															if (tempNumber[i].indexOf("}") != -1) {
																list1.add(list1.get(j) + tempNumber[i].substring(0, tempNumber[i].length() - 1));
																list1.remove(j);
																i++;
																j++;
																flag1 = true;
															} else {
																list1.add(list1.get(j) + tempNumber[i] + ",");
																list1.remove(j);
																i++;
															}
														}
													} else {
														list1.add(tempNumber[i]);
														i++;
														j++;
													}
												}
												nameArray = list1.toArray(new String[list1.size()]);
											} else {
												nameArray = tempvalue.split(",");
											}

										} else if (type == 256) {
											nameArray = tempvalue.split("weaver_ecology");
										}
										for (int m = 0; m < nameArray.length; m++) {
											String tempName = nameArray[m];
											String treeSql = "";
											if (!tempName.isEmpty()) {
												tempName = tempName.trim();
												//解决浏览框名称为整数，判断有误情况
												String realTempvalue = analyzeNameValue(tempName);
												String tempid = "";
												if (realTempvalue.startsWith("tree_")) {
													String[] valuearr = realTempvalue.split("_");
													if (valuearr.length == 3) {
														for (int n = 0; n < list.size(); n++) {
															Map<String, String> setMap = list.get(n);
															if (setMap.get("nodeid").equals(valuearr[1])) {
																setMap.put("showfield", "id");
															} else {
																continue;
															}
															Map<String, Object> value = impExcelUtil.getTreeValue("", "", setMap, valuearr[2]);
															treeSql = Util.null2String(value.get("sql"));
															if (value.size()>0 && listBak.get(0).size()>0){
																setMap.put("showfield", listBak.get(0).get("showfield"));
															}
															if (!"".equals(Util.null2String(value.get("id")))) {
																if (!tempIdStr.equals("")) {
																	tempIdStr += ",";
																}
																tempid = Util.null2String(value.get("id"));
																tempIdStr += Util.null2String(value.get("id"));
																break;
															}
														}
													}
												} else if (showlevel && realTempvalue.indexOf(levelsplitchar) > 0) {
													Map<String, Object> value = impExcelUtil.importTreeDataAllLevel(list, levelsplitchar, realTempvalue);
													if (!tempIdStr.equals("")) {
														tempIdStr += ",";
													}
													tempid = Util.null2String(value.get("id"));
													tempIdStr += Util.null2String(value.get("id"));
													treeSql = Util.null2String(value.get("sql"));
												} else {
													for (int n = 0; n < list.size(); n++) {
														Map<String, String> setMap = list.get(n);
														Map<String, Object> value = impExcelUtil.getTreeValue("", "", setMap, realTempvalue);
														treeSql = Util.null2String(value.get("sql"));
														if (!"".equals(Util.null2String(value.get("id")))) {
															if (!tempIdStr.equals("")) {
																tempIdStr += ",";
															}
															tempid = Util.null2String(value.get("id"));
															tempIdStr += Util.null2String(value.get("id"));
															break;
														}
													}
												}
												if (tempid.equals("")) {
													// 防止数据的英文加号拆分出错
													tempName = tempName.replace("+", "＋");
													treeSql = treeSql.replace("+", "＋");
													errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempName);
													errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempName +
															"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename + "+<a style='color:red'>" + tempName + "</a>:"
															+ SystemEnv.getHtmlLabelName(391276, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + treeSql);
													IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempName + "</a>:" + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + treeSql + "<br/>" + SystemEnv.getHtmlLabelName(391299, user.getLanguage()));
													iserrordata = true;
													tempIdStr = "";
												}
											}
										}

									}
									tempvalue = tempIdStr.replace("'", "''");
								} else {
									if (!isNumber && !isNullValue) {//非主键值
										rs.executeSql("select tablename,columname,keycolumname from workflow_browserurl where id=" + type);
										if (rs.next()) {
											ArrayList tempvalues = null;
											if (type == 1) {//如果是单人力不分割
												tempvalues = new ArrayList();
												tempvalues.add(tempvalue);
											} else {
												tempvalues = Util.TokenizerString(tempvalue, ",");
											}
											tempvalue = "";
											String keyname = Util.null2String(rs.getString("keycolumname"));
											String tablename = Util.null2String(rs.getString("tablename"));
											String columname = Util.null2String(rs.getString("columname"));
											String columnameCopy = columname;
											String[] realProjectName = CubeUtil.getRealProjectName(tablename, columname);
											tablename = realProjectName[0];
											columname = realProjectName[1];
											columnameCopy = columname;
											String columnameall = "";
											if (tablename.toLowerCase().equals("hrmdepartment") || tablename.toLowerCase().equals("hrmdepartmentallview")) {
												columname = "departmentmark";
												columnameall = "departmentname";
											} else if (tablename.toLowerCase().equals("hrmsubcompanyallview")) {
												columnameall = columname;
												columname = "subcompanydesc";
											}

											//部门及分部封存，人员离职过滤
											String hrmFilterCondiction = "";
											if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompanyallview".equalsIgnoreCase(tablename.toLowerCase())) {
												hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='')";
											} else if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
												hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
											} else if ("crm_customerinfo".equalsIgnoreCase(tablename)) {
												hrmFilterCondiction = " and deleted=0";
											}
											if ((!keyname.equals("") && !tablename.equals("") && !columname.equals("")) || isDepSup) {
												for (int n = 0; n < tempvalues.size(); n++) {
													columname = columnameCopy;
													rs = new RecordSet();
													if (SystemEnv.getHtmlLabelName(16139, user.getLanguage()).equals(Util.null2String(tempvalues.get(n)).trim())) {//系统管理员
														if (tempvalue.equals("")) {
															tempvalue = "1";
														} else {
															tempvalue += "," + "1";
														}
														continue;
													}
													String importValue = Util.null2String(tempvalues.get(n)).trim();

													//添加判断value 是不是id 或者编号
													if (isNumberOrCode(importValue)) {
														hrmFilterCondiction = "";
													}
													String keyValue = importValue;
													if ("hrmresource".equalsIgnoreCase(tablename.toLowerCase()) && importValue.toLowerCase().startsWith("workcode_")) {
														keyValue = keyValue.substring(9);
														columname = "workcode";
													} else if ("hrmdepartment".equalsIgnoreCase(tablename.toLowerCase()) && importValue.toLowerCase().startsWith("deptcode_")) {
														keyValue = keyValue.substring(9);
														keyValue = checkDepartAndSubpany(keyValue);
														columname = "departmentcode";
													} else if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
														if (importValue.startsWith("LZRY_")) {
															keyValue = keyValue.substring(5);
															hrmFilterCondiction = "";//包含LZRY_ 就可以导入所有类型的人员
														} else {
															hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
														}
													} else {
														//解决浏览框名称为整数，判断有误情况
														keyValue = analyzeNameValue(keyValue);
													}
													if (type == 164 || type == 169 || type == 170 || type == 194 || type == 168 || type == 167 || isDepSup) {
														keyValue = checkDepartAndSubpany(keyValue);
													}
													if (!"".equals(keyValue)) {
														if(type==179){
															if (!"".equals(columnameall)) {
																sql = "select " + keyname + " from " + tablename
																		+ " where " + columnameall + " ='" + keyValue
																		+ "'  and isdata=1  order by " + keyname + " desc";
																rs.executeSql(sql);
															}
															if (rs.getCounts()<=0) {
																sql = "select " + keyname + " from " + tablename
																		+ " where " + columname + " ='" + keyValue
																		+ "'  and isdata=1  order by " + keyname + " desc";
																rs.executeSql(sql);
															}
															if (rs.next()) {
																if (tempvalue.equals("")) {
																	tempvalue = rs.getString(1);
																} else {
																	tempvalue += "," + rs.getString(1);
																}
															} else { //先判断下是否是多语言结构
																if (!"".equals(columnameall)) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where (" + columnameall + " like '%"+"`~`7 "+keyValue+"`~`"+"%' or " + columnameall + " like '%"+"`~`8 "+keyValue+"`~`"+"%' or " + columnameall + " like '%"+"`~`9 "+keyValue+"`~`"+"%')"
																			+ "  and isdata=1  order by " + keyname + " desc";
																	rs.executeSql(sql);
																}
																if (rs.getCounts()<=0) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where (" + columname + " like '%"+"`~`7 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`8 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`9 "+keyValue+"`~`"+"%')"
																			+ "  and isdata=1  order by " + keyname + " desc";
																	rs.executeSql(sql);
																}
																if (rs.next()) {
																	if (tempvalue.equals("")) {
																		tempvalue = rs.getString(1);
																	} else {
																		tempvalue += "," + rs.getString(1);
																	}
																} else {
																	sql = "select " + keyname + " from " + tablename
																			+ " where (" + columname + " like '%"+"`~`7 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`8 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`9 "+keyValue+"`~`"+"%' or "+columname+"='"+keyValue+"')"
																			+ "  and isdata=1  order by " + keyname + " desc";
																	errorRow.add(sheetcount + "," + (rows+1) + "," + (col+1) +","+importValue);
																	errorTable.add(sheetcount + "+" + (rows+1) + "+" + (col+1) +"+"+importValue+
																			"+"+fieldlabelname+"+"+fieldname+"+"+fielddbtype+"+"+maintablename+
																			"+<a style='color:red'>"+importValue+"</a>:"+SystemEnv.getHtmlLabelName(391271, user.getLanguage())+"<br/>"+SystemEnv.getHtmlLabelName(132258, user.getLanguage())+":<br/>"+sql);
																	IdMap.put(id+"sql",SystemEnv.getHtmlLabelName(21778, user.getLanguage())+":"+fieldlabelname+"-<a style='color:red'>"+importValue+"</a>:"+"<br/>"+SystemEnv.getHtmlLabelName(132258, user.getLanguage())+":<br/>"+sql+"<br/>"+SystemEnv.getHtmlLabelName(391303, user.getLanguage()));

																	iserrordata = true;
																}
															}
														}else if(type==23){
															if (!"".equals(columnameall)) {
																sql = "select " + keyname + " from " + tablename
																		+ " where " + columnameall + " ='" + keyValue
																		+ "'  and isdata=2  order by " + keyname + " desc";
																//	+ "' "+hrmFilterCondiction+" order by " + keyname + " desc";
																rs.executeSql(sql);
															}
															if (rs.getCounts()<=0) {
																sql = "select " + keyname + " from " + tablename
																		+ " where " + columname + " ='" + keyValue
																		+ "'  and isdata=2  order by " + keyname + " desc";
																//	+ "' "+hrmFilterCondiction+" order by " + keyname + " desc";
																rs.executeSql(sql);
															}
															if (rs.next()) {
																if (tempvalue.equals("")) {
																	tempvalue = rs.getString(1);
																} else {
																	tempvalue += "," + rs.getString(1);
																}
															} else { //先判断下是否是多语言结构
																if (!"".equals(columnameall)) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where (" + columnameall + " like '%"+"`~`7 "+keyValue+"`~`"+"%' or " + columnameall + " like '%"+"`~`8 "+keyValue+"`~`"+"%' or " + columnameall + " like '%"+"`~`9 "+keyValue+"`~`"+"%')"
																			+ "'  and isdata=2  order by " + keyname + " desc";

																	rs.executeSql(sql);
																}
																if (rs.getCounts()<=0) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where (" + columname + " like '%"+"`~`7 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`8 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`9 "+keyValue+"`~`"+"%')"
																			+ "'  and isdata=2  order by " + keyname + " desc";
																	rs.executeSql(sql);
																}
																if (rs.next()) {
																	if (tempvalue.equals("")) {
																		tempvalue = rs.getString(1);
																	} else {
																		tempvalue += "," + rs.getString(1);
																	}
																} else {
																	sql = "select " + keyname + " from " + tablename
																			+ " where ( " + columname + " like '%"+"`~`7 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`8 "+keyValue+"`~`"+"%' or " + columname + " like '%"+"`~`9 "+keyValue+"`~`"+"%' or "+columname+"='"+keyValue+"')"
																			+ "'  and isdata=2  order by " + keyname + " desc";
																	errorRow.add(sheetcount + "," + (rows+1) + "," + (col+1) +","+importValue);
																	errorTable.add(sheetcount + "+" + (rows+1) + "+" + (col+1) +"+"+importValue+
																			"+"+fieldlabelname+"+"+fieldname+"+"+fielddbtype+"+"+maintablename+
																			"+<a style='color:red'>"+importValue+"</a>:"+SystemEnv.getHtmlLabelName(391271, user.getLanguage())+"<br/>"+SystemEnv.getHtmlLabelName(132258, user.getLanguage())+":<br/>"+sql);
																	IdMap.put(id+"sql",SystemEnv.getHtmlLabelName(21778, user.getLanguage())+":"+fieldlabelname+"-<a style='color:red'>"+importValue+"</a>:"+"<br/>"+SystemEnv.getHtmlLabelName(132258, user.getLanguage())+":<br/>"+sql+"<br/>"+SystemEnv.getHtmlLabelName(391303, user.getLanguage()));

																	iserrordata = true;
																}
															}
														}else{
															if (!"".equals(columnameall)) {
																sql = "select " + keyname + " from " + tablename
																		+ " where " + columnameall + " ='" + keyValue
																		+ "' " + hrmFilterCondiction + " order by " + keyname + " desc";
																rs.executeSql(sql);
															}
															if (rs.getCounts() <= 0) {
																sql = "select " + keyname + " from " + tablename
																		+ " where " + columname + " ='" + keyValue
																		+ "' " + hrmFilterCondiction + " order by " + keyname + " desc";
																rs.executeSql(sql);
															}
															if (rs.next()) {
																if (tempvalue.equals("")) {
																	tempvalue = rs.getString(1);
																} else {
																	tempvalue += "," + rs.getString(1);
																}
															} else { //先判断下是否是多语言结构
																if (!"".equals(columnameall)) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where ( " + columnameall + " like '%" + "`~`7 " + keyValue + "`~`" + "%' or " + columnameall + " like '%" + "`~`8 " + keyValue + "`~`" + "%' or " + columnameall + " like '%" + "`~`9 " + keyValue + "`~`" + "%' )"
																			+ " " + hrmFilterCondiction + " order by " + keyname + " desc";
																	rs.executeSql(sql);
																}
																if (rs.getCounts() <= 0) {
																	sql = "select " + keyname + " from " + tablename
																			+ " where (" + columname + " like '%" + "`~`7 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`8 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`9 " + keyValue + "`~`" + "%')"
																			+ " " + hrmFilterCondiction + " order by " + keyname + " desc";
																	rs.executeSql(sql);
																}
																if (rs.next()) {
																	if (tempvalue.equals("")) {
																		tempvalue = rs.getString(1);
																	} else {
																		tempvalue += "," + rs.getString(1);
																	}
																} else {
																	sql = "select " + keyname + " from " + tablename
																			+ " where (" + columname + " like '%" + "`~`7 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`8 " + keyValue + "`~`" + "%' or " + columname + " like '%" + "`~`9 " + keyValue + "`~`" + "%' or " + columname + "='" + keyValue + "')"
																			+ " " + hrmFilterCondiction + " order by " + keyname + " desc";
																	errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + importValue);
																	errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + importValue +
																			"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
																			"+<a style='color:red'>" + importValue + "</a>:" + SystemEnv.getHtmlLabelName(391271, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
																	IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + importValue + "</a>:" + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql + "<br/>" + SystemEnv.getHtmlLabelName(391303, user.getLanguage()));

																	iserrordata = true;
																}
															}
														}
													} else {
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + importValue);
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + importValue +
																"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
																"+<a style='color:red'>" + importValue + "</a>:" + SystemEnv.getHtmlLabelName(391278, user.getLanguage()) + keyValue + SystemEnv.getHtmlLabelName(382055, user.getLanguage()));
														IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + importValue + "</a>:" + SystemEnv.getHtmlLabelName(10000150, user.getLanguage()) + "!" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
														iserrordata = true;
													}
												}
											}
										} else {
											tempvalue = "";
										}
									} else {//浏览按钮ID导入验证
										rs.executeSql("select tablename,columname,keycolumname from workflow_browserurl where id=" + type);
										if (rs.next()) {
											ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
											tempvalue = "";
											String keyname = Util.null2String(rs.getString("keycolumname"));
											String tablename = Util.null2String(rs.getString("tablename"));
											String columname = Util.null2String(rs.getString("columname"));
											String[] realProjectName = CubeUtil.getRealProjectName(tablename, columname);
											tablename = realProjectName[0];
											columname = realProjectName[1];
											if (tablename.toLowerCase().equals("hrmdepartment")) {
												columname = "departmentname";
											}
											//部门及分部封存，人员离职过滤
											String hrmFilterCondiction = "";
											if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompanyallview".equalsIgnoreCase(tablename.toLowerCase())) {
												hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='')";
											} else if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
												hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
											} else if ("crm_customerinfo".equalsIgnoreCase(tablename)) {
												hrmFilterCondiction = " and deleted=0";
											}
											if (!keyname.equals("") && !tablename.equals("") && !columname.equals("")) {
												for (int n = 0; n < tempvalues.size(); n++) {
													String importValue = Util.null2String(tempvalues.get(n)).trim();
													if ("1".equals(Util.null2String(tempvalues.get(n)).trim())) {
														if (tempvalue.equals("")) {
															tempvalue = "1";
														} else {
															tempvalue += "," + "1";
														}
														continue;
													}
													//添加判断value 是不是id 或者编号
													if (isNumberOrCode(((String) tempvalues.get(n)).trim())) {
														hrmFilterCondiction = "";
													}
													if ("HrmResource".equalsIgnoreCase(tablename.toLowerCase())) {
														if (importValue.startsWith("LZRY_")) {
															importValue = importValue.substring(5);
															hrmFilterCondiction = "";//包含LZRY_ 就可以导入所有类型的人员
														} else {
															hrmFilterCondiction = " and (status in(0,1,2,3) or status is null)";
														}
													}
													sql = "select " + keyname + " from " + tablename
															+ " where " + keyname + " ='" + importValue
															+ "' " + hrmFilterCondiction + " order by " + keyname + " desc";
													rs.executeSql(sql);
													if (rs.next()) {
														if (tempvalue.equals("")) {
															tempvalue = rs.getString(1);
														} else {
															tempvalue += "," + rs.getString(1);
														}
													} else {
														errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + ((String) tempvalues.get(n)).trim());
														errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalues.get(n)).trim() +
																"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
																"+<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391271, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
														IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql + "<br/>" + SystemEnv.getHtmlLabelName(391303, user.getLanguage()));
														iserrordata = true;
														//												writeErrorRow();
													}
												}
											}
										} else {
											tempvalue = "";
										}
									}
								}
								if (isDepSup) {  //当>在上面导入出问题时，这里可以继续导入
									String flagStr = "";
									String keyname = "";
									String tablename = "";
									if ((type == 4 || type == 57) || (type == 167 || type == 168)) {
										if (tempvalue.toLowerCase().startsWith("virtual_")) {
											flagStr = "virtual_";
											if (tempvalue.startsWith("VIRTUAL_")) {
												flagStr = "VIRTUAL_";
											}
											keyname = "departmentname";
											tablename = "HrmDepartmentVirtual";
										} else if (tempvalue.startsWith("-")) {
											keyname = "id";
											tablename = "HrmDepartmentVirtual";
										} else if (tempvalue.startsWith("deptcode_")) {
											tablename = "HrmDepartment";
											keyname = "departmentcode";
											if (tempvalue.indexOf("deptcode_") != -1) {
												tempvalue = tempvalue.replace("deptcode_", "");
											} else {
												tempvalue = tempvalue.substring(9);
											}
										} else {
											tablename = "HrmDepartment";
											keyname = "departmentname";
											if (isNumber) {
												keyname = "id";
											}
										}
									} else if ((type == 164 || type == 194) || (type == 170 || type == 169)) {
										if (tempvalue.toLowerCase().startsWith("virtual_")) {
											flagStr = "virtual_";
											if (tempvalue.startsWith("VIRTUAL_")) {
												flagStr = "VIRTUAL_";
											}
											keyname = "subcompanyname";
											tablename = "hrmsubcompanyvirtual";
										} else if (tempvalue.startsWith("-")) {
											keyname = "id";
											tablename = "hrmsubcompanyvirtual";
										} else {
											tablename = "hrmsubcompany";
											keyname = "subcompanyname";
											if (isNumber) {
												keyname = "id";
											}
										}
									}
									//部门及分部封存，人员离职过滤
									String hrmFilterCondiction = "";
									if ("HrmDepartment".equalsIgnoreCase(tablename.toLowerCase()) || "hrmsubcompany".equalsIgnoreCase(tablename.toLowerCase())
											|| "HrmDepartmentVirtual".equalsIgnoreCase(tablename.toLowerCase()) ||
											"hrmsubcompanyvirtual".equalsIgnoreCase(tablename.toLowerCase())) {
										hrmFilterCondiction = " and (canceled!=1 or canceled is null or canceled='')";
									}

									ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
									tempvalue = "";
									String values = "";
									for (int n = 0; n < tempvalues.size(); n++) {
										if (!((String) tempvalues.get(n)).trim().toLowerCase().startsWith(flagStr))
											continue;
										values += ",'" + ((String) tempvalues.get(n)).trim().replace(flagStr, "") + "'";
									}
									if (!StringHelper.isEmpty(values)) {
										values = values.substring(1);
										for (int n = 0; n < tempvalues.size(); n++) {
											String value = ((String) tempvalues.get(n)).trim().replace(flagStr, "");
											value = checkDepartAndSubpany(value);
											if (isNumberOrCode(value)) {
												hrmFilterCondiction = "";
											}
											sql = "select id," + keyname + " as showname from " + tablename + "  where " + keyname + " = '" + value + "'  " + hrmFilterCondiction + " order by id desc";
											rs.executeSql(sql);
											if (!rs.next()) {//判断是否为多语言
												String tempSqlTemp = "select id," + keyname + " as showname from " + tablename +
														" where (" + keyname + " like '%" + "`~`7 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`8 " + value + "`~`" + "%' or " + keyname + " like '%" + "`~`9 " + value + "`~`" + "%')"
														+ hrmFilterCondiction + " order by id desc";
												rs.execute(tempSqlTemp);
											}
											rs.beforFirst();
											boolean isExists = false;
											while (rs.next()) {
												String showname = rs.getString("showname");
												showname = Util.formatMultiLang(showname, user.getLanguage() + "");
												String tempValue = (String) tempvalues.get(n);
												tempValue = checkDepartAndSubpany(tempValue.trim());
												String shownameNew = (flagStr + showname).replace("'", "''");
												if (shownameNew.equals(tempValue)) {
													tempvalue += "," + rs.getString(1);
													isExists = true;
													break;
												}
											}
											if (!isExists) {
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + ((String) tempvalues.get(n)).trim());
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + ((String) tempvalues.get(n)).trim() +
														"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
														"+<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(391271, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
												IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + ((String) tempvalues.get(n)).trim() + "</a>:" + SystemEnv.getHtmlLabelName(127576, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql + "<br/>" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
												iserrordata = true;
											}
										}
										if (tempvalue.startsWith(",")) {
											tempvalue = tempvalue.substring(1);
										}
									}
								}
								//---------------------------提取end-----------------------------

							} else if (htmltype == 4) {
								if (!isNullValue) {
									if (tempvalue.equals("1") || tempvalue.toLowerCase().trim().equals(SystemEnv.getHtmlLabelName(163, user.getLanguage()).toLowerCase().trim())) {
										tempvalue = "1";
									} else if (tempvalue.equals("0") || tempvalue.toLowerCase().trim().equals(SystemEnv.getHtmlLabelName(161, user.getLanguage()).toLowerCase().trim())) {
										tempvalue = "0";
									} else {
										errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
										errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
												"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
												"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391252, user.getLanguage()));
										IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-" + tempvalue + ":" + SystemEnv.getHtmlLabelName(391303, user.getLanguage()));
										iserrordata = true;
//								writeErrorRow();
										tempvalue = "";
									}
								}
							} else if (htmltype == 5) {
								if (!isNullValue) {
									if (type == 2) {
										ArrayList tempvalues = Util.TokenizerString(tempvalue, ",");
										tempvalue = "";
										for (int i = 0; i < tempvalues.size(); i++) {
											sql = "select selectvalue from workflow_selectitem where (selectname='" + ((String) tempvalues.get(i)).trim() + "' or  selectname like '%`~`7 " + ((String) tempvalues.get(i)).trim() + "`~`%' or selectname like '%`~`8 " + ((String) tempvalues.get(i)).trim() + "`~`%' or selectname like '%`~`9 " + ((String) tempvalues.get(i)).trim() + "`~`%') and fieldid=" + fieldid + " and (cancel is null  or cancel = 0)";
											rs.executeSql(sql);
											if (rs.next()) {
												if (tempvalue.equals("")) {
													tempvalue = rs.getString(1);
												} else {
													tempvalue += "," + rs.getString(1);
												}
											} else {
												errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalues.get(i));
												errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalues.get(i) +
														"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
														"+<a style='color:red'>" + tempvalues.get(i) + "</a>:" + SystemEnv.getHtmlLabelName(391279, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
												IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalues.get(i) + "</a><br>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql + "！" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
												iserrordata = true;
											}
										}
									} else {
										if ("seclevel".equals(fieldname)) {//密级字段默认值等于公开 公开默认值为 4（由人力资源定义）
											tempvalue = "4";
										} else {
											List<String> selectvalueList = ModeCacheManager.getInstance().getSelectValByName(fieldid, tempvalue, user.getLanguage());
											if (selectvalueList.size() == 1) {
												tempvalue = selectvalueList.get(0);
											} else {
												sql = "select selectvalue from workflow_selectitem where (selectname='" + tempvalue + "' or  selectname like '%`~`7 " + tempvalue + "`~`%' or selectname like '%`~`8 " + tempvalue + "`~`%' or selectname like '%`~`9 " + tempvalue + "`~`%') and fieldid=" + fieldid + " and (cancel is null  or cancel = 0)";
												rs.executeSql(sql);
												if (rs.next()) {
													tempvalue = rs.getString(1);
												} else {
													errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
													errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
															"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
															"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391279, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql);
													IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a>" + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + sql + "!<br/>" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
													iserrordata = true;
													tempvalue = "";
												}
											}
										}

									}
								}
							} else if (htmltype == 6 && !isNullValue) {
								StringBuffer value = new StringBuffer();
								String[] tempvalues = tempvalue.split(",");
								for (String val : tempvalues) {
									Map<String, String> map = doImportForFileOrImg(val, type);
									if (map.containsKey("errorStr") && !StringHelper.isEmpty(map.get("errorStr"))) {
										errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + val);
										errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + val +
												"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
												"+<a style='color:red'>" + val + "</a>:" + map.get("errorStr") + "<br/>");
										iserrordata = true;
									} else if (!StringHelper.isEmpty(map.get("value"))) {
										value.append(",").append(map.get("value"));
									}
								}
								String valuetemp = value.toString();
								if (!StringHelper.isEmpty(valuetemp) && valuetemp.startsWith(",")) {
									valuetemp = valuetemp.substring(1);
								}
								tempvalue = valuetemp;
							} else if (htmltype == 8 && !isNullValue) {
								SelectItemPageService selectItemPageService = new SelectItemPageService();
								Map<String, Integer> map = selectItemPageService.getTopSelectItemIdByField(Util.getIntValue(fieldid), 1);

								int selectitemid = map.get("selectitemid");
								int level = map.get("level");
								sql = "select id from mode_selectitempagedetail where mainid=" + selectitemid + " and statelev=" + level + " and name='" + tempvalue + "'";
								rs.executeSql(sql);
								if (rs.next()) {
									tempvalue = rs.getString("id");
								} else {
									errorRow.add(sheetcount + "," + (rows + 1) + "," + (col + 1) + "," + tempvalue);
									errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (col + 1) + "+" + tempvalue +
											"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
											"+<a style='color:red'>" + tempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391279, user.getLanguage()) + sql);
									IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + tempvalue + "</a>:" + sql + "!" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
									iserrordata = true;
									tempvalue = "";
								}
							}

							if (!tempvalue.equals("") || isNullValue) {
								if ("5".equals(type + "") && htmltype == 1) {
									//QC:311928 ,如果输入自带分号，那么先去掉分号，转换为double
									if (tempvalue != null && tempvalue.indexOf(",") != -1) {
										tempvalue = tempvalue.replace(",", "");
									}
									tempvalue = Util.toDecimalDigits(tempvalue, qfws);
									tempvalue = Util.milfloatFormat(tempvalue);
								} else if (type == 3 && htmltype == 1) {//浮点数
									int digitsIndex = fielddbtype.indexOf(",");
									int decimaldigits_t = 0;
									if (digitsIndex > -1) {
										decimaldigits_t = Util.getIntValue(fielddbtype.substring(digitsIndex + 1, fielddbtype.length() - 1), 2);
									} else {
										decimaldigits_t = 2;
									}
									if (tempvalue.indexOf(",") != -1) {
										tempvalue = tempvalue.replace(",", "");
									}
									tempvalue = Util.toDecimalDigits(tempvalue + "", decimaldigits_t);
								}
								//tempvalue = Util.toHtmltextarea(tempvalue);
							}
						}
						if (!"".equals(conditionfield) && importtype == 3 && fieldname.equalsIgnoreCase(conditionfield)) {//更新
							conditionFieldValue = tempvalue;
							mainKeyValue = tempvalue;
						}
						if (!"".equals(tempvalue) || isNullValue) {
							updatesql += " " + fieldname + " = ";
							//valueList.add(tempvalue);
							fielddbtype = fielddbtype.toLowerCase();
							tempvalue = isNullValue ? null : InterfacesUtil.getSubStringValue(fielddbtype, tempvalue);
							if (isNullValue) {
								updatesql += tempvalue + ",";
							} else {
								updatesql += "'" + tempvalue + "',";
							}
							/*if (fielddbtype.indexOf("int") != -1 || fielddbtype.indexOf("number") != -1	|| fielddbtype.indexOf("decimal") != -1	|| fielddbtype.indexOf("browser.") != -1) {
								updatesql += "'" + tempvalue + "',";
							} else {
								updatesql += "'" + tempvalue + "',";
							}*/
						}
					}
					//导入时判断字段唯一性
					//由于重复性验证改造为组合验证,非单个字段,这里先记录本行的数据信息,等字段循环完毕再判断是否重复
					if ((!"".equals(keyField) && keyFields.contains(fieldname.toLowerCase()))
							|| (!"".equals(conditionfield) && conditionfield.equalsIgnoreCase(fieldname))) {
						if (htmltype == 1 && (type == 3 || type == 4 || type == 5)) {
							if (tempvalue.indexOf(",") != -1) {
								tempvalue = tempvalue.replace(",", "");
							}
							if (type == 3 && !"".equals(tempvalue)) {
								BigDecimal bigDecimal = new BigDecimal(tempvalue);
								tempvalue = bigDecimal.stripTrailingZeros().toPlainString();
							}
						}
						Map<String, String> rowdataMap = new HashMap<String, String>();
						rowdataMap.put("htmltype", htmltype + "");
						rowdataMap.put("type", type + "");
						rowdataMap.put("tempvalue", tempvalue);
						rowdataMap.put("col", (col + 1) + "");
						rowdataMap.put("oldtempvalue", CubeCipherUitl.decrypt(oldtempvalue));//提示信息需要解密
						rowdataMap.put("fieldlabelname", fieldlabelname);
						rowdataMap.put("fieldname", fieldname);
						rowdataMap.put("fielddbtype", fielddbtype);
						rowdataMap.put("maintablename", maintablename);
						rowdatainfosMap.put(fieldname.toLowerCase(), rowdataMap);
					}
				}
				if (!allisnull) {
//					isnull = true;
				}
				if (importtype == 3) {//更新
					//先判断数据在数据库是否存在
					Map<String, String> rowdatainfo = rowdatainfosMap.get(conditionfield);
					if (rowdatainfo != null) {
						String tempvalue = rowdatainfo.get("tempvalue");//当前要更新的条件字段值
						String col = rowdatainfo.get("col");//当前要更新的条件字段值
						String oldtempvalue = rowdatainfo.get("oldtempvalue");//原始值
						String fieldlabelname = rowdatainfo.get("fieldlabelname");//字段名称
						String fieldname = rowdatainfo.get("fieldname");//字段名
						String fielddbtype = rowdatainfo.get("fielddbtype");//字段类型
						if (!conditionFieldMap.containsKey(tempvalue)) {//如果数据库不存在该值
							if (updateadddata == 1) { //如果选择了追加
								//判断追加是否重复
								Map<String, Object> result = this.judgeExistsOrNot(keyMap, keyField, rowdatainfosMap);
								boolean databaseflag = "true".equals(result.get("isrepeat"));//与数据是否重复
								List<Map<String, String>> repeats = (List<Map<String, String>>) result.get("repeats");//组合验证如果有多个组合,并且都不符合,则要提示多条
								boolean excelflag = false;
								if (!databaseflag) {//与数据没重复,判断与excel中数据有没有重复
									result = this.judgeExistsOrNot(keyMapExcel, keyField, rowdatainfosMap);
									excelflag = "true".equals(result.get("isrepeat"));//与数据是否重复
									repeats = (List<Map<String, String>>) result.get("repeats");
								}
								if (databaseflag) {
									String message = this.putError(sheetcount, rows, maintablename, id, true, repeats);
									iserrordata = true;
									if (!isImportedWithIgnoringError) {
										ImpExcelServer.setProgressCanImport(key, false, message);
										canImport = false;
									}
								} else if (excelflag) {
									String message = this.putError(sheetcount, rows, maintablename, id, false, repeats);
									iserrordata = true;
									if (!isImportedWithIgnoringError) {
										ImpExcelServer.setProgressCanImport(key, false, message);
										canImport = false;
									}
								} else {
									addData2Excel(keyMapExcel, keyField, rowdatainfosMap, rows);
								}
							} else {//提示错误
								errorRow.add(sheetcount + "," + (rows + 1) + "," + col + "," + oldtempvalue + SystemEnv.getHtmlLabelName(132251, user.getLanguage()));
								errorTable.add(sheetcount + "+" + (rows + 1) + "+" + col + "+" + oldtempvalue + SystemEnv.getHtmlLabelName(132251, user.getLanguage()) +
										"+" + fieldlabelname + "+" + fieldname + "+" + fielddbtype + "+" + maintablename +
										"+<a style='color:red'>" + oldtempvalue + "</a>:" + SystemEnv.getHtmlLabelName(132251, user.getLanguage()));
								IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + SystemEnv.getHtmlLabelName(132251, user.getLanguage()) + "!" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
								iserrordata = true;
							}
						}
					} else {
						if (ismainKeyid && updateadddata == 1) {//如果是根据id更新，并且勾选了不满足就追加
							//判断追加是否重复
							Map<String, Object> result = this.judgeExistsOrNot(keyMap, keyField, rowdatainfosMap);
							boolean databaseflag = "true".equals(result.get("isrepeat"));//与数据是否重复
							List<Map<String, String>> repeats = (List<Map<String, String>>) result.get("repeats");//组合验证如果有多个组合,并且都不符合,则要提示多条
							boolean excelflag = false;
							if (!databaseflag) {//与数据没重复,判断与excel中数据有没有重复
								result = this.judgeExistsOrNot(keyMapExcel, keyField, rowdatainfosMap);
								excelflag = "true".equals(result.get("isrepeat"));//与数据是否重复
								repeats = (List<Map<String, String>>) result.get("repeats");
							}
							if (databaseflag) {
								String message = this.putError(sheetcount, rows, maintablename, id, true, repeats);
								iserrordata = true;
								if (!isImportedWithIgnoringError) {
									ImpExcelServer.setProgressCanImport(key, false, message);
									canImport = false;
								}
							} else if (excelflag) {
								String message = this.putError(sheetcount, rows, maintablename, id, false, repeats);
								iserrordata = true;
								if (!isImportedWithIgnoringError) {
									ImpExcelServer.setProgressCanImport(key, false, message);
									canImport = false;
								}
							}
						}
					}
				}
				//字段循环完毕进行重复验证
				if (importtype != 3 && !"".equals(keyField)) {
					//判断数据库是否重复
					Map<String, Object> result = this.judgeExistsOrNot(keyMap, keyField, rowdatainfosMap);
					boolean databaseflag = "true".equals(result.get("isrepeat"));//与数据是否重复
					List<Map<String, String>> repeats = (List<Map<String, String>>) result.get("repeats");//组合验证如果有多个组合,并且都不符合,则要提示多条
					boolean excelflag = false;
					if (!databaseflag) {//与数据没重复,判断与excel中数据有没有重复
						result = this.judgeExistsOrNot(keyMapExcel, keyField, rowdatainfosMap);
						excelflag = "true".equals(result.get("isrepeat"));//与数据是否重复
						repeats = (List<Map<String, String>>) result.get("repeats");
					}
					if (importtype == 1 || importtype == 2) {//追加z
						if (databaseflag) {
							String message = this.putError(sheetcount, rows, maintablename, id, true, repeats);
							iserrordata = true;
							if (!isImportedWithIgnoringError) {
								ImpExcelServer.setProgressCanImport(key, false, message);
								canImport = false;
							}
						} else if (excelflag) {
							String message = this.putError(sheetcount, rows, maintablename, id, false, repeats);
							iserrordata = true;
							if (!isImportedWithIgnoringError) {
								ImpExcelServer.setProgressCanImport(key, false, message);
								canImport = false;
							}
						} else {
							addData2Excel(keyMapExcel, keyField, rowdatainfosMap, rows);
						}
					}
//					else if(importtype==2){ //覆盖
//						if(excelflag){
//							this.putError(sheetcount, rows, maintablename, id, importtype, false, repeats);
//							iserrordata = true;
//							if(!isImportedWithIgnoringError) {
//								ImpExcelServer.setProgressCanImport(key,false,MessageFormat.format(SystemEnv.getHtmlLabelName(132250, user.getLanguage()),sheetIndex,rows,"","",""));
//								canImport=false;
//							}
//						}else{
//							keyMapExcel.put(oldtempvalue, rows+1);
//						}
//					}
				}

				//数据ID列
				String mainKeydata = "";
				if ((mainFieldIds.contains("-1000") || ismainKeyid)) {
					int dataIdCol = mainFieldIds.indexOf("-1000");
					String colName = Util.null2String(POIUtil.getValue(sheet, 0, dataIdCol)).trim();
					if (!SystemEnv.getHtmlLabelName(81287, user.getLanguage()).equals(colName) &&!"Data ID".equals(colName)) {//数据ID
						errorRow.add(sheetcount + "," + (rows + 1) + ",2," + SystemEnv.getHtmlLabelName(132252, user.getLanguage()));
						errorTable.add(sheetcount + "+" + (rows + 1) + "+2+" + SystemEnv.getHtmlLabelName(132252, user.getLanguage()) +
								"+" + SystemEnv.getHtmlLabelName(81287, user.getLanguage()) + "+id+int+" + maintablename + "+" + colName + ":" + SystemEnv.getHtmlLabelName(503401, user.getLanguage()));//数据ID,不是数据ID字段！
						IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(132252, user.getLanguage()) + "！" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
						iserrordata = true;
						if (!isImportedWithIgnoringError) {
							ImpExcelServer.setProgressCanImport(key, false, MessageFormat.format(SystemEnv.getHtmlLabelName(132253, user.getLanguage()), sheetIndex, rows));
							canImport = false;
						}
					} else {
						mainKeydata = Util.null2String(POIUtil.getValue(sheet, rows, dataIdCol)).trim();
						if (!"".equals(mainKeydata) && importtype == 3 && ismainKeyid) {
							isnull = false;
							Pattern pattern = Pattern.compile("^(-)?[1-9][0-9]*$"); //验证正数或负数
							Matcher isNum = pattern.matcher(mainKeydata.trim());
							if (!isNum.matches()) {//非数字
								errorRow.add(sheetcount + "," + (rows + 1) + "," + dataIdCol + "," + SystemEnv.getHtmlLabelName(132254, user.getLanguage()) + "！");
								errorTable.add(sheetcount + "+" + (rows + 1) + "+" + dataIdCol + "+" + SystemEnv.getHtmlLabelName(132254, user.getLanguage()) + "！" +
										"+" + SystemEnv.getHtmlLabelName(81287, user.getLanguage()) + "+id+int+" + maintablename + "+" + dataIdCol + ":" + SystemEnv.getHtmlLabelName(503402, user.getLanguage()));//数据ID,非整数，校验主键有误
								IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(132254, user.getLanguage()) + "！" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
								iserrordata = true;
							}
							if (!conditionFieldMap.containsKey(mainKeydata) && updateadddata != 1) {//当根据数据id更新的时候，表中没有该id且没有勾选追加
								errorRow.add(sheetcount + "," + (rows + 1) + "," + dataIdCol + "," + mainKeydata + SystemEnv.getHtmlLabelName(132251, user.getLanguage()));
								errorTable.add(sheetcount + "+" + (rows + 1) + "+" + dataIdCol + "+" + mainKeydata + SystemEnv.getHtmlLabelName(132251, user.getLanguage()) +
										"+" + SystemEnv.getHtmlLabelName(81287, user.getLanguage()) + "+" + "id" + "+" + "int" + "+" + maintablename +
										"+<a style='color:red'>" + mainKeydata + "</a>:" + SystemEnv.getHtmlLabelName(132251, user.getLanguage()));
								IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + "dataid" + SystemEnv.getHtmlLabelName(132251, user.getLanguage()) + "!" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
								iserrordata = true;
							}
						} else if ("".equals(mainKeydata) && importtype == 3 && ismainKeyid) {
							if (!isnull) {
								errorRow.add(sheetcount + "," + (rows + 1) + "," + dataIdCol + "," + SystemEnv.getHtmlLabelName(132255, user.getLanguage()) + "！");
								errorTable.add(sheetcount + "+" + (rows + 1) + "+" + dataIdCol + "+" + SystemEnv.getHtmlLabelName(132255, user.getLanguage()) + "！" +
										"+" + SystemEnv.getHtmlLabelName(81287, user.getLanguage()) + "+id+int+" + maintablename + "+" + dataIdCol + ":" + SystemEnv.getHtmlLabelName(503403, user.getLanguage()));//数据ID,校验主键有误，数据ID为空
								IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(132255, user.getLanguage()) + "！" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
								iserrordata = true;
							}
						}
					}
				}
				//创建人列
				String modedatacreater = "";
				if (mainFieldIds.contains("-1001")) {
					int creatorCol = mainFieldIds.indexOf("-1001");
					modedatacreater = Util.null2String(POIUtil.getValue(sheet, rows, creatorCol)).trim();
					//判断是否为空
					if (!"".equals(modedatacreater)) {
						isnull = false;
						Pattern pattern = Pattern.compile("^(-)?[1-9][0-9]*$"); //验证正数或负数
						Matcher isNum = pattern.matcher(modedatacreater.trim());
						if (!isNum.matches()) {//非数字 进行ID获取
							if (modedatacreater.indexOf(">") > -1) {//如果人员里面有> 代表逐级导入
								ArrayList tempvalues = Util.TokenizerString(modedatacreater, ",");
								String temps = "";
								for (int n = 0; n < tempvalues.size(); n++) {
									String temp = Util.null2String(tempvalues.get(n));
									Map<String, String> tempvalueMap = getIdByPathName(2, temp);
									if (Util.null2String(tempvalueMap.get("flag")).equals("0")) {
										temp = tempvalueMap.get("value");
									} else {
										errorRow.add(sheetcount + "," + (rows + 1) + "," + creatorCol + "," + modedatacreater + SystemEnv.getHtmlLabelName(132256, user.getLanguage()));
										errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (creatorCol + 1) + "+" + modedatacreater + SystemEnv.getHtmlLabelName(132256, user.getLanguage()) +
												"+" + SystemEnv.getHtmlLabelName(125357, user.getLanguage()) + "+modedatacreater+int" + "+" + maintablename + "+<a style='color:red'>" + modedatacreater + "</a>:" + SystemEnv.getHtmlLabelName(503404, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + "select id from hrmresource where lastname='" + temp + "' and departmentid=0");//创建人,在人力资源未找到值
										IdMap.put(id + "sql", "<a style='color:red'>" + modedatacreater + "</a>:" + SystemEnv.getHtmlLabelName(132256, user.getLanguage()) + "!");
										iserrordata = true;
									}
									temps += "," + temp;
								}
								if (temps.length() > 0) {
									temps = temps.substring(1);
								}
								modedatacreater = temps;
							} else {
								String hrmSql = "select id from HrmResource where ";
								if (modedatacreater.toLowerCase().startsWith("workcode_")) {
									modedatacreater = modedatacreater.substring(9);
									hrmSql = "select id from HrmResource where workcode='" + modedatacreater + "' order by id desc";
								} else {
									hrmSql = "select id from HrmResource where lastname='" + modedatacreater + "'";
								}
								recordSet.execute(hrmSql);
								if (recordSet.next()) {
									modedatacreater = Util.null2String(recordSet.getString("id"));
								} else {
									errorRow.add(sheetcount + "," + (rows + 1) + "," + creatorCol + "," + modedatacreater + SystemEnv.getHtmlLabelName(132256, user.getLanguage()));
									errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (creatorCol + 1) + "+" + modedatacreater + SystemEnv.getHtmlLabelName(132256, user.getLanguage()) +
											"+" + SystemEnv.getHtmlLabelName(125357, user.getLanguage()) + "+modedatacreater+int" + "+" + maintablename + "+<a style='color:red'>" + modedatacreater + "</a>:" + SystemEnv.getHtmlLabelName(503404, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + hrmSql);//创建人,在人力资源未找到值
									IdMap.put(id + "sql", "<a style='color:red'>" + modedatacreater + "</a>:" + SystemEnv.getHtmlLabelName(132256, user.getLanguage()) + "!");
									iserrordata = true;
								}
							}
						}
						updatesql += " modedatacreater = '" + modedatacreater + "',";
						//valueList.add(modedatacreater);
					} else {
						if (!isnull && importtype != 3) {
							modedatacreater = user.getUID() + "";
							updatesql += " modedatacreater = '" + modedatacreater + "',";
							//valueList.add(modedatacreater);
						}
					}
				}
				//创建日期时间列
				if (mainFieldIds.contains("-1002")) {
					int creatDateCol = mainFieldIds.indexOf("-1002");
					//判断是否为空
					Cell cell = POIUtil.getCell(sheet, rows, creatDateCol);
					String checkvalue = Util.null2String(POIUtil.getValue(sheet, rows, creatDateCol)).trim();
					checkvalue = ImpExcelUtil.getDateOrTime(cell, checkvalue, 2);
					if (checkvalue.startsWith("#@ERROR@#")) {
						checkvalue = checkvalue.replace("#@ERROR@#", "");
						errorRow.add(sheetcount + "," + (rows + 1) + "," + (creatDateCol) + "," + checkvalue + "," + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));
						errorTable.add(sheetcount + "+" + (rows + 1) + "+" + (creatDateCol + 1) + "+" + checkvalue + "+" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) +
								"+" + SystemEnv.getHtmlLabelName(722, user.getLanguage()) + "+modedatacreatedate+varchar(2000)+" + maintablename + "+<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()));//创建日期
						IdMap.put(id + "sql", "<a style='color:red'>" + checkvalue + "</a>:" + SystemEnv.getHtmlLabelName(24944, user.getLanguage()) + "!" + SystemEnv.getHtmlLabelName(391286, user.getLanguage()));
						iserrordata = true;
						checkvalue = "";
					} else if (!StringHelper.isEmpty(checkvalue)) {
						isnull = false;
						updatesql += " modedatacreatedate = '" + checkvalue + "',";
						//valueList.add(checkvalue);
					}
				}

				if (isHaveModedatastatus) {
					updatesql += " modedatastatus = '0',";
				}

				Map<String, Object> oldData = new HashMap<String, Object>();
				if (!isnull && !iserrordata && rowCanImport) {
					if (importtype == 1 || importtype == 2) {//追加或覆盖
						int billid = getMainId(maintablename, modeid, user.getUID(), user.getType());
						//插入formbizid
						String formBizId = ShardingActionHelper.constructBizId(billid, formid);
						rs.executeUpdate(String.format("update %s set form_biz_id = '%s' where id = %d", maintablename, formBizId, billid));
						if (needlogFieldList.size() > 0) {
							oldData = formInfoService.getTableData(tableName, billid, columnNames);
						}
						if (updatesql.trim().endsWith(" set") || !allisnull) {
							flagMsg = SystemEnv.getHtmlLabelName(514873, user.getLanguage());
							flag = false;
						} else {
							updatesql = updatesql.substring(0, updatesql.length() - 1);
							updatesql += " where id = " + billid;
							//valueList.add(billid);
							flag = rs.executeSql(updatesql);
							if (!flag) {
								writeLog(updatesql);
								flagMsg = SystemEnv.getHtmlLabelName(132258, user.getLanguage());
							}
						}
						//添加置顶计算逻辑 formid billid

						String formId = formid + "";
						int classprotect =0;
						try{
							String sqlp = "select classprotect from modeinfo where id =?";
							rs.executeQuery(sqlp,modeid);
							if(rs.next()){
								classprotect=rs.getInt("classprotect");
							}
						}catch (Exception e){
							e.printStackTrace();
						}
						if (flag && classprotect==1) {

							SaveConditionUtil.buildTopDataForExcelImport(billid, maintablename, formId, modeid);

							// 添加 密级逻辑
							Map<String, Object> params = new HashMap<>();
							params.put("billid", billid + "");
							params.put("billtablename", maintablename);
							params.put("formId", formId);
							params.put("formmodeid", modeid);
							params.put("userId", user.getUID());
							AddSeclevelUtil addSeclevelUtil = new AddSeclevelUtil();
							addSeclevelUtil.updateSeclevelForImport(params);

						}

						if (billid <= 0) {
							flag = false;
							flagMsg = SystemEnv.getHtmlLabelName(132259, user.getLanguage());
						}

						if (flag) {//更新成功，则记录当前数据
							//-----记录增加删除------
							billList.add(String.valueOf(billid));
							creatoridMap.put(String.valueOf(billid), modedatacreater);
							addBillIdList.add(billid + "");
							IdMap.put(id, String.valueOf(billid));
							//CodeBuild codeBuild = new CodeBuild(modeid);
							//String codeStr = codeBuild.getModeCodeStr(formid,billid);//生成编号

							//权限统一放在主表以及子表数据全部添加完毕后生成---子表字段也支持权限
							//ModeRightInfo ModeRightInfo = new ModeRightInfo();
							//ModeRightInfo.editModeDataShare(user.getUID(),modeid,billid);//新建的时候添加共享
							if (!isdetailright) {//如果权限与明细表无关,则现在生成权限
								int creatorid = Util.getIntValue(modedatacreater);
								if (creatorid == -1) {
									creatorid = user.getUID();
								}
								ExpExcelUtil.getInstance().getAsynimpPool().submit(new ImpAsynTask(ImpAsynTask.TASK_RIGHT, billid, modeid, creatorid));
							}
							//------------记录新建日志----------------
							String operatedesc = SystemEnv.getHtmlLabelName(125682, user.getLanguage());//新建（导入追加）
							int htmllabelindex = 125682;

							String operatetype = "1";//操作的类型： 1：新建 2：修改 3：删除 4：查看
							if (importtype == 2) {
								operatedesc = SystemEnv.getHtmlLabelName(125683, user.getLanguage());//新建（导入覆盖）
								htmllabelindex = 125683;
							}

							Map<String, Object> nowData = new HashMap<String, Object>();
							if (needlogFieldList.size() > 0) {
								nowData = formInfoService.getTableData(tableName, billid, columnNames);
							}
							writeBeatchLog(modeid, operatedesc, operatetype, billid, needlogFieldList, oldData, nowData, htmllabelindex);
							//------------记录新建日志----------------
						} else {//更新失败，删除当前数据
							IdMap.put(id + "sql", updatesql);
							sql = "delete from " + maintablename + " where id = " + billid;
							rs.executeSql(sql);
						}
					} else if (importtype == 3) {//更新
						List<String> billids = new ArrayList<String>();
						boolean isInsert = false;
						if (!ismainKeyid) {
							String billidstr = getMapValue(conditionFieldMap, conditionFieldValue);
							if (billidstr != null && !"".equals(billidstr)) {
								for (String billid : billidstr.split(",")) {
									if (!"".equals(billid)) {
										billids.add(billid);
									}
								}
							}
						} else {
							if (updateadddata == 1) { //如果选择了追加
								String billidstr = getMapValue(conditionFieldMap, mainKeydata);
								if (billidstr != null && !"".equals(billidstr)) {
									for (String billid : billidstr.split(",")) {
										if (!"".equals(billid)) {
											billids.add(billid);
										}
									}
								}
							} else {
								billids.add(mainKeydata);
								//billids.add( "'"+mainKeydata+"'");
							}
						}
						if (updateadddata == 1 && billids.size() <= 0) {
							isInsert = true;
						}

						if (isInsert) {
							int newBillid = getMainId(maintablename, modeid, user.getUID(), user.getType());
							//插入formbizid
							String formBizId = ShardingActionHelper.constructBizId(newBillid, formid);
							rs.executeUpdate(String.format("update %s set form_biz_id = '%s' where id = %d", maintablename , formBizId, newBillid));
							if (needlogFieldList.size() > 0) {
								oldData = formInfoService.getTableData(tableName, newBillid, columnNames);
							}
							updatesql = updatesql.substring(0, updatesql.length() - 1);
							updatesql += " where id = " + newBillid;
							//valueList.add(newBillid);
							if (rowCanImport) {
								flag = rs.executeSql(updatesql);
								if (!flag) {
									writeLog(updatesql);
									flagMsg = SystemEnv.getHtmlLabelName(132258, user.getLanguage());
								}
							}
							if (newBillid <= 0) {
								flag = false;
								flagMsg = SystemEnv.getHtmlLabelName(132260, user.getLanguage());
							}
							if (flag) { //更新成功，则记录当前数据
								conditionFieldMap.put(conditionFieldValue, newBillid + "");
								//-----记录增加删除------
								addBillIdList.add(String.valueOf(newBillid));
								billList.add(String.valueOf(newBillid));
								creatoridMap.put(String.valueOf(newBillid), modedatacreater);
								IdMap.put(id, newBillid);
								Map<String, Object> nowData = new HashMap<String, Object>();
								if (needlogFieldList.size() > 0) {
									nowData = formInfoService.getTableData(tableName, newBillid, columnNames);
								}
								if (!isdetailright) {//如果权限与明细表无关,则现在生成权限
									int creatorid = Util.getIntValue(modedatacreater);
									if (creatorid == -1) {
										creatorid = user.getUID();
									}
									ExpExcelUtil.getInstance().getAsynimpPool().submit(new ImpAsynTask(ImpAsynTask.TASK_RIGHT, newBillid, modeid, creatorid));
								}
								//------------记录新建日志----------------
								String operatedesc = SystemEnv.getHtmlLabelName(125684, user.getLanguage());//新建（导入更新追加）
								int htmllabelindex = 125684;
								String operatetype = "1";//操作的类型： 1：新建 2：修改 3：删除 4：查看
								writeBeatchLog(modeid, operatedesc, operatetype, newBillid, needlogFieldList, oldData, nowData, htmllabelindex);
								//------------记录新建日志----------------
							} else {
								IdMap.put(id + "sql", updatesql);
							}
						} else {
							Map<String, Map<String, Object>> oldDatas = new HashMap<String, Map<String, Object>>();
							if (needlogFieldList.size() > 0) {
								if (columnNames == null || columnNames.trim().equals("")) {
									columnNames = "*";
								}
								if (columnNames.lastIndexOf(",") == columnNames.length() - 1) {
									columnNames = columnNames.substring(0, columnNames.lastIndexOf(","));
								}
								String ids = billids.stream().collect(Collectors.joining(",")).replaceAll("'", "");
								sql = "select id," + columnNames + " from " + tableName + " where id  in (" + ids + ")";
								oldDatas = new BaseDao().getResultMapByMap(sql, "id");
							}
							updatesql = updatesql.substring(0, updatesql.length() - 1);
							String sqlwhere = "";
							if (!"".equals(conditionfield) && !"dataid".equals(conditionfield)) {
								//数据库字段类型若为text 则转为 varchar(max)进行判断
								if ("text".equals(conditionfielddbType)) {
									sqlwhere = " where cast( " + conditionfield + " as varchar(max)) = " + " '" + mainKeyValue + "'";
									//valueList.add(mainKeyValue);
									//数据库字段类型若为clob 则转为 varchar进行判断
								} else if ("clob".equals(conditionfielddbType)) {
									sqlwhere = " where to_char( " + conditionfield + " ) = " + " '" + mainKeyValue + "'";
									//valueList.add(mainKeyValue);
								} else {
									sqlwhere = " where " + conditionfield + " = " + " '" + mainKeyValue + "'";
									//valueList.add(mainKeyValue);
								}
							} else {
								//这种情况,billids应该只有一个
								sqlwhere = " where id = " + billids.get(0);
								//valueList.add(billids.get(0));
							}
							updatesql += sqlwhere;
							if (rowCanImport) {
								flag = rs.executeSql(updatesql);
								if (!flag) {
									writeLog(updatesql);
//									errorTable.add(updatesql);
									errorTable.add(sheetcount + "+" + (rows + 1) + "+" + "" + "+" + "" +  //导入更新时，如果存在行只有id时的处理
											"+" + "" + "+" + "" + "+" + "" + "+" + maintablename +
											"+<a style='color:red'>" + "" + "</a>" + SystemEnv.getHtmlLabelName(514873, user.getLanguage()) + "<br/>" + SystemEnv.getHtmlLabelName(132258, user.getLanguage()) + ":<br/>" + updatesql);
									IdMap.put(id + "sql", updatesql);
									flagMsg = SystemEnv.getHtmlLabelName(132258, user.getLanguage());
								} else {
									setDataBaseValue(keyField, maintablename, keyMap, sqlwhere);
								}
							}
							if (flag) {
								for (String billid : billids) {
									oldData = oldDatas.get(billid.replaceAll("'", ""));
									//-----记录增加删除------
									updateList.add(String.valueOf(billid));
									//添加置顶计算逻辑
									String formId = formid + "";
									int billidInt = Util.getIntValue(billid);
									SaveConditionUtil.buildTopDataForExcelUpdate(billidInt, maintablename, formId, modeid);
									
									/**
									 * qc1769430。解决批量导入更新，创建人为空时，会用当前登陆人覆盖之前的创建人的权限。
									 * */
									RecordSet rscr = new RecordSet();
									String sqlStr2 = "select modedatacreater from " + maintablename + " where id = " + billid;
									rscr.execute(sqlStr2);
									String modedatacreaterNew = "";
									if(rscr.next()){
										modedatacreaterNew = rscr.getString("modedatacreater");
									}
									if (modedatacreater == null || modedatacreater == ""){
										modedatacreater =modedatacreaterNew;
									}
									
									billList.add(String.valueOf(billid).replaceAll("'", ""));
									if (!isdetailright) {//如果权限与明细表无关,则现在生成权限
										int creatorid = Util.getIntValue(modedatacreater);
										if (creatorid == -1) {
											creatorid = user.getUID();
										}
										ExpExcelUtil.getInstance().getAsynimpPool().submit(new ImpAsynTask(ImpAsynTask.TASK_RIGHT, Util.getIntValue(billid.replaceAll("'", "")), modeid, creatorid));
									}
									creatoridMap.put(String.valueOf(billid).replaceAll("'", ""), modedatacreater);
									if (IdMap.containsKey(id)) {
										IdMap.put(id, IdMap.get(id) + "," + String.valueOf(billid).replaceAll("'", ""));
									} else {
										IdMap.put(id, String.valueOf(billid).replaceAll("'", ""));
									}
								}
								Map<String, Map<String, Object>> nowDatas = new HashMap<String, Map<String, Object>>();
								if (needlogFieldList.size() > 0) {
									if (columnNames == null || columnNames.trim().equals("")) {
										columnNames = "*";
									}
									if (columnNames.lastIndexOf(",") == columnNames.length() - 1) {
										columnNames = columnNames.substring(0, columnNames.lastIndexOf(","));
									}
									String ids = billids.stream().collect(Collectors.joining(",")).replaceAll("'", "");
									sql = "select id," + columnNames + " from " + tableName + " where id  in (" + ids + ")";
									nowDatas = new BaseDao().getResultMapByMap(sql, "id");
								}
								//------------记录日志----------------
								String operatedesc = SystemEnv.getHtmlLabelName(125699, user.getLanguage());// 修改（导入更新）
								String operatetype = "2";//操作的类型： 1：新建 2：修改 3：删除 4：查看
								int htmllabelindex = 125699;
								//	writeBeatchLog(modeid,operatedesc, operatetype, billids,needlogFieldList,oldDatas,nowDatas);
								writeBeatchLog(modeid, operatedesc, operatetype, billids, needlogFieldList, oldDatas, nowDatas, htmllabelindex);
							}
						}
					}
				}

				//插入数据
				if ((!isnull && (!flag)) || iserrordata) {
					if (!"".equals(flagMsg)) {
						flagMsg = "~~weaverSplit~~" + flagMsg;
					}
					errorRow.add(sheetcount + "," + (rows + 1) + flagMsg);
					errorRowList.add(rows);
				}

				if (isnull) {
					ImpExcelServer.setProgressCanImport(key, false, MessageFormat.format(SystemEnv.getHtmlLabelName(132261, user.getLanguage()), sheetIndex, rows));
					canImport = false;
					if (!rowCanImport) {
						errorRow.removeAll(indexList);
						errorTable.removeAll(indexList);
					}
				}

				rows++;
			}
			IdMap.put("billList", billList);
			IdMap.put("creatoridMap", creatoridMap);
			IdMap.put("addBillIdList", addBillIdList);
		} catch (Exception e) {
			writeLog("导入主表异常 modeId=" + modeid + " formid=" + formid + " Exception : " + e);
			writeLog(e);
			Errmsg = SystemEnv.getHtmlLabelName(27593, user.getLanguage()) + e.getMessage() + "!\\n";
		} finally {
			doneSignal.countDown();
		}

	}

	/**
	 * 设置数据库数据,用于判断与数据库数据是否重复
	 *
	 * @param keyField
	 * @param maintablename
	 * @param keyMap
	 * @param sqlwhere      全部就传null
	 */
	private void setDataBaseValue(String keyField, String maintablename,
								  Map<String, Map<String, String>> keyMap, String sqlwhere) {
		RecordSet rs = new RecordSet();
		String sql;
		if (!"".equals(keyField) && !"dataid".equals(keyField)) {
			String[] arr1 = keyField.split("\\|");
			for (String arr : arr1) {
				sql = "select id," + arr + " from " + maintablename;
				if (sqlwhere != null && !"".equals(sqlwhere)) {
					sql += sqlwhere;
				}
				rs.execute(sql);
				String[] arr2 = arr.split(",");
				Map<String, String> groupMap = new HashMap<String, String>();
				if (keyMap.containsKey(arr)) {
					groupMap = keyMap.get(arr);
				}
				while (rs.next()) {
					String endvalue = "";
					for (String field : arr2) {
						String value = Util.null2String(rs.getString(field));
						value = value.trim();//去除两头的空格防止导入重复校验出错
						endvalue += value + Util.getSeparator();
					}
					endvalue = endvalue.replaceAll(Util.getSeparator() + "$", "");
					groupMap.put(endvalue, rs.getString("id"));
				}
				keyMap.put(arr, groupMap);
			}
		}
	}


	/**
	 * 将组合的重复验证字段转换为list集合  like  wb1,wb2|fds,wb3
	 *
	 * @param keyfield
	 * @return
	 */
	private List<String> getKeyFields(String keyfield) {
		List<String> list = new ArrayList<String>();
		if (!"".equals(keyfield)) {
			String[] arr1 = keyfield.split("\\|");
			for (String arr : arr1) {
				String[] arr2 = arr.split(",");
				for (String field : arr2) {
					field = field.toLowerCase();
					if (!"".equals(field) && !list.contains(field)) {
						list.add(field);
					}
				}
			}
		}
		return list;
	}


	/**
	 * 正则表达式字段校验
	 *
	 * @param fieldid
	 * @param value
	 * @return
	 */
	public boolean checkDataByExpression(String fieldid, String value) {
		if (Util.null2String(value).equals("")) {
			return true;
		} else if (checkMap.containsKey(fieldid)) {
			String expression = checkMap.get(fieldid);
			Pattern pattern = Pattern.compile(expression);
			Matcher matcher = pattern.matcher(value);
			boolean bool = matcher.find();
			return bool;
		}
		return true;
	}

	/**
	 * 解析浏览框名称的值：如果为name_整数，则去掉name_前缀
	 *
	 * @param nameValue
	 * @return
	 */
	public String analyzeNameValue(String nameValue) {
		if (nameValue == null || "".equals(nameValue)) return "";
		String realNameValue = "";
		String[] nameValues = nameValue.split(",");
		Pattern pattern = Pattern.compile("^(-)?[1-9][0-9]*$"); //验证正数或负数
		if (nameValues.length > 0) {
			for (String value : nameValues) {
				//value = value.trim();
				if (value.toLowerCase().startsWith("name_")) {
					String realValue = value.substring("name_".length());
					Matcher isNum = pattern.matcher(realValue);
					if (isNum.matches()) {
						realNameValue += realValue + ",";
					} else {
						realNameValue += value + ",";
					}
				} else {
					realNameValue += value + ",";
				}
			}
		}
		if (realNameValue.length() > 0) {
			if (nameValue.endsWith(",")) {
				realNameValue = realNameValue.substring(0, realNameValue.length());
			} else {
				realNameValue = realNameValue.substring(0, realNameValue.length() - 1);
			}

		}
		return realNameValue;
	}

	/**
	 * 解析浏览框id的值：如果为key_非整数，则去掉key_前缀
	 *
	 * @param id
	 * @return
	 */
	public Map analyzeIdValue(String id) {
		HashMap resultMap = new HashMap();
		if (id == null || "".equals(id)) return resultMap;
		String realNameValue = "";
		String realIdValue = "";
		String[] idValues = id.split(",");
		if (idValues.length > 0) {
			for (String value : idValues) {
				//value = value.trim();
				if (value.toLowerCase().startsWith("key_")) {
					String realValue = value.substring("key_".length());
					realIdValue += realValue + ",";
				} else {
					realNameValue += value + ",";
				}
			}
		}

		if (realNameValue.length() > 0) {
			if (id.endsWith(",")) {
				realNameValue = realNameValue.substring(0, realNameValue.length());
			} else {
				realNameValue = realNameValue.substring(0, realNameValue.length() - 1);
			}

		}

		if (realIdValue.length() > 0) {
			if (id.endsWith(",")) {
				realIdValue = realIdValue.substring(0, realIdValue.length());
			} else {
				realIdValue = realIdValue.substring(0, realIdValue.length() - 1);
			}
		}
		resultMap.put("id", realIdValue);
		resultMap.put("name", realNameValue);
		return resultMap;
	}

	/**
	 * 错误信息加入
	 *
	 * @param sheetcount    表格索引
	 * @param rows          行号
	 * @param maintablename 主表名
	 * @param id
	 * @param isdatabase    是否是与数据库数据重复(否则是excel重复)
	 * @param repeats
	 */
	private String putError(int sheetcount, int rows, String maintablename, String id, Boolean isdatabase,
							List<Map<String, String>> repeats) {
		String message = "";
		for (Map<String, String> result : repeats) {
			String col = result.get("col");
			String oldtempvalue = result.get("oldtempvalue");
			String fieldlabelname = result.get("fieldlabelname");
			String fieldname = result.get("fieldname");
			String fielddbtype = result.get("fielddbtype");
			String msg = result.get("msg");
			String msgdetail = result.get("msgdetail");
			String tablefield = result.get("tablefield");
			String hisrows = result.get("rows");
			if (isdatabase) {//数据库重复
				errorRow.add(sheetcount + "," + (rows + 1) + "," + col + "," + msg + "," + SystemEnv.getHtmlLabelName(24943, user.getLanguage()));
				errorTable.add(sheetcount + "+" + (rows + 1) + "+" + col + "+" + msg + "+" + SystemEnv.getHtmlLabelName(24943, user.getLanguage()) +
						"+" + Util.getSeparator() + "+" + Util.getSeparator() + "+" + tablefield + "+" + maintablename +
						"+" + msgdetail + SystemEnv.getHtmlLabelName(24943, user.getLanguage()));
				IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + oldtempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391309, user.getLanguage()));
				message += MessageFormat.format(SystemEnv.getHtmlLabelName(132248, user.getLanguage()), sheetIndex, rows, col, msg) + "<br/>";
			} else {//excel重复
				errorRow.add(sheetcount + "," + (rows + 1) + "," + col + "," + msg + "," + MessageFormat.format(SystemEnv.getHtmlLabelName(132249, user.getLanguage()), hisrows));
				errorTable.add(sheetcount + "+" + (rows + 1) + "+" + col + "+" + msg + "+" + MessageFormat.format(SystemEnv.getHtmlLabelName(132249, user.getLanguage()), hisrows) +
						"+" + Util.getSeparator() + "+" + Util.getSeparator() + "+" + tablefield + "+" + maintablename +
						"+" + msgdetail + MessageFormat.format(SystemEnv.getHtmlLabelName(132249, user.getLanguage()), hisrows));
				IdMap.put(id + "sql", SystemEnv.getHtmlLabelName(21778, user.getLanguage()) + ":" + fieldlabelname + "-<a style='color:red'>" + oldtempvalue + "</a>:" + SystemEnv.getHtmlLabelName(391309, user.getLanguage()));
				message += MessageFormat.format(SystemEnv.getHtmlLabelName(132250, user.getLanguage()), sheetIndex, rows, col, msg, hisrows) + "<br/>";
			}
		}
		message = message.replaceAll("<br/>$", "");
		return message;
	}

	/**
	 * 记录导入的excel数据,用于判断下面的数据是否和excel中的数据重复
	 *
	 * @param keyMapExcel     记录已导入的excell数据
	 * @param keyfield        组合验证
	 * @param rowdatainfosMap 要加入的行信息
	 */
	private void addData2Excel(Map<String, Map<String, String>> keyMapExcel, String keyfield, Map<String, Map<String, String>> rowdatainfosMap, int rows) {
		if (keyfield == null || "".equals(keyfield)) {
			return;
		}
		String[] arr1 = keyfield.split("\\|");
		for (String arr : arr1) {
			Map<String, String> groupMap = new HashMap<String, String>();
			if (keyMapExcel.containsKey(arr)) {
				groupMap = keyMapExcel.get(arr);
			}
			String[] arr2 = arr.split(",");
			String endvalue = "";
			for (String field : arr2) {
				field = field.toLowerCase();
				Map<String, String> data = rowdatainfosMap.get(field);
				String value = Util.null2String(data.get("tempvalue"));
				endvalue += value + Util.getSeparator();
			}
			endvalue = delEndChar(endvalue);
			groupMap.put(endvalue, (rows + 1) + "");
			keyMapExcel.put(arr, groupMap);
		}
	}


	/**
	 * 判断重复性验证字段是否重复
	 *
	 * @param keyMap          数据库字段值
	 * @param keyfield        重复性验证字段   类似  wb1,wb2|wb3,wb4 (用|分隔,每个|代表一个分组)
	 * @param rowdatainfosMap 当前导入行信息
	 * @param exist           判断在数据库存在还是不存在
	 * @return [isrepeat]是否重复</ br>
	 * [repeats]重复信息 Map<String, String></br>
	 * repeats中key值如下:[col] 列数(已加1)</br>
	 * [oldtempvalue] excel输入值</br>
	 * [fieldlabelname] 字段名称</br>
	 * [fieldname]	字段名</br>
	 * [fielddbtype] 字段类型</br>
	 * [msg] 提示</br>
	 * [msgdetail] 提示明细</br>
	 */
	public Map<String, Object> judgeExistsOrNot(Map<String, Map<String, String>> keyMap, String keyfield, Map<String, Map<String, String>> rowdatainfosMap) {
		String[] group = keyfield.split("\\|");
		boolean flag = false;
		List<Boolean> issingles = new ArrayList<Boolean>();//是否是单个字段
		List<String> listRepeats = new ArrayList<String>();//重复的验证字段
		String rows = "";
		for (String arr : group) {
			Map<String, String> currKeyMap = keyMap.get(arr);
			String[] arr2 = arr.split(",");
			String value = "";//要验证是否重复的值
			for (String field : arr2) {
				field = field.toLowerCase();
				Map<String, String> rowdatainfo = rowdatainfosMap.get(field);
				if (rowdatainfo != null) {
					String tempvalue = rowdatainfo.get("tempvalue");
					value += tempvalue + Util.getSeparator();
				}
			}
			value = delEndChar(value);
			if (currKeyMap != null && currKeyMap.containsKey(value) && !value.equals("")) {
				flag = true;
				rows = currKeyMap.get(value);
				listRepeats.add(arr);
				issingles.add(arr2.length > 1 ? false : true);
			}
		}
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("isrepeat", Util.null2String(flag));
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		if (flag) {//如果重复
			for (int i = 0; i < listRepeats.size(); i++) {
				String[] infos = {"", "", "", "", "", "", "", "", ""};
				String[] repeats = listRepeats.get(i).split(",");
				Boolean issingle = issingles.get(i);
				for (String field : repeats) {
					Map<String, String> rowdatainfo = rowdatainfosMap.get(field);
					if (rowdatainfo != null) {
						infos[0] += rowdatainfo.get("col") + ",";//列数
						infos[1] += rowdatainfo.get("oldtempvalue") + Util.getSeparator();//原始值
						infos[2] += rowdatainfo.get("fieldlabelname") + ",";//字段名称
						infos[3] += rowdatainfo.get("fieldname") + ",";//字段名
						infos[4] += rowdatainfo.get("fielddbtype") + Util.getSeparator();//字段类型
						infos[5] += "【" + rowdatainfo.get("fieldlabelname") + ":\"" + rowdatainfo.get("oldtempvalue") + "\"】" + ",";//提示
						infos[6] += "【" + rowdatainfo.get("fieldlabelname") + ":<a style='color:red'>\"" + rowdatainfo.get("oldtempvalue") + "\"</a>】" + ",";//提示明细
						infos[7] += rowdatainfo.get("fieldlabelname") + "(" + rowdatainfo.get("fieldname") + "," + rowdatainfo.get("fielddbtype") + ")" + "<br/>";
					}
				}
				for (int j = 0; j < infos.length; j++) {
					infos[j] = delEndChar(infos[j]);//去掉末尾分隔符
					if ((j == 5 || j == 6) && !issingle) {//提示//如果是组合验证,添加前缀
						infos[j] = SystemEnv.getHtmlLabelName(388904, user.getLanguage()) + infos[j];
					}
				}
				Map<String, String> single = new HashMap<String, String>();
				single.put("col", infos[0]);
				single.put("oldtempvalue", infos[1]);
				single.put("fieldlabelname", infos[2]);
				single.put("fieldname", infos[3]);
				single.put("fielddbtype", infos[4]);
				single.put("msg", infos[5]);
				single.put("msgdetail", infos[6]);
				single.put("tablefield", infos[7]);
				single.put("rows", rows);
				list.add(single);
			}
			result.put("repeats", list);
		}
		return result;
	}

	/**
	 * 去除末尾的逗号或分隔符
	 *
	 * @return
	 */
	private String delEndChar(String str) {
		str = str.replaceAll(Util.getSeparator() + "$", "").replaceAll(",$", "");
		return str;
	}


	/**
	 * 判断某个值在map中是否存在，兼容浮点数判断
	 *
	 * @param keyMap
	 * @param key
	 * @param htmltype
	 * @param type
	 * @return
	 */
	public boolean judgeExists(Map keyMap, String key, int htmltype, int type) {
		boolean flag = false;
		key = checkDepartAndSubpany(key);
		if (htmltype == 1 && (type == 3 || type == 4)) {
			double keyValue;
			try {
				keyValue = Double.parseDouble(key);
			} catch (Exception e) {
				return flag;
			}
			Set keys = keyMap.keySet();
			if (keys != null) {
				Iterator iterator = keys.iterator();
				while (iterator.hasNext()) {
					Object keyObject = iterator.next();
					try {
						double tmpKeyValue = Double.parseDouble(keyObject.toString());
						if (Double.compare(tmpKeyValue, keyValue) == 0) flag = true;
					} catch (Exception e) {
						continue;
					}
				}
			}
		} else {
			flag = keyMap.containsKey(key.trim());
		}
		return flag;
	}

	public int getMainId(String billtablename, int formmodeid, int userid, int usertype) {
		int billid = -1;
		BaseBean bb = new BaseBean();
		bb.writeLog("getMainId-billtablename:"+billtablename);
		bb.writeLog("getMainId-formmodeid:"+formmodeid);
		bb.writeLog("getMainId-userid:"+userid);
		bb.writeLog("getMainId-usertype:"+usertype);

		String currentdate = DateHelper.getCurrentDate();

		String currenttime = DateHelper.getCurrentTime();
		//取数据库服务器的当前时间
		RecordSet rs = new RecordSet();
		rs.executeProc("GetDBDateAndTime", "");
		if (rs.next()) {
			currentdate = rs.getString("dbdate");
			currenttime = rs.getString("dbtime");
		}
		billid = modeDataIDUpdateSingle.getModeDataNewIdByUUID(billtablename, formmodeid, userid, usertype, currentdate, currenttime);
		return billid;
	}

	/**
	 * 批量插入日志,以及更新最后修改人和修改时间
	 *
	 * @param modeid
	 * @param operatedesc
	 * @param operatetype
	 * @param billids          主键id集合
	 * @param needlogFieldList 需要记录日志的表单字段
	 * @param oldDatas         更新前的旧数据集合
	 * @param nowDatas         更新后的数据集合
	 */
	private void writeBeatchLog(int modeid, String operatedesc, String operatetype, List<String> billids
			, List<Map<String, Object>> needlogFieldList, Map<String, Map<String, Object>> oldDatas, Map<String, Map<String, Object>> nowDatas, int htmllabelindex) {
		updateModifierAndTime(operatetype, billids, formid);
		batchInsertLog(modeid, billids, operatetype, operatedesc, user, needlogFieldList, oldDatas, nowDatas, htmllabelindex);
	}

	/**
	 * 批量插入日志,以及更新最后修改人和修改时间
	 *
	 * @param modeid
	 * @param operatedesc
	 * @param operatetype
	 * @param billids          主键id集合
	 * @param needlogFieldList 需要记录日志的表单字段
	 * @param oldDatas         更新前的旧数据集合
	 * @param nowDatas         更新后的数据集合
	 */
//	private void writeBeatchLog(int modeid, String operatedesc, String operatetype, List<String> billids
//			,List<Map<String, Object>> needlogFieldList,Map<String, Map<String, Object>>oldDatas,Map<String, Map<String, Object>> nowDatas){
//		updateModifierAndTime(operatetype, billids, formid);
//		batchInsertLog(modeid, billids, operatetype, operatedesc, user, needlogFieldList, oldDatas, nowDatas);
//	}
//
//	private void batchInsertLog(int modeid,List<String> billids,String operatetype,String operatedesc,User user,List<Map<String, Object>> needlogFieldList
//			,Map<String, Map<String, Object>>oldDatas,Map<String, Map<String, Object>> nowDatas){
//		if (billids.size()<=0) {
//			return;
//		}
//		int count=billids.size();
//		String tablename  = "ModeViewLog_"+modeid;
//		String relatedname=SystemEnv.getHtmlLabelName(128713,user.getLanguage());
//		int operateuserid=user.getUID();
//		String operatedate=DateHelper.getCurrentDate();
//		String operatetime=DateHelper.getCurrentTime();
//		List<List<Object>> params = new ArrayList<List<Object>>();
//		for (String billid : billids) {
//			List<Object> param = new ArrayList<Object>();
//			param.add(billid);
//			param.add(relatedname);
//			param.add(operatetype);
//			param.add(operatedesc);
//			param.add(user.getUID());
//			param.add(operatedate);
//			param.add(operatetime);
//			param.add(clientaddress);
//			params.add(param);
//		}
//		String batchsql = "insert into "+tablename+"(relatedid,relatedname,operatetype,operatedesc,operateuserid,operatedate,operatetime,clientaddress)values(?,?,?,?,?,?,?,?)";
//		RecordSetTrans trans = new RecordSetTrans();
//		trans.setAutoCommit(false);
//		try {
//        	trans.executeBatchSql(batchsql, params);
//        	trans.commit();
//        	RecordSet rs = new RecordSet();
//        	String idsql="";
//        	if(rs.getDBType().contains("sqlserver")){
//        		idsql="select id,relatedid from (select top "+count+" id,relatedid from "+tablename+" order by id desc) t order by id asc";
//			}else if(rs.getDBType().contains("mysql")){
//				idsql="select id,relatedid from (select id,relatedid from "+tablename+" order by id desc limit "+count+") t order by id asc";
//			}else if(rs.getDBType().contains("oracle")){
//				idsql="select id,relatedid from ( select id,relatedid from "+tablename+" order by id desc) t where rownum<="+count+" order by id asc";
//			}
//        	rs.executeQuery(idsql);
//        	Map<String, String> idsMap = new HashMap<String, String>();
//        	while (rs.next()) {
//				String viewlogid = rs.getString("id");
//				String billid = rs.getString("relatedid");
//				idsMap.put(billid, viewlogid);
//				this.modeLogMap.put(billid, viewlogid);
//			}
//        	if(needlogFieldList!=null&&needlogFieldList.size() > 0){//明细日志插入
//        		params = new ArrayList<List<Object>>();
//        		batchsql = "insert into ModeLogFieldDetail(viewlogid,fieldid,modeid,fieldvalue,prefieldvalue) values(?,?,?,?,?)";
//        		for (String billid : billids) {
//        			Map<String, Object> oldData = oldDatas.get(billid);
//        			Map<String, Object> nowData = nowDatas.get(billid);
//        			for(int i = 0; i < needlogFieldList.size(); i++){
//        				List<Object> param = new ArrayList<Object>();
//    					Map<String, Object> needlogField = needlogFieldList.get(i);
//    					String fieldid = Util.null2String(needlogField.get("id"));
//    					String fieldname = Util.null2String(needlogField.get("fieldname"));
//    					String oldFieldValue = Util.null2String(oldData.get(fieldname));
//    					String nowFieldValue = Util.null2String(nowData.get(fieldname));
//    					if(!oldFieldValue.equals(nowFieldValue)){
//    						String viewlogid=idsMap.get(billid);
//    						param.add(viewlogid);
//    	        			param.add(fieldid);
//    	        			param.add(modeid);
//    	        			param.add(nowFieldValue);
//    	        			param.add(oldFieldValue);
//    	        			params.add(param);
//    					}
//    				}
//				}
//        		if (params.size()>0) {
//        			trans = new RecordSetTrans();
//        			trans.setAutoCommit(false);
//        			trans.executeBatchSql(batchsql, params);
//        			trans.commit();
//				}
//        	}
//		} catch (Exception e) {
//			trans.rollback();
//			trans.writeLog(e);
//		}
//	}
	private void batchInsertLog(int modeid, List<String> billids, String operatetype, String operatedesc, User user, List<Map<String, Object>> needlogFieldList
			, Map<String, Map<String, Object>> oldDatas, Map<String, Map<String, Object>> nowDatas, int htmllabelindex) {
		if (billids.size() <= 0) {
			return;
		}
		int count = billids.size();
		String tablename = "ModeViewLog_" + modeid;
		String relatedname = SystemEnv.getHtmlLabelName(128713, user.getLanguage());
		int operateuserid = user.getUID();
		String operatedate = DateHelper.getCurrentDate();
		String operatetime = DateHelper.getCurrentTime();
		List<List<Object>> params = new ArrayList<List<Object>>();
		//校验是否存在 htmllabelindex
		RecordSet rsGetHtmlLableIndex = new RecordSet();
		String sqlGetHtmllabelindex = " select htmllabelindex from " + tablename +" where 1=2";
		boolean htmlLabelIndexFlag = true;
		rsGetHtmlLableIndex.execute(sqlGetHtmllabelindex);
		if (!"".equals(rsGetHtmlLableIndex.getExceptionMsg())) {
			String addHtmlLableIndex = " alter table " + tablename + "  add htmllabelindex  int ";
			htmlLabelIndexFlag = rsGetHtmlLableIndex.execute(addHtmlLableIndex);
		}
		for (String billid : billids) {
			List<Object> param = new ArrayList<Object>();
			param.add(billid);
			param.add(relatedname);
			param.add(operatetype);
			param.add(operatedesc);
			param.add(user.getUID());
			param.add(operatedate);
			param.add(operatetime);
			param.add(clientaddress);
			if (htmlLabelIndexFlag) {
				param.add(htmllabelindex);
			}
			params.add(param);
		}

		String batchsql = "insert into " + tablename + "(relatedid,relatedname,operatetype,operatedesc,operateuserid,operatedate,operatetime,clientaddress)values(?,?,?,?,?,?,?,?)";
		if (htmlLabelIndexFlag) {
			batchsql = "insert into " + tablename + "(relatedid,relatedname,operatetype,operatedesc,operateuserid,operatedate,operatetime,clientaddress,htmllabelindex)values(?,?,?,?,?,?,?,?,?)";
		}
		RecordSetTrans trans = new RecordSetTrans();
		trans.setAutoCommit(false);
		try {
			trans.executeBatchSql(batchsql, params);
			trans.commit();
			RecordSet rs = new RecordSet();
			String idsql = "";
			if (rs.getDBType().contains("sqlserver")) {
				idsql = "select id,relatedid from (select top " + count + " id,relatedid from " + tablename + " order by id desc) t order by id asc";
			} else if (rs.getDBType().contains("mysql")) {
				idsql = "select id,relatedid from (select id,relatedid from " + tablename + " order by id desc limit " + count + ") t order by id asc";
			} else if (rs.getDBType().contains("oracle")) {
				idsql = "select id,relatedid from ( select id,relatedid from " + tablename + " order by id desc) t where rownum<=" + count + " order by id asc";
			} else if (rs.getDBType().contains("postgresql")) {
				idsql = "select id,relatedid from (select id,relatedid from " + tablename + " order by id desc limit " + count + ") t order by id asc";
			}
			rs.executeQuery(idsql);
			Map<String, String> idsMap = new HashMap<String, String>();
			while (rs.next()) {
				String viewlogid = rs.getString("id");
				String billid = rs.getString("relatedid");
				idsMap.put(billid, viewlogid);
				this.modeLogMap.put(billid, viewlogid);
			}
			if (needlogFieldList != null && needlogFieldList.size() > 0) {//明细日志插入
				params = new ArrayList<List<Object>>();
				batchsql = "insert into ModeLogFieldDetail(viewlogid,fieldid,modeid,fieldvalue,prefieldvalue,detailtable) values(?,?,?,?,?,?)";
				for (String billid : billids) {
					Map<String, Object> oldData = oldDatas.get(billid);
					Map<String, Object> nowData = nowDatas.get(billid);
					for (int i = 0; i < needlogFieldList.size(); i++) {
						List<Object> param = new ArrayList<Object>();
						Map<String, Object> needlogField = needlogFieldList.get(i);
						String fieldid = Util.null2String(needlogField.get("id"));
						String fieldname = Util.null2String(needlogField.get("fieldname"));
						String detailtable = Util.null2String(needlogField.get("detailtable"));
						String oldFieldValue = Util.null2String(oldData.get(fieldname));
						String nowFieldValue = Util.null2String(nowData.get(fieldname));
						if (!oldFieldValue.equals(nowFieldValue)) {
							String viewlogid = idsMap.get(billid);
							param.add(viewlogid);
							param.add(fieldid);
							param.add(modeid);
							param.add(nowFieldValue);
							param.add(oldFieldValue);
							param.add(detailtable);
							params.add(param);
						}
					}
				}
				if (params.size() > 0) {
					trans = new RecordSetTrans();
					trans.setAutoCommit(false);

					trans.executeBatchSql(batchsql, params);
					trans.commit();
				}
			}
		} catch (Exception e) {
			trans.rollback();
			trans.writeLog(e);
		}
	}

	/**
	 * 批量更新最后修改人和修改时间
	 *
	 * @param operatetype
	 * @param billids
	 * @param formid
	 */
	private void updateModifierAndTime(String operatetype, List<String> billids, int formid) {
		if (!"2".equals(operatetype)) {
			return;
		}
		if (billids.size() <= 0) {
			return;
		}
		String tablename = new FormInfoService().getTablenameByFormid(Util.getIntValue(formid));
		if ("".equals(tablename)) {
			return;
		}
		RecordSetTrans trans = new RecordSetTrans();
		trans.setAutoCommit(false);
		String batchsql = "update " + tablename + " set modedatamodifier=?,modedatamodifydatetime=? where id=?";
		String modifydatatime = DateHelper.getCurDateTime();
		int uid = user.getUID();
		List<List<Object>> params = new ArrayList<List<Object>>();
		for (String billid : billids) {
			List<Object> param = new ArrayList<Object>();
			param.add(uid);
			param.add(modifydatatime);
			param.add(billid);
			params.add(param);
		}
		try {
			trans.executeBatchSql(batchsql, params);
			trans.commit();
		} catch (Exception e) {
			trans.rollback();
			trans.writeLog(e);
		}

	}

	public void writeBeatchLog(int modeid, String operatedesc, String operatetype, int relatedid
			, List<Map<String, Object>> needlogFieldList, Map<String, Object> oldData, Map<String, Object> nowData, int htmllabelindex) {
		List<String> billids = new ArrayList<String>(1);
		billids.add(relatedid + "");
		Map<String, Map<String, Object>> oldDatas = new HashMap<String, Map<String, Object>>();
		oldDatas.put(relatedid + "", oldData);
		Map<String, Map<String, Object>> nowDatas = new HashMap<String, Map<String, Object>>();
		nowDatas.put(relatedid + "", nowData);
		writeBeatchLog(modeid, operatedesc, operatetype, billids,
				needlogFieldList, oldDatas, nowDatas, htmllabelindex);
	}

	/**
	 * 根据key获取value值，兼容浮点数
	 *
	 * @param keyMap
	 * @param key
	 * @return
	 */
	public String getMapValue(Map keyMap, String key) {
		String result = "";
		if (keyMap.containsKey(key.trim())) {
			result = Util.null2String(keyMap.get(key.trim()));
		} else if (Util.null2String(key).length() > 15) {
			//qc407268
		} else {
			double keyValue;
			try {
				keyValue = Double.parseDouble(key);
			} catch (Exception e) {
				return result;
			}
			Set keys = keyMap.keySet();
			if (keys != null) {
				Iterator iterator = keys.iterator();
				while (iterator.hasNext()) {
					Object keyObject = iterator.next();
					try {
						double tmpKeyValue = Double.parseDouble(keyObject.toString());
						if (Double.compare(tmpKeyValue, keyValue) == 0)
							result = Util.null2String(keyMap.get(keyObject));
					} catch (Exception e) {
						continue;
					}
				}
			}
		}
		return result;
	}

	// 计算列转换的值.
	public void getColCalStr(int formid, int billid, String mainTableName,
							 Map map, int mainid, int isbill, String dtname) {
		RecordSet rs = new RecordSet();
		RecordSet rs2 = new RecordSet();
		String colcalstr = "";
		String maincalstr = "";
		String rowcalstr = "";
		String sql = "select * from workflow_formdetailinfo where formid =" + formid;
		if (formid != 0)
			rs.executeSql(sql);
		if (rs.next()) {
			colcalstr = rs.getString("colcalstr");
			maincalstr = rs.getString("maincalstr");
			rowcalstr = rs.getString("rowcalstr");
		}
		// 计算多个明细表的行列规则
		if (rowcalstr != null && !"".equals(rowcalstr.trim())) {
			String[] rowcalstrs = rowcalstr.split(";");
			for (int ii = 0; ii < rowcalstrs.length; ii++) {
				colCal(rowcalstrs[ii], isbill, formid, map, mainid, billid);
			}
		}

		// 下面计算总和
		if (maincalstr != null && !"".equals(maincalstr.trim())) {
			String[] m = maincalstr.split(";");
			for (int i = 0; i < m.length; i++) {
				String detailTableName = "";
				String dfname = "";
				String mfname = "";
				String[] temp = m[i].split("=");
				String mf = temp[0].replace("mainfield_", "");
				String qfws = "";
				String df = temp[1].replace("detailfield_", "");
				if (isbill > 0) {
					sql = "select fieldname,qfws from workflow_billfield where id = "
							+ mf;
				} else {
					sql = "select fieldname from workflow_formdict where id = "
							+ mf;

				}
				rs2.executeSql(sql);
				if (rs2.next()) {
					mfname = rs2.getString("fieldname");
					qfws = rs2.getString("qfws");
				}

				// 得到等于号左边的对应的fdname.
				dfname = getFdName(df, isbill, formid);
				// 得到明细表名
				detailTableName = getDtName(df, isbill, formid);

				String mainKey = (String) map.get(detailTableName);
				if (mainKey == null || "".equals(mainKey.trim())) {
					mainKey = "mainid";
				}
				double d = 0;
//				sql = "select sum(" + dfname + ") dd from " + detailTableName
//						+ " where " + mainKey + " = " + mainid;
//				rs2.executeSql(sql);
//				if (rs2.next()) {
//					d = Util.getDoubleValue(rs2.getString("dd"), 0);
//				}

				sql = "select " + dfname + " dd from " + detailTableName
						+ " where " + mainKey + " = " + mainid;
				rs2.executeSql(sql);
				double ddvaluesum = 0;
				while (rs2.next()) {
					String ddvalue = Util.null2String(rs2.getString("dd"));
					ddvaluesum += Util.getDoubleValue(ddvalue.replace(",", ""), 0);
				}
				String dstr = "";
				String sql2 = "select fieldhtmltype,type,fielddbtype,qfws from workflow_billfield where id=" + df;
				rs2.executeSql(sql2);
				if (rs2.next()) {
					String fieldhtmltype = rs2.getString("fieldhtmltype");
					String type = rs2.getString("type");
					String fielddbtype = Util.null2String(rs2.getString("fielddbtype"));

					if (fieldhtmltype.equals("1") && type.equals("2")) {
						BigDecimal b = new BigDecimal(ddvaluesum);
						int f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
						dstr = Util.toDecimalDigits(f1 + "", 0);
					} else if (fieldhtmltype.equals("1") && type.equals("4")) {
						BigDecimal b = new BigDecimal(ddvaluesum + "");
						double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
						dstr = Util.toDecimalDigits(f1 + "", 2);
					} else if (fieldhtmltype.equals("1") && type.equals("5")) {
						BigDecimal b = new BigDecimal(ddvaluesum + "");
						double f1 = b.setScale(Util.getIntValue(qfws, 2), BigDecimal.ROUND_HALF_UP).doubleValue();
						dstr = Util.toDecimalDigits(f1 + "", Util.getIntValue(qfws, 2));
						dstr = Util.milfloatFormat(dstr + "");
					} else if (type.equals("" + 3) && fieldhtmltype.equals("1")) {
						int digitsIndex = fielddbtype.indexOf(",");
						int decimaldigits_t = 0;
						if (digitsIndex > -1) {
							decimaldigits_t = Util.getIntValue(fielddbtype.substring(digitsIndex + 1, fielddbtype.length() - 1), 2);
						} else {
							decimaldigits_t = 2;
						}
						BigDecimal b = new BigDecimal(ddvaluesum + "");
						double f1 = b.setScale(decimaldigits_t, BigDecimal.ROUND_HALF_UP).doubleValue();
						dstr = Util.toDecimalDigits(f1 + "", decimaldigits_t);
					} else {
						dstr = ddvaluesum + "";
					}
				}

				// 更新新表单
				if (isbill > 0 && formid < 0)
					sql = " update  " + mainTableName + " set " + mfname + " = '" + dstr + "' where id = " + mainid;
				rs.executeSql(sql);
			}
		}
	}


	// 得到明细表字段的属性描述
	private String getFdName(String fid, int isbill, int formid) {
		RecordSet rs = new RecordSet();
		String sql;
		if (isbill > 0) {
			sql = "select fieldname from workflow_billfield where id = " + fid;
		} else {
			sql = "SELECT  a.fieldname FROM workflow_formfield wf , ( SELECT DISTINCT id , fielddbtype , fieldname ,description FROM workflow_formdictdetail ) a WHERE wf.formid = "
					+ formid
					+ " AND wf.isdetail = '1' "
					+ "AND wf.fieldid = a.id AND a.id =  " + fid;
		}
		rs.executeSql(sql);
		if (rs.next()) {
			return rs.getString("fieldname");
		}

		return null;
	}

	private String getDtName(String id, int isbill, int formid) {
		RecordSet rs = new RecordSet();
		String sql;
		if (isbill > 0) {
			sql = "select detailtable from workflow_billfield where id = " + id;
			// 查询明细表列名
			rs.executeSql(sql);
			if (rs.next()) {
				return rs.getString("detailtable");
			}
		} else
			return "workflow_formdetail";
		return null;
	}

	// 计算一个明细表的行列表达式.
	private void colCal(String rowcalstr, int isbill, int formid, Map map,
						int mainid, int billid) {
		String sql = "";
		Set fdName = new HashSet();
		RecordSet rs2 = new RecordSet();
		RecordSet rs = new RecordSet();
		String firstFid = "";
		String firstFname = "";
		Pattern pattern = Pattern.compile("detailfield[_](\\d+)");
		Matcher matcher = null;
		matcher = pattern.matcher(rowcalstr);
		while (matcher.find()) {
			if ("".equals(firstFid)) {
				firstFid = matcher.group(1);
			} else {
				fdName.add(matcher.group(1));
			}
		}
		// 得到等于号左边的对应的fdname.
		firstFname = getFdName(firstFid, isbill, formid);
		// 得到明细表名
		String detailTableName = getDtName(firstFid, isbill, formid);

		List l = new ArrayList();
		l.addAll(fdName);
		Iterator it = l.iterator();
		String allV = "";
		Map mmm = new HashMap();
		int count = 0;
		while (it.hasNext()) {
			String fidid = (String) it.next();
			String fdname = getFdName(fidid + "", isbill, formid);
			allV += fdname + ",";
			mmm.put(fdname, fidid);
			count++;
		}
		if (allV.length() > 0) {
			allV = allV.substring(0, allV.length() - 1);
			String mainKey = (String) map.get(detailTableName);
			if (isbill > 0)
				sql = "select " + allV + ",id from " + detailTableName + " where " + mainKey + " = " + mainid;
			rs.executeSql(sql);
			while (rs.next()) {
				FelEngine fel = new FelEngineImpl();
				FelContext ctx = fel.getContext();
				Iterator iterator = mmm.keySet().iterator();
				while (iterator.hasNext()) {
					String eee = (String) iterator.next();
					int index = 1 + l.indexOf(mmm.get(eee));
					String string = rs.getString(index);
					// 如果没有这个明细值,就设置为0
					if (string == null || "".equals(string)) {
						ctx.set("detailfield_" + mmm.get(eee), new Double(0.0));
					} else {
						if (string.indexOf(",") != -1) {
							string = string.replace(",", "");
						}
						double d = Util.getDoubleValue(string, 0);
						ctx.set("detailfield_" + mmm.get(eee), d);
					}
				}
				String idString = rs.getString(l.size() + 1);
				Object result = fel.eval(rowcalstr.substring(rowcalstr
						.indexOf("=") + 1, rowcalstr.length()));

				if (result != null && !result.toString().equals("") && !"NaN".equals(result.toString()) && !"Infinity".equals(result.toString())) {
					String sql2 = "select fieldhtmltype,type,fielddbtype,qfws from workflow_billfield where id=" + firstFid;
					rs2.executeSql(sql2);
					if (rs2.next()) {
						String fieldhtmltype = rs2.getString("fieldhtmltype");
						String type = rs2.getString("type");
						String qfws = rs2.getString("qfws");
						String fielddbtype = Util.null2String(rs2.getString("fielddbtype"));
						if (fieldhtmltype.equals("1") && type.equals("2")) {
							BigDecimal b = new BigDecimal(result + "");
							int f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
							result = Util.toDecimalDigits(f1 + "", 0);
						} else if (fieldhtmltype.equals("1") && type.equals("4")) {
							BigDecimal b = new BigDecimal(result + "");
							double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							result = Util.toDecimalDigits(f1 + "", 2);
						} else if (fieldhtmltype.equals("1") && type.equals("5")) {
							BigDecimal b = new BigDecimal(result + "");
							double f1 = b.setScale(Util.getIntValue(qfws, 2), BigDecimal.ROUND_HALF_UP).doubleValue();
							result = Util.toDecimalDigits(f1 + "", Util.getIntValue(qfws, 2));
							result = Util.milfloatFormat(result + "");
						} else if (type.equals("3") && fieldhtmltype.equals("1")) {
							int digitsIndex = fielddbtype.indexOf(",");
							int decimaldigits_t = 0;
							if (digitsIndex > -1) {
								decimaldigits_t = Util.getIntValue(fielddbtype.substring(digitsIndex + 1, fielddbtype.length() - 1), 2);
							} else {
								decimaldigits_t = 2;
							}
							BigDecimal b = new BigDecimal(result + "");
							double f1 = b.setScale(decimaldigits_t, BigDecimal.ROUND_HALF_UP).doubleValue();
							result = Util.toDecimalDigits(f1 + "", decimaldigits_t);
						}
					}
				}
				if (!"NaN".equals(result.toString()) && !"Infinity".equals(result.toString())) {
					sql = "update " + detailTableName + " set " + firstFname
							+ " = '" + result + "' where id = " + idString;
					rs2.execute(sql);
				}
			}
		}
	}

	/**
	 * @param type 0 分部  1 部门  2 人
	 * @param path 全路径
	 * @return
	 */
	public Map<String, String> getIdByPathName(int type, String path) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("flag", "0");//默认成功
		String id = "";
		ArrayList<String> tempvalues = new ArrayList<String>();
		if (path.indexOf(">") > -1) {
			tempvalues = Util.TokenizerString(path, ">");
		} else if (this.isDepartAndSubpany) {
			tempvalues = Util.TokenizerString(path, this.sepCharacter);
		}
		int count = tempvalues.size();
		if (type == 0) {
			int pid = 0;
			for (int i = 0; i < count; i++) {
				String orgname = Util.null2String(tempvalues.get(i)).trim();
				map.put("orgname", orgname);
				int orgid = getSubcompanyByName(orgname, pid);
				map.put("value", orgid + "");
				pid = orgid;
				if (orgid == -1) {//找分部
					map.put("flag", "1");//失败
					map.put("message", SystemEnv.getHtmlLabelName(503406, user.getLanguage()));//失败,分部没有找到
					return map;
				}
			}
		} else if (type == 1) {
			int pid = 0;
			int suptype = 0;
			for (int i = 0; i < count; i++) {
				String orgname = Util.null2String(tempvalues.get(i)).trim();
				map.put("orgname", orgname);
				int orgid = 0;
				//第一级必须是分部
				if (i != 0 || !"2".equals(deptShowLevel)) {
					orgid = getDeptByName(orgname, pid, suptype);
					map.put("value", orgid + "");
					if (orgid != -1) {
						pid = orgid;
					}
				} else {
					orgid = -1;
				}
				if (orgid == -1) {
					//部门找不到再找分部
					orgid = getSubcompanyByName(orgname, pid);
					pid = orgid;
					if (orgid == -1) {
						map.put("flag", "1");//失败
						map.put("message", SystemEnv.getHtmlLabelName(503407, user.getLanguage()));//失败,组织架构没有找到
						return map;
					} else {
						suptype = 0;//分部找到了
					}
				} else {
					suptype = 1;//部门找到了
				}
			}
		} else if (type == 2) {
			int pid = 0;
			int suptype = 0;
			for (int i = 0; i < count; i++) {
				String orgname = Util.null2String(tempvalues.get(i)).trim();
				map.put("orgname", orgname);
				int orgid = 0;
				if (i == count - 1) {//最后一级直接找人
					int userid = getUserByName(orgname, pid);
					map.put("value", userid + "");
					if (userid == -1) {
						map.put("flag", "1");//失败
						map.put("message", SystemEnv.getHtmlLabelName(503408, user.getLanguage()));//失败,人员没有找到
						return map;
					} else {
						return map;
					}

				}
				//第一级必须是分部
				if (i != 0) {
					orgid = getDeptByName(orgname, pid, suptype);
					if (orgid != -1) {
						pid = orgid;
					}
				} else {
					orgid = -1;
				}
				if (orgid == -1) {
					//部门找不到再找分部
					orgid = getSubcompanyByName(orgname, pid);
					pid = orgid;
					if (orgid == -1) {
						map.put("flag", "1");//失败
						map.put("message", SystemEnv.getHtmlLabelName(503407, user.getLanguage()));//失败,组织架构没有找到
						return map;
					} else {
						suptype = 0;//分部找到了
					}
				} else {
					suptype = 1;//部门找到了
				}
			}
		}
		return map;
		/*
		Map<String, String> map= new HashMap<String, String>();
		String id="";
		ArrayList<String> tempvalues = Util.TokenizerString(path,">");
		int count=tempvalues.size();
		int selecttype=0;

		map.put("flag", 0+"");
		int pid=0;
		for (int i = 0; i < count; i++) {
			int orgid=0;
			String orgname = Util.null2String(tempvalues.get(i)).trim();
			map.put("orgname", orgname);
			if(selecttype==0){//按分部找
				orgid=getSubcompanyByName(orgname, pid);
				map.put("value", orgid+"");
				if(orgid==-1&&type==0){//找分部
					map.put("flag", "1");//失败
					map.put("message", "分部没有找到");//失败
					return map;
				}else if(orgid==-1&&(type==1||type==2)){//找部门  分部下找部门
					orgid = getDeptByName(orgname, pid, 0);
					map.put("value", orgid+"");
					if(orgid==-1){
						map.put("flag", "1");//失败
						map.put("message", "部门没有找到");//失败
						return map;
					}else{
						selecttype=1;
					}
				}
				pid=orgid;
			}else{//按部门找
				orgid = getDeptByName(orgname, pid, 1);//部门下找部门
				map.put("value", orgid+"");
				if(orgid==-1&&type==1){
					map.put("flag", "1");//失败
					map.put("message", "部门没有找到");//失败
					return map;
				}else if(orgid==-1&&type==2){
					orgid = getUserByName(orgname, pid);
					map.put("value", orgid+"");
					if(orgid==-1){
						map.put("flag", "1");//失败
						map.put("message", "人员没有找到");//失败
					}
				}
				pid=orgid;
			}
		}

		return map;
		*/
	}

	/**
	 * 根据名称获取部门
	 *
	 * @param name 部门
	 * @param pid  pid
	 * @return
	 */
	public int getSubcompanyByName(String name, int pid) {
		int companyid = -1;
		RecordSet rs = new RecordSet();
		String sql = "";
		if (pid == 0) {
			sql = "select id from HrmSubCompany where (subcompanyname='" + name + "' or  subcompanyname like '%`~`7 " + name + "`~`%'  or  subcompanyname like '%`~`8 " + name + "`~`%'  or  subcompanyname like '%`~`9 " + name + "`~`%')  and (canceled <> 1 or canceled is null or canceled='') ";
		} else {
			sql = "select id from HrmSubCompany where (subcompanyname='" + name + "' or  subcompanyname like '%`~`7 " + name + "`~`%'  or  subcompanyname like '%`~`8 " + name + "`~`%'  or  subcompanyname like '%`~`9 " + name + "`~`%')  and (canceled <> 1 or canceled is null or canceled='')  and supsubcomid=" + pid;
		}
		rs.executeSql(sql);
		if (rs.getCounts() <= 0) {
			if (pid == 0) {
				sql = "select id from HrmSubCompany where (subcompanydesc='" + name + "' or  subcompanydesc like '%`~`7 " + name + "`~`%'  or  subcompanydesc like '%`~`8 " + name + "`~`%'  or  subcompanydesc like '%`~`9 " + name + "`~`%') and (canceled <> 1 or canceled is null or canceled='')";
			} else {
				sql = "select id from HrmSubCompany where (subcompanydesc='" + name + "' or  subcompanydesc like '%`~`7 " + name + "`~`%'  or  subcompanydesc like '%`~`8 " + name + "`~`%'  or  subcompanydesc like '%`~`9 " + name + "`~`%') and (canceled <> 1 or canceled is null or canceled='') and supsubcomid=" + pid;
			}
			rs.executeSql(sql);
		}
		if (rs.next()) {
			companyid = Util.getIntValue(rs.getString("id"), -1);
		}
		return companyid;
	}

	/**
	 * @param name 名称
	 * @param pid  上级id
	 * @param type 0 分部 1部门
	 * @return
	 */
	public int getDeptByName(String name, int pid, int suptype) {
		int deptid = -1;
		String sql = "";
		if (suptype == 0) {//找分部下的部门
			sql = "select id from hrmdepartment where supdepid =0 and (departmentname='" + name + "' or  departmentname like '%`~`7 " + name + "`~`%'  or  departmentname like '%`~`8 " + name + "`~`%'  or  departmentname like '%`~`9 " + name + "`~`%') and (canceled <> 1 or canceled is null or canceled='') ";
			if (pid > 0) {
				sql += " and subcompanyid1='" + pid + "' ";
			}
		} else {//找部门下的部门
			sql = "select id from hrmdepartment where  (departmentname='" + name + "' or departmentname like '%`~`7 " + name + "`~`%'  or  departmentname like '%`~`8 " + name + "`~`%'  or  departmentname like '%`~`9 " + name + "`~`%') and (canceled <> 1 or canceled is null or canceled='') ";
			if (pid > 0) {
				sql += " and supdepid='" + pid + "' ";
			}
		}
		RecordSet rs = new RecordSet();
		rs.executeSql(sql);
		if (rs.getCounts() <= 0) {
			if (suptype == 0) {//找分部下的部门
				sql = "select id from hrmdepartment where supdepid =0 and (departmentmark='" + name + "' or  departmentmark like '%`~`7 " + name + "`~`%'  or  departmentmark like '%`~`8 " + name + "`~`%'  or  departmentmark like '%`~`9 " + name + "`~`%') and (canceled <> 1 or canceled is null or canceled='') ";
				if (pid > 0) {
					sql += " and subcompanyid1='" + pid + "' ";
				}
			} else {//找部门下的部门
				sql = "select id from hrmdepartment where (departmentmark='" + name + "' or departmentmark like '%`~`7 " + name + "`~`%'  or  departmentmark like '%`~`8 " + name + "`~`%'  or  departmentmark like '%`~`9 " + name + "`~`%') and (canceled <> 1 or canceled is null or canceled='') ";
				if (pid > 0) {
					sql += " and supdepid='" + pid + "' ";
				}
			}
			rs.executeSql(sql);
		}
		if (rs.next()) {
			deptid = Util.getIntValue(rs.getString("id"), -1);
		}
		return deptid;
	}

	/**
	 * @param name 用户名称
	 * @param pid  部门id
	 * @return
	 */
	public int getUserByName(String name, int pid) {
		int userid = -1;
		String sql = "";
		sql = "select id from hrmresource where (lastname='" + name + "' or lastname like '%`~`7 " + name + "`~`%'  or  lastname like '%`~`8 " + name + "`~`%'  or  lastname like '%`~`9 " + name + "`~`%') and departmentid='" + pid + "' ";
		RecordSet rs = new RecordSet();
		rs.executeSql(sql);
		if (rs.next()) {
			userid = Util.getIntValue(rs.getString("id"), -1);
		}
		return userid;
	}


	private String sepCharacter = "";
	private String applyToModel = "";
	private String deptShowLevel = "";  //1:部门全路径  2:组织全路径  0:本部门
	private boolean isDepartAndSubpany = false;//用于处理部门，判断是分部导入时配置自定义的全路径

	public void initDepartAndSubpany() {
		RecordSet rs = new RecordSet();
		rs.executeQuery("select * from HrmOrganizationShowSet");
		while (rs.next()) {
			sepCharacter = Util.null2String(rs.getString("sepCharacter"));
			sepCharacter = getEscapingsSepCharacter(sepCharacter);
			applyToModel = Util.null2String(rs.getString("applyToModel"));
			deptShowLevel = Util.null2String(rs.getString("deptShowLevel"));
		}
		if ("1".equals(applyToModel)) {
			this.isDepartAndSubpany = true;
		}
		this.sepCharacter = sepCharacter;
		this.applyToModel = applyToModel;
	}


	/**
	 * 用于处理部门，分部导入时配置自定义的全路径
	 */
    public String checkDepartAndSubpany(String value) {
        boolean isContainsSep=false;//值中是否含有全路径的分割符
        String oriValue=value;
        if ("1".equals(applyToModel)) {
            // value = getEscapingsSepCharacter(value);
            value = value.replace("\\", "\\\\");
            boolean flag = value.indexOf(",") > -1;
            if (value.indexOf(sepCharacter) > -1 && !flag) {
                isContainsSep=true;
                String[] changeValue = value.split(sepCharacter);
                value = changeValue[changeValue.length - 1];
            } else if (value.indexOf(sepCharacter) > -1 && flag) {
                isContainsSep=true;
                String[] values = value.split(",");
                String plValue = "";
                for (String v : values) {
                    v = getEscapingsSepCharacter(v);
                    if (v.indexOf(sepCharacter) > -1) {
                        String[] changValue = v.split(sepCharacter);
                        v = changValue[changValue.length - 1];
                        plValue = v + ",";
                    } else {
                        plValue = v + ",";
                    }
                }
                value = plValue.substring(0, plValue.length() - 1);
            }
        }
        return isContainsSep?value:oriValue;
    }

	/**
	 * 将层级间分隔符进行转义，否则会报错
	 *
	 * @param sepCharacter
	 * @return
	 */
	private String getEscapingsSepCharacter(String sepCharacter) {
		String escapingsSepCharacter = "";
		escapingsSepCharacter = sepCharacter.replace("\\", "\\\\").replace("*", "\\*")
				.replace("+", "\\+").replace("|", "\\|")
				.replace("{", "\\{").replace("}", "\\}")
				.replace("(", "\\(").replace(")", "\\)")
				.replace("^", "\\^").replace("$", "\\$")
				.replace("[", "\\[").replace("]", "\\]")
				.replace("?", "\\?").replace(",", "\\,")
				.replace(".", "\\.").replace("&", "\\&");
		return escapingsSepCharacter;
	}

	/**
	 * 加密字段值处理方法
	 *
	 * @param realTempvalue 原始字段值
	 * @param tablename     表名
	 * @param showfield     字段名
	 * @param flag          是否明细，1是明细，0是主表
	 * @return
	 */
	public String getFieldEncryptValue(String realTempvalue, String tablename, String showfield, String flag) {
		RecordSet rs = new RecordSet();
		String sql = "select t2.fieldname, t1.isencrypt from ModeFormFieldEncrypt t1, workflow_billfield t2, workflow_bill t3"
				+ " where t1.fieldid=t2.id and t3.id=t1.formid and  t3.tablename ='" + tablename + "'";
		if ("1".equals(flag)) {
			sql = "select t2.fieldname, t1.isencrypt from ModeFormFieldEncrypt t1, workflow_billfield t2, workflow_bill t3, workflow_billdetailtable t4"
					+ " where t1.fieldid=t2.id and t3.id=t1.formid and t3.id=t4.billid and t4.tablename ='" + tablename + "'";
		}
		rs.executeQuery(sql);
		while (rs.next()) {
			if (showfield.equalsIgnoreCase(Util.null2String(rs.getString("fieldname"))) && 1 == Util.getIntValue(Util.null2String(rs.getString("isencrypt")))) {
				realTempvalue = CubeCipherUitl.encrypt(realTempvalue);
			}
		}
		//对于虚拟表单，实际表字段加密了，但是虚拟表没有设置字段加密，上面的逻辑检测不到，单独处理
		if (realTempvalue.startsWith("cube~cipher~start")) {
			realTempvalue = CubeCipherUitl.decrypt(realTempvalue);
		}
		return realTempvalue;
	}

	/**
	 * 判断是否是加密字段
	 *
	 * @param tablename 表名
	 * @param showfield 字段名
	 * @param flag      是否明细，1是明细，0是主表
	 * @return
	 */
	private boolean isEntryField(String tablename, String showfield, String flag) {
		boolean result = false;
		RecordSet rs = new RecordSet();
		String sql = "select t2.fieldname, t1.isencrypt from ModeFormFieldEncrypt t1, workflow_billfield t2, workflow_bill t3"
				+ " where t1.fieldid=t2.id and t3.id=t1.formid and  upper(t3.tablename) =upper('" + tablename + "')  and t1.isencrypt=1";
		if ("1".equals(flag)) {
			sql = "select t2.fieldname, t1.isencrypt from ModeFormFieldEncrypt t1, workflow_billfield t2, workflow_bill t3, workflow_billdetailtable t4"
					+ " where t1.fieldid=t2.id and t3.id=t1.formid and t3.id=t4.billid and upper(t4.tablename) =upper('" + tablename + "')  and t1.isencrypt=1";
		}
		rs.executeQuery(sql);
		while (rs.next()) {
			if (showfield.equalsIgnoreCase(Util.null2String(rs.getString("fieldname")))) {
				result = true;
			}
		}
		return result;
	}

	/**
	 * 验证字符串是code 或者 数字（id）
	 *
	 * @param tempValue
	 * @return
	 */
	public Boolean isNumberOrCode(String tempValue) {
		Boolean result = false;
		Pattern pattern = Pattern.compile("^(-)?[1-9][0-9]*$"); //验证正数或负数
		if (StringHelper.isNotEmpty(tempValue)) {
			Matcher isNum = pattern.matcher(tempValue.trim());
			if (isNum.matches() || tempValue.startsWith("workcode_") || tempValue.startsWith("deptcode_") || tempValue.startsWith("virtual_")) {
				result = true;
			}
		}
		return result;
	}

	public Map<String, String> getRealFileOrImg(RecordSet rs, String parentid, String value, int index, String[] docpaths, int type) {
		Map<String, String> map = new HashMap<String, String>();
		if (index == docpaths.length - 1) {
			rs.executeQuery("select id from docdetail where docsubject = ? and seccategory = ? order by id", docpaths[index], parentid);
			while (rs.next()) {
				value = Util.null2String(rs.getString("id"));
				if (!StringHelper.isEmpty(value) && type == 2) {//图片需要判断后缀名
					try {
						DocImageManager DocImageManager = new DocImageManager();
						DocImageManager.resetParameter();
						DocImageManager.setDocid(Integer.parseInt(value));
						DocImageManager.selectDocImageInfo();

						String filename = "";
						String fileExtendName = "";
						if (DocImageManager.next()) {
							filename = DocImageManager.getImagefilename();
							fileExtendName = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
						}

						if (StringHelper.isEmpty(filename)) {
							value = "";
						} else if (!",jpg,jpeg,png,gif,bmp,".contains("," + fileExtendName + ",")) {
							value = "";
						}
					} catch (Exception e) {
						value = "";
						writeLog(e);
					}
				}
				if (!StringHelper.isEmpty(value)) {
					map.put("value", value);
					map.put("errorStr", "");
					break;
				}
			}
			if (!map.containsKey("value")) {
				map.put("value", "");
				map.put("errorStr", docpaths[index] + value + SystemEnv.getHtmlLabelName(132306, user.getLanguage()));
			}
			return map;
		} else {
			rs.executeQuery("select id from docseccategory where categoryname = ? and parentid = ? order by id", docpaths[index], parentid);
			while (rs.next()) {
				String categoryid = Util.null2String(rs.getString("id"));
				if (!StringHelper.isEmpty(categoryid)) {
					map = getRealFileOrImg(rs, categoryid, value, index + 1, docpaths, type);
				}
				if (map.containsKey("value") && !StringHelper.isEmpty(map.get("value"))) {
					break;
				}
			}
			if (!map.containsKey("value")) {
				map.put("value", "");
				map.put("errorStr", docpaths[index] + value + SystemEnv.getHtmlLabelName(132306, user.getLanguage()));
			}
			return map;
		}
	}

	/**
	 * 附件图片导入
	 * 支持id,name_,目录路径
	 *
	 * @param val 文件名称
	 * @return
	 */
	public Map<String, String> doImportForFileOrImg(String val, int type) {
		val = val.trim();
		RecordSet rs = new RecordSet();
		Map<String, String> map = new HashMap<String, String>();
		if (val.contains(">")) {
			String[] docpaths = val.split(">");
			val = "";
			if (!StringHelper.isEmpty(docpaths[0])) {
				rs.executeQuery("select id from docseccategory where categoryname = ? order by id", docpaths[0]);
				while (rs.next()) {
					String categoryid = Util.null2String(rs.getString("id"));
					if (!StringHelper.isEmpty(categoryid)) {
						map = getRealFileOrImg(rs, categoryid, "", 1, docpaths, type);
					}
					//只要第一个满足的文档id
					if (map.containsKey("value") && !StringHelper.isEmpty(map.get("value"))) {
						break;
					}
				}
			}
			if (!map.containsKey("value")) {
				map.put("value", "");
				map.put("errorStr", docpaths[docpaths.length - 1] + SystemEnv.getHtmlLabelName(132306, user.getLanguage()));
			}
		} else {
			Pattern pattern = Pattern.compile("^(-)?[1-9][0-9]*$"); //验证正数或负数
			Matcher isNum = pattern.matcher(val);
			if (!isNum.matches()) {//名称
				boolean isname = false;
				if (val.startsWith("name_")) {
					val = val.substring("name_".length());
					isname = true;
				}
				rs.executeQuery("select id from docdetail where docsubject = ? order by id", val);

				while (rs.next()) {

					val = Util.null2String(rs.getString("id"));
					if (!StringHelper.isEmpty(val) && type == 2) {//图片需要判断后缀名
						try {
							DocImageManager DocImageManager = new DocImageManager();
							DocImageManager.resetParameter();
							DocImageManager.setDocid(Integer.parseInt(val));
							DocImageManager.selectDocImageInfo();

							String filename = "";
							String fileExtendName = "";
							if (DocImageManager.next()) {
								filename = DocImageManager.getImagefilename();
								fileExtendName = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
							}

							if (StringHelper.isEmpty(filename)) {
								val = "";
							} else if (!",jpg,jpeg,png,gif,bmp,".contains("," + fileExtendName + ",")) {
								val = "";
							}
						} catch (Exception e) {
							val = "";
							writeLog(e);
						}
					}
					if (!StringHelper.isEmpty(val)) {
						map.put("value", val);
						map.put("errorStr", "");
						break;
					}
				}
				if (!map.containsKey("value")) {
					map.put("value", "");
					map.put("errorStr", (isname ? "name_" + val : val) + SystemEnv.getHtmlLabelName(132306, user.getLanguage()));
				}
			} else {
				if (!StringHelper.isEmpty(val)) {
					map.put("value", val);
					map.put("errorStr", "");
				}
			}
		}
		return map;
	}


	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	private void createTable(String modeid_userid,String conditionField){
		String id = "id int IDENTITY(1,1) NOT NULL,";
		RecordSet rs = new RecordSet();
		String dbType = rs.getDBType();
		String checkSql ="";
		String tablename = "M_"+modeid_userid;
		boolean isMysql = DBConstant.DB_TYPE_MYSQL.equals(dbType);
		long time = System.currentTimeMillis();// 校验sql不sql缓存
		if (DBConstant.DB_TYPE_ORACLE.equals(dbType)) {
			id = " id integer NOT NULL,";
			checkSql ="select COUNT(1) from user_tables where upper(table_name)=? and "+time+"="+time;
		}else if (isMysql) {
			id = " id int auto_increment not null primary key,";// mysql中自增的必须为主键或唯一键等。
			checkSql ="select COUNT(1) from information_schema.tables where upper(table_name)=? and table_schema = database() and "+time+"="+time;
		}else if(DBConstant.DB_TYPE_SQLSERVER.equals(dbType)){
			checkSql ="SELECT COUNT(1) FROM sysobjects WHERE upper(name)=? and "+time+"="+time;
		}else if (DBConstant.DB_TYPE_POSTGRESQL.equals(dbType)) {
			id = " id SERIAL not null primary key,";// mysql中自增的必须为主键或唯一键等。
			checkSql ="select COUNT(1) from information_schema.tables where upper(table_name)=upper(?) and table_schema = 'PUBLIC' and "+time+"="+time;
		}
		rs.executeQuery(checkSql,tablename);
		rs.next();
		int counts = Util.getIntValue(rs.getString(1));
		if (counts == 0) {
			StringBuffer sb = new StringBuffer();
			sb.append("create table "+tablename);
			sb.append("( " +id);
			sb.append(conditionField+" varchar(2000))");
			rs.execute(sb.toString());
			if (DBConstant.DB_TYPE_ORACLE.equals(dbType)) {
				createSequenceAndTrigger(tablename);
			}
		}

	}

	public void createSequenceAndTrigger(String tablename) {
		RecordSet rs = new RecordSet();
		try {
			StringBuffer restr = new StringBuffer();
			restr.append("create sequence ").append(tablename).append("_id");
			restr.append(" start with 1");
			restr.append(" increment by 1");

			String appendSql = "";
			if ("jc".equalsIgnoreCase(ConnectionPool.getInstance().getOrgindbtype())){
				appendSql = " MAXVALUE 9223372036854775807 ";
			}else {
				appendSql = " nomaxvalue ";
			}
			restr.append(appendSql);

			restr.append(" nocycle ");
			rs.execute(restr.toString());

			restr = new StringBuffer("");
			restr.append("create or replace trigger ").append(tablename).append("_Trigger");
			restr.append(" before insert on ").append(tablename);
			restr.append(" for each row ");
			restr.append(" begin ");
			restr.append(" select ").append(tablename).append("_id.nextval into :new.id from dual; ");
			restr.append("end; ");
			rs.setChecksql(false);
			rs.execute(restr.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public  Boolean IsCreateTempTab(String conditionfield,ArrayList fieldNameList,ArrayList fieldTypeList,ArrayList fieldHtmlTypeList){
		RecordSet rs = new RecordSet();
		if(conditionfield.equals("dataid")){
			//更新字段为数据id，创建字段为dataid的临时表
			rs.executeQuery("select 1 from M_"+modeid+"_"+user.getUID()+" where 1=2");
			if (!"".equals(rs.getExceptionMsg())||rs.getExceptionMsg()!=null)createTable(modeid+"_"+user.getUID(),conditionfield);	
			return true;
		}else{
			//处理更新字段为单行文本-文本，创建临时表
			Boolean IsSingleText=IsSingleText(conditionfield,fieldNameList,fieldTypeList,fieldHtmlTypeList);
					if(IsSingleText){
					rs.executeQuery("select 1 from M_"+modeid+"_"+user.getUID()+" where 1=2");
					if (!"".equals(rs.getExceptionMsg())||rs.getExceptionMsg()!=null)createTable(modeid+"_"+user.getUID(),conditionfield);
						return true;
					}else{
						return false;	
					}				

				}							

		}
	
	//判断更新字段是否是单行文本或者数据id
	public  Boolean IsSingleText(String conditionfield,ArrayList fieldNameList,ArrayList fieldTypeList,ArrayList fieldHtmlTypeList){
		if(conditionfield.equals("dataid")){
			return true;
		}else{
		for (int k = 0; k < fieldNameList.size(); k++) {
			String fieldname = Util.null2String((String) fieldNameList.get(k));
			String fieldtype = Util.null2String((String)fieldTypeList.get(k));
			String fieldhtmltype = Util.null2String((String)fieldHtmlTypeList.get(k));
			if (conditionfield.equals(fieldname)&&"1".equals(fieldhtmltype)&&"1".equals(fieldtype)) {
				return true;
				}				
			}
		return false;
		}
	}
		
}
