瀏覽代碼

增加对比时间交集方法
增加rediskey的常量池

hgw 3 年之前
父節點
當前提交
6120da7803

+ 26 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/constant/LiveRoomConstant.java

@@ -0,0 +1,26 @@
+package com.yonge.cooleshow.biz.dal.constant;
+
+public interface LiveRoomConstant {
+
+    //替换的字符串
+    String USER_ID = "${userId}";
+
+    //替换的字符串
+    String ROOM_UID = "${roomUid}";
+
+    //缓存排头
+    String COOLESHOW = "COOLESHOW";
+
+    //直播间累计用户信息-指只要进入到该房间的用户都要记录
+    String LIVE_ROOM_TOTAL_USER_LIST = String.join(":", COOLESHOW, "LIVE_ROOM_TOTAL_USER_LIST", ROOM_UID);
+
+    //用户当前对应的直播间Uid
+    String LIVE_USER_ROOM = String.join(":", COOLESHOW, "LIVE_ROOM_USER", USER_ID);
+
+    //房间点赞数
+    String LIVE_ROOM_LIKE = String.join(":", COOLESHOW, "LIVE_ROOM_LIKE", ROOM_UID);
+
+    //房间的信息
+    String LIVE_ROOM_INFO = String.join(":", COOLESHOW, "LIVE_ROOM_INFO", ROOM_UID);
+
+}

+ 48 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/WrapperUtil.java

@@ -105,6 +105,13 @@ public class WrapperUtil {
     }
 
     /**
+     * 检查对象是否有值
+     */
+    public static <T> void checkObj(T obj, String errMsg) {
+        Optional.ofNullable(obj).orElseThrow(() -> new BizException(errMsg));
+    }
+
+    /**
      * 全部有值则为true
      *
      * @param obj 多个对象
@@ -187,4 +194,45 @@ public class WrapperUtil {
                 .orElse(new HashMap<String, Object>());
     }
 
+    /**
+     * 判断2个时间段是否有交集-默认允许结束时间和开始时间相等
+     *
+     * @param startDateOne 第一个时间段的开始时间
+     * @param endDateOne   第一个时间段的结束时间
+     * @param startDateTwo 第二个时间段的开始时间
+     * @param endDateTwo   第二个时间段的结束时间
+     * @return 有交集 true 无交集 false
+     */
+    public static Boolean inInterSection(Date startDateOne, Date endDateOne, Date startDateTwo, Date endDateTwo) {
+        return inInterSection(startDateOne, endDateOne, startDateTwo, endDateTwo, true);
+    }
+
+    /**
+     * 判断2个时间段是否有交集
+     *
+     * @param startDateOne 第一个时间段的开始时间
+     * @param endDateOne   第一个时间段的结束时间
+     * @param startDateTwo 第二个时间段的开始时间
+     * @param endDateTwo   第二个时间段的结束时间
+     * @param eq           是否允许结束时间和开始时间相等 true 允许
+     * @return 有交集 true 无交集 false
+     */
+    public static Boolean inInterSection(Date startDateOne, Date endDateOne, Date startDateTwo, Date endDateTwo, boolean eq) {
+        Date maxStartDate = startDateOne;
+        if (maxStartDate.before(startDateTwo)) {
+            maxStartDate = startDateTwo;
+        }
+
+        Date minEndDate = endDateOne;
+        if (endDateTwo.before(minEndDate)) {
+            minEndDate = endDateTwo;
+        }
+        //是否允许结束时间和开始时间相等 true 允许
+        if (eq) {
+            return maxStartDate.before(minEndDate);
+        } else {
+            return maxStartDate.before(minEndDate) || (maxStartDate.getTime() == minEndDate.getTime());
+        }
+    }
+
 }