Bläddra i källkod

Merge remote-tracking branch 'origin/master'

weijianghai 2 år sedan
förälder
incheckning
2e2f759bf0

+ 4 - 0
src/main/java/com/nokia/hb/config/web/WebSocketHandshakeInterceptor.java

@@ -40,6 +40,10 @@ public class WebSocketHandshakeInterceptor implements HandshakeInterceptor {
         Cookie[] cookies = httpServletRequest.getCookies();
         log.debug("username: {}", username);
         log.debug("cookies: {}", JSON.toJSONString(cookies));
+        if (cookies == null) {
+            log.warn("cookies is null");
+            return false;
+        }
         String sessionId = null;
         for (Cookie cookie : cookies) {
             if ("JSESSIONID".equals(cookie.getName())) {

+ 10 - 1
src/main/java/com/nokia/hb/controller/IndicatorController.java

@@ -22,9 +22,18 @@ public class IndicatorController {
     /**
      * 查询指标树形结构
      */
-    @Operation(summary = "查询指标树形结构")
+    @Operation(summary = "查询指标树形结构(添加修改指标模板)")
     @PostMapping("/api/initTreeIndicator")
     public R<List<TreeNode>> initTreeIndicator() {
         return indicatorService.initTreeIndicator();
     }
+
+    /**
+     * 查询指标树形结构
+     */
+    @Operation(summary = "查询指标树形结构(所有指标)")
+    @PostMapping("/api/allIndicator")
+    public R<List<TreeNode>> allIndicator() {
+        return indicatorService.allIndicator();
+    }
 }

+ 18 - 0
src/main/java/com/nokia/hb/service/IndicatorService.java

@@ -39,4 +39,22 @@ public class IndicatorService {
         m.forEach((k, v) -> allTree.getChildren().add(new TreeNode(k, k, v)));
         return R.ok(res);
     }
+
+    public R<List<TreeNode>> allIndicator() {
+        List<PerCfgIndicator> indicators = perCfgIndicatorMapper.all();
+        Map<String, List<TreeNode>> m = new HashMap<>();
+        TreeNode allTree = new TreeNode("所有指标", "所有指标", new ArrayList<>());
+        List<TreeNode> res = new ArrayList<>();
+        res.add(allTree);
+        indicators.forEach(i -> {
+            String indicatorType = i.getIndicatorType();
+            String indicatorCn = i.getIndicatorCn();
+            String indicatorId = i.getIndicatorEn();
+            TreeNode t = new TreeNode(indicatorCn, indicatorId, null);
+            m.putIfAbsent(indicatorType, new ArrayList<>());
+            m.get(indicatorType).add(t);
+        });
+        m.forEach((k, v) -> allTree.getChildren().add(new TreeNode(k, k, v)));
+        return R.ok(res);
+    }
 }

+ 5 - 5
src/main/resources/application.yml

@@ -2,10 +2,10 @@ server:
   port: 9003
   servlet:
     context-path: /
-#    session:
-#      cookie:
-#        secure: false
-#        http-only: false
+    session:
+      cookie:
+        secure: true
+        http-only: true
   tomcat:
     uri-encoding: UTF-8
     max-threads: 800
@@ -29,4 +29,4 @@ spring:
     username: pmparse
     password: abc123!
 session:
-  timeout: 60
+  timeout: 300

+ 63 - 10
src/main/resources/templates/template.html

@@ -96,6 +96,7 @@
                 <button type="button" class="layui-btn layui-btn-sm" onclick="addTemplate()">添加指标模板</button>
                 <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="deleteTemplate()">删除指标模板</button>
                 <div id="allArea"></div>
+                <div id="allMetrics"></div>
                 <div id="indicatorTemplate"></div>
                 <div id="add-template" style="display: none;">
                     <form class="layui-form" action="">
@@ -166,9 +167,6 @@
 <script>
     const host = window.location.host
     const username = window.sessionStorage.getItem('userName')
-    // if(!username){
-    //     window.location.href = '/login'
-    // }
     const socket = new WebSocket(`ws://${host}/ws?username=${username}`);
     socket.onopen = (event) => {
         console.log(event)
@@ -227,6 +225,7 @@
             });
             initTreeCity(tree)
             initTreeIndicator(tree)
+            initAllIndicator(tree)
             initTreeIndicatorTemplate(tree)
             // console.log(window.sessionStorage.getItem('userName'))
             $("#userName").text(window.sessionStorage.getItem('userName'))
@@ -267,7 +266,19 @@
                             showCheckbox: true,
                             accordion: true,
                             id: 'Id3',
-                            data: r?.data
+                            data: r?.data,
+                            oncheck: function(obj){
+                                // console.log(obj);
+                                if(obj.checked) {
+                                    // console.log('tree.getChecked("Id4"): ', tree.getChecked('Id4'));
+                                    tree.getChecked('Id4').length = 0
+                                    tree.setChecked('Id4', [])
+                                    tree.reload('Id4', {
+                                        //新的参数
+                                    });
+                                    // console.log(' ----++++ ',  tree.getChecked('Id4'));
+                                }
+                            }
                         });
                         return
                     }
