package com.ruoyi.energymeter.util;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.ZoneId;
|
|
/**
|
* 登录态与时间工具:系统级定时任务不会携带登录态,这里统一兜底。
|
*/
|
public final class EnergyMeterSupport {
|
|
private EnergyMeterSupport() {
|
}
|
|
public static Long currentTenantId() {
|
try {
|
return SecurityUtils.getLoginUser().getTenantId();
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
|
public static Long currentUserId() {
|
try {
|
return SecurityUtils.getUserId();
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
|
public static boolean isAdmin() {
|
try {
|
return SecurityUtils.getLoginUser().getUser().isAdmin();
|
} catch (Exception e) {
|
return false;
|
}
|
}
|
|
public static LocalDate today() {
|
return LocalDate.now(ZoneId.of("Asia/Shanghai"));
|
}
|
|
public static LocalDateTime now() {
|
return LocalDateTime.now(ZoneId.of("Asia/Shanghai"));
|
}
|
|
public static String truncate(String text, int maxLength) {
|
if (text == null) {
|
return null;
|
}
|
return text.length() <= maxLength ? text : text.substring(0, maxLength);
|
}
|
}
|