diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java index 89825196b5..cd94ab0b1c 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java @@ -4,8 +4,13 @@ import com.fr.base.TableData; import com.fr.base.TableDataBean; import com.fr.data.MultiResultTableData; import com.fr.data.TableDataSource; + +import com.fr.decision.webservice.bean.dataset.ServerDataSetBean; + +import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.DataSetProcessorFactory; import com.fr.design.data.BasicTableDataUtils; import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.MapCompareUtils; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.NameableCreator; @@ -17,22 +22,22 @@ import com.fr.file.TableDataOperatorImpl; import com.fr.general.ComparatorUtils; import com.fr.general.NameObject; import com.fr.log.FineLoggerFactory; -import com.fr.rpc.ExceptionHandler; -import com.fr.rpc.RPCInvokerExceptionInfo; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; import com.fr.third.org.apache.commons.collections4.MapUtils; -import com.fr.workspace.WorkContext; +import com.fr.workspace.server.repository.tabledata.TableDataRepository; import javax.swing.DefaultListModel; import javax.swing.JPanel; import javax.swing.SwingUtilities; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -42,7 +47,7 @@ import java.util.Map; public class TableDataPaneListPane extends JListControlPane implements TableDataPaneController { private boolean isNamePermitted = true; private Map dsNameChangedMap = new HashMap<>(); - + private final Map populatedTableDataSnapshot = new LinkedHashMap<>(); public TableDataPaneListPane() { super(); dsNameChangedMap.clear(); @@ -197,7 +202,7 @@ public class TableDataPaneListPane extends JListControlPane implements TableData @Override public void populate(TableDataSource tds) { List nameObjectList = new ArrayList(); - + populatedTableDataSnapshot.clear(); Iterator tableDataNameIterator = tds.getTableDataNameIterator(); while (tableDataNameIterator.hasNext()) { String tableDataName = (String) tableDataNameIterator.next(); @@ -205,6 +210,11 @@ public class TableDataPaneListPane extends JListControlPane implements TableData if (tableData != null) { nameObjectList.add(new NameObject(tableDataName, tableData)); + try { + populatedTableDataSnapshot.put(tableDataName, (TableData) tableData.clone()); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } } } @@ -233,15 +243,59 @@ public class TableDataPaneListPane extends JListControlPane implements TableData @Override public void update(Map tableDataMap) { - List tableDataBeans = getUpdateTableDataBeans(); - try { - WorkContext.getCurrent().get(TableDataOperator.class, new ExceptionHandler() { - @Override - public Object callHandler(RPCInvokerExceptionInfo exceptionInfo) { - // 走老的方式 - return saveByOldWay(tableDataBeans); + Nameable[] res = this.update(); + Map dataMap = new HashMap<>(); + Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> dataMap.put(no.getName(), (TableData) no.getObject())); + List addDatas = new ArrayList<>(); + List updateDatas = new ArrayList<>(); + List deleteDatas = new ArrayList<>(); + MapCompareUtils.contrastMapEntries(populatedTableDataSnapshot, dataMap, (entryEventKind, s, tabledata) -> { + try { + switch (entryEventKind) { + case REMOVED: + deleteDatas.add(DataSetProcessorFactory.getServerDataSetBean(s, tabledata)); + break; + case ADDED: + addDatas.add(DataSetProcessorFactory.getServerDataSetBean(s, tabledata)); + break; + case UPDATED: + updateDatas.add(DataSetProcessorFactory.getServerDataSetBean(s, tabledata)); + break; + default: + break; } - }).saveTableData(new ArrayList<>(tableDataMap.keySet()), tableDataBeans); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + }, new MapCompareUtils.UpdateRule() { + @Override + public boolean needUpdate(TableData origin, TableData tableData) { + return needUpdate0(origin, tableData); + } + /** + * 是否需要更新处理 + */ + private boolean needUpdate0(TableData origin, TableData tableData) { + return !tableData.equals(origin); + } + + }); + submit(addDatas, updateDatas, deleteDatas); + + + } + + private void submit(List addDatas, List updateDatas, List deleteDatas){ + try { + for (ServerDataSetBean bean : addDatas) { + TableDataRepository.getInstance().add(bean); + } + for (ServerDataSetBean bean : updateDatas) { + TableDataRepository.getInstance().update(bean); + } + for (ServerDataSetBean bean : deleteDatas) { + TableDataRepository.getInstance().delete(bean); + } } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/DesignCorePluginComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/DesignCorePluginComponent.java new file mode 100644 index 0000000000..af39a0fc40 --- /dev/null +++ b/designer-realize/src/main/java/com/fanruan/boot/env/DesignCorePluginComponent.java @@ -0,0 +1,43 @@ +package com.fanruan.boot.env; + +import com.fanruan.boot.CorePluginComponent; +import com.fanruan.carina.Carina; +import com.fanruan.carina.annotions.DependsOn; +import com.fanruan.carina.annotions.FineComponent; +import com.fanruan.carina.annotions.Start; +import com.fanruan.carina.annotions.Supplemental; +import com.fanruan.plugin.autonomy.AutonomyClassManagerGroup; +import com.fanruan.plugin.autonomy.AutonomyClassManagerProvider; +import com.fr.plugin.ExtraClassManager; + +/** + * DesignCorePluginComponent + * + * @author Destiny.Lin + * @since 11.0 + * Created on 2024/8/9 + */ +@FineComponent(name = "design_plugin_core") +@DependsOn(dependencies = {"design_plugin"}) +public class DesignCorePluginComponent extends CorePluginComponent { + + /** + * prepare + */ + @Supplemental + public void supportFunctionDef() { + super.supportFunctionDef(); + } + + /** + * start + */ + @Start + public void start() { + ExtraClassManager.getInstance().registerAutonomyClassManager(Carina.getApplicationContext().group(AutonomyClassManagerGroup.class).getAll().toArray(new AutonomyClassManagerProvider[0])); + /// 插件下沉不能直接调用fbp的逻辑,此时内置服务器未启动,一部分逻辑要拆到内置服务器启动的时候再做 + //super.start(); + } + + +} diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java index 7c6f1e774a..1465cba495 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java @@ -32,7 +32,7 @@ import java.util.List; * Created on 2024/7/2 */ @FineComponent(name = "design_function_update") -@DependsOn(dependencies = "design_plugin") +@DependsOn(dependencies = "design_plugin_core") public class DesignUpdateComponent { /**