Browse Source

REPORT-91503 保存模板频繁报错锁定信息不一致,在这个弹窗另存为一定会失败。

处理创建模板备份文件时的锁定问题,以及锁定可能失败的问题
newui
Yvan-欧阳帆 2 years ago
parent
commit
fe85bf9711
  1. 34
      designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java
  2. 2
      designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java

34
designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java

@ -85,28 +85,42 @@ public class TemplateUtils {
private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) { private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) {
new SwingWorker<Void, Void>() { new SwingWorker<Boolean, Void>() {
@Override @Override
protected Void doInBackground() throws Exception { protected Boolean doInBackground() throws Exception {
// 读取模板数据 // 读取模板数据
byte[] content = getTemplateData(createByEditingTemplate, oldPath); byte[] content = getTemplateData(createByEditingTemplate, oldPath);
try (OutputStream out = file.asOutputStream()) { OutputStream out = null;
try {
// 加锁 // 加锁
WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath()); boolean saveAsLock = WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath());
if (!saveAsLock) {
// 加锁失败时,直接返回
return false;
}
out = file.asOutputStream();
out.write(content); out.write(content);
} finally { } finally {
// 解锁 try {
WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); if (out != null) {
out.close();
}
} finally {
// 解锁
WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath());
}
} }
return null; return true;
} }
@Override @Override
protected void done() { protected void done() {
try { try {
get(); if (!get()) {
// 创建备份成功后 throw new Exception("[RemoteDesign] back up template file failed");
}
// 创建备份成功后,关闭原模板
doAfterCreateTemplate.run(); doAfterCreateTemplate.run();
if (openNewTemplate) { if (openNewTemplate) {
DesignerContext.getDesignerFrame().openTemplate(file); DesignerContext.getDesignerFrame().openTemplate(file);
@ -126,7 +140,7 @@ public class TemplateUtils {
* *
* @param readCurrentEditingTemplate 是否读取当前编辑模板 * @param readCurrentEditingTemplate 是否读取当前编辑模板
* @param path 模板路径 * @param path 模板路径
* @return 模板文件数据 * @return 模板文件数据
*/ */
private static byte[] getTemplateData(boolean readCurrentEditingTemplate, String path) throws Exception { private static byte[] getTemplateData(boolean readCurrentEditingTemplate, String path) throws Exception {
byte[] content = new byte[0]; byte[] content = new byte[0];

2
designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java

@ -139,7 +139,7 @@ public class SaveFailureHandler implements ThrowableHandler {
new FileNodeFILE(new FileNode(template.getPath(), false)), new FileNodeFILE(new FileNode(template.getPath(), false)),
true, true,
true, true,
// 创建并打开备份模板后,关闭原模板 // 创建并打开备份模板后,关闭原模板,无需释放原模板锁(锁定信息不一致 = 此用户模板锁信息已被清除)
() -> HistoryTemplateListCache.getInstance().closeSelectedReport(template)); () -> HistoryTemplateListCache.getInstance().closeSelectedReport(template));
} }
} }

Loading…
Cancel
Save