package com.product.module.data.service;


import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.product.common.collect.SetUtils;
import com.product.common.excel.EasyExcelUtil;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.Global;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldMetaEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.file.service.FileManagerService;
import com.product.module.data.config.CmnCode;
import com.product.module.data.config.CmnConst;
import com.product.module.data.service.idel.ISystemDataUpLoadService;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import com.product.util.SystemParamReplace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;

@Service
public class SystemDataUpLoadService extends AbstractBaseService implements ISystemDataUpLoadService {
	@Autowired
	private BaseDao baseDao;
	@Autowired
	private FileManagerService fileManagerService;
	@Autowired
	private QueryFilterService queryFilterService;

	@Autowired
	private PermissionService permissionService;

	public List<Map<String, Object>> getPrompt() throws BaseException {
		StringBuilder sql = new StringBuilder();
		sql.append(" select prompt_name `value` ,prompt_name `label` ,'prompt' type FROM product_sys_prompt ");
		sql.append(" union all ");
		sql.append(" select concat('銆�',dict_name,'銆�') dict_name,dict_name,'dict' type FROM product_sys_dict where is_used=1 group by dict_name ");
		FieldSetEntity f = new FieldSetEntity();
		f.setTableName("x");
		f.setValue("desc", "楂樼骇鍙傜収锛屾櫘閫氬弬鐓�");
		DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{});
		List<Map<String, Object>> result = Lists.newArrayList();
		if (!BaseUtil.dataTableIsEmpty(dt)) {
			List<Map<String, Object>> promptList = Lists.newArrayList();
			List<Map<String, Object>> dictList = Lists.newArrayList();
			Map<String, Object> item;
			for (int i = 0; i < dt.getRows(); i++) {
				String type = dt.getString(i, "type");
				String value = dt.getString(i, "value");
				String label = dt.getString(i, "label");
				item = Maps.newHashMap();
				item.put("value", value);
				item.put("label", label);
				if ("prompt".equals(type)) {
					promptList.add(item);
				} else {
					dictList.add(item);
				}
			}
			item = Maps.newHashMap();
			item.put("label", "楂樼骇鍙傜収");
			item.put("children", promptList);
			item.put("value", "~楂樼骇鍙傜収~");
			result.add(item);
			item = Maps.newHashMap();
			item.put("label", "鏅€氬弬鐓�");
			item.put("children", dictList);
			item.put("value", "~鏅€氬弬鐓");
			result.add(item);
		}
		return result;
	}


	/**
	 * 妯℃澘涓婁紶
	 *
	 * @param rpe
	 * @return
	 */
	@Override
	@Transactional
	public JSONObject uploadTemplate(RequestParameterEntity rpe) {
		FieldSetEntity paramFse = rpe.getFormData();
		String sourceFileName = paramFse.getString(CmnConst.FIELD_TEMPLATE_INFO);
		if (StringUtils.isEmpty(sourceFileName) || !sourceFileName.endsWith(".xlsx")) {
			throw new BaseException(CmnCode.UPLOAD_TEMPLATE_NOT_ALLOWED_FORMAT.getValue(), CmnCode.UPLOAD_TEMPLATE_NOT_ALLOWED_FORMAT.getText());
		}

		FieldSetEntity fse = fileManagerService.uploadFile(rpe);
		JSONObject resultObj = new JSONObject();
		resultObj.put(CmnConst.FIELD_TEMPLATE_INFO, fse.getString(CmnConst.FIELD_TEMPLATE_INFO));
		return resultObj;
	}

	/**
	 * 瑙f瀽妯℃澘锛岃幏鍙朎xcel琛ㄥご淇℃伅
	 *
	 * @param fse
	 * @return
	 */
	public JSONObject analysisTemplate(FieldSetEntity fse) {
		String attachmentUUID = fse.getString(CmnConst.FIELD_TEMPLATE_INFO);
		DataTableEntity modelDte = null;

		String modelUUID = fse.getUUID();
		boolean needAnalysisFlag = true;
		if (!StringUtils.isEmpty(modelUUID)) {
			FieldSetEntity preModelFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, modelUUID, true);
			String preAttachmentUUID = preModelFse.getString(CmnConst.FIELD_TEMPLATE_INFO);
			modelDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{preModelFse.getString(CmnConst.FIELD_UPLOAD_SIGN)}, null, null, Integer.MAX_VALUE, 1, true);
			if (preAttachmentUUID.equals(attachmentUUID)) {
				// 鍚屾牱鐨勬枃浠讹紝涓嶉渶瑕侀噸鏂拌В鏋�
				needAnalysisFlag = false;
			}
		}

		FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, attachmentUUID, false);
		if (needAnalysisFlag) {
			// 闇€瑕侀噸鏂拌В鏋�
			String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL);
			String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE);
			String path = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName;
			File templateFile = new File(path);
			// 鍒涘缓鏂囦欢娴佹搷浣滃璞�
			try (InputStream inputStream = new FileInputStream(templateFile)) {
				Map<String, List<List<String>>> map = EasyExcelUtil.readExcelByStringFromInputStream(inputStream, null);
				DataTableEntity subDte;
				Map<String, FieldSetEntity> subMap;
				FieldSetEntity mainFse;
				FieldSetEntity subFse;
				List<List<String>> list;
				int index = 0;
				for (Map.Entry<String, List<List<String>>> entry : map.entrySet()) {
					list = entry.getValue();
					if (list.isEmpty()) {
						continue;
					}
					subDte = new DataTableEntity();
					mainFse = null;
					for (String excelHeader : list.get(list.size() - 1)) {
						if (StringUtils.isEmpty(excelHeader)) {
							throw new BaseException(CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getValue(), CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getText());
						}
						subFse = null;
						if (modelDte != null && modelDte.getRows() > index) {
							mainFse = modelDte.getFieldSetEntity(index);
							subMap = dte2Map(mainFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_EXCEL_HEADER);
							if (subMap.containsKey(excelHeader)) {
								// 鍘熸湁鐨勫瓧娈�
								subFse = subMap.get(excelHeader);
							}
						}
						if (subFse == null) {
							// 鏈韩娌℃湁鐨勫瓧娈�
							subFse = new FieldSetEntity();
							subFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB);
							subFse.setValue(CmnConst.FIELD_EXCEL_HEADER, excelHeader);
						}
						subDte.addFieldSetEntity(subFse);
					}
					if (mainFse == null) {
						mainFse = new FieldSetEntity();
						mainFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
						if (modelDte == null) {
							modelDte = new DataTableEntity();
						}
						modelDte.addFieldSetEntity(mainFse);
					} else {
						mainFse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB);
					}
					mainFse.setValue("start_row_index", list.size() - 1);
					mainFse.addSubDataTable(subDte);
					index++;
				}
			} catch (Exception e) {
				e.printStackTrace();
				throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getText());
			}
		}

		JSONObject resultObj = new JSONObject();
		resultObj.put("sheet_info", BaseUtil.dataTableEntityToJson(modelDte));
		resultObj.put(CmnConst.FIELD_UPLOAD_SIGN, SpringMVCContextHolder.getCurrentUser().getClient_uuid() + "_" + attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE) + "_" + System.currentTimeMillis());
		return resultObj;
	}

	/**
	 * 淇濆瓨
	 *
	 * @param fse
	 */
	@Override
	@Transactional
	public void saveTemplate(FieldSetEntity fse) {
		if (StringUtils.isEmpty(fse.getUUID())) {
			addTemplate(fse);
		} else {
			updateTemplate(fse);
		}
	}

	/**
	 * 鏂板妯℃澘
	 *
	 * @param fse
	 */
	private void addTemplate(FieldSetEntity fse) {
		SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
		String orgLevelUUID = curUser.getOrg_level_uuid();
		String clientUUID = curUser.getClient_uuid();
		String attachmentUUID = fse.getString(CmnConst.FIELD_TEMPLATE_INFO);
		FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, attachmentUUID, false);
		String uploadSign = clientUUID + "_" + attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE) + "_" + System.currentTimeMillis();
		int sheetOrder = 1;
		fse.setValue(CmnConst.FIELD_SHEET_ORDER, sheetOrder);
		fse.setValue(CmnConst.FIELD_UPLOAD_SIGN, uploadSign);
		// 淇濆瓨鏁版嵁瀵煎叆妯℃澘淇℃伅
		DataTableEntity modelDte = fse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
		if (!BaseUtil.dataTableIsEmpty(modelDte)) {
			FieldSetEntity tempFse;
			for (int i = 0; i < modelDte.getRows(); i++) {
				tempFse = modelDte.getFieldSetEntity(i);
				tempFse.setValue(CmnConst.FIELD_UPLOAD_SIGN, uploadSign);
				tempFse.setValue(CmnConst.FIELD_SHEET_ORDER, ++sheetOrder);
				BaseUtil.addOrgLeveLUUID(tempFse, Collections.singletonList(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), orgLevelUUID, curUser);
				baseDao.saveFieldSetEntity(tempFse);
			}
			fse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
		}
		BaseUtil.addOrgLeveLUUID(fse, Collections.singletonList(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), orgLevelUUID, curUser);
		baseDao.saveFieldSetEntity(fse);

		String mvcUUID = fse.getString(CmnConst.FIELD_FUNCTION_UUID);
		String buttonTitle = fse.getString(CmnConst.FILED_BUTTON_TITLE);
		// todo 寰呮祴璇曪紝鍒涘缓mvc鐩稿叧鍐呭
		dealMvcInfo(mvcUUID, buttonTitle, uploadSign);
	}

	/**
	 * 澶勭悊mvc涓鍏ラ厤缃俊鎭�
	 *
	 * @param mvcUUID
	 * @param buttonTitle
	 */
	private void dealMvcInfo(String mvcUUID, String buttonTitle, String uploadSign) {
		FieldSetEntity firstPageFse = getFirstPageFse(mvcUUID);
		if (firstPageFse == null) {
			throw new BaseException(CmnCode.GET_MVC_FIRST_PAGE_INFO_FAIL.getValue(), CmnCode.GET_MVC_FIRST_PAGE_INFO_FAIL.getText());
		}
		FieldSetEntity preImportButtonFse = getImportButtonFse(firstPageFse, mvcUUID);

		SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
		if (preImportButtonFse == null) {
			// 鏈韩娌℃湁瀵煎叆鎸夐挳锛岃嚜鍔ㄥ垱寤� todo

			// 鎸夐挳
			FieldSetEntity importButtonFse = new FieldSetEntity();
			importButtonFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_BUTTONS);
			importButtonFse.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
			importButtonFse.setValue(CmnConst.FILED_BUTTON_NAME, "default_import");
			importButtonFse.setValue(CmnConst.FILED_BUTTON_TITLE, buttonTitle);
			importButtonFse.setValue(CmnConst.FILED_STATUS_UUID, 1);
			importButtonFse.setValue(CmnConst.FILED_CATEGORY_UUID, "import");
			importButtonFse.setValue(CmnConst.FILED_CLIENT_TYPE_UUID, "Web");
			importButtonFse.setValue(CmnConst.FILED_ROUTE_NAME, BaseUtil.getPageCode());
			importButtonFse.setValue("params", "{\"upload_sign\":\"" + uploadSign + "\"}");
			importButtonFse.setValue("button_category_uuid", "import");
			importButtonFse.setValue("button_type", 2);
			importButtonFse.setValue("is_main", 0);
			BaseUtil.createCreatorAndCreationTime(curUser, importButtonFse);
			baseDao.saveFieldSetEntity(importButtonFse);

//            // 椤甸潰
//            FieldSetEntity importPageFse = new FieldSetEntity();
//            importPageFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_PAGE);
//            importPageFse.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
//            importPageFse.setValue(CmnConst.FIELD_PAGE_NAME, "榛樿瀵煎叆椤甸潰");
//            importPageFse.setValue(CmnConst.FIELD_PAGE_TYPE, 2);
//            importPageFse.setValue(CmnConst.FIELD_PAGE_TYPE, 2);
//            BaseUtil.createCreatorAndCreationTime(curUser, importPageFse);
//            baseDao.saveFieldSetEntity(importPageFse);

			// 杩炵嚎-鍒楄〃鐣岄潰-瀵煎叆鎸夐挳
			FieldSetEntity importLinkFse1 = new FieldSetEntity();
			importLinkFse1.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK);
			importLinkFse1.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
			importLinkFse1.setValue(CmnConst.FIELD_LINK_TYPE, 0);
			importLinkFse1.setValue(CmnConst.FIELD_LINE_FROM, firstPageFse.getUUID());
			importLinkFse1.setValue(CmnConst.FIELD_FROM_TYPE, 2);
			importLinkFse1.setValue(CmnConst.FIELD_LINE_TO, importButtonFse.getUUID());
			importLinkFse1.setValue(CmnConst.FIELD_TO_TYPE, 1);
			BaseUtil.createCreatorAndCreationTime(curUser, importLinkFse1);
			baseDao.saveFieldSetEntity(importLinkFse1);
