diff --git a/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandler.java b/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandler.java index 4e3dff159ceb417f4bd25db6295815a2ebf3a4e8..10d39dec251376ebf128e857058688048cd14263 100644 --- a/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandler.java +++ b/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandler.java @@ -53,7 +53,7 @@ public interface INotifyPolicyHandler { */ String getAuthName(); - INotifyPolicyHandlerGroup getGroup(); +// INotifyPolicyHandlerGroup getGroup(); /** * 是否公开,默认公开 diff --git a/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandlerGroup.java b/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandlerGroup.java index 31305ab3bef5f220ce2e883f4693845a44f45d97..3f69dc6d619cf99bd304af3429bc70922e8ba5ed 100644 --- a/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandlerGroup.java +++ b/src/main/java/neatlogic/framework/notify/core/INotifyPolicyHandlerGroup.java @@ -15,7 +15,7 @@ */ package neatlogic.framework.notify.core; - +@Deprecated public interface INotifyPolicyHandlerGroup { String getValue(); diff --git a/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java b/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java index 53103b65b8d844b9005a79095a8409a71b8b0659..6dbf956ce29ce8059a0563261aded32986be9aae 100644 --- a/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java +++ b/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java @@ -24,58 +24,48 @@ import neatlogic.framework.bootstrap.NeatLogicWebApplicationContext; import neatlogic.framework.common.RootComponent; import neatlogic.framework.common.util.ModuleUtil; import neatlogic.framework.dto.module.ModuleVo; -import neatlogic.framework.notify.dto.NotifyPolicyHandlerVo; import neatlogic.framework.notify.dto.NotifyTreeVo; import neatlogic.framework.notify.dto.NotifyTriggerVo; import neatlogic.framework.util.$; import org.apache.commons.collections4.CollectionUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; @RootComponent public class NotifyPolicyHandlerFactory extends ModuleInitializedListenerBase { - private static final List notifyPolicyHandlerList = new ArrayList<>(); - private static final Map notifyPolicyHandlerMap = new HashMap<>(); private static final List moduleTreeVoList = new ArrayList<>(); private static final Map moduleTreeVoMap = new HashMap<>(); - private static final List notifyPolicyTreeVoList = new ArrayList<>(); +// private static final List notifyPolicyTreeVoList = new ArrayList<>(); + +// private static final Map notifyPolicyGroupTreeVoMap = new HashMap<>(); + + private static final Map handler2ModuleGroupIdMap = new HashMap<>(); - private static final Map notifyPolicyGroupTreeVoMap = new HashMap<>(); + private static final Map handler2ModuleIdMap = new HashMap<>(); public static INotifyPolicyHandler getHandler(String handler) { return notifyPolicyHandlerMap.get(handler); } - public static NotifyPolicyHandlerVo getNotifyPolicyHandlerVo(String handler) { - for (NotifyPolicyHandlerVo notifyPolicyHandlerVo : notifyPolicyHandlerList) { - if (Objects.equals(notifyPolicyHandlerVo.getHandler(), handler)) { - try { - return notifyPolicyHandlerVo.clone(); - } catch (CloneNotSupportedException e) { - return notifyPolicyHandlerVo; - } - } - } - return null; + public static List getHandlerList() { + return new ArrayList<>(notifyPolicyHandlerMap.values()); } - public static List getNotifyPolicyHandlerList() { - List notifyPolicyHandlerVoList = new ArrayList<>(); - notifyPolicyHandlerList.forEach(o -> { - try { - NotifyPolicyHandlerVo handlerVo = o.clone(); - handlerVo.setName($.t(handlerVo.getName())); - notifyPolicyHandlerVoList.add(handlerVo); - } catch (CloneNotSupportedException e) { - notifyPolicyHandlerVoList.add(o); - } - }); - return notifyPolicyHandlerVoList; + + public static String getModuleIdByHandler(String handler) { + return handler2ModuleIdMap.get(handler); + } + + public static String getModuleGroupIdByHandler(String handler) { + return handler2ModuleGroupIdMap.get(handler); } public static List getModuleTreeVoList() { @@ -159,9 +149,9 @@ public class NotifyPolicyHandlerFactory extends ModuleInitializedListenerBase { return resultList; } - public static List getNotifyPolicyTreeVoList() { - return notifyPolicyTreeVoList; - } +// public static List getNotifyPolicyTreeVoList() { +// return notifyPolicyTreeVoList; +// } @Override public void onInitialized(NeatLogicWebApplicationContext context) { @@ -171,29 +161,26 @@ public class NotifyPolicyHandlerFactory extends ModuleInitializedListenerBase { INotifyPolicyHandler notifyPolicyHandler = entry.getValue(); if (notifyPolicyHandler.isPublic()) { notifyPolicyHandlerMap.put(notifyPolicyHandler.getClassName(), notifyPolicyHandler); - notifyPolicyHandlerList.add(new NotifyPolicyHandlerVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName(), notifyPolicyHandler.getAuthName(), moduleVo.getId(), moduleVo.getGroup(), notifyPolicyHandler.isAllowMultiPolicy())); - - INotifyPolicyHandlerGroup notifyPolicyHandlerGroup = notifyPolicyHandler.getGroup(); - if (notifyPolicyHandlerGroup == null) { - notifyPolicyTreeVoList.add(new NotifyTreeVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName())); - } else { - NotifyTreeVo notifyPolicyGroupTreeVo = notifyPolicyGroupTreeVoMap.get(notifyPolicyHandlerGroup.getValue()); - if (notifyPolicyGroupTreeVo == null) { - notifyPolicyGroupTreeVo = new NotifyTreeVo(notifyPolicyHandlerGroup.getValue(), notifyPolicyHandlerGroup.getText()); - notifyPolicyGroupTreeVoMap.put(notifyPolicyHandlerGroup.getValue(), notifyPolicyGroupTreeVo); - notifyPolicyTreeVoList.add(notifyPolicyGroupTreeVo); - } - notifyPolicyGroupTreeVo.addChildren(new NotifyTreeVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName())); - } + handler2ModuleGroupIdMap.put(notifyPolicyHandler.getClassName(), moduleVo.getGroup()); + handler2ModuleIdMap.put(notifyPolicyHandler.getClassName(), moduleVo.getId()); +// notifyPolicyHandlerList.add(new NotifyPolicyHandlerVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName(), notifyPolicyHandler.getAuthName(), moduleVo.getId(), moduleVo.getGroup(), notifyPolicyHandler.isAllowMultiPolicy())); + +// INotifyPolicyHandlerGroup notifyPolicyHandlerGroup = notifyPolicyHandler.getGroup(); +// if (notifyPolicyHandlerGroup == null) { +// notifyPolicyTreeVoList.add(new NotifyTreeVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName())); +// } else { +// NotifyTreeVo notifyPolicyGroupTreeVo = notifyPolicyGroupTreeVoMap.get(notifyPolicyHandlerGroup.getValue()); +// if (notifyPolicyGroupTreeVo == null) { +// notifyPolicyGroupTreeVo = new NotifyTreeVo(notifyPolicyHandlerGroup.getValue(), notifyPolicyHandlerGroup.getText()); +// notifyPolicyGroupTreeVoMap.put(notifyPolicyHandlerGroup.getValue(), notifyPolicyGroupTreeVo); +// notifyPolicyTreeVoList.add(notifyPolicyGroupTreeVo); +// } +// notifyPolicyGroupTreeVo.addChildren(new NotifyTreeVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName())); +// } } NotifyTreeVo treeVo = new NotifyTreeVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName()); List children = new ArrayList<>(); -// if (CollectionUtils.isNotEmpty(notifyPolicyHandler.getNotifyTriggerListForNotifyTree())) { -// for (NotifyTriggerVo notifyTriggerVo : notifyPolicyHandler.getNotifyTriggerListForNotifyTree()) { -// children.add(new NotifyTreeVo(notifyTriggerVo.getTrigger(), notifyTriggerVo.getTriggerName())); -// } -// } if (CollectionUtils.isNotEmpty(notifyPolicyHandler.getNotifyTriggerList())) { for (NotifyTriggerVo notifyTriggerVo : notifyPolicyHandler.getNotifyTriggerList()) { children.add(new NotifyTreeVo(notifyTriggerVo.getTrigger(), notifyTriggerVo.getTriggerName())); diff --git a/src/main/java/neatlogic/framework/notify/dto/NotifyPolicyHandlerVo.java b/src/main/java/neatlogic/framework/notify/dto/NotifyPolicyHandlerVo.java index 763507962682fdb3953387926824ca4bb0db228e..ade8fcf178a1f47001f852a5a112a3a3396c458c 100644 --- a/src/main/java/neatlogic/framework/notify/dto/NotifyPolicyHandlerVo.java +++ b/src/main/java/neatlogic/framework/notify/dto/NotifyPolicyHandlerVo.java @@ -20,6 +20,7 @@ package neatlogic.framework.notify.dto; * @author linbq * @since 2021/7/23 15:30 **/ +@Deprecated public class NotifyPolicyHandlerVo implements Cloneable{ private String handler; private String name; diff --git a/src/main/java/neatlogic/module/framework/notify/exception/ExceptionNotifyPolicyHandler.java b/src/main/java/neatlogic/module/framework/notify/exception/ExceptionNotifyPolicyHandler.java index 2b7ecc46d67f2d6439dfe618da4a8e604c5949bf..a10561609e4f3d36f8f49c4015c670812bf7a007 100644 --- a/src/main/java/neatlogic/module/framework/notify/exception/ExceptionNotifyPolicyHandler.java +++ b/src/main/java/neatlogic/module/framework/notify/exception/ExceptionNotifyPolicyHandler.java @@ -19,12 +19,10 @@ package neatlogic.module.framework.notify.exception; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.label.NOTIFY_POLICY_MODIFY; import neatlogic.framework.dto.ConditionParamVo; -import neatlogic.framework.notify.core.INotifyPolicyHandlerGroup; import neatlogic.framework.notify.core.NotifyHandlerType; import neatlogic.framework.notify.core.NotifyPolicyHandlerBase; import neatlogic.framework.notify.dto.NotifyTriggerTemplateVo; import neatlogic.framework.notify.dto.NotifyTriggerVo; -import neatlogic.framework.util.I18nUtils; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -38,7 +36,7 @@ import java.util.List; public class ExceptionNotifyPolicyHandler extends NotifyPolicyHandlerBase { @Override public String getName() { - return "通知异常"; + return "term.framework.exceptionnotify"; } /** @@ -49,10 +47,10 @@ public class ExceptionNotifyPolicyHandler extends NotifyPolicyHandlerBase { return NOTIFY_POLICY_MODIFY.class.getSimpleName(); } - @Override - public INotifyPolicyHandlerGroup getGroup() { - return null; - } +// @Override +// public INotifyPolicyHandlerGroup getGroup() { +// return null; +// } @Override protected List myNotifyTriggerList() { diff --git a/src/main/java/neatlogic/module/framework/notify/service/NotifyServiceImpl.java b/src/main/java/neatlogic/module/framework/notify/service/NotifyServiceImpl.java index 6b7d900636f105c220fc52c0ce39a826a2d70ba9..c10a836286391a41cd57166c82b27d89addfac26 100644 --- a/src/main/java/neatlogic/module/framework/notify/service/NotifyServiceImpl.java +++ b/src/main/java/neatlogic/module/framework/notify/service/NotifyServiceImpl.java @@ -24,17 +24,15 @@ import neatlogic.framework.notify.core.NotifyPolicyHandlerFactory; import neatlogic.framework.notify.crossover.INotifyServiceCrossoverService; import neatlogic.framework.notify.dao.mapper.NotifyMapper; import neatlogic.framework.notify.dto.InvokeNotifyPolicyConfigVo; -import neatlogic.framework.notify.dto.NotifyPolicyHandlerVo; import neatlogic.framework.notify.dto.NotifyPolicyVo; import neatlogic.framework.notify.exception.NotifyPolicyHandlerNotFoundException; import neatlogic.framework.notify.exception.NotifyPolicyNotFoundException; +import neatlogic.framework.util.$; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.List; -import java.util.Objects; @Service public class NotifyServiceImpl implements NotifyService, INotifyServiceCrossoverService { @@ -88,17 +86,16 @@ public class NotifyServiceImpl implements NotifyService, INotifyServiceCrossover if (notifyPolicyHandler == null) { throw new NotifyPolicyHandlerNotFoundException(notifyPolicyVo.getHandler()); } + String moduleGroup = NotifyPolicyHandlerFactory.getModuleGroupIdByHandler(notifyPolicyVo.getHandler()); + if (moduleGroup == null) { + throw new NotifyPolicyHandlerNotFoundException(notifyPolicyVo.getHandler()); + } String moduleGroupName = ""; - List notifyPolicyHandlerList = NotifyPolicyHandlerFactory.getNotifyPolicyHandlerList(); - for (NotifyPolicyHandlerVo notifyPolicyHandlerVo : notifyPolicyHandlerList) { - if (Objects.equals(notifyPolicyHandlerVo.getHandler(), notifyPolicyVo.getHandler())) { - ModuleGroupVo moduleGroupVo = ModuleUtil.getModuleGroup(notifyPolicyHandlerVo.getModuleGroup()); - if (moduleGroupVo != null) { - moduleGroupName = moduleGroupVo.getGroupName(); - } - } + ModuleGroupVo moduleGroupVo = ModuleUtil.getModuleGroup(moduleGroup); + if (moduleGroupVo != null) { + moduleGroupName = moduleGroupVo.getGroupName(); } - String handlerName = notifyPolicyHandler.getName(); + String handlerName = $.t(notifyPolicyHandler.getName()); invokeNotifyPolicyConfigVo.setPolicyPath(moduleGroupName + "/" + handlerName + "/" + notifyPolicyVo.getName()); } return invokeNotifyPolicyConfigVo;