package com.product.data.utli; import com.google.common.collect.Maps; import com.product.common.lang.StringUtils; import com.product.core.cache.DataPoolCacheImpl; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.exception.BaseException; import com.product.data.config.CmnConst; import com.product.data.config.DatabaseType; import com.product.data.config.ErrorCode; import java.util.HashMap; import java.util.Map; /** * @Author cheng * @Date 2022/2/8 16:36 * @Desc 通用工具类 */ public class CommonUtils { public static String getFieldName(String fieldName, DatabaseType dbe) { switch (dbe) { case MySql: return "`" + fieldName + "`"; case SqlServer: return "[" + fieldName + "]"; case Oracle: case PSQL: return "\"" + fieldName + '\"'; case Informix: //todo } return fieldName; } /** * 获取字段缓存根据表名 * * @param tableName 表名 * @return * @throws BaseException */ public static Map> getSystemFieldByCache(String tableName) throws BaseException { DataPoolCacheImpl dataPoolCache = DataPoolCacheImpl.getInstance(); DataTableEntity tableInfo = dataPoolCache.getCacheData("所有表信息", new String[]{tableName}); if (DataTableEntity.isEmpty(tableInfo) || StringUtils.isEmpty(tableInfo.getString(0, CmnConst.UUID))) { throw new BaseException(ErrorCode.GET_TABLE_CACHE_FAIL.getValue(), ErrorCode.GET_TABLE_CACHE_FAIL.getText()); } String table_uuid = tableInfo.getString(0, CmnConst.UUID); DataTableEntity fieldInfo = dataPoolCache.getCacheData("表字段信息", new String[]{table_uuid}); if (DataTableEntity.isEmpty(fieldInfo)) { throw new BaseException(ErrorCode.GET_FIELD_CACHE_FAIL.getValue(), ErrorCode.GET_FIELD_CACHE_FAIL.getText()); } Map> resultMap = new HashMap<>(); for (int i = 0; i < fieldInfo.getRows(); i++) { FieldSetEntity fs = fieldInfo.getFieldSetEntity(i); Map values = fs.getValues(); String field_name = fs.getString(CmnConst.FIELD_NAME); resultMap.put(field_name, Maps.newHashMap(values)); } return resultMap; } }