@@ -276,6 +287,38 @@
             });
         }
 
+        function initAllIndicator(tree) {
+            $.ajax({
+                type: "POST",
+                url: '/api/allIndicator',
+                success: function (r) {
+                    if (r?.success) {
+                        treeIn = tree.render({
+                            elem: '#allMetrics',
+                            showCheckbox: true,
+                            accordion: true,
+                            id: 'Id4',
+                            data: r?.data,
+                            oncheck: function(obj){
+                                // console.log(obj);
+                                if(obj.checked) {
+                                    // console.log('tree.getChecked("Id3"): ', tree.getChecked('Id3'));
+                                    tree.getChecked('Id3').length = 0
+                                    tree.setChecked('Id3', [])
+                                    tree.reload('Id3', {
+                                        //新的参数
+                                    });
+                                    // console.log(' ---- ',  tree.getChecked('Id3'));
+                                }
+                            }
+                        });
+                        return
+                    }
+                    alert(r?.message ?? '发生错误了');
+                }
+            });
+        }
+        
         function initTreeIndicator(tree) {
             $.ajax({
                 type: "POST",
@@ -287,7 +330,7 @@
                             showCheckbox: true,
                             accordion: true,
                             id: 'Id2',
-                            data: r?.data
+                            data: r?.data,
                         });
                         return
                     }
@@ -295,7 +338,6 @@
                 }
             });
         }
-
         function renderTable(condition, searchType, table, citys, quxians, indicators, timeType, startTime, endTime) {
             var tishi = layer.load(1, {
                 shadeClose: false,
@@ -359,7 +401,7 @@
                 alert('填选择时间')
                 return;
             }
-            if (tree.getChecked('Id3').length === 0) {
+            if (tree.getChecked('Id3').length === 0 &&  tree.getChecked('Id4').length === 0) {
                 alert('请选择指标')
                 return;
             }
@@ -384,7 +426,17 @@
                     })
                 });
             }
-            let checkData2 = tree.getChecked('Id3')[0].children;
+            // console.log('0000000', tree.getChecked('Id4')[0]);
+
+            let checkData2 ;
+            console.log('3333 ', tree.getChecked('Id3')[0]?.children);
+            console.log('4444 ', tree.getChecked('Id4')[0]?.children);
+            if(tree.getChecked('Id3')[0]?.children){
+                checkData2= tree.getChecked('Id3')[0].children ;
+            }
+            if(tree.getChecked('Id4')[0]?.children){
+                checkData2= tree.getChecked('Id4')[0].children ;
+            }
             const indicators = new Set();
             checkData2.forEach(eee => {
                 eee.children.forEach(ee => {
@@ -392,6 +444,7 @@
                 })
             });
             indicators.add('eci')
+            indicators.add('sdate')
             let timeType = $('#timeType').val()
             let sdate = $('#time1').val()
             const [startTime, endTime] = sdate.split(' - ')
@@ -491,8 +544,8 @@
                 // url: '/api/json/citys.json',
                 url: '/api/logout',
                 success: function (r) {
-                    layer.msg('退出登录成功');
                     window.sessionStorage.clear()
+                    layer.msg('退出登录成功');
                     setTimeout(() => window.location.href = '/login', 1000)
                 }
             });
@@ -509,7 +562,7 @@
             },1000)
         });
         window.onbeforeunload=function(e){
-            if (!window.sessionStorage.getItem('userName')) {
+            if (window.sessionStorage.getItem('userName')) {
                 logOutFun()
             }
         }