//            // 杩炵嚎-瀵煎叆鎸夐挳-瀵煎叆椤甸潰
//            FieldSetEntity importLinkFse2 = new FieldSetEntity();
//            importLinkFse2.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK);
//            importLinkFse2.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
//            importLinkFse2.setValue(CmnConst.FIELD_LINK_TYPE, 0);
//            importLinkFse2.setValue(CmnConst.FIELD_LINE_FROM, importButtonFse.getUUID());
//            importLinkFse2.setValue(CmnConst.FIELD_FROM_TYPE, 1);
//            importLinkFse2.setValue(CmnConst.FIELD_LINE_TO, importPageFse.getUUID());
//            importLinkFse2.setValue(CmnConst.FIELD_TO_TYPE, 2);
//            BaseUtil.createCreatorAndCreationTime(curUser, importLinkFse2);
//            baseDao.saveFieldSetEntity(importLinkFse2);
		} else {
			// 鏈韩瀛樺湪瀵煎叆鎸夐挳锛岀洿鎺ユ浛鎹㈢浉搴旂殑鏁版嵁 todo
			preImportButtonFse.setValue("", "");
			BaseUtil.updatedRegeneratorAndUpdateTime(curUser, preImportButtonFse);
			baseDao.saveFieldSetEntity(preImportButtonFse);
		}
	}

	/**
	 * 鎻愬彇鎸囧畾mvc涓€愬叆鍙c€戝悗绗竴涓〉闈�
	 *
	 * @param mvcUUID
	 * @return
	 */
	private FieldSetEntity getFirstPageFse(String mvcUUID) {
		StringBuilder sql = new StringBuilder(256);
		sql.append("select p.* from (")
				.append("\n    select * FROM product_sys_function_buttons where is_main=1 and function_uuid=?")
				.append("\n) b")
				.append("\ninner join product_sys_link l on b.uuid=l.line_from")
				.append("\ninner join product_sys_mvc_page p on l.line_to=p.uuid");
		FieldSetEntity firstPageFse = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{mvcUUID}, false);
		return firstPageFse;
	}

	/**
	 * 鍏ュ彛鍚庣涓€涓〉闈箣鍚庣殑瀵煎叆
	 *
	 * @param firstPageFse
	 * @param mvcUUID
	 * @return
	 */
	private FieldSetEntity getImportButtonFse(FieldSetEntity firstPageFse, String mvcUUID) {
		StringBuilder sql = new StringBuilder(256);
		sql.append("select b.* from (")
				.append("\n    select * FROM product_sys_mvc_page where uuid=?")
				.append("\n) p")
				.append("\ninner join product_sys_link l on p.uuid=l.line_to")
				.append("\ninner join (")
				.append("\n    select * FROM product_sys_function_buttons where function_uuid=? and button_category_uuid='import'")
				.append("\n) b on l.line_from=b.uuid");
		FieldSetEntity preImportButtonFse = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{firstPageFse.getUUID(), mvcUUID}, false);
		return preImportButtonFse;
	}

	/**
	 * 淇敼妯℃澘
	 *
	 * @param fse
	 */
	private void updateTemplate(FieldSetEntity fse) {
		SystemUser curUser = SpringMVCContextHolder.getCurrentUser();

		// 淇濆瓨鏁版嵁瀵煎叆妯℃澘淇℃伅
		DataTableEntity modelDte = fse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
		if (!BaseUtil.dataTableIsEmpty(modelDte)) {
			FieldSetEntity tempFse;
			for (int i = 0; i < modelDte.getRows(); i++) {
				tempFse = modelDte.getFieldSetEntity(i);
				BaseUtil.updatedRegeneratorAndUpdateTime(curUser, tempFse);
				baseDao.saveFieldSetEntity(tempFse);
			}
		}
		fse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
		BaseUtil.updatedRegeneratorAndUpdateTime(curUser, fse);
		baseDao.saveFieldSetEntity(fse);
	}

	/**
	 * 鏌ヨ妯℃澘閰嶇疆璇︽儏
	 *
	 * @param fse
	 * @return
	 */
	public FieldSetEntity findTemplate(FieldSetEntity fse) {
		String uploadSign = fse.getString(CmnConst.FIELD_UPLOAD_SIGN);
		DataTableEntity dt = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{uploadSign}, null, "sheet_order", Integer.MAX_VALUE, 1, true);
		if (!BaseUtil.dataTableIsEmpty(dt)) {
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
			DataTableEntity sub = new DataTableEntity();
			for (int i = 0; i < dt.getRows(); i++) {
				if (i == 0) {
					fs.setValue(CmnConst.FIELD_TITLE, dt.getString(0, CmnConst.FIELD_TITLE));
					fs.setValue(CmnConst.FIELD_FUNCTION_UUID, dt.getString(0, CmnConst.FIELD_FUNCTION_UUID));
					fs.setValue(CmnConst.FILED_BUTTON_TITLE, dt.getString(0, CmnConst.FILED_BUTTON_TITLE));
					fs.setValue(CmnConst.UUID, dt.getString(0, CmnConst.UUID));
					fs.setValue(CmnConst.FIELD_UPLOAD_SIGN, dt.getString(0, CmnConst.FIELD_UPLOAD_SIGN));
					fs.setValue(CmnConst.FIELD_TEMPLATE_INFO, dt.getString(0, CmnConst.FIELD_TEMPLATE_INFO));
				}
				String before_func = dt.getString(i, CmnConst.FIELD_BEFORE_FUNC);
				String after_func = dt.getString(i, CmnConst.FIELD_AFTER_FUNC);
				String table_name = dt.getString(i, CmnConst.TABLE_NAME);
				String startRowIndex = dt.getString(i, "start_row_index");
				FieldSetEntity f = new FieldSetEntity();
				f.setTableName("sheet_info");
				f.setValue(CmnConst.FIELD_BEFORE_FUNC, before_func);
				f.setValue(CmnConst.FIELD_AFTER_FUNC, after_func);
				f.setValue(CmnConst.UUID, dt.getString(i, CmnConst.UUID));
				f.setValue(CmnConst.TABLE_NAME, table_name);
				f.setValue("start_row_index", startRowIndex);
				f.setSubData(dt.getFieldSetEntity(i).getSubData());
				sub.addFieldSetEntity(f);
			}
			fs.addSubDataTable(sub);
			return fs;
		}
		return null;
	}

	/**
	 * 妯℃澘鍙拌处-宸﹁竟鏍戠粨鏋�
	 *
	 * @param fse
	 * @return
	 */
	public DataTableEntity listTemplate(FieldSetEntity fse) {
		int pageSize = fse.getInteger(CmnConst.PAGESIZE) == null ? Integer.MAX_VALUE : fse.getInteger(CmnConst.PAGESIZE);
		int curPage = fse.getInteger(CmnConst.CPAGE) == null ? 1 : fse.getInteger(CmnConst.CPAGE);
		SystemUser user = SpringMVCContextHolder.getCurrentUser();
		StringBuilder filter = new StringBuilder(128);
		filter.append("org_level_uuid=? and length(title)>0");
		String queryFilter = queryFilterService.getQueryFilter(fse);
		if (!StringUtils.isEmpty(queryFilter)) {
			filter.append(" and ").append(queryFilter);
		}
		List<Object> paramList = Lists.newArrayList();
		paramList.add(user.getOrg_level_uuid());
		String[] filterParamArr = !StringUtils.isEmpty(fse.getString("~select_params~")) ? fse.getString("~select_params~").split(",") : null;
		if (filterParamArr != null) {
			Collections.addAll(paramList, filterParamArr);
		}
		return baseDao.listTable(fse.getTableName(), filter.toString(), paramList.toArray(), null, fse.getString(""), pageSize, curPage);
	}

	/**
	 * 鏁版嵁涓婁紶妯℃澘鍒犻櫎
	 *
	 * @param fse
	 * @throws BaseException
	 */
	@Override
	@Transactional
	public void deleteModel(FieldSetEntity fse) throws BaseException {
		String uploadSign = fse.getString(CmnConst.FIELD_UPLOAD_SIGN);
		DataTableEntity modelDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{uploadSign});
		if (BaseUtil.dataTableIsEmpty(modelDte)) {
			throw new BaseException(CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getText());
		}
		FieldSetEntity mainModelFse = null;
		FieldSetEntity tempFse;
		List<String> uuidParamList = Lists.newArrayList();
		for (int i = 0; i < modelDte.getRows(); i++) {
			tempFse = modelDte.getFieldSetEntity(i);
			uuidParamList.add(tempFse.getUUID());
			if (!StringUtils.isEmpty(tempFse.getString(CmnConst.FIELD_FUNCTION_UUID))) {
				mainModelFse = tempFse;
			}
		}
		if (mainModelFse == null) {
			throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_MAIN_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_MAIN_INFO_FAIL.getText());
		}

		// 鍒犻櫎mvc鐩稿叧鐨勮〃淇℃伅
		String mvcUUID = mainModelFse.getString(CmnConst.FIELD_FUNCTION_UUID);
		FieldSetEntity firstPageFse = getFirstPageFse(mvcUUID);
		// 瀵煎叆鎸夐挳
		FieldSetEntity importButtonFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_BUTTONS, "function_uuid=? and button_name='default_import'", new Object[]{mvcUUID}, false);
		if (importButtonFse != null) {
			// 杩炵嚎-瀵煎叆鎸夐挳-瀵煎叆椤甸潰
//            FieldSetEntity secondLinkFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=1 and line_from=?", new Object[]{mvcUUID, importButtonFse.getUUID()}, false);
			// 鍒犻櫎-瀵煎叆椤甸潰
//            baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_PAGE, new Object[]{secondLinkFse.getString(CmnConst.FIELD_LINE_TO)});
			// 鍒犻櫎-杩炵嚎-瀵煎叆鎸夐挳-瀵煎叆椤甸潰
//            baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=1 and line_from=?", new Object[]{mvcUUID, importButtonFse.getUUID()});
			// 鍒犻櫎-杩炵嚎-鍒楄〃鐣岄潰-瀵煎叆鎸夐挳
			baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=2 and to_type=1 and line_from=? and line_to=?", new Object[]{mvcUUID, firstPageFse.getUUID(), importButtonFse.getUUID()});
			// 鍒犻櫎-瀵煎叆鎸夐挳
			baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_BUTTONS, new Object[]{importButtonFse.getUUID()});

		}
		// 鍒犻櫎闄勪欢
		FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, mainModelFse.getString(CmnConst.FIELD_TEMPLATE_INFO), false);
		if (attachmentFse != null) {
			String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL);
			String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE);
			String path = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName;
			File templateFile = new File(path);
			templateFile.delete();
			// 鍒犻櫎闄勪欢琛�
			baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, new Object[]{attachmentFse.getUUID()});
		}
		// 鍒犻櫎妯℃澘瀛愯〃
		String filter = BaseUtil.buildQuestionMarkFilter(CmnConst.FIELD_MODEL_UUID, uuidParamList.size(), true);
		baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB, filter, uuidParamList.toArray());
		// 鍒犻櫎妯℃澘涓昏〃
		baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, uuidParamList.toArray());
	}

	/**
	 * 妯℃澘涓嬭浇
	 *
	 * @param fse
	 * @param response
	 * @throws IOException
	 */
	public void downloadTemplate(FieldSetEntity fse, HttpServletResponse response) throws IOException {
		String upload_sign = fse.getString("upload_sign");
		FieldSetEntity templateFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=? AND length(title)>0", new Object[]{upload_sign}, false);
		String attachmentUUID = templateFse.getString(CmnConst.FIELD_TEMPLATE_INFO);
		fse.setValue(CmnConst.UUID, attachmentUUID);
		fileManagerService.getFileContent(fse, response);
	}

	/**
	 * 涓氬姟鍔熻兘瀵煎叆-涓婁紶鏂囦欢
	 *
	 * @param rpe
	 * @return
	 */
	@Override
	@Transactional
	public String recordDataImport(RequestParameterEntity rpe) {
		FieldSetEntity ff = fileManagerService.uploadFile(rpe);
		FieldSetEntity fse = rpe.getFormData();
		fse.setValue(CmnConst.FIELD_IS_SUCCESS, 0);
		SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
		fse.setValue(CmnConst.FIELD_ORG_LEVEL_UUID, curUser.getOrg_level_uuid());
		BaseUtil.createCreatorAndCreationTime(curUser, fse);
		fse.setValue("import_info", ff.getString("import_info"));
		baseDao.saveFieldSetEntity(fse);
		return fse.getUUID();
	}

	/**
	 * 涓氬姟鍔熻兘瀵煎叆-瑙f瀽骞朵繚瀛樺埌鏁版嵁搴�
	 *
	 * @param fse
	 * @return
	 */
	@Override
	@Transactional
	public void recordDataSave(FieldSetEntity fse) {
		SystemUser curUser = SpringMVCContextHolder.getCurrentUser();

		FieldSetEntity logFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD, fse.getUUID(), false);
		if (logFse == null) {
			throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_UPLOAD_RECORD_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_UPLOAD_RECORD_FAIL.getText());
		}

		// 鑾峰彇妯℃澘淇℃伅
		DataTableEntity templateDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{logFse.getString(CmnConst.FIELD_UPLOAD_SIGN)}, null, "sheet_order", Integer.MAX_VALUE, 1, true);

		// 鑾峰彇瀵煎叆鏂囦欢淇℃伅
		FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, logFse.getString(CmnConst.FIELD_IMPORT_INFO), false);
		String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL);
		String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE);
		Map<String, List<List<String>>> dataMap = new HashMap<>();
		try {
			String filePath = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName;
			dataMap = EasyExcelUtil.readExcelByString(filePath);
			
			if ("product_project_budget".equals(templateDte.getString(0, CmnConst.TABLE_NAME))) {
				for (int i = 1; i < dataMap.size(); i++) {
					templateDte.addFieldSetEntity(templateDte.getFieldSetEntity(0).clones());
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 灏佽鍒癲te涓�
		List<DataTableEntity> beforeSaveDataList = Lists.newArrayList();
		List<String> titleList;
		List<List<String>> dataList;
		List<String> rowList;
		String singleValue;// 鍗曞厓鏍煎唴鐨勫€�
		int index = 0;
		FieldSetEntity curTemplateFse;
		Map<String, FieldSetEntity> curSubMap;
		List<List<List<String>>> headerDataList = Lists.newArrayList();
		List<Map<String, FieldSetEntity>> fieldInfoList = Lists.newArrayList();
		FieldSetEntity curFieldFse;
		FieldSetEntity recordFse;// 涓氬姟琛╢se
		DataTableEntity recordDte;// 涓氬姟琛╠te
		for (Map.Entry<String, List<List<String>>> entry : dataMap.entrySet()) {
			dataList = entry.getValue();
			if (dataList.isEmpty()) {
				continue;
			}

			recordDte = new DataTableEntity();
			curTemplateFse = templateDte.getFieldSetEntity(index);
			curSubMap = dte2Map(curTemplateFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_EXCEL_HEADER);
			fieldInfoList.add(curSubMap);
			// 瀛楁瀵瑰簲鐨別xcel 琛ㄥご绱㈠紩
			Map<String, String> fieldIndex = Maps.newHashMap();
			//琛ㄥご寮€濮嬭 cheng update 2023骞�6鏈�30鏃�15:48:22 澶氳澶存椂锛岃〃澶村紑濮嬭涓嶄竴瀹氭槸绗竴琛�
			int startRowIndex = 1;
			if (!StringUtils.isEmpty(curTemplateFse.getString("start_row_index")) && NumberUtil.isNumber(curTemplateFse.getString("start_row_index"))) {
				startRowIndex = Integer.parseInt(curTemplateFse.getString("start_row_index"));
				if (startRowIndex < 1) {
					startRowIndex = 1;
				}
			}

			titleList = dataList.get(startRowIndex);
			if (startRowIndex > 0) {
				headerDataList.add(dataList.subList(0, startRowIndex));
			} else {
				headerDataList.add(new ArrayList<>());
			}
			for (int i = startRowIndex + 1; i < dataList.size(); i++) {
				rowList = dataList.get(i);
				System.out.println(rowList.toString());
				recordFse = new FieldSetEntity();
				recordFse.setTableName(curTemplateFse.getString(CmnConst.FIELD_TABLE_NAME));
				//瀛楁瀵瑰簲鐨勫垪
				int j = 0;
				for (; j < titleList.size() && j<14; j++) {
					if (rowList.size() < (j + 1)) {
						singleValue = null;
					} else {
						singleValue = rowList.get(j);
					}
					curFieldFse = curSubMap.get(titleList.get(j));
					System.out.println(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME)+":"+singleValue);
					recordFse.setValue(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), singleValue);
					if (i == 1 || rowList.size() > fieldIndex.size()) {
						fieldIndex.put(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), String.valueOf(j));
					}
				}
				recordFse.setValue("~colName~", titleList);
				recordFse.setValue("~fieldIndex~", fieldIndex);
				// fieldSet 瀵瑰簲鐨勮
				recordFse.setValue("~row~", i);
				recordDte.addFieldSetEntity(recordFse);
			}
			beforeSaveDataList.add(recordDte);
			index++;
		}

		// 鏁版嵁瑙f瀽淇濆瓨
		String orgLevelUUID = curUser.getOrg_level_uuid();
		String actualValue;
		FieldMetaEntity meta;
		Object[] fieldArr;
		DataTableEntity tempDte;
		String fieldName;
		for (int i = 0; i < beforeSaveDataList.size(); i++) {
			tempDte = beforeSaveDataList.get(i);

			// 淇濆瓨鍓嶅鐞�
			try {
				tempDte = spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_BEFORE_FUNC), tempDte, headerDataList.get(i));
				if (BaseUtil.dataTableIsEmpty(tempDte)) {
					throw new BaseException(CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getValue(), CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getText());
				}
			} catch (BaseException e) {
				throw e;
			} catch (Exception e) {
				e.printStackTrace();
				throw new BaseException(CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_FAIL.getText());
			}

			meta = tempDte.getMeta();
			fieldArr = meta.getFields();

			curTemplateFse = templateDte.getFieldSetEntity(i);
			curSubMap = dte2Map(curTemplateFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_FIELD_NAME);
			boolean isMultiFlag;
			StringBuilder errorMsg = new StringBuilder(8);
			for (int j = 0; j < tempDte.getRows(); j++) {
				recordFse = tempDte.getFieldSetEntity(j);
				for (Object fieldNameObj : fieldArr) {
					if (fieldNameObj == null) {
						continue;
					}
					fieldName = fieldNameObj.toString();
					singleValue = recordFse.getString(fieldName);

					curFieldFse = curSubMap.get(fieldName);
					if (curFieldFse != null) {
						// 鎻愬彇鐪熷疄鍊�
						if (!StringUtils.isEmpty(curFieldFse.getString(CmnConst.FIELD_PROMPT_NAME))) {
							isMultiFlag = curFieldFse.getString(CmnConst.FIELD_IS_MULTI) == null ? false : "1".equals(curFieldFse.getString(CmnConst.FIELD_IS_MULTI));
							// 鏍规嵁鍙傜収鍚嶇О锛屽弬鐓х被鍨嬶紝鏄剧ず鍩熺殑鍊硷紝鑾峰彇闅愯棌鍩熺殑鍊�
							actualValue = getRealValue(curFieldFse.getString(CmnConst.FIELD_PROMPT_NAME), singleValue, isMultiFlag);
						} else {
							actualValue = singleValue;
						}
						recordFse.setValue(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), actualValue);
					}
				}
				try {
					BaseUtil.createCreatorAndCreationTime(curUser, recordFse);
					baseDao.saveFieldSetEntity(recordFse);
				} catch (BaseException e) {
					e.printStackTrace();
//                    errorMsg.append("瀵煎叆鏁版嵁閿欒锛歕n\t");
					errorMsg.append(String.format("绗�%s涓猻heet锛岀%s琛�,%s", i + 1, j + 1, e.getMessageInfo() != null ? e.getMessageInfo() : "")).append("\n");
//                    throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), String.format("%s: 绗�%s涓猻heet锛岀%s琛�", CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getText(), i + 1, j + 1), e);
				} catch (Exception e) {
					errorMsg.append(String.format("绗�%s涓猻heet锛岀%s琛�,%s", i + 1, j + 1, e.getMessage() != null ? e.getMessage() : "")).append("\n");
//                    throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), String.format("%s: 绗�%s涓猻heet锛岀%s琛�", CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getText(), i + 1, j + 1));
				}
			}
			if (errorMsg.length() > 0) {
				throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), errorMsg.toString());
			}

			// 淇濆瓨鍚庡鐞�
			try {
				spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_AFTER_FUNC), tempDte, headerDataList.get(i));
			} catch (BaseException e) {
				SpringMVCContextHolder.getSystemLogger().error(e);
			} catch (Exception e) {
				throw new BaseException(CmnCode.UPLOAD_TEMPLATE_AFTER_FUNC_EXEC_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_AFTER_FUNC_EXEC_FAIL.getText());
			}
		}

		// 鏇存柊璁板綍琛ㄦ儏鍐�
		logFse.setValue(CmnConst.FIELD_IS_SUCCESS, 1);
		BaseUtil.updatedRegeneratorAndUpdateTime(curUser, fse);
		baseDao.saveFieldSetEntity(logFse);
	}

	/**
	 * dte鎸夌収鎸囧畾fse涓殑鍊间綔涓簁ey杞崲涓簃ap
	 *
	 * @param dte
	 * @param keyFieldName
	 * @return
	 */
	private Map<String, FieldSetEntity> dte2Map(DataTableEntity dte, String keyFieldName) {
		Map<String, FieldSetEntity> resultMap = Maps.newHashMap();
		FieldSetEntity tempFse;
		for (int i = 0; i < dte.getRows(); i++) {
			tempFse = dte.getFieldSetEntity(i);
			resultMap.put(tempFse.getString(keyFieldName), tempFse);
		}
		return resultMap;
	}

	public static void main(String[] args) {
		Class<?> a = DataTableEntity.class;
		Class<DataTableEntity> b = DataTableEntity.class;
		System.out.println(a.equals(b));
	}

	/**
	 * 浜嬩欢鍓嶆垨鑰呬簨浠跺悗璋冪敤閫昏緫鏂规硶鐨勭壒娈婂鐞�
	 *
	 * @param functionContent
	 * @param dte
	 * @param headerDataList
	 * @return
	 */
	private DataTableEntity spDeal(String functionContent, DataTableEntity dte, List<List<String>> headerDataList) throws BaseException {
		if (functionContent == null) {
			return dte;
		}
		functionContent = functionContent.trim();
		if (StringUtils.isEmpty(functionContent)) {
			return dte;
		}
		String className = functionContent.substring(0, functionContent.indexOf("."));
		String methodName = functionContent.substring(functionContent.indexOf(".") + 1, functionContent.indexOf("("));
		//鏍规嵁className鑾峰彇绫�
		Object bean = SpringUtil.getBean(className);
		//浣跨敤huTool鐨勫弽灏勫伐鍏风被鑾峰彇鏂规硶锛屾柟娉曠殑鍙傛暟绫诲瀷涓篋ataTableEntity銆丩ist<List<String>>
		Method method = ReflectUtil.getMethod(bean.getClass(), methodName, DataTableEntity.class, List.class);
		if (method != null) {
			Type genericReturnType = method.getGenericReturnType();
			//鍒ゆ柇method杩斿洖鍊间负DataTableEntity.class
			boolean isBackDataTable = genericReturnType.getTypeName().equals("com.product.core.entity.DataTableEntity");
			//鍒ゆ柇绗簩涓弬鏁扮殑娉涘瀷绫诲瀷
			Type[] types = method.getGenericParameterTypes();
			Type type = types[1];
			//鍒ゆ柇绫诲瀷鏄惁涓篖ist<List<String>>锛屽鏋滄槸鍒欒皟鐢ㄦ柟娉�
			if (isBackDataTable && type.getTypeName().equals("java.util.List<java.util.List<java.lang.String>>")) {
				return ReflectUtil.invoke(bean, methodName, dte, headerDataList);
			}
		}

		return ReflectUtil.invoke(bean, methodName, dte);
	}

	/**
	 * 鑾峰彇鐪熷疄鍊�
	 *
	 * @param promptName
	 * @param showValue
	 * @return
	 */
	private String getRealValue(String promptName, String showValue, boolean isMultiFlag) {
		String realValue = showValue;
		DataTableEntity promptDte;
		FieldSetEntity promptFse;
		if (promptName.startsWith("銆�")) {
			// 鏅€氬弬鐓�
			promptName = promptName.replace("銆�", "").replace("銆�", "");
			promptDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_COMMON_PROMPT, new String[]{promptName});
			if (!BaseUtil.dataTableIsEmpty(promptDte)) {
				Set<String> showSet = SetUtils.string2Set(showValue, ",");
				Set<String> realSet = Sets.newLinkedHashSet();
				for (int i = 0; i < promptDte.getRows(); i++) {
					promptFse = promptDte.getFieldSetEntity(i);
					if (isMultiFlag) {
						if (showSet.contains(promptFse.getString(CmnConst.FIELD_DICT_LABEL))) {
							realSet.add(promptFse.getString(CmnConst.FIELD_DICT_VALUE));
						}
					} else {
						if (showValue.equals(promptFse.getString(CmnConst.FIELD_DICT_LABEL))) {
							realValue = promptFse.getString(CmnConst.FIELD_DICT_VALUE);
							break;
						}
					}
				}
				if (!realSet.isEmpty()) {
					realValue = SetUtils.set2String(realSet, ",");
				}
			}
		} else {
			// 楂樼骇鍙傜収
			promptFse = BaseUtil.getSingleInfoByCache(CmnConst.CACHE_ADVANCED_PROMPT, new String[]{promptName});
			String sourceTableName = promptFse.getString(CmnConst.FILED_SOURCE_TABLE);
			String filter = promptFse.getString(CmnConst.FILED_FILTER);
			String showFieldName = promptFse.getString(CmnConst.FILED_VIEW_FIELD);
			Set<String> showSet = SetUtils.string2Set(showValue, ",");
			String promptFilter = BaseUtil.buildQuestionMarkFilter(showFieldName, isMultiFlag ? showSet.size() : 1, true);
			StringBuilder sql = new StringBuilder(256);
			String realFieldName = promptFse.getString(CmnConst.FILED_VALUE_FIELD);
			sql.append("select GROUP_CONCAT(").append(realFieldName).append(") real_value from ").append(sourceTableName).append(" where ").append(promptFilter);
			if (!StringUtils.isEmpty(filter)) {
				filter = SystemParamReplace.systemParamsReplace(filter);
				sql.append(" and ").append(filter);
			}
			// 琛ュ厖鐗瑰畾瀛楁鏁版嵁杩囨护
			if (!StringUtils.isEmpty(promptFse.getString("org_filter_field")) || !StringUtils.isEmpty(promptFse.getString("user_filter_field"))) {
				String dataFilter = permissionService.getDataFilter(sourceTableName,
						promptFse.getString("user_filter_field"), promptFse.getString("org_filter_field"));
				if (!StringUtils.isEmpty(dataFilter)) {
					sql.append(" and ").append(dataFilter);
				}
			}
			FieldSetEntity sourceFse = baseDao.getFieldSetEntityBySQL(sql.toString(), showSet.toArray(), false);
			if (sourceFse != null) {
				realValue = sourceFse.getString("real_value");
			}
		}
		return realValue;
	}
}