Browse Source

REPORT-51360 设计器消息提醒

feature/10.0
Lanlan 3 years ago
parent
commit
e875233546
  1. 117
      designer-base/src/main/java/com/fr/design/login/message/DesignerMessageHelper.java
  2. 69
      designer-base/src/main/java/com/fr/design/login/message/DesignerModuleClickType.java
  3. 31
      designer-base/src/main/java/com/fr/design/login/message/NotificationJumpType.java
  4. 2
      designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

117
designer-base/src/main/java/com/fr/design/login/message/DesignerMessageHelper.java

@ -0,0 +1,117 @@
package com.fr.design.login.message;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager;
import com.fr.design.dialog.NotificationDialog;
import com.fr.design.dialog.NotificationDialogAction;
import com.fr.design.event.DesignerOpenedListener;
import com.fr.design.login.utils.DesignerLoginUtils;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.utils.BrowseUtils;
import com.fr.general.CloudCenter;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSON;
import com.fr.json.JSONFactory;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @author Lanlan
* @version 10.0
* Created by Lanlan on 2021/6/11
*/
public class DesignerMessageHelper {
private static final long DELAY = 1L;
private static final String STATUS = "status";
private static final String DATA = "data";
private static final String SUCCESS = "success";
private static final String MESSAGE_ID = "messageId";
private static final String TITLE = "title";
private static final String BODY = "body";
private static final String JUMP_TYPE = "jumpType";
private static final String JUMP_TO = "jumpTo";
private static DesignerMessageHelper instance;
private DesignerMessageHelper() {
}
public static DesignerMessageHelper getInstance() {
if (instance == null) {
instance = new DesignerMessageHelper();
}
return instance;
}
public void prepareShowMessage() {
DesignerContext.getDesignerFrame().addDesignerOpenedListener(new DesignerOpenedListener() {
@Override
public void designerOpened() {
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("DesignerMessageHelper"));
service.schedule(new Runnable() {
@Override
public void run() {
try {
pullLatestMessageAndShow();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}, DELAY, TimeUnit.MINUTES);
service.shutdown();
}
});
}
private void pullLatestMessageAndShow() throws Exception {
String url = CloudCenter.getInstance().acquireUrlByKind("designer.message.push", "https://market.fanruan.com/api/v1/message/designer");
Map<String, String> params = new HashMap<>();
params.put("designerId", DesignerEnvManager.getEnvManager().getUUID());
String result = HttpToolbox.post(url, params);
JSONObject response = JSONFactory.createJSON(JSON.OBJECT, result);
String status = response.optString(STATUS);
if (SUCCESS.equals(status)) {
JSONObject data = response.optJSONObject(DATA);
String messageId = data.optString(MESSAGE_ID);
String title = data.optString(TITLE);
String body = data.optString(BODY);
int jumpType = data.optInt(JUMP_TYPE);
String jumpTo = data.optString(JUMP_TO);
if (StringUtils.isNotEmpty(messageId) && StringUtils.isNotEmpty(title) && StringUtils.isNotEmpty(body) && jumpType > 0 && StringUtils.isNotEmpty(jumpTo)) {
NotificationJumpType notificationJumpType = NotificationJumpType.valueOf(jumpType);
if (notificationJumpType == NotificationJumpType.WEB_URL) {
NotificationDialog.Builder()
.owner(DesignerContext.getDesignerFrame())
.title(title)
.modal(true)
.messageType(NotificationDialog.NEW_MESSAGE)
.message(body)
.notificationDialogAction(new NotificationDialogAction() {
@Override
public void doClick() {
String ssoUrl = DesignerLoginUtils.generateDesignerSSOUrl(jumpTo);
BrowseUtils.browser(ssoUrl);
}
}).build();
} else if (notificationJumpType == NotificationJumpType.DESIGNER_MODULE) {
DesignerModuleClickType designerModuleClickType = DesignerModuleClickType.valueOf(jumpTo);
NotificationDialog.Builder()
.owner(DesignerContext.getDesignerFrame())
.title(title)
.modal(true)
.messageType(NotificationDialog.NEW_MESSAGE)
.message(body)
.notificationDialogAction(designerModuleClickType.getAction())
.build();
}
}
}
}
}

69
designer-base/src/main/java/com/fr/design/login/message/DesignerModuleClickType.java

@ -0,0 +1,69 @@
package com.fr.design.login.message;
import com.fr.config.ServerPreferenceConfig;
import com.fr.design.dialog.NotificationDialogAction;
import com.fr.design.extra.WebViewDlgHelper;
import com.fr.design.os.impl.SupportOSImpl;
import com.fr.design.upm.UpmFinder;
import com.fr.design.utils.DesignUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.stable.os.Arch;
import com.fr.stable.os.OperatingSystem;
/**
* @author Lanlan
* @version 10.0
* Created by Lanlan on 2021/6/11
*/
public enum DesignerModuleClickType {
PLUGIN("PLUGIN", new NotificationDialogAction() {
@Override
public void doClick() {
try {
if (Arch.getArch() == Arch.ARM || OperatingSystem.isLinux() || SupportOSImpl.MACOS_WEB_PLUGIN_MANAGEMENT.support()) {
DesignUtils.visitEnvServerByParameters("#management/plugin", null, null);
return;
}
if (ServerPreferenceConfig.getInstance().isUseOptimizedUPM() || SupportOSImpl.MACOS_NEW_PLUGIN_MANAGEMENT.support()) {
UpmFinder.showUPMDialog();
} else {
WebViewDlgHelper.createPluginDialog();
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}),
REUSE("REUSE", new NotificationDialogAction() {
@Override
public void doClick() {
try {
// TODO
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}),
UNKNOWN(StringUtils.EMPTY, new NotificationDialogAction() {
@Override
public void doClick() {
}
});
private String jumpTo;
private NotificationDialogAction action;
DesignerModuleClickType(String jumpTo, NotificationDialogAction action) {
this.jumpTo = jumpTo;
this.action = action;
}
public String getJumpTo() {
return jumpTo;
}
public NotificationDialogAction getAction() {
return action;
}
}

31
designer-base/src/main/java/com/fr/design/login/message/NotificationJumpType.java

@ -0,0 +1,31 @@
package com.fr.design.login.message;
/**
* @author Lanlan
* @version 10.0
* Created by Lanlan on 2021/6/11
*/
public enum NotificationJumpType {
WEB_URL(1),
DESIGNER_MODULE(2),
UNKNOWN(-1);
private int jumpType;
NotificationJumpType(int jumpType) {
this.jumpType = jumpType;
}
public int getJumpType() {
return jumpType;
}
public static NotificationJumpType valueOf(int jumpType) {
for(NotificationJumpType value : NotificationJumpType.values()) {
if(value.getJumpType() == jumpType) {
return value;
}
}
return UNKNOWN;
}
}

2
designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

@ -41,6 +41,7 @@ import com.fr.design.javascript.ParameterJavaScriptPane;
import com.fr.design.javascript.ProcessTransitionAdapter;
import com.fr.design.login.DesignerLoginType;
import com.fr.design.login.guide.DesignerGuideHelper;
import com.fr.design.login.message.DesignerMessageHelper;
import com.fr.design.login.socketio.LoginAuthServer;
import com.fr.design.mainframe.BaseJForm;
import com.fr.design.mainframe.FormHierarchyTreePane;
@ -141,6 +142,7 @@ public class DesignerActivator extends Activator implements Prepare {
public void run() {
DesignerPushUpdateManager.getInstance().preparePushUpdate();
DesignerGuideHelper.prepareShowGuideDialog();
DesignerMessageHelper.getInstance().prepareShowMessage();
}
});

Loading…
Cancel
Save