Yue 1 неделя назад
Родитель
Сommit
158d245a15

+ 12 - 9
SERVER/VberAdminPlusV3/vber-admin/src/main/java/com/vber/web/controller/AuthController.java

@@ -20,6 +20,8 @@ import com.vber.common.satoken.utils.LoginHelper;
 import com.vber.common.social.config.properties.SocialLoginConfigProperties;
 import com.vber.common.social.config.properties.SocialProperties;
 import com.vber.common.social.utils.SocialUtils;
+import com.vber.common.sse.dto.SseMessageDto;
+import com.vber.common.sse.utils.SseMessageUtils;
 import com.vber.common.tenant.helper.TenantHelper;
 import com.vber.system.domain.bo.SysTenantBo;
 import com.vber.system.domain.vo.SysClientVo;
@@ -46,10 +48,12 @@ import org.springframework.web.bind.annotation.*;
 
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 认证
@@ -70,7 +74,6 @@ public class AuthController {
     private final ISysTenantService tenantService;
     private final ISysSocialService socialUserService;
     private final ISysClientService clientService;
-    @SuppressWarnings("unused")
     private final ScheduledExecutorService scheduledExecutorService;
     @SuppressWarnings("unused")
     private final VbConfig vbConfig;
@@ -106,13 +109,13 @@ public class AuthController {
         // 登录
         LoginVo loginVo = IAuthStrategy.login(body, client, grantType);
 
-        // Long userId = LoginHelper.getUserId();
-        // scheduledExecutorService.schedule(() -> {
-        // SseMessageDto dto = new SseMessageDto();
-        // dto.setUserIds(List.of(userId));
-        // dto.setMessage("欢迎登录" + vbConfig.getName());
-        // SseMessageUtils.publishMessage(dto);
-        // }, 3, TimeUnit.SECONDS);
+        Long userId = LoginHelper.getUserId();
+        scheduledExecutorService.schedule(() -> {
+            SseMessageDto dto = new SseMessageDto();
+            dto.setUserIds(List.of(userId));
+            dto.setMessage(DateUtils.getTodayHour(new Date()) + "好,欢迎登录 RuoYi-Vue-Plus 后台管理系统");
+            SseMessageUtils.publishMessage(dto);
+        }, 3, TimeUnit.SECONDS);
         return R.ok(loginVo);
     }
 
@@ -124,7 +127,7 @@ public class AuthController {
      */
     @GetMapping("/binding/{source}")
     public R<String> authBinding(@PathVariable("source") String source, @RequestParam String tenantId,
-                                 @RequestParam String domain) {
+            @RequestParam String domain) {
         SocialLoginConfigProperties obj = socialProperties.getType().get(source);
         if (ObjectUtil.isNull(obj)) {
             return R.fail(source + "平台账号暂不支持");

+ 81 - 1
SERVER/VberAdminPlusV3/vber-common/vber-common-core/src/main/java/com/vber/common/core/utils/DateUtils.java

@@ -2,6 +2,10 @@ package com.vber.common.core.utils;
 
 import com.vber.common.core.enums.FormatsType;
 import com.vber.common.core.exception.ServiceException;
+
+import cn.hutool.core.date.DateUnit;
+import cn.hutool.core.date.DateUtil;
+
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 import java.lang.management.ManagementFactory;
@@ -20,7 +24,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
     private static final String[] PARSE_PATTERNS = {
             "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
             "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
-            "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
+            "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM" };
 
     @Deprecated
     private DateUtils() {
@@ -297,4 +301,80 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         }
     }
 
+    /**
+     * 根据指定日期时间获取时间段(凌晨 / 上午 / 中午 / 下午 / 晚上)
+     *
+     * @param date 日期时间
+     * @return 时间段描述
+     */
+    public static String getTodayHour(Date date) {
+        int hour = DateUtil.hour(date, true);
+        if (hour <= 6) {
+            return "凌晨";
+        } else if (hour < 12) {
+            return "上午";
+        } else if (hour == 12) {
+            return "中午";
+        } else if (hour <= 18) {
+            return "下午";
+        } else {
+            return "晚上";
+        }
+    }
+
+    /**
+     * 将日期格式化为仿微信的友好时间
+     * <p>
+     * 规则说明:
+     * 1. 未来时间:yyyy-MM-dd HH:mm
+     * 2. 今天:
+     * - 1 分钟内:刚刚
+     * - 1 小时内:X 分钟前
+     * - 超过 1 小时:凌晨/上午/中午/下午/晚上 HH:mm
+     * 3. 昨天:昨天 HH:mm
+     * 4. 本周:周X HH:mm
+     * 5. 今年内:MM-dd HH:mm
+     * 6. 非今年:yyyy-MM-dd HH:mm
+     *
+     * @param date 日期时间
+     * @return 格式化后的时间描述
+     */
+    public static String formatFriendlyTime(Date date) {
+        if (date == null) {
+            return "";
+        }
+        Date now = DateUtil.date();
+
+        // 未来时间或非今年
+        if (date.after(now) || DateUtil.year(date) != DateUtil.year(now)) {
+            return parseDateToStr(FormatsType.YYYY_MM_DD_HH_MM, date);
+        }
+
+        // 今天
+        if (DateUtil.isSameDay(date, now)) {
+            long minutes = DateUtil.between(date, now, DateUnit.MINUTE);
+            if (minutes < 1) {
+                return "刚刚";
+            }
+            if (minutes < 60) {
+                return minutes + "分钟前";
+            }
+            return getTodayHour(date) + " " + DateUtil.format(date, "HH:mm");
+        }
+
+        // 昨天
+        if (DateUtil.isSameDay(date, DateUtil.yesterday())) {
+            return "昨天 " + DateUtil.format(date, "HH:mm");
+        }
+
+        // 本周
+        if (DateUtil.isSameWeek(date, now, true)) {
+            return DateUtil.dayOfWeekEnum(date).toChinese("周")
+                    + " " + DateUtil.format(date, "HH:mm");
+        }
+
+        // 今年内其它时间
+        return DateUtil.format(date, "MM-dd HH:mm");
+    }
+
 }