Browse Source
Merge in DESIGN/design from ~DESTINY.LIN/design:fbp-1.0 to fbp-1.0 * commit '3cb01e02b231e75f00a7b1a1cc2e9c2e79d2731b': REPORT-114392 FR-FBP版本本地设计适配 优化部分卡顿逻辑 REPORT-114392 FR-FBP版本本地设计适配 优化部分卡顿逻辑 REPORT-114392 FR-FBP版本本地设计适配 修复数据连接fbp-1.0
Destiny.Lin-林锦龙
5 months ago
11 changed files with 334 additions and 24 deletions
@ -0,0 +1,62 @@
|
||||
package com.fr.design.cache; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.design.data.tabledata.wrapper.TableDataFactory; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 设计器缓存管理 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/8/11 |
||||
*/ |
||||
public class DesignCacheManager { |
||||
|
||||
public static ThreadLocal<Map<String, TableData>> cacheTableData = new ThreadLocal<>(); |
||||
|
||||
/** |
||||
* 处理任务(使用数据集缓存) |
||||
*/ |
||||
public static void processByCacheTableData(Task task) { |
||||
try { |
||||
cacheTableData.set(TableDataFactory.getTableDatas()); |
||||
task.process(); |
||||
} finally { |
||||
cacheTableData.remove(); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 是否使用数据集的缓存 |
||||
*/ |
||||
public static boolean useDataCache() { |
||||
return cacheTableData.get() != null; |
||||
} |
||||
|
||||
/** |
||||
* 获取数据集缓存 |
||||
*/ |
||||
public static ThreadLocal<Map<String, TableData>> getCacheTableData() { |
||||
return cacheTableData; |
||||
} |
||||
|
||||
/** |
||||
* 设置数据集缓存 |
||||
*/ |
||||
public static void setCacheTableData(ThreadLocal<Map<String, TableData>> cacheTableData) { |
||||
DesignCacheManager.cacheTableData = cacheTableData; |
||||
} |
||||
|
||||
/** |
||||
* 任务 |
||||
*/ |
||||
public interface Task { |
||||
/** |
||||
* 处理 |
||||
*/ |
||||
void process(); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.design.data; |
||||
|
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.security.encryption.transmission.TransmissionEncryptionManager; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.workspace.server.repository.WorkplaceConstants; |
||||
|
||||
/** |
||||
* 数据加解密工具类 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/8/9 |
||||
*/ |
||||
public class DataEncryptionHelper { |
||||
|
||||
/** |
||||
* 密码加密 |
||||
*/ |
||||
public static String encryptPassWord(String password) { |
||||
// 如果是空密码或者默认密码,就返回默认的星号回去
|
||||
if (StringUtils.isEmpty(password) || StringUtils.equals(password, DecisionServiceConstants.DEFAULT_PASSWORD)) { |
||||
return DecisionServiceConstants.DEFAULT_PASSWORD; |
||||
} |
||||
return encrypt(password); |
||||
} |
||||
|
||||
/** |
||||
* 加密字符串 |
||||
*/ |
||||
public static String encrypt(String str) { |
||||
return TransmissionEncryptionManager.getInstance().getEncryption(WorkplaceConstants.getEncryptionMode()).encrypt(str, WorkplaceConstants.getEncryptionKey()); |
||||
} |
||||
|
||||
/** |
||||
* 解密字符串 |
||||
*/ |
||||
public static String decrypt(String str) { |
||||
return TransmissionEncryptionManager.getInstance().getEncryption(WorkplaceConstants.getDecryptionMode()).decrypt(str, WorkplaceConstants.getDecryptionKey()); |
||||
} |
||||
} |
@ -0,0 +1,137 @@
|
||||
package com.fr.design.data.datapane.preview; |
||||
|
||||
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; |
||||
import com.fr.base.DataSetProcessors; |
||||
import com.fr.base.Parameter; |
||||
import com.fr.base.ParameterHelper; |
||||
import com.fr.base.ParameterTypeHandler; |
||||
import com.fr.base.TableData; |
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.data.impl.DBTableData; |
||||
import com.fr.data.impl.NameDatabaseConnection; |
||||
import com.fr.decision.fun.UniversalServerTableDataProvider; |
||||
import com.fr.decision.privilege.TransmissionTool; |
||||
import com.fr.decision.webservice.bean.dataset.ParameterBean; |
||||
import com.fr.decision.webservice.bean.dataset.SQLDataSetBean; |
||||
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean; |
||||
import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.SQLDataSetProcessor; |
||||
import com.fr.design.data.DataEncryptionHelper; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.general.sql.SqlUtils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.ParameterProvider; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.workspace.server.entity.connection.ConnectionBean; |
||||
import com.fr.workspace.server.repository.connection.ConnectionRepository; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 数据集bean工具类 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/8/9 |
||||
*/ |
||||
public class TableDataBeanHelper { |
||||
|
||||
|
||||
/** |
||||
* 根据序列化数据生成tabledata |
||||
*/ |
||||
public static TableData getTableDataSet(Map<String, Connection> connectionMap, String type, String tableDataSetData) throws Exception { |
||||
if (DataSetProcessors.getProcessors().containsKey(type)) { |
||||
if (StringUtils.equals(SQLDataSetProcessor.TYPE, type)) { |
||||
return deserialize4SQL(connectionMap, null, new JSONObject(tableDataSetData)); |
||||
} else { |
||||
UniversalServerTableDataProvider processor = DataSetProcessors.getProcessors().get(type); |
||||
return (TableData) processor.deserialize(null, new JSONObject(tableDataSetData)); |
||||
} |
||||
|
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取服务器数据集传输的bean |
||||
*/ |
||||
public static ServerDataSetBean getServerDataSetBean(String name, TableData tableData) { |
||||
for (UniversalServerTableDataProvider processor : DataSetProcessors.getProcessors().values()) { |
||||
if (SQLDataSetProcessor.KEY.classForTableData() == tableData.getClass()) { |
||||
return serialize4SQL(name, tableData); |
||||
} else if (processor.classForTableData() == tableData.getClass()) { |
||||
ServerDataSetBean bean = new ServerDataSetBean(); |
||||
try { |
||||
bean.setDatasetData(processor.serialize(tableData).toString()); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
bean.setDatasetData(StringUtils.EMPTY); |
||||
} |
||||
bean.setDatasetName(name); |
||||
bean.setDatasetType(processor.nameForTableData()); |
||||
return bean; |
||||
} |
||||
} |
||||
return new ServerDataSetBean(name); |
||||
} |
||||
|
||||
private static ServerDataSetBean serialize4SQL(String name, TableData tableData) { |
||||
ServerDataSetBean bean = new ServerDataSetBean(); |
||||
try { |
||||
bean.setDatasetData(serialize4SQL0((DBTableData) tableData).toString()); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
bean.setDatasetData(StringUtils.EMPTY); |
||||
} |
||||
bean.setDatasetName(name); |
||||
bean.setDatasetType(SQLDataSetProcessor.KEY.nameForTableData()); |
||||
return bean; |
||||
} |
||||
|
||||
private static Object serialize4SQL0(DBTableData dataSet) { |
||||
SQLDataSetBean bean = new SQLDataSetBean(); |
||||
if (dataSet.getDatabase() instanceof NameDatabaseConnection) { |
||||
bean.setDatabase(((NameDatabaseConnection) dataSet.getDatabase()).getName()); |
||||
} |
||||
bean.setQuery(DataEncryptionHelper.encrypt(dataSet.getQuery())); |
||||
List<ParameterBean> parameterBeans = new ArrayList<>(); |
||||
ParameterProvider[] parameters = dataSet.getParameters(Calculator.createCalculator()); |
||||
for (ParameterProvider parameter : parameters) { |
||||
parameterBeans.add(new ParameterBean(parameter.getValue().getClass().getSimpleName(), parameter.getName(), GeneralUtils.objectToString(parameter.getValue()))); |
||||
} |
||||
bean.setParameters(parameterBeans); |
||||
return JSONObject.mapFrom(bean); |
||||
} |
||||
|
||||
|
||||
private static TableData deserialize4SQL(Map<String, Connection> connectionMap, DBTableData oldDataSet, JSONObject object) { |
||||
DBTableData tableData = new DBTableData(); |
||||
SQLDataSetBean bean = object.mapTo(SQLDataSetBean.class); |
||||
tableData.setQuery(DataEncryptionHelper.decrypt(bean.getQuery())); |
||||
Connection connection = connectionMap.get(bean.getDatabase()); |
||||
if (connection != null) { |
||||
tableData.setDatabase(new NameDatabaseConnection(bean.getDatabase())); |
||||
} else { |
||||
throw new RuntimeException("not find conn by " + bean.getDatabase()); |
||||
} |
||||
String sql = SqlUtils.clearSqlComments(DataEncryptionHelper.decrypt(bean.getQuery())); |
||||
Parameter[] parameters = new Parameter[bean.getParameters().size()]; |
||||
for (int i = 0; i < parameters.length; i++) { |
||||
ParameterBean parameterBean = bean.getParameters().get(i); |
||||
parameters[i] = (Parameter) ParameterTypeHandler.getInstance().parseParameter(parameterBean, new Parameter(parameterBean.getName())); |
||||
} |
||||
tableData.setParameters(ParameterHelper.analyzeAndUnionSameParameters(new String[]{sql}, parameters)); |
||||
if (oldDataSet != null) { |
||||
tableData.setMaxMemRowCount(oldDataSet.getMaxMemRowCount()); |
||||
tableData.setPageQuerySql(oldDataSet.getPageQuerySql()); |
||||
tableData.setShare(oldDataSet.isShare()); |
||||
tableData.setDataQueryProcessor(oldDataSet.getDataQueryProcessor()); |
||||
} |
||||
return tableData; |
||||
} |
||||
} |
Loading…
Reference in new issue