diff --git a/README.md b/README.md
index 010cb57..06eb7a4 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
# open-JSD-8997
-JSD-8997 根据参数或其他请求条件控制决策平台的报表目录展现
\ No newline at end of file
+JSD-8997 根据参数或其他请求条件控制决策平台的报表目录展现\
+免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
+仅作为开发者学习参考使用!禁止用于任何商业用途!\
+为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。
\ No newline at end of file
diff --git a/plugin.xml b/plugin.xml
new file mode 100644
index 0000000..7818921
--- /dev/null
+++ b/plugin.xml
@@ -0,0 +1,39 @@
+
+
+ com.fr.plugin.xxxx.xxxx.menu
+ com.fr.plugin.xxxx.xxxx.menu
+
+ yes
+ 1.18
+ 10.0
+ 2018-07-31
+ fr.open
+
+
+ [2021-11-13]【1.1】过滤逻辑修改。
+ [2021-11-13]【1.2】增加一个报表。
+ [2021-11-13]【1.3】增加登出调用。
+ [2021-11-15]【1.4】增加保存日志拦截。
+ [2021-11-18]【1.5】修改日志注入机制。
+ [2021-11-19]【1.6】增加导出日志注入。
+ [2021-11-21]【1.7】增加导出日志类型转换。
+ [2021-11-21]【1.8】增加导出日志result类型转换。
+ [2021-11-21]【1.9】打印导出日志。
+ [2021-11-23]【1.10】日志推送逻辑修改。
+ [2021-11-26]【1.11】增加特定报表隐藏。
+ [2021-11-29]【1.12】增加日志详细输出和隐藏根目录菜单。
+ [2021-11-29]【1.13】自定义报表和定制报表不隐藏。
+ [2021-11-29]【1.14】自定义报表和定制报表不隐藏。
+ [2021-11-30]【1.15】指定范围报表目录隐藏。
+ [2021-11-30]【1.16】问题修改。
+ [2021-11-30]【1.17】问题修改。
+ [2021-11-30]【1.18】问题修改。
+ ]]>
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/fr/plugin/xxxx/xxxx/menu/Constants.java b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/Constants.java
new file mode 100644
index 0000000..a10b905
--- /dev/null
+++ b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/Constants.java
@@ -0,0 +1,9 @@
+package com.fr.plugin.xxxx.xxxx.menu;
+
+/**
+ * @author fr.open
+ * @date 2020/5/14
+ */
+public class Constants {
+ public static final String PLUGIN_ID = "com.fr.plugin.xxxx.xxxx.menu";
+}
diff --git a/src/main/java/com/fr/plugin/xxxx/xxxx/menu/CustomLogInOutEventProvider.java b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/CustomLogInOutEventProvider.java
new file mode 100644
index 0000000..8143e5f
--- /dev/null
+++ b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/CustomLogInOutEventProvider.java
@@ -0,0 +1,18 @@
+package com.fr.plugin.xxxx.xxxx.menu;
+
+import com.fr.decision.fun.impl.AbstractLogInOutEventProvider;
+import com.fr.decision.webservice.login.LogInOutResultInfo;
+import com.fr.general.PropertiesUtils;
+
+/**
+ * @Author fr.open
+ * @Date 2020/11/13
+ * @Description
+ **/
+public class CustomLogInOutEventProvider extends AbstractLogInOutEventProvider {
+ @Override
+ public String logoutAction(LogInOutResultInfo result) {
+ return PropertiesUtils.getProperties("sso").getProperty("logout");
+ }
+
+}
diff --git a/src/main/java/com/fr/plugin/xxxx/xxxx/menu/GlobalFilter.java b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/GlobalFilter.java
new file mode 100644
index 0000000..2625d19
--- /dev/null
+++ b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/GlobalFilter.java
@@ -0,0 +1,228 @@
+package com.fr.plugin.xxxx.xxxx.menu;
+
+import com.fr.base.PropertiesUtils;
+import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
+import com.fr.decision.webservice.v10.config.ConfigService;
+import com.fr.intelli.record.Focus;
+import com.fr.intelli.record.MetricRegistry;
+import com.fr.intelli.record.Original;
+import com.fr.json.JSONArray;
+import com.fr.json.JSONObject;
+import com.fr.log.FineLoggerFactory;
+import com.fr.plugin.context.PluginContexts;
+import com.fr.plugin.xxxx.xxxx.menu.log.MyLogCacheMetric;
+import com.fr.plugin.xxxx.xxxx.menu.util.HttpUtil;
+import com.fr.plugin.xxxx.xxxx.menu.util.TokenFactory;
+import com.fr.plugin.transform.FunctionRecorder;
+import com.fr.record.analyzer.EnableMetrics;
+import com.fr.stable.StringUtils;
+import com.fr.stable.fun.Authorize;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+
+/**
+ * @Author fr.open
+ * @Date 2021/10/29
+ * @Description
+ **/
+@FunctionRecorder
+@Authorize(callSignKey = Constants.PLUGIN_ID)
+@EnableMetrics
+public class GlobalFilter extends AbstractGlobalRequestFilterProvider {
+
+ private static final String MENU_URI = "/rest/openapi/security/v3/system/service-capability";
+
+ private static final Map REAL_MAP;
+
+ private MyLogCacheMetric cacheMetric = new MyLogCacheMetric();
+
+ static {
+ REAL_MAP = new HashMap<>();
+ REAL_MAP.put("AXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ REAL_MAP.put("XXXX", "capacity,asset");
+ REAL_MAP.put("XXXX", "capacity|asset");
+ }
+
+ private static final String[] menu = new String[]{"XXXX","XXXX","XXXX","XXXX","XXXX","XXXX"};
+
+ @Override
+ public void init(FilterConfig filterConfig) {
+ super.init(filterConfig);
+ MetricRegistry.register(cacheMetric);
+ }
+
+ @Override
+ public String filterName() {
+ return "global";
+ }
+
+ @Override
+ @Focus(id = Constants.PLUGIN_ID, text = "XXXX权限过滤", source = Original.PLUGIN)
+ public String[] urlPatterns() {
+ if (PluginContexts.currentContext().isAvailable()) {
+ String servletPathName = "decision";
+ try {
+ servletPathName = ConfigService.getInstance().getBasicParam().getServletPathName();
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error(e.getMessage(), e);
+ }
+ return new String[]{
+ "/" + servletPathName + "/v10/view/entry/tree",
+
+ };
+ } else {
+ return new String[0];
+ }
+ }
+
+ @Override
+ public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
+ try {
+ ResponseWrapperImpl responseWrapper = new ResponseWrapperImpl(res);
+ filterChain.doFilter(req, responseWrapper);
+ byte[] dataStream = responseWrapper.getDataStream();
+ //JSONObject object = new JSONObject(readJsonFile("/Users/hujian/Desktop/1.json"));
+ JSONObject object = new JSONObject(new String(dataStream));
+ JSONArray array = new JSONArray();
+ JSONArray resArray = new JSONArray();
+ JSONObject map = getMenuAuth();
+ Set set = new HashSet();
+ Set level1 = new HashSet<>();
+ Map children = new HashMap<>();
+ for (int i = 0; i < object.getJSONArray("data").size(); i++) {
+ JSONObject data = object.getJSONArray("data").getJSONObject(i);
+ String text = data.getString("text");
+ if (StringUtils.equals("decision-directory-root", data.getString("pId"))
+ && Stream.of(menu).anyMatch(text::equals)
+ ) {
+ level1.add(data.getString("id"));
+ children.put(data.getString("id"),0);
+ }
+ if (StringUtils.equals(text, "自定义报表") || StringUtils.equals(text, "定制报表")) {
+ set.add(data.getString("id"));
+ }
+ if (!REAL_MAP.containsKey(text)) {
+ array.add(data);
+ continue;
+ }
+ if (checkAuth(REAL_MAP.get(text), map)) {
+ array.add(data);
+ }
+ }
+ FineLoggerFactory.getLogger().info("level1 menu is {}",level1);
+ FineLoggerFactory.getLogger().info("get filter size is {}", set);
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject data = array.getJSONObject(i);
+ //只处理俩个特定的一级节点
+ if (set.contains(data.getString("pId"))) {
+ //只有包含这俩的不处理,其他不展示
+ if ((data.getString("text").endsWith("流程图") || data.getString("text").endsWith("列表"))) {
+ resArray.add(data);
+ }
+ } else {
+ //非特定的不做处理
+ resArray.add(data);
+ }
+ }
+ Map dataMap = new HashMap<>();
+ for (int i = 0; i < resArray.size(); i++) {
+ JSONObject data = resArray.getJSONObject(i);
+ //只处理俩个特定的一级节点
+ if (level1.contains(data.getString("pId"))) {
+ Integer count = children.get(data.getString("pId"));
+ count = count == null?0:count;
+ children.put(data.getString("pId"),count+1);
+ }
+ dataMap.put(data.getString("id"),data);
+ }
+ FineLoggerFactory.getLogger().info("children res {}",children);
+ children.forEach((k,v) -> {
+ if(v == 0){
+ JSONObject remove = dataMap.remove(k);
+ FineLoggerFactory.getLogger().info("remove menu is {}",remove.getString("text"));
+ }
+ });
+
+ FineLoggerFactory.getLogger().info("check auth menu result is {}", dataMap.values());
+ object.put("data", new JSONArray(dataMap.values()));
+ res.getOutputStream().write(object.toString().getBytes(StandardCharsets.UTF_8));
+ } catch (IOException e) {
+ FineLoggerFactory.getLogger().error(e.getMessage(), e);
+ } catch (ServletException e) {
+ FineLoggerFactory.getLogger().error(e.getMessage(), e);
+ }
+ }
+
+ private boolean checkAuth(String text, JSONObject map) {
+ if (text.contains("|")) {
+ Boolean[] flag = new Boolean[]{false};
+ Stream.of(text.split("\\|")).forEach(e -> flag[0] = flag[0] || map.getBoolean(e));
+ return flag[0];
+ } else if (text.contains(",")) {
+ Boolean[] flag = new Boolean[]{true};
+ Stream.of(text.split(",")).forEach(e -> flag[0] = flag[0] && map.getBoolean(e));
+ return flag[0];
+ }
+ return map.getBoolean(text);
+
+ }
+
+ private JSONObject getMenuAuth() {
+ String tokenUrl = PropertiesUtils.getProperties("conf").getProperty("tokenUrl");
+ String userid = PropertiesUtils.getProperties("conf").getProperty("userid");
+ String value = PropertiesUtils.getProperties("conf").getProperty("value");
+ String prefix = PropertiesUtils.getProperties("conf").getProperty("prefix");
+ String token = TokenFactory.getToken(tokenUrl, userid, value);
+ FineLoggerFactory.getLogger().info("get token is {}", token);
+ Map headerMap = new HashMap();
+ headerMap.put("openid", token);
+ String res = HttpUtil.sendGet(prefix + MENU_URI, null, headerMap, null);
+ FineLoggerFactory.getLogger().info("get menu auth res is {}", res);
+ JSONObject object = new JSONObject(res);
+ return object.getJSONObject("data");
+ }
+
+ public static String readJsonFile(String fileName) {
+ String jsonStr = "";
+ try {
+ File jsonFile = new File(fileName);
+ FileReader fileReader = new FileReader(jsonFile);
+ Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
+ int ch = 0;
+ StringBuffer sb = new StringBuffer();
+ while ((ch = reader.read()) != -1) {
+ sb.append((char) ch);
+ }
+ fileReader.close();
+ reader.close();
+ jsonStr = sb.toString();
+ return jsonStr;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /*public static void main(String[] args) {
+ new GlobalFilter().doFilter(null,null,null);
+ }*/
+}
diff --git a/src/main/java/com/fr/plugin/xxxx/xxxx/menu/PluginLifecycleMonitor.java b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/PluginLifecycleMonitor.java
new file mode 100644
index 0000000..fc4be9d
--- /dev/null
+++ b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/PluginLifecycleMonitor.java
@@ -0,0 +1,21 @@
+package com.fr.plugin.xxxx.xxxx.menu;
+
+import com.fr.plugin.context.PluginContext;
+import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
+
+/**
+ * @Author fr.open
+ * @Date 2020/9/15
+ * @Description
+ **/
+public class PluginLifecycleMonitor extends AbstractPluginLifecycleMonitor {
+
+ @Override
+ public void afterRun(PluginContext pluginContext) {
+ //MetricRegistry.register(new MyLogCacheMetric());
+ }
+
+ @Override
+ public void beforeStop(PluginContext pluginContext) {
+ }
+}
diff --git a/src/main/java/com/fr/plugin/xxxx/xxxx/menu/ResponseWrapperImpl.java b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/ResponseWrapperImpl.java
new file mode 100644
index 0000000..0b459a7
--- /dev/null
+++ b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/ResponseWrapperImpl.java
@@ -0,0 +1,84 @@
+package com.fr.plugin.xxxx.xxxx.menu;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.WriteListener;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * @author fr.open
+ * @Date 2021/8/1
+ */
+public class ResponseWrapperImpl extends HttpServletResponseWrapper {
+ ByteArrayOutputStream output;
+ FilterServletOutputStream filterOutput;
+
+ public ResponseWrapperImpl(HttpServletResponse response) {
+ super(response);
+ output = new ByteArrayOutputStream();
+ }
+
+ @Override
+ public ServletOutputStream getOutputStream() throws IOException {
+ if (filterOutput == null) {
+ filterOutput = new FilterServletOutputStream(output);
+ }
+ return filterOutput;
+ }
+
+ public void setContent(ByteArrayOutputStream output){
+ this.output = output;
+ this.filterOutput = null;
+ }
+
+ public void clear(){
+ output = new ByteArrayOutputStream();
+ filterOutput = new FilterServletOutputStream(output);
+ }
+ public ByteArrayOutputStream getOut(){
+ return output;
+ }
+
+ public byte[] getDataStream() {
+ return output.toByteArray();
+ }
+
+ class FilterServletOutputStream extends ServletOutputStream {
+ DataOutputStream output;
+
+ public FilterServletOutputStream(OutputStream output) {
+ this.output = new DataOutputStream(output);
+ }
+
+ @Override
+ public void write(int arg0) throws IOException {
+ output.write(arg0);
+ }
+
+ @Override
+ public void write(byte[] arg0, int arg1, int arg2) throws IOException {
+ output.write(arg0, arg1, arg2);
+ }
+
+ @Override
+ public void write(byte[] arg0) throws IOException {
+ output.write(arg0);
+ System.out.printf("");
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setWriteListener(WriteListener writeListener) {
+
+ }
+ }
+}
diff --git a/src/main/java/com/fr/plugin/xxxx/xxxx/menu/bean/Token.java b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/bean/Token.java
new file mode 100644
index 0000000..68ffe55
--- /dev/null
+++ b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/bean/Token.java
@@ -0,0 +1,34 @@
+package com.fr.plugin.xxxx.xxxx.menu.bean;
+
+/**
+ * @Author fr.open
+ * @Date 2021/11/11
+ * @Description
+ **/
+public class Token {
+
+ private String token;
+
+ private Long timeout;
+
+ public Token(String token, long timeout) {
+ this.timeout = timeout;
+ this.token = token;
+ }
+
+ public String getToken() {
+ return token;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+
+ public Long getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(Long timeout) {
+ this.timeout = timeout;
+ }
+}
diff --git a/src/main/java/com/fr/plugin/xxxx/xxxx/menu/log/MyLogCacheMetric.java b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/log/MyLogCacheMetric.java
new file mode 100644
index 0000000..b9e2fee
--- /dev/null
+++ b/src/main/java/com/fr/plugin/xxxx/xxxx/menu/log/MyLogCacheMetric.java
@@ -0,0 +1,158 @@
+package com.fr.plugin.xxxx.xxxx.menu.log;
+
+import com.fr.base.PropertiesUtils;
+import com.fr.decision.log.ExecuteMessage;
+import com.fr.decision.record.OperateMessage;
+import com.fr.intelli.record.scene.impl.LogCacheMetric;
+import com.fr.json.JSONObject;
+import com.fr.locale.InterProvider;
+import com.fr.locale.InterProviderFactory;
+import com.fr.log.FineLoggerFactory;
+import com.fr.plugin.holger.hwny.menu.util.HttpUtil;
+import com.fr.plugin.holger.hwny.menu.util.TokenFactory;
+import com.fr.stable.StringUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+/**
+ * @Author fr.open
+ * @Date 2021/11/14
+ * @Description
+ **/
+public class MyLogCacheMetric extends LogCacheMetric {
+
+ private static final String[] ARRAY = new String[]{"page","view","write","form","write_plus","page_plus"};
+
+ private static final String LOG_API = "/rest/openapi/security/v3/log/op-logs";
+
+ private static final String system = "op-report-system";
+
+ private static final Map exportType;
+
+ static {
+ exportType = new HashMap<>();
+ exportType.put(0,"分页预览");
+ exportType.put(1,"在线分析");
+ exportType.put(2,"填报预览");
+ exportType.put(3,"决策报表预览");
+ exportType.put(4,"行式引擎");
+ exportType.put(5,"在线编辑");
+ exportType.put(7,"新引擎预览");
+ exportType.put(10,"Excel 分页导出");
+ exportType.put(11,"Excel 原样导出");
+ exportType.put(12,"Excel 整页导出");
+ exportType.put(13,"Excel 分页分 sheet 导出");
+ exportType.put(14,"PDF 导出");
+ exportType.put(15,"Word 导出");
+ exportType.put(16,"SVG 导出");
+ exportType.put(17,"CSV 导出");
+ exportType.put(18,"文本导出");
+ exportType.put(19,"JPG 图片导出");
+ exportType.put(20,"PNG 图片导出");
+ exportType.put(21,"GIF 图片导出");
+ exportType.put(22,"BMP 图片导出");
+ exportType.put(23,"WBMP 图片导出");
+ exportType.put(24,"内置数据集导出模板");
+ exportType.put(25,"HTML 导出");
+ exportType.put(26,"填报 HTML 导出");
+ exportType.put(27,"BI 导出 Excel");
+ exportType.put(30,"Flash 打印");
+ exportType.put(31,"PDF 打印");
+ exportType.put(32,"Applet 打印");
+ exportType.put(33,"零客户端打印");
+ exportType.put(34,"本地软件打印");
+ }
+
+ @Override
+ public void submit(Object o) {
+ super.submit(o);
+ if (o instanceof OperateMessage) {
+ OperateMessage message = (OperateMessage) o;
+ sendMessage(coverJSONByMessage(message));
+ }
+ if (o instanceof ExecuteMessage) {
+ ExecuteMessage message = (ExecuteMessage) o;
+ sendMessage(coverJSONByExportMessage(message));
+ }
+ }
+
+ private JSONObject coverJSONByExportMessage(ExecuteMessage message) {
+ FineLoggerFactory.getLogger().info("export message is {}",JSONObject.mapFrom(message));
+ JSONObject object = new JSONObject();
+ object.put("userName", message.getUsername());
+ object.put("templateId", system);
+ String type = exportType.get(message.getType());
+ String detail = String.format("报表%s执行%s操作", message.getTemplate(), type);
+ object.put("detail", detail);
+ FineLoggerFactory.getLogger().info("get export detail is {}",detail);
+ if(Stream.of(ARRAY).anyMatch(type::contains)){
+ object.put("result", message.getComplete() == 1 ? "SUCCESSFUL" : "FAILURE");
+ }else {
+ object.put("result","SUCCESSFUL");
+
+ }
+ object.put("terminal", message.getIp());
+ return object;
+ }
+
+ private void sendMessage(JSONObject object) {
+ String tokenUrl = PropertiesUtils.getProperties("conf").getProperty("tokenUrl");
+ String userid = PropertiesUtils.getProperties("conf").getProperty("userid");
+ String value = PropertiesUtils.getProperties("conf").getProperty("value");
+ String prefix = PropertiesUtils.getProperties("conf").getProperty("prefix");
+ String token = TokenFactory.getToken(tokenUrl, userid, value);
+ FineLoggerFactory.getLogger().info("get token is {}", token);
+ Map headerMap = new HashMap();
+ headerMap.put("openid", token);
+ FineLoggerFactory.getLogger().info("url {} send data is {}", prefix + LOG_API, object);
+ String res = HttpUtil.doJSONPost(prefix + LOG_API, headerMap, object, null, null);
+ FineLoggerFactory.getLogger().info("save log res is {}", res);
+ }
+
+ @Override
+ public void submit(List