소스 검색

调整画板使用时间统计逻辑

Eric 2 년 전
부모
커밋
c6d640d0f1

+ 57 - 24
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/websocket/WsConnectRecordInfo.java

@@ -8,16 +8,25 @@ public class WsConnectRecordInfo {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private Long id;
 
     /**
      *
      * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column ws_connect_record_info.session_id_
+     *
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
+     */
+    private String sessionId;
+
+    /**
+     *
+     * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.room_id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private String roomId;
 
@@ -26,7 +35,7 @@ public class WsConnectRecordInfo {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.user_id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private Long userId;
 
@@ -35,7 +44,7 @@ public class WsConnectRecordInfo {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.client_type_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private String clientType;
 
@@ -44,7 +53,7 @@ public class WsConnectRecordInfo {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.connect_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private Date connectTime;
 
@@ -53,7 +62,7 @@ public class WsConnectRecordInfo {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.disconnect_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private Date disconnectTime;
 
@@ -62,7 +71,7 @@ public class WsConnectRecordInfo {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.online_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private Long onlineTime;
 
@@ -71,7 +80,7 @@ public class WsConnectRecordInfo {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database column ws_connect_record_info.created_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     private Date createdTime;
 
@@ -81,7 +90,7 @@ public class WsConnectRecordInfo {
      *
      * @return the value of ws_connect_record_info.id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Long getId() {
         return id;
@@ -93,7 +102,7 @@ public class WsConnectRecordInfo {
      *
      * @param id the value for ws_connect_record_info.id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setId(Long id) {
         this.id = id;
@@ -101,11 +110,35 @@ public class WsConnectRecordInfo {
 
     /**
      * This method was generated by MyBatis Generator.
+     * This method returns the value of the database column ws_connect_record_info.session_id_
+     *
+     * @return the value of ws_connect_record_info.session_id_
+     *
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
+     */
+    public String getSessionId() {
+        return sessionId;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method sets the value of the database column ws_connect_record_info.session_id_
+     *
+     * @param sessionId the value for ws_connect_record_info.session_id_
+     *
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
+     */
+    public void setSessionId(String sessionId) {
+        this.sessionId = sessionId;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
      * This method returns the value of the database column ws_connect_record_info.room_id_
      *
      * @return the value of ws_connect_record_info.room_id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public String getRoomId() {
         return roomId;
@@ -117,7 +150,7 @@ public class WsConnectRecordInfo {
      *
      * @param roomId the value for ws_connect_record_info.room_id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setRoomId(String roomId) {
         this.roomId = roomId;
@@ -129,7 +162,7 @@ public class WsConnectRecordInfo {
      *
      * @return the value of ws_connect_record_info.user_id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Long getUserId() {
         return userId;
@@ -141,7 +174,7 @@ public class WsConnectRecordInfo {
      *
      * @param userId the value for ws_connect_record_info.user_id_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setUserId(Long userId) {
         this.userId = userId;
@@ -153,7 +186,7 @@ public class WsConnectRecordInfo {
      *
      * @return the value of ws_connect_record_info.client_type_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public String getClientType() {
         return clientType;
@@ -165,7 +198,7 @@ public class WsConnectRecordInfo {
      *
      * @param clientType the value for ws_connect_record_info.client_type_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setClientType(String clientType) {
         this.clientType = clientType;
@@ -177,7 +210,7 @@ public class WsConnectRecordInfo {
      *
      * @return the value of ws_connect_record_info.connect_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Date getConnectTime() {
         return connectTime;
@@ -189,7 +222,7 @@ public class WsConnectRecordInfo {
      *
      * @param connectTime the value for ws_connect_record_info.connect_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setConnectTime(Date connectTime) {
         this.connectTime = connectTime;
@@ -201,7 +234,7 @@ public class WsConnectRecordInfo {
      *
      * @return the value of ws_connect_record_info.disconnect_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Date getDisconnectTime() {
         return disconnectTime;
@@ -213,7 +246,7 @@ public class WsConnectRecordInfo {
      *
      * @param disconnectTime the value for ws_connect_record_info.disconnect_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setDisconnectTime(Date disconnectTime) {
         this.disconnectTime = disconnectTime;
@@ -225,7 +258,7 @@ public class WsConnectRecordInfo {
      *
      * @return the value of ws_connect_record_info.online_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Long getOnlineTime() {
         return onlineTime;
@@ -237,7 +270,7 @@ public class WsConnectRecordInfo {
      *
      * @param onlineTime the value for ws_connect_record_info.online_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setOnlineTime(Long onlineTime) {
         this.onlineTime = onlineTime;
@@ -249,7 +282,7 @@ public class WsConnectRecordInfo {
      *
      * @return the value of ws_connect_record_info.created_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Date getCreatedTime() {
         return createdTime;
@@ -261,7 +294,7 @@ public class WsConnectRecordInfo {
      *
      * @param createdTime the value for ws_connect_record_info.created_time_
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setCreatedTime(Date createdTime) {
         this.createdTime = createdTime;

+ 87 - 17
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/websocket/WsConnectRecordInfoExample.java

@@ -9,7 +9,7 @@ public class WsConnectRecordInfoExample {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     protected String orderByClause;
 
@@ -17,7 +17,7 @@ public class WsConnectRecordInfoExample {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     protected boolean distinct;
 
@@ -25,7 +25,7 @@ public class WsConnectRecordInfoExample {
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     protected List<Criteria> oredCriteria;
 
@@ -33,7 +33,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public WsConnectRecordInfoExample() {
         oredCriteria = new ArrayList<Criteria>();
@@ -43,7 +43,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setOrderByClause(String orderByClause) {
         this.orderByClause = orderByClause;
@@ -53,7 +53,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public String getOrderByClause() {
         return orderByClause;
@@ -63,7 +63,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void setDistinct(boolean distinct) {
         this.distinct = distinct;
@@ -73,7 +73,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public boolean isDistinct() {
         return distinct;
@@ -83,7 +83,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public List<Criteria> getOredCriteria() {
         return oredCriteria;
@@ -93,7 +93,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void or(Criteria criteria) {
         oredCriteria.add(criteria);
@@ -103,7 +103,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Criteria or() {
         Criteria criteria = createCriteriaInternal();
@@ -115,7 +115,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public Criteria createCriteria() {
         Criteria criteria = createCriteriaInternal();
@@ -129,7 +129,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     protected Criteria createCriteriaInternal() {
         Criteria criteria = new Criteria();
@@ -140,7 +140,7 @@ public class WsConnectRecordInfoExample {
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public void clear() {
         oredCriteria.clear();
@@ -152,7 +152,7 @@ public class WsConnectRecordInfoExample {
      * This class was generated by MyBatis Generator.
      * This class corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     protected abstract static class GeneratedCriteria {
         protected List<Criterion> criteria;
@@ -255,6 +255,76 @@ public class WsConnectRecordInfoExample {
             return (Criteria) this;
         }
 
+        public Criteria andSessionIdIsNull() {
+            addCriterion("session_id_ is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdIsNotNull() {
+            addCriterion("session_id_ is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdEqualTo(String value) {
+            addCriterion("session_id_ =", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdNotEqualTo(String value) {
+            addCriterion("session_id_ <>", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdGreaterThan(String value) {
+            addCriterion("session_id_ >", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdGreaterThanOrEqualTo(String value) {
+            addCriterion("session_id_ >=", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdLessThan(String value) {
+            addCriterion("session_id_ <", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdLessThanOrEqualTo(String value) {
+            addCriterion("session_id_ <=", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdLike(String value) {
+            addCriterion("session_id_ like", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdNotLike(String value) {
+            addCriterion("session_id_ not like", value, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdIn(List<String> values) {
+            addCriterion("session_id_ in", values, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdNotIn(List<String> values) {
+            addCriterion("session_id_ not in", values, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdBetween(String value1, String value2) {
+            addCriterion("session_id_ between", value1, value2, "sessionId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSessionIdNotBetween(String value1, String value2) {
+            addCriterion("session_id_ not between", value1, value2, "sessionId");
+            return (Criteria) this;
+        }
+
         public Criteria andRoomIdIsNull() {
             addCriterion("room_id_ is null");
             return (Criteria) this;
@@ -700,7 +770,7 @@ public class WsConnectRecordInfoExample {
      * This class was generated by MyBatis Generator.
      * This class corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated do_not_delete_during_merge Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated do_not_delete_during_merge Fri Nov 04 16:18:23 CST 2022
      */
     public static class Criteria extends GeneratedCriteria {
 
@@ -713,7 +783,7 @@ public class WsConnectRecordInfoExample {
      * This class was generated by MyBatis Generator.
      * This class corresponds to the database table ws_connect_record_info
      *
-     * @mbg.generated Mon Oct 31 11:58:02 CST 2022
+     * @mbg.generated Fri Nov 04 16:18:23 CST 2022
      */
     public static class Criterion {
         private String condition;

+ 3 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/WsConnectService.java

@@ -7,12 +7,13 @@ public interface WsConnectService {
 
     /**
      * 保存用户ws连接记录信息
+     * @param sessionId 会话ID
      * @param roomId 房间ID
      * @param userid 用户ID
      * @param clientType 客户端类型
      * @return int
      */
-    int saveWsConnectRecordInfo(String roomId, String userid, String clientType);
+    int saveWsConnectRecordInfo(String sessionId, String roomId, String userid, String clientType);
 
     /**
      * 更新用户ws连接断开时间
@@ -21,5 +22,5 @@ public interface WsConnectService {
      * @param clientType 客户端类型
      * @return int
      */
-    int updateWsDisconnectRecordInfo(String roomId, String userId, String clientType);
+    int updateWsDisconnectRecordInfo(String sessionId, String roomId, String userId, String clientType);
 }

+ 12 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/WsConnectServiceImpl.java

@@ -9,6 +9,7 @@ import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -24,20 +25,24 @@ public class WsConnectServiceImpl implements WsConnectService {
     /**
      * 保存用户ws连接记录信息
      *
+     * @param sessionId  会放ID
      * @param roomId     房间ID
      * @param userid     用户ID
      * @param clientType 客户端类型
      * @return int
      */
     @Override
-    public int saveWsConnectRecordInfo(String roomId, String userid, String clientType) {
+    public int saveWsConnectRecordInfo(String sessionId, String roomId, String userid, String clientType) {
 
+        Date date = DateTime.now().toDate();
         // 连接记录信息
         WsConnectRecordInfo record = new WsConnectRecordInfo();
+        record.setSessionId(sessionId);
         record.setRoomId(roomId);
         record.setUserId(Long.parseLong(userid));
         record.setClientType(clientType);
-        record.setConnectTime(DateTime.now().toDate());
+        record.setConnectTime(date);
+        record.setCreatedTime(date);
 
         // 保存连接记录信息
         return wsConnectRecordInfoMapper.insertSelective(record);
@@ -45,18 +50,20 @@ public class WsConnectServiceImpl implements WsConnectService {
 
     /**
      * 更新用户ws连接断开时间
-     *
+     * @param sessionId  会话ID
      * @param roomId     房间ID
      * @param userId     用户
      * @param clientType 客户端类型
      * @return int
      */
     @Override
-    public int updateWsDisconnectRecordInfo(String roomId, String userId, String clientType) {
+    public int updateWsDisconnectRecordInfo(String sessionId, String roomId, String userId, String clientType) {
 
         // 查询连接记录信息
         WsConnectRecordInfoExample example = new WsConnectRecordInfoExample();
-        example.or().andRoomIdEqualTo(roomId)
+        example.or()
+                .andSessionIdEqualTo(sessionId)
+                .andRoomIdEqualTo(roomId)
                 .andUserIdEqualTo(Long.parseLong(userId))
                 .andClientTypeEqualTo(clientType)
                 .andDisconnectTimeIsNull();

+ 41 - 24
mec-biz/src/main/resources/config/mybatis/WsConnectRecordInfoMapper.xml

@@ -5,9 +5,10 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     <id column="id_" jdbcType="BIGINT" property="id" />
+    <result column="session_id_" jdbcType="VARCHAR" property="sessionId" />
     <result column="room_id_" jdbcType="VARCHAR" property="roomId" />
     <result column="user_id_" jdbcType="BIGINT" property="userId" />
     <result column="client_type_" jdbcType="VARCHAR" property="clientType" />
@@ -20,7 +21,7 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     <where>
       <foreach collection="oredCriteria" item="criteria" separator="or">
@@ -54,7 +55,7 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     <where>
       <foreach collection="example.oredCriteria" item="criteria" separator="or">
@@ -88,16 +89,16 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
-    id_, room_id_, user_id_, client_type_, connect_time_, disconnect_time_, online_time_, 
-    created_time_
+    id_, session_id_, room_id_, user_id_, client_type_, connect_time_, disconnect_time_, 
+    online_time_, created_time_
   </sql>
   <select id="selectByExample" parameterType="com.ym.mec.biz.dal.entity.websocket.WsConnectRecordInfoExample" resultMap="BaseResultMap">
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     select
     <if test="distinct">
@@ -116,7 +117,7 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     select 
     <include refid="Base_Column_List" />
@@ -127,7 +128,7 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     delete from ws_connect_record_info
     where id_ = #{id,jdbcType=BIGINT}
@@ -136,7 +137,7 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     delete from ws_connect_record_info
     <if test="_parameter != null">
@@ -147,26 +148,31 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
-    insert into ws_connect_record_info (id_, room_id_, user_id_, 
-      client_type_, connect_time_, disconnect_time_, 
-      online_time_, created_time_)
-    values (#{id,jdbcType=BIGINT}, #{roomId,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, 
-      #{clientType,jdbcType=VARCHAR}, #{connectTime,jdbcType=TIMESTAMP}, #{disconnectTime,jdbcType=TIMESTAMP}, 
-      #{onlineTime,jdbcType=BIGINT}, #{createdTime,jdbcType=TIMESTAMP})
+    insert into ws_connect_record_info (id_, session_id_, room_id_, 
+      user_id_, client_type_, connect_time_, 
+      disconnect_time_, online_time_, created_time_
+      )
+    values (#{id,jdbcType=BIGINT}, #{sessionId,jdbcType=VARCHAR}, #{roomId,jdbcType=VARCHAR}, 
+      #{userId,jdbcType=BIGINT}, #{clientType,jdbcType=VARCHAR}, #{connectTime,jdbcType=TIMESTAMP}, 
+      #{disconnectTime,jdbcType=TIMESTAMP}, #{onlineTime,jdbcType=BIGINT}, #{createdTime,jdbcType=TIMESTAMP}
+      )
   </insert>
   <insert id="insertSelective" parameterType="com.ym.mec.biz.dal.entity.websocket.WsConnectRecordInfo">
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     insert into ws_connect_record_info
     <trim prefix="(" suffix=")" suffixOverrides=",">
       <if test="id != null">
         id_,
       </if>
+      <if test="sessionId != null">
+        session_id_,
+      </if>
       <if test="roomId != null">
         room_id_,
       </if>
@@ -193,6 +199,9 @@
       <if test="id != null">
         #{id,jdbcType=BIGINT},
       </if>
+      <if test="sessionId != null">
+        #{sessionId,jdbcType=VARCHAR},
+      </if>
       <if test="roomId != null">
         #{roomId,jdbcType=VARCHAR},
       </if>
@@ -220,7 +229,7 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     select count(*) from ws_connect_record_info
     <if test="_parameter != null">
@@ -231,13 +240,16 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     update ws_connect_record_info
     <set>
       <if test="record.id != null">
         id_ = #{record.id,jdbcType=BIGINT},
       </if>
+      <if test="record.sessionId != null">
+        session_id_ = #{record.sessionId,jdbcType=VARCHAR},
+      </if>
       <if test="record.roomId != null">
         room_id_ = #{record.roomId,jdbcType=VARCHAR},
       </if>
@@ -268,10 +280,11 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     update ws_connect_record_info
     set id_ = #{record.id,jdbcType=BIGINT},
+      session_id_ = #{record.sessionId,jdbcType=VARCHAR},
       room_id_ = #{record.roomId,jdbcType=VARCHAR},
       user_id_ = #{record.userId,jdbcType=BIGINT},
       client_type_ = #{record.clientType,jdbcType=VARCHAR},
@@ -287,10 +300,13 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     update ws_connect_record_info
     <set>
+      <if test="sessionId != null">
+        session_id_ = #{sessionId,jdbcType=VARCHAR},
+      </if>
       <if test="roomId != null">
         room_id_ = #{roomId,jdbcType=VARCHAR},
       </if>
@@ -319,10 +335,11 @@
     <!--
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Mon Oct 31 11:58:02 CST 2022.
+      This element was generated on Fri Nov 04 16:18:23 CST 2022.
     -->
     update ws_connect_record_info
-    set room_id_ = #{roomId,jdbcType=VARCHAR},
+    set session_id_ = #{sessionId,jdbcType=VARCHAR},
+      room_id_ = #{roomId,jdbcType=VARCHAR},
       user_id_ = #{userId,jdbcType=BIGINT},
       client_type_ = #{clientType,jdbcType=VARCHAR},
       connect_time_ = #{connectTime,jdbcType=TIMESTAMP},

+ 45 - 7
mec-websocket/src/main/java/com/ym/mec/web/handler/WhiteboardHandler.java

@@ -8,9 +8,7 @@ import com.corundumstudio.socketio.annotation.OnDisconnect;
 import com.corundumstudio.socketio.annotation.OnEvent;
 import com.corundumstudio.socketio.protocol.Packet;
 import com.corundumstudio.socketio.protocol.PacketType;
-import com.corundumstudio.socketio.store.pubsub.DispatchMessage;
 import com.corundumstudio.socketio.store.pubsub.PubSubStore;
-import com.corundumstudio.socketio.store.pubsub.PubSubType;
 import com.google.common.collect.Lists;
 import com.ym.mec.biz.service.WsConnectService;
 import com.ym.mec.web.support.anno.NamespaceReference;
@@ -18,6 +16,7 @@ import com.ym.mec.web.support.anno.OnNamespace;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
@@ -40,6 +39,10 @@ public class WhiteboardHandler {
 
     // 初始化房间
     private static final String EVENT_INIT_ROOM = "init-room";
+    // 心跳配置
+    private static final String EVENT_HEARTBEAT_CONFIG = "heartbeat-config";
+    // 心跳事件
+    private static final String EVENT_HEARTBEAT_SYNC = "heartbeat-sync";
     // 第一次进入房间
     private static final String EVENT_FIRST_IN_ROOM = "first-in-room";
     // 加入房间
@@ -110,13 +113,24 @@ public class WhiteboardHandler {
         // 客户端类型
         String clientType = client.getHandshakeData().getSingleUrlParam(CLIENT_TYPE);
 
-        log.info("onConnect client={}, ns={}, roomId={}", client.getSessionId(), client.getNamespace().getName(), roomId);
+        log.debug("onConnect client={}, ns={}, roomId={}, userId={}", client.getSessionId(),
+                client.getNamespace().getName(), roomId, userId);
         //发送初始化房间事件
         client.sendEvent(EVENT_INIT_ROOM);
 
+        // 发送心跳同步事件
+        WhiteboardMessage.HeartbeatConfig config = WhiteboardMessage.HeartbeatConfig
+                .builder()
+                .event(EVENT_HEARTBEAT_SYNC)
+                .timestamp(DateTime.now().getMillis())
+                .build();
+
+        client.sendEvent(EVENT_HEARTBEAT_CONFIG, config);
+
         if (StringUtils.isNoneBlank(roomId, userId, clientType)) {
 
-            wsConnectService.saveWsConnectRecordInfo(roomId, userId, clientType);
+            wsConnectService.saveWsConnectRecordInfo(client.getSessionId().toString(), roomId,
+                    userId, clientType);
         }
     }
 
@@ -134,7 +148,8 @@ public class WhiteboardHandler {
         // 客户端类型
         String clientType = client.getHandshakeData().getSingleUrlParam(CLIENT_TYPE);
 
-        log.info("onDisconnect client={}, ns={}, roomId={}", client.getSessionId(), client.getNamespace().getName(), roomId);
+        log.debug("onDisconnect client={}, ns={}, roomId={}, userId={}", client.getSessionId(),
+                client.getNamespace().getName(), roomId, userId);
         client.disconnect();
 
         // 通知用户参与所有房间,用户变化信息
@@ -155,10 +170,33 @@ public class WhiteboardHandler {
 
         if (StringUtils.isNoneBlank(roomId, userId, clientType)) {
 
-            wsConnectService.updateWsDisconnectRecordInfo(roomId, userId, clientType);
+            wsConnectService.updateWsDisconnectRecordInfo(client.getSessionId().toString(), roomId, userId, clientType);
         }
     }
 
+    /**
+     * 画板心跳同步监听
+     * @param client SocketIOClient
+     * @param timestamp 时间戳
+     */
+    @OnEvent(value = EVENT_HEARTBEAT_SYNC)
+    public void onHeartbeatSync(SocketIOClient client, Long timestamp) {
+
+        // 房间ID
+        String roomId = client.getHandshakeData().getSingleUrlParam(ROOM_ID);
+        // 用户ID
+        String userId = client.getHandshakeData().getSingleUrlParam(USER_ID);
+        // 客户端类型
+        String clientType = client.getHandshakeData().getSingleUrlParam(CLIENT_TYPE);
+
+        log.debug("onHeartbeatSync client={}, ns={}, roomId={}, userId={}, timestamp={}", client.getSessionId(),
+                client.getNamespace().getName(), roomId, userId, timestamp);
+
+        if (StringUtils.isNoneBlank(roomId, userId, clientType)) {
+
+            wsConnectService.updateWsDisconnectRecordInfo(client.getSessionId().toString(), roomId, userId, clientType);
+        }
+    }
 
     /**
      * 加入房间事件
@@ -167,7 +205,7 @@ public class WhiteboardHandler {
      */
     @OnEvent(value = EVENT_JOIN_ROOM)
     public void joinRoom(SocketIOClient client, String roomId) {
-        log.info("joinRoom roomId={}", roomId);
+        log.debug("joinRoom roomId={}", roomId);
 
         // 加入房间
         client.joinRoom(roomId);

+ 33 - 0
mec-websocket/src/main/java/com/ym/mec/web/handler/WhiteboardMessage.java

@@ -0,0 +1,33 @@
+package com.ym.mec.web.handler;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 画板消息
+ * Created by Eric.Shang on 2022/11/4.
+ */
+public class WhiteboardMessage {
+
+    /**
+     * 心跳同步配置
+     */
+    @Data
+    @Builder
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class HeartbeatConfig implements Serializable {
+
+        // 事件名称
+        private String event;
+        // 当前时间戳
+        private Long timestamp;
+        // 心跳同步间隔(默认60s)
+        private Integer interval = 60;
+
+    }
+}