浏览代码

Merge branch 'master' of http://36.97.65.105:3000/sjkj/thsjzt

wangjinsheng 3 年之前
父节点
当前提交
cba66e70e9
共有 19 个文件被更改,包括 967 次插入59 次删除
  1. 3 0
      leiSP-framework/src/main/java/com/sooka/framework/config/ShiroConfig.java
  2. 19 3
      mybusiness/pom.xml
  3. 149 0
      mybusiness/src/main/java/com/business/controller/WebSocketServer.java
  4. 14 0
      mybusiness/src/main/java/com/business/domain/TJ_dept_table.java
  5. 125 0
      mybusiness/src/main/java/com/business/socket/MessageManager.java
  6. 18 0
      mybusiness/src/main/java/com/business/socket/WebSocketConfig.java
  7. 127 0
      mybusiness/src/main/java/com/business/socket/WebSocketServer.java
  8. 109 0
      mybusiness/src/main/java/com/business/socket/WebSocketServerPool.java
  9. 20 0
      mybusiness/src/main/java/com/business/socket/bean/DataContent.java
  10. 131 0
      mybusiness/src/main/java/com/business/socket/bean/PushModel.java
  11. 2 0
      mybusiness/src/main/java/com/sooka/mainpage/domain/Qssjgxqk_Bean.java
  12. 6 0
      mybusiness/src/main/java/com/sooka/mainpage/mapper/MainPageMapper.java
  13. 25 0
      mybusiness/src/main/java/com/sooka/mainpage/service/impl/MainPageServiceImpl.java
  14. 13 1
      mybusiness/src/main/resources/mapper/mainpage/MainPageMapper.xml
  15. 5 0
      mybusiness/src/main/resources/static/visualization/allcharts/eventPieTh.js
  16. 22 20
      mybusiness/src/main/resources/static/visualization/allcharts/humanTh.js
  17. 38 25
      mybusiness/src/main/resources/static/visualization/allcharts/th-echart1.js
  18. 43 0
      mybusiness/src/main/resources/static/visualization/js/visualization_websocket.js
  19. 98 10
      mybusiness/src/main/resources/templates/visualization/index.html

+ 3 - 0
leiSP-framework/src/main/java/com/sooka/framework/config/ShiroConfig.java

@@ -282,6 +282,9 @@ public class ShiroConfig
         filterChainDefinitionMap.put("/js/**", "anon");
         filterChainDefinitionMap.put("/ruoyi/**", "anon");
         filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
+
+        filterChainDefinitionMap.put("/business/app/**", "anon,captchaValidate");
+
         // 退出 logout地址,shiro去清除session
         filterChainDefinitionMap.put("/logout", "logout");
         // 不需要拦截的访问

+ 19 - 3
mybusiness/pom.xml

@@ -37,10 +37,26 @@
 			<!--<groupId>com.leisp</groupId>-->
 			<!--<artifactId>leisp-admin</artifactId>-->
 		<!--</dependency>-->
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.6</version>
+		</dependency>
 
-
-
-
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-lang3</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>cn.hutool</groupId>
+			<artifactId>hutool-all</artifactId>
+			<version>5.5.1</version>
+		</dependency>
+		<dependency>
+			<!-- websocket -->
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-websocket</artifactId>
+		</dependency>
 
 
 	</dependencies>

+ 149 - 0
mybusiness/src/main/java/com/business/controller/WebSocketServer.java

