|
|
@@ -146,11 +146,11 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
Panel panel = panelDao.checkExist(panelCode);
|
|
|
PanelInstance panelInstance = panelInstanceDao.findByPanelCode(panelCode);
|
|
|
if (panelInstance == null || panel.getVersion() > panelInstance.getPanelVersion()) {
|
|
|
- // 如果面板有更新,先删除旧的实例
|
|
|
if (panelInstance != null) {
|
|
|
- deleteOne(panelInstance.codeNotEmpty());
|
|
|
+ panelInstance = updateInstance(panelCode, panelInstance);
|
|
|
+ } else {
|
|
|
+ panelInstance = generateInstance(panelCode);
|
|
|
}
|
|
|
- panelInstance = generateInstance(panelCode, panelInstance);
|
|
|
}
|
|
|
try {
|
|
|
NewbieJdbcSupport jdbc = dataSourceManager.getJdbc(panel.getDataSourceCode());
|
|
|
@@ -402,23 +402,44 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 生成面板实例
|
|
|
+ * 更新面板实例
|
|
|
*
|
|
|
* @param panelCode 面板 code
|
|
|
* @param oldPanelInstance 旧的面板实例
|
|
|
* @return 面板实例
|
|
|
*/
|
|
|
- private PanelInstance generateInstance(@NotEmpty("panelCode") String panelCode, PanelInstance oldPanelInstance) {
|
|
|
+ private PanelInstance updateInstance(@NotEmpty("panelCode") String panelCode, @NotEmpty("oldPanelInstance") PanelInstance oldPanelInstance) throws OperationException {
|
|
|
+ Panel panel = panelDao.checkExist(panelCode);
|
|
|
+ PanelInstance panelInstance;
|
|
|
+ try {
|
|
|
+ panelInstance = ObjectUtils.clone(oldPanelInstance);
|
|
|
+ } catch (IOException | ClassNotFoundException e) {
|
|
|
+ throw new IllegalStateException("更新面板实例时,旧实例克隆失败", e);
|
|
|
+ }
|
|
|
+ panelInstance.setPanelVersion(panel.getVersion());
|
|
|
+ panelInstance.toParameters(generateParameters(panelCode));
|
|
|
+ List<Kanban> kanbans = kanbanDao.findByPanelCode(panelCode);
|
|
|
+ if (CollectionUtils.isEmpty(kanbans)) {
|
|
|
+ throw new IllegalStateException("面板 '" + panel.getName() + "' 未关联看板");
|
|
|
+ }
|
|
|
+ panelInstance.initKanbanCodes(kanbans);
|
|
|
+ recoverOldParameterValues(panelInstance, oldPanelInstance);
|
|
|
+ panelInstanceDao.update(panelInstance);
|
|
|
+ return getOne(panelInstance.codeNotEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成面板实例
|
|
|
+ *
|
|
|
+ * @param panelCode 面板 code
|
|
|
+ * @return 面板实例
|
|
|
+ */
|
|
|
+ private PanelInstance generateInstance(@NotEmpty("panelCode") String panelCode) throws OperationException {
|
|
|
Panel panel = panelDao.checkExist(panelCode);
|
|
|
PanelInstance panelInstance = new PanelInstance();
|
|
|
panelInstance.setUserCode(SystemSession.getUser().codeNotEmpty());
|
|
|
panelInstance.setPanelCode(panelCode);
|
|
|
panelInstance.setPanelVersion(panel.getVersion());
|
|
|
- // 切换频率、刷新频率
|
|
|
- if (oldPanelInstance != null) {
|
|
|
- panelInstance.setSwitchFrequency(oldPanelInstance.getSwitchFrequency());
|
|
|
- panelInstance.setRefreshFrequency(oldPanelInstance.getRefreshFrequency());
|
|
|
- }
|
|
|
initSwitchFrequence(panelInstance);
|
|
|
panelInstance.toParameters(generateParameters(panelCode));
|
|
|
List<Kanban> kanbans = kanbanDao.findByPanelCode(panelCode);
|
|
|
@@ -426,9 +447,6 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
throw new IllegalStateException("面板 '" + panel.getName() + "' 未关联看板");
|
|
|
}
|
|
|
panelInstance.initKanbanCodes(kanbans);
|
|
|
- if (oldPanelInstance != null) {
|
|
|
- recoverOldParameters(panelInstance, oldPanelInstance);
|
|
|
- }
|
|
|
return panelInstanceDao.save(panelInstance);
|
|
|
}
|
|
|
|
|
|
@@ -460,7 +478,7 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
* @param panelInstance 面板实例
|
|
|
* @param oldPanelInstance 旧的面板实例
|
|
|
*/
|
|
|
- private void recoverOldParameters(@NotEmpty("panelInstance") PanelInstance panelInstance, @NotEmpty("oldPanelInstance") PanelInstance oldPanelInstance) {
|
|
|
+ private void recoverOldParameterValues(@NotEmpty("panelInstance") PanelInstance panelInstance, @NotEmpty("oldPanelInstance") PanelInstance oldPanelInstance) {
|
|
|
// 参数
|
|
|
List<Parameter> parameters = panelInstance.fromParameters();
|
|
|
List<Parameter> oldParameters = oldPanelInstance.fromParameters();
|