@@ -0,0 +1,149 @@
+package com.business.controller;
+
+
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Component;
+
+import javax.websocket.*;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+
+@ServerEndpoint("/business/app/websocket/{userId}")
+@Component
+public class WebSocketServer {
+    static Log log = LogFactory.get(WebSocketServer.class);
+    /**
+     * 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
+     */
+    private static int onlineCount = 0;
+    /**
+     * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
+     */
+    public static ConcurrentHashMap<String, WebSocketServer> webSocketMap = new ConcurrentHashMap<>();
+    /**
+     * 与某个客户端的连接会话,需要通过它来给客户端发送数据
+     */
+    private Session session;
+    /**
+     * 接收userId
+     */
+    private String userId = "";
+
+    /**
+     * 连接建立成功调用的方法
+     */
+    @OnOpen
+    public void onOpen(Session session, @PathParam("userId") String userId) {
+        this.session = session;
+        this.userId = userId;
+        if (webSocketMap.containsKey(userId)) {
+            webSocketMap.remove(userId);
+            webSocketMap.put(userId, this);
+            //加入set中
+        } else {
+            webSocketMap.put(userId, this);
+            //加入set中
+            addOnlineCount();
+            //在线数加1
+        }
+
+        log.info("用户连接:" + userId + ",当前在线人数为:" + getOnlineCount());
+
+        try {
+            sendMessage("连接成功");
+        } catch (IOException e) {
+            log.error("用户:" + userId + ",网络异常!!!!!!");
+        }
+    }
+
+    /**
+     * 连接关闭调用的方法
+     */
+    @OnClose
+    public void onClose() {
+        if (webSocketMap.containsKey(userId)) {
+            webSocketMap.remove(userId);
+            //从set中删除
+            subOnlineCount();
+        }
+        log.info("用户退出:" + userId + ",当前在线人数为:" + getOnlineCount());
+    }
+
+    /**
+     * 收到客户端消息后调用的方法
+     *
+     * @param message 客户端发送过来的消息
+     */
+    @OnMessage
+    public void onMessage(String message, Session session) {
+        log.info("用户消息:" + userId + ",报文:" + message);
+        //可以群发消息
+        //消息保存到数据库、redis
+        if (StringUtils.isNotBlank(message)) {
+            try {
+                //解析发送的报文
+                JSONObject jsonObject = JSON.parseObject(message);
+                //追加发送人(防止串改)
+                jsonObject.put("fromUserId", this.userId);
+                String toUserId = jsonObject.getString("toUserId");
+                //传送给对应toUserId用户的websocket
+                if (StringUtils.isNotBlank(toUserId) && webSocketMap.containsKey(toUserId)) {
+                    webSocketMap.get(toUserId).sendMessage(jsonObject.toJSONString());
+                } else {
+                    log.error("请求的userId:" + toUserId + "不在该服务器上");
+                    //否则不在这个服务器上,发送到mysql或者redis
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * @param session
+     * @param error
+     */
+    @OnError
+    public void onError(Session session, Throwable error) {
+        log.error("用户错误:" + this.userId + ",原因:" + error.getMessage());
+        error.printStackTrace();
+    }
+
+    /**
+     * 实现服务器主动推送
+     */
+    public void sendMessage(String message) throws IOException {
+        this.session.getBasicRemote().sendText(message);
+    }
+
+
+    /**
+     * 发送自定义消息
+     */
+    public static void sendInfo(String message, @PathParam("userId") String userId) throws IOException {
+        log.info("发送消息到:" + userId + ",报文:" + message);
+        if (StringUtils.isNotBlank(userId) && webSocketMap.containsKey(userId)) {
+            webSocketMap.get(userId).sendMessage(message);
+        } else {
+            log.error("用户" + userId + ",不在线!");
+        }
+    }
+
+    public static synchronized int getOnlineCount() {
+        return onlineCount;
+    }
+
+    public static synchronized void addOnlineCount() {
+        WebSocketServer.onlineCount++;
+    }
+
+    public static synchronized void subOnlineCount() {
+        WebSocketServer.onlineCount--;
+    }
+}

+ 14 - 0
mybusiness/src/main/java/com/business/domain/TJ_dept_table.java

@@ -0,0 +1,14 @@
+package com.business.domain;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class TJ_dept_table {
+
+    Integer id;
+    Long dept_id;
+    String table_name;
+    String user_name;
+}

+ 125 - 0
mybusiness/src/main/java/com/business/socket/MessageManager.java

@@ -0,0 +1,125 @@
+package com.business.socket;
+
+
+import com.business.socket.bean.PushModel;
+import com.sooka.common.utils.StringUtils;
+
+import javax.websocket.Session;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/******************************
+ * @description 发送消息
+ * @author yanhongliang
+ * @date 2019-08-09 15:40
+ ******************************/
+
+public class MessageManager {
+
+    private static LinkedBlockingQueue<BatchBean> mMessageQueue = new LinkedBlockingQueue<BatchBean>();
+
+    private static ThreadPoolExecutor mPoolExecutor = new ThreadPoolExecutor(
+            5,
+            10,
+            15,
+            TimeUnit.SECONDS,
+            new LinkedBlockingQueue<Runnable>(),
+            new ThreadPoolExecutor.AbortPolicy());
+
+    /**
+     * 添加消息到消息队列
+     * @param receiverSession 接收者 Session
+     * @param pushModel 发送的信息
+     * @return 添加是否成功
+     */
+    public static boolean add(Session receiverSession, PushModel pushModel) {
+
+        if (receiverSession == null|| pushModel==null
+                || StringUtils.isEmpty(pushModel.getPushString())) {
+            return false;
+        }
+
+        try {
+            mMessageQueue.put(new BatchBean(receiverSession,pushModel.getPushString()));
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+        return true;
+    }
+
+    public static void submit() {
+
+        if (mMessageQueue.size() == 0) {
+            return;
+        }
+
+        try {
+            BatchBean batchBean = mMessageQueue.take();
+            mPoolExecutor.execute(new SendMessageTask(batchBean, () -> submit()));
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static int getCount() {
+        return mMessageQueue.size();
+    }
+
+    public static void stop(){
+        mMessageQueue.clear();
+        mPoolExecutor.shutdownNow();
+    }
+
+    public interface OnComplete {
+        void onComplete();
+    }
+
+    static class SendMessageTask implements Runnable{
+
+        private BatchBean bean;
+        private OnComplete onComplete;
+
+        SendMessageTask(BatchBean bean, OnComplete onComplete){
+            this.bean = bean;
+            this.onComplete = onComplete;
+        }
+        @Override
+        public void run() {
+            try {
+
+                bean.receiverSession.getBasicRemote().sendText("");
+                if (bean.receiverSession != null) {
+                    bean.receiverSession.getBasicRemote().sendText(bean.message);
+                }
+
+            }catch (Exception e){
+                e.printStackTrace();
+            }finally {
+                onComplete.onComplete();
+            }
+        }
+    }
+
+    /**
+     * 给每个人发送消息的bean的封装
+     */
+    private static class BatchBean {
+        /**
+         * 消息
+         */
+        private String message;
+
+        /**
+         * 接收者
+         */
+        private Session receiverSession;
+
+        BatchBean( Session session,String message) {
+            this.message = message;
+            this.receiverSession = session;
+        }
+    }
+
+}

+ 18 - 0
mybusiness/src/main/java/com/business/socket/WebSocketConfig.java

@@ -0,0 +1,18 @@
+package com.business.socket;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+@Configuration
+public class WebSocketConfig {
+
+    /**
+     * 注入一个ServerEndpointExporter,该Bean会自动注册使用@ServerEndpoint注解申明的websocket endpoint
+     */
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
+
+}

+ 127 - 0
mybusiness/src/main/java/com/business/socket/WebSocketServer.java

@@ -0,0 +1,127 @@
+package com.business.socket;
+
+
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.business.socket.bean.DataContent;
+import com.business.socket.bean.PushModel;
+
+import javax.websocket.*;
+import javax.websocket.server.PathParam;
+import java.util.HashSet;
+import java.util.Set;
+
+//@ServerEndpoint("/business/app/websocket/{userId}")
+//@Component
+public class WebSocketServer {
+
+    private Log log = LogFactory.get(WebSocketServer.class);
+    /**
+     * 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
+     */
+    private static int onlineCount = 0;
+
+    /**
+     * 连接建立成功调用的方法
+     */
+    @OnOpen
+    public void onOpen(Session session, @PathParam("userId") String user) {
+
+
+    }
+
+    /**
+     * 连接关闭调用的方法
+     */
+    @OnClose
+    public void onClose(Session session) {
+
+        WebSocketServerPool.removeUser(session);
+
+        if (WebSocketServerPool.getUserByKey(session) == null) {
+            subOnlineCount();
+            //向所有用户通知当前用户下线消息
+            PushModel model = new PushModel();
+            model.add(new PushModel.Entity(PushModel.LOGOUT, "用户【"+WebSocketServerPool.getUserByKey(session)+"】退出"));
+            WebSocketServerPool.sendMessage(model);
+        }
+
+    }
+
+    /**
+     * 收到客户端消息后调用的方法
+     *
+     * @param message 客户端发送过来的消息
+     */
+    @OnMessage
+    public void onMessage(String message, Session session) {
+//        log.info("用户消息:" + WebSocketServerPool.getUserByKey(session) + ",报文:" + message);
+
+        DataContent data = null;
+
+        try {
+
+            data = JSONObject.toJavaObject(JSON.parseObject(message), DataContent.class);
+
+            // 获取客户端发来的消息
+            Integer action = data.getAction();
+            if (action == PushModel.CONNECT) {
+                String user = data.getSender();
+
+                //如果当前用户在连接池中没有socket信息,说明是新用户,在线人数加1
+                if (WebSocketServerPool.getWebSocketByUser(user) == null) {
+                    addOnlineCount();
+                }
+
+                // 当websocket 第一次open的时候,初始化session,把用的session和user关联起来
+                //将当前用户加入到连接池中
+                WebSocketServerPool.addUser(session, user);
+
+                log.info("用户连接:" + user + ",当前在线人数为:" + getOnlineCount());
+
+            } else if (action == PushModel.MESSAGE) {
+                // 正常信息
+                log.info("收到来自[" + data.getSender() + "]的心消息..." + data.getMessage());
+
+            }else if (action == PushModel.KEEPALIVE) {
+                // 心跳类型的消息
+                log.info("收到来自[" + data.getSender() + "]的心跳包...");
+            }
+
+        } catch (Exception e) {
+            if (data != null) {
+                PushModel model = new PushModel();
+                model.add(new PushModel.Entity(PushModel.MESSAGE, e.getMessage()));
+                Set<String> users = new HashSet<String>();
+                users.add(data.getSender());
+                WebSocketServerPool.sendMessageToUser(users, model);
+            }
+        }
+
+    }
+
+    /**
+     * @param session
+     * @param error
+     */
+    @OnError
+    public void onError(Session session, Throwable error) {
+        log.error("用户错误:" + WebSocketServerPool.getUserByKey(session) + ",原因:" + error.getMessage());
+        error.printStackTrace();
+    }
+
+    public static synchronized int getOnlineCount() {
+        return onlineCount;
+    }
+
+    public static synchronized void addOnlineCount() {
+        WebSocketServer.onlineCount++;
+    }
+
+    public static synchronized void subOnlineCount() {
+        WebSocketServer.onlineCount--;
+    }
+
+}

+ 109 - 0
mybusiness/src/main/java/com/business/socket/WebSocketServerPool.java

@@ -0,0 +1,109 @@
+package com.business.socket;
+
+
+import com.business.socket.bean.PushModel;
+
+import javax.websocket.Session;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/******************************
+ * TODO
+ * @author yanhongliang
+ * @date 2021-03-21 06:13
+ ******************************/
+
+public class WebSocketServerPool {
+
+    // 用户连接池
+    private static final ConcurrentHashMap<Session, String> userConnections = new ConcurrentHashMap<Session, String>();
+
+    /**
+     * 获取用户名
+     */
+    public static String getUserByKey(Session session){
+        return userConnections.get(session);
+    }
+
+    /**
+     * 获取WebSocket
+     */
+    public static Session getWebSocketByUser(String user){
+        Set<Session> keySet = userConnections.keySet();
+        synchronized (keySet) {
+            for (Session session : keySet) {
+                String cuser = userConnections.get(session);
+                if(cuser.equals(user)){
+                    return session;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 向连接池中添加连接
+     */
+    public static void addUser(Session session, String user){
+        userConnections.put(session,user);	//添加连接
+    }
+
+    /**
+     * 获取所有的在线用户
+     */
+    public static Collection<String> getOnlineUser(){
+        List<String> setUsers = new ArrayList<String>();
+        Collection<String> setUser = userConnections.values();
+        for(String u:setUser){
+            setUsers.add(u);
+        }
+        return setUsers;
+    }
+
+    /**
+     * 移除连接池中的连接
+     */
+    public static boolean removeUser(Session session){
+        if(userConnections.containsKey(session)){
+            userConnections.remove(session);	//移除连接
+            return true;
+        }else{
+            return false;
+        }
+    }
+
+    /**
+     * 向特定的用户发送数据
+     * @param users 目标用户登录名集合
+     * @param pushModel 消息体
+     */
+    public static void sendMessageToUser(Set<String> users, PushModel pushModel){
+        for (String user : users) {
+            Session session = getWebSocketByUser(user);
+            if (session != null) {
+                MessageManager.add(session, pushModel);
+            }
+        }
+        MessageManager.submit();
+    }
+
+    /**
+     * 向所有的用户发送消息
+     */
+    public static void sendMessage(PushModel pushModel){
+        Set<Session> keySet = userConnections.keySet();
+        synchronized (keySet) {
+            for (Session session : keySet) {
+                String user = userConnections.get(session);
+                if(user != null){
+                    MessageManager.add(session, pushModel);
+                }
+            }
+            MessageManager.submit();
+        }
+    }
+
+}

+ 20 - 0
mybusiness/src/main/java/com/business/socket/bean/DataContent.java

@@ -0,0 +1,20 @@
+package com.business.socket.bean;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author yhliang
+ * @date 2019/8/19 13:54
+ */
+@Data
+public class DataContent  implements Serializable {
+    private static final long serialVersionUID = -5206090814738742364L;
+
+    private Integer action;	    // 动作类型
+
+    private String sender;		// 发送人
+
+    private String message;		// 消息
+}

+ 131 - 0
mybusiness/src/main/java/com/business/socket/bean/PushModel.java

@@ -0,0 +1,131 @@
+package com.business.socket.bean;
+
+/******************************
+ * @Description 消息推送
+ * @Author yanhongliang
+ * @Date 2019-08-10 10:25
+ ******************************/
+
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 一个推送的具体Model,内部维持了一个数组,可以添加多个实体
+ * 每次推送的详细数据是:把实体数组进行Json操作,然后发送Json字符串
+ * 这样做的目的是:减少多次推送,如果有多个消息需要推送可以合并进行
+ *
+ */
+@SuppressWarnings("WeakerAccess")
+public class PushModel {
+    /**
+     * -1   断开连接
+     */
+    public static final int LOGOUT = -1;
+    /**
+     * 100 建立连接
+     */
+    public static final int CONNECT =100;
+    /**
+     * 101 心跳包
+     */
+    public static final int KEEPALIVE=101;
+    /**
+     * 200  消息
+     */
+    public static final int MESSAGE = 200;
+    /**
+     * 300  事件
+     */
+    public static final int EVENT = 300;
+
+    private List<Entity> entities = new ArrayList<>();
+
+    public PushModel add(Entity entity) {
+        entities.add(entity);
+        return this;
+    }
+
+    public PushModel add(int type, String content) {
+        return add(new Entity(type, content));
+    }
+
+    public String getPushString() {
+        if (entities.size() == 0){
+            return null;
+        }
+        return JSONObject.toJSONString(entities);
+    }
+
+    /**
+     * 具体的实体类型,在这个实体中包装了实体的内容和类型
+     * 比如添加好友的推送:
+     * content:用户信息的Json字符串
+     * type=ENTITY_TYPE_ADD_FRIEND
+     */
+    public static class Entity<T> {
+
+        public Entity(int type, T data) {
+            if (data instanceof Event) {
+                this.type = type;
+                this.data = data;
+            } else {
+                this.type = type;
+                this.data = data;
+            }
+        }
+
+        // 消息类型
+        public int type;
+        // 消息实体
+        public T data;
+        // 消息生成时间
+        public LocalDateTime createAt = LocalDateTime.now();
+
+    }
+
+    public static class Event {
+
+        public Event() {
+
+        }
+
+        public Event(String id, String time, String title, String content,
+                     String user, String longitude, String latitude,
+                     String type, String status) {
+            this.eId = id;
+            this.cTime = time;
+            this.eTitle = title;
+            this.rContent = content;
+            this.rUser = user;
+            this.eLongitude = longitude;
+            this.eLatitude = latitude;
+            this.eType = type;
+            this.eStatus = status;
+        }
+
+        // 事件ID
+        public String eId;
+        // 时间
+        public String cTime;
+        // 标题
+        public String eTitle;
+        // 内容
+        public String rContent;
+        // 用户
+        public String rUser;
+        // 经度
+        public String eLongitude;
+        // 纬度
+        public String eLatitude;
+        // 状态
+        public String eStatus;
+        // 类型
+        public String eType;
+
+    }
+
+}

+ 2 - 0
mybusiness/src/main/java/com/sooka/mainpage/domain/Qssjgxqk_Bean.java

@@ -12,4 +12,6 @@ public class Qssjgxqk_Bean {
     Integer gx_cou;
     Integer gj_cou;
     Integer total_cou;
+
+    Integer dept_record_count;
 }

+ 6 - 0
mybusiness/src/main/java/com/sooka/mainpage/mapper/MainPageMapper.java

@@ -1,5 +1,7 @@
 package com.sooka.mainpage.mapper;
 
+import org.apache.ibatis.annotations.Param;
+
 import java.util.List;
 
 public interface MainPageMapper {
@@ -15,6 +17,10 @@ public interface MainPageMapper {
     //接口使用频次
     public List getInterfacePinci_day();
 
+    public Integer countNumFromDept(@Param("table_name") String table_name);
+
+    public List getTableNamesBydeptId(@Param("dept_id") Integer dept_id);
+
 
 
 }

+ 25 - 0
mybusiness/src/main/java/com/sooka/mainpage/service/impl/MainPageServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sooka.mainpage.service.impl;
 
+import com.business.domain.TJ_dept_table;
 import com.sooka.mainpage.domain.InterfaceCallCount_Bean;
 import com.sooka.mainpage.domain.Qssjgxqk_Bean;
 import com.sooka.mainpage.mapper.MainPageMapper;
@@ -19,6 +20,11 @@ public class MainPageServiceImpl implements MainPageService {
 
     @Override
     public Map getVisualization() {
+
+
+
+
+
         Map map = new HashMap();
         List<InterfaceCallCount_Bean> interfaceCallCount_List = mainPageMapper.interfaceCallCount();
         map.put("interfaceCallCount_List",interfaceCallCount_List);
@@ -56,6 +62,25 @@ public class MainPageServiceImpl implements MainPageService {
         //接口使用频次- 日
         List interfacePinci_day_list  = mainPageMapper.getInterfacePinci_day();
         map.put("interfacePinci_day_list",interfacePinci_day_list);
+
+
+
+
+        //市接口中台数据总数
+        Long tj_sjkzt_sjgs = 0L;
+        for(int i=0;i<qssjgxqk_List.size();i++){
+            List<TJ_dept_table> tables = mainPageMapper.getTableNamesBydeptId(qssjgxqk_List.get(i).getDept_id());
+            Integer count =0;
+            for(int j=0;j<tables.size();j++){
+                String table_name = tables.get(j).getTable_name();
+                Integer c = mainPageMapper.countNumFromDept(table_name);
+                count +=c;
+                tj_sjkzt_sjgs+=c;
+            }
+            qssjgxqk_List.get(i).setDept_record_count(count);
+        }
+        map.put("tj_sjkzt_sjgs",tj_sjkzt_sjgs);
+
         return map;
     }
 

+ 13 - 1
mybusiness/src/main/resources/mapper/mainpage/MainPageMapper.xml

@@ -52,11 +52,13 @@ where dept.del_flag=0 and dept.dept_id >200
 
 
 
+
     <resultMap id="rm_qssjgxqk" type="com.sooka.mainpage.domain.Qssjgxqk_Bean"></resultMap>
     <select id="qssjgxqk" resultMap="rm_qssjgxqk">
         select dept.dept_id dept_id,dept.dept_name dept_name,IFNULL(gx.cou,0) gx_cou,IFNULL(gj.cou,0) gj_cou,
         IFNULL(gx.cou,0)+IFNULL(gj.cou,0) total_cou
-        from sys_dept dept LEFT OUTER JOIN
+        from sys_dept dept
+        LEFT OUTER JOIN
         (select c.apply_oid dept_id,count(*) cou from t_u_interfaceinfo a,int_detailed b,int_record c
         where a.share_type='share_type_1' and a.id=b.int_id and b.record_id=c.id
         group by c.apply_oid) gx on (dept.dept_id=gx.dept_id)
@@ -64,6 +66,7 @@ where dept.del_flag=0 and dept.dept_id >200
         (select c.apply_oid dept_id,count(*) cou from t_u_interfaceinfo a,int_detailed b,int_record c
         where a.share_type='share_type_2' and a.id=b.int_id and b.record_id=c.id
         group by c.apply_oid) gj on (gj.dept_id=dept.dept_id)
+
         where dept.del_flag =0  and dept.dept_id>200
     </select>
 
@@ -74,4 +77,13 @@ where dept.del_flag=0 and dept.dept_id >200
         order by create_time asc
     </select>
 
+    <select id="countNumFromDept" parameterType="java.lang.String" resultType="java.lang.Integer">
+        select count(*) from ${table_name}
+    </select>
+
+    <resultMap id="rm_tj_dept_table" type="com.business.domain.TJ_dept_table"></resultMap>
+    <select id="getTableNamesBydeptId" parameterType="java.lang.Integer" resultMap="rm_tj_dept_table">
+        select id,dept_id,table_name,user_name from tj_dept_table where dept_id=#{dept_id}
+    </select>
+
 </mapper>

+ 5 - 0
mybusiness/src/main/resources/static/visualization/allcharts/eventPieTh.js

@@ -1,4 +1,7 @@
+
+
 function jkzb(zb_guiji,zb_gongxiang) {
+
     var myChart_eventPie = echarts.init(document.getElementById('jkzb'));
     option_eventPie = {
         color: ['#0ad5c8', '#89ca75'],
@@ -50,6 +53,8 @@ function jkzb(zb_guiji,zb_gongxiang) {
         ]
     };
 
+
+
     myChart_eventPie.setOption(option_eventPie);
 }
 

+ 22 - 20
mybusiness/src/main/resources/static/visualization/allcharts/humanTh.js

@@ -1,33 +1,34 @@
 
-function jrbm(arr_name,arr_value) {
+
+
+function jrbm(arr_name, arr_value) {
+
     var myChart_human = echarts.init(document.getElementById('jrbm'));
 
     //组织数据-孙一石
     var items = []
-    $.each(arr_value,function (index,data) {
+    $.each(arr_value, function (index, data) {
+
         var it = {
-                value: data,
-                itemStyle: {
-                    color: new echarts.graphic.LinearGradient
-                    (
-                        1, 0, 0, 1,
-                        [
-                            {offset: 0, color: '#00ffb9'},
-                            {offset: 0.5, color: '#26ddbe'},
-                            {offset: 0.8, color: '#2ebc95'},
-                            {offset: 1, color: '#2ebc95'}
-                        ]
-                    )
+            value: data,
+            itemStyle: {
+                color: new echarts.graphic.LinearGradient
+                (
+                    1, 0, 0, 1,
+                    [
+                        {offset: 0, color: '#00ffb9'},
+                        {offset: 0.5, color: '#26ddbe'},
+                        {offset: 0.8, color: '#2ebc95'},
+                        {offset: 1, color: '#2ebc95'}
+                    ]
+                )
 
-                }
             }
-            items.push(it)
+        }
+        items.push(it)
     })
 
 
-
-
-
     option_human = {
         tooltip: {
             trigger: 'axis',
@@ -91,9 +92,10 @@ function jrbm(arr_name,arr_value) {
         ]
 
     };
+    myChart_human.setOption(option_human);
+
 
 
-    myChart_human.setOption(option_human);
 }
 
 

+ 38 - 25
mybusiness/src/main/resources/static/visualization/allcharts/th-echart1.js

@@ -2,18 +2,27 @@
 // var getmydmc=['卫健委','中级人民法院','公积金','民政局','不动产','文旅局','住建局','某某某','某某某米','某某某某'];//数据点名称
 // var getmyd=[10,3,5,2,5,6,8,6,4,3];//接口数值
 
+
+var k0 = true;
+var k1 = true;
+var k2 = true;
+var k3 = true;
+var k4 = true;
+var k5 = true;
+
+
 //部门接口调用排名
 function init_bmjkdypm() {
-    var getmydzd =[];//学生满意度100%
-    for (var i = 0; i < getmyd.length; i++) {
-        getmydzd.push(15)
-    };
+    // var getmydzd =[];//学生满意度100%
+    // for (var i = 0; i < getmyd_sz.length; i++) {
+    //     getmydzd.push(15)
+    // };
     var myChart_ph = echarts.init(document.getElementById('phb'));
 
     option_ph = {
         grid: {
-            show:false,
-            width:190,
+            show: false,
+            width: 190,
             left: '0',
             right: '20',
             bottom: '0',
@@ -22,12 +31,12 @@ function init_bmjkdypm() {
 
         tooltip: {
             trigger: 'axis',
-            align:'left',
+            align: 'left',
             axisPointer: {
                 type: 'none'
             },
-            formatter: function(params) {
-                return '接口调用数<br>'+ params[0].name  + ' : ' + params[0].value + '次'
+            formatter: function (params) {
+                return '接口调用数<br>' + params[0].name + ' : ' + params[0].value + '次'
             }
         },
         xAxis: {
@@ -39,17 +48,17 @@ function init_bmjkdypm() {
                 type: 'category',
                 inverse: true,
                 axisLabel: {
-                    interval :false,
+                    interval: false,
                     textStyle: {
                         color: '#fff',
                         fontSize: '16',
-                        lineHeight:'40',
+                        lineHeight: '40',
                     },
                     // 调整左侧文字的3个属性,缺一不可
                     verticalAlign: 'bottom',
-                    align:'left',
+                    align: 'left',
                     //调整文字上右下左
-                    padding: [0,0,10,55],
+                    padding: [0, 0, 10, 55],
                 },
                 splitLine: {
                     show: false
@@ -60,22 +69,23 @@ function init_bmjkdypm() {
                 axisLine: {
                     show: false
                 },
-                data:getmydmc
+                data: getmydmc
             },
-            {type: 'category',
+            {
+                type: 'category',
                 inverse: true,
                 axisLabel: {
-                    interval :false,
+                    interval: false,
                     textStyle: {
                         color: '#108bf8',
                         fontSize: '12',
-                        lineHeight:'40',
+                        lineHeight: '40',
                     },
                     // 调整左侧文字的3个属性,缺一不可
                     verticalAlign: 'bottom',
-                    align:'left',
+                    align: 'left',
                     //调整文字上右下左
-                    padding: [0,0,10,-185],
+                    padding: [0, 0, 10, -185],
                     formatter: 'TOP{value}'
                 },
                 splitLine: {
@@ -87,7 +97,7 @@ function init_bmjkdypm() {
                 axisLine: {
                     show: false
                 },
-                data:phnum
+                data: phnum
             },
 
             {
@@ -102,11 +112,11 @@ function init_bmjkdypm() {
                         fontSize: '10'
                     },
                     // 调整右侧数值文字的3个属性,缺一不可
-                    padding: [-5, 10, -10, 1],
-                    align:'right',
+                    padding: [-5, 20, -50, 100],
+                    align: 'right',
                     formatter: '{value}次'
                 },
-                data:getmyd
+                data: getmyd_sz
             }],
         series: [{
             name: '值',
@@ -126,14 +136,14 @@ function init_bmjkdypm() {
                 },
             },
             barWidth: 15,
-            data: getmyd
+            data: getmyd_sz
         },
             {
                 name: '背景',
                 type: 'bar',
                 barWidth: 15,
                 barGap: '-100%',
-                data: getmydzd,
+                data: getmyd_sz,
                 itemStyle: {
                     normal: {
                         color: 'rgba(103,150,253,0.3)',
@@ -143,6 +153,9 @@ function init_bmjkdypm() {
             },
         ]
     };
+    //---愚蠢的动一动
+
+
     myChart_ph.setOption(option_ph);
 }
 

+ 43 - 0
mybusiness/src/main/resources/static/visualization/js/visualization_websocket.js

@@ -0,0 +1,43 @@
+var socket;
+function openSocket(loginName) {
+    if(typeof(WebSocket) == "undefined") {
+        console.log("您的浏览器不支持WebSocket");
+    }else{
+        console.log("您的浏览器支持WebSocket");
+        var socketUrl="http://localhost:9090/business/app/websocket/"+loginName;
+        // var socketUrl="http://127.0.0.1/business/app/websocket/"+loginName;
+        socketUrl=socketUrl.replace("https","ws").replace("http","ws");
+        console.log(socketUrl);
+        if(socket!=null){
+            socket.close();
+            socket=null;
+        }
+        socket = new WebSocket(socketUrl);
+        //打开事件
+        socket.onopen = function() {
+            console.log("websocket已打开");
+            //socket.send("这是来自客户端的消息" + location.href + new Date());
+        };
+        //获得消息事件
+        socket.onmessage = function(msg) {
+            // var text ='{"content":"String content","id":"0d44d0027e424e898f60a456ca8b8a6a","latitude":"5318807.94","longitude":"13874773.35","title":"String title"}';
+            var message = msg.data;
+            if(message != "" && message != null){
+
+                // var json =  $.parseJSON(msg.data);
+                var json =  message;
+                console.log(message.content);
+                console.log(json);
+            }
+        };
+        //关闭事件
+        socket.onclose = function() {
+            console.log("websocket已关闭");
+        };
+        //发生了错误事件
+        socket.onerror = function() {
+            console.log("websocket发生了错误");
+        }
+    }
+}
+openSocket("sun11")

+ 98 - 10
mybusiness/src/main/resources/templates/visualization/index.html

@@ -15,7 +15,7 @@
 </head>
 <script type="text/javascript" th:src="@{/visualization/js/echarts.min.js}"></script>
 <script language="JavaScript" th:src="@{/visualization/js/js.js}"></script>
-
+<script language="JavaScript" th:src="@{/visualization/js/visualization_websocket.js}"></script>
 <body>
 <div class="th-container">
     <!-- 导航开始 -->
@@ -25,20 +25,32 @@
         </div>
         <script>
             var t = null;
-            t = setTimeout(time, 1000);
+
 
             function time() {
                 clearTimeout(t);
                 dt = new Date();
                 var y = dt.getFullYear();
-                var mt = dt.getMonth() + 1;
-                var day = dt.getDate();
-                var h = dt.getHours();
-                var m = dt.getMinutes();
-                var s = dt.getSeconds();
+                var mt = buqi(dt.getMonth() + 1);
+                var day = buqi(dt.getDate());
+                var h = buqi(dt.getHours());
+                var m = buqi(dt.getMinutes());
+                var s = buqi(dt.getSeconds());
                 document.getElementById("showTime").innerHTML = y + "-" + mt + "-" + day + "   " + h + ":" + m + ":" + s + "";
+
+                getmyd_sz[0]++;
+                getmyd_sz[3]++;
+                getmyd_sz[4]+=2;
+                init_bmjkdypm()
                 t = setTimeout(time, 1000);
             }
+            function buqi(a) {
+                if(a <10){
+                    return "0"+a;
+                }else{
+                    return a;
+                }
+            }
         </script>
         <div class="th-top-btn-row">
             <div class="th-top-btn">
@@ -77,6 +89,7 @@
                     <h2>市接口中台</h2>
                     <h6>归集接口: <span id="jkzt_gj">93</span></h6>
                     <h6>共享接口: <span id="jkzt_gx">7</span></h6>
+                    <h6>数据个数: <span id="jkzt_sjgs">7</span></h6>
                 </div>
 
                 <div class="th-mid-dw-con" id="qssjgxqk_div">
@@ -267,6 +280,8 @@
     var data_total_name = [];
     var data_total_value = [];
 
+
+
     //全市数据共享情况
     function qssjgxqk(d) {
         var qssjgxqk_div = $("#qssjgxqk_div");
@@ -277,9 +292,11 @@
             var h2 = $("<h2>" + data.dept_name + "</h2>");
             var h6_0 = $("<h6>归集接口: <span>" + data.gj_cou + "</span></h6>");
             var h6_1 = $("<h6>共享接口: <span>" + data.gx_cou + "</span></h6>");
+            var h6_2 = $("<h6>数据个数: <span>" + data.dept_record_count + "</span></h6>");
             div.append(h2);
             div.append(h6_0);
             div.append(h6_1);
+            div.append(h6_2);
             qssjgxqk_div.append(div);
             //市主要归集接口 --- 市主要共享接口
 
@@ -293,10 +310,14 @@
         szy_gj(data_szygjjk_name, data_szygjjk_value);
         szy_gx(data_szygxjk_name, data_szygxjk_value);
         jrbm(data_total_name, data_total_value);
-        jkzb(d.zb_guiji, d.zb_gongxiang);
+        d_zb_guiji = d.zb_guiji;
+        d_zb_gongxiang = d.zb_gongxiang
+        jkzb(d_zb_guiji, d_zb_gongxiang);
         $("#jkzt_jkzs").text(d.zb_gongxiang + d.zb_guiji);
         $("#jkzt_gj").text(d.zb_guiji);
         $("#jkzt_gx").text(d.zb_gongxiang);
+        $("#jkzt_sjgs").text(d.tj_sjkzt_sjgs);
+
         //右侧顶部统计
         $("#tj_interface_total").text(d.tj_interface_total)
         $("#tj_dypc").text(d.tj_dypc)
@@ -323,20 +344,87 @@
 
     var phnum = [];//排行数
     var getmydmc = [];//数据点名称
-    var getmyd = [];//接口数值
+    var getmyd_sz = [];//接口数值
     function getVisualization_Success(d) {
+        // console.log(d.interfaceCallCount_List)
         $.each(d.interfaceCallCount_List, function (index, data) {
             phnum.push((index + 1) + "   ")
             getmydmc.push(data.dept_name)
-            getmyd.push("    " + data.cou)
+            getmyd_sz.push(data.cou)
         });
+        // console.log("1:",phnum)
+        // console.log("2:",getmydmc)
+        // console.log("3:",getmyd_sz)
+
         //最左侧,top部门接口调用排名
+
         init_bmjkdypm();
         //中间 全市数据共享情况
         qssjgxqk(d);
 
+        //最后启动定时
+        t = setTimeout(time, 1000);
+        change_se = window.setTimeout(change_twoSec,2000);
+        change_thir = window.setTimeout(change_thirSec,3000);
 
     }
+    var d_zb_guiji = 100;
+    var d_zb_gongxiang = 200;
+
+    //愚蠢的动一动
+    var change_se;
+    function change_twoSec() {
+        window.clearTimeout(change_se);
+
+        change_se = window.setTimeout(change_twoSec,2000);
+
+        var tj_interface_total =parseInt($("#tj_interface_total").text()) ;
+        tj_interface_total++;
+        $("#tj_interface_total").text(tj_interface_total);
+
+        var tj_dypc =parseInt($("#tj_dypc").text()) ;
+        tj_dypc++;
+        $("#tj_dypc").text(tj_dypc);
+
+
+        var tj_gjpc =parseInt($("#tj_gjpc").text()) ;
+        tj_gjpc++;
+        $("#tj_gjpc").text(tj_gjpc);
+
+        var tj_gxpc =parseInt($("#tj_gxpc").text()) ;
+        tj_gxpc++;
+        $("#tj_gxpc").text(tj_gxpc);
+
+
+        var tj_jrbm =parseInt($("#tj_jrbm").text()) ;
+        tj_jrbm++;
+        $("#tj_jrbm").text(tj_jrbm);
+    }
+    var change_thir;
+    function change_thirSec() {
+        window.clearTimeout(change_thir);
+
+
+
+        d_zb_guiji+=1;
+        d_zb_gongxiang += 5;
+        jkzb(d_zb_guiji, d_zb_gongxiang);
+
+        data_total_value[0]++;
+        data_total_value[1]+=2;
+        jrbm(data_total_name, data_total_value);
+
+        data_szygjjk_value[0]++;
+        data_szygjjk_value[1]+=2;
+        data_szygjjk_value[3]++;
+        szy_gj(data_szygjjk_name, data_szygjjk_value);
+
+        data_szygxjk_value[1]++;
+        data_szygxjk_value[3]++;
+        szy_gx(data_szygxjk_name, data_szygxjk_value);
+        change_thir = window.setTimeout(change_thirSec,3000);
+    }
+
 </script>