feat: 指定应用的时区

This commit is contained in:
xiaozzzi 2024-02-06 18:12:35 +08:00
parent 10fc6d7f26
commit 9ae8778ab2
6 changed files with 28 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import javax.sql.DataSource;
import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.TimeZone;
/**
* 启动检查配置文件内容, 用于检查配置项是否正确
@ -34,6 +35,7 @@ public class PropertiesCheckListener implements ApplicationListener<ApplicationE
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment env = event.getEnvironment();
setTimeZone(env);
log.warn("\n\n正在检查 Blossom 后台配置项\n\n" +
"\n[CHECK] ==========================================================================================================================" +
"\n[CHECK] 使用环境: [{}], 版本: [{}]" +
@ -46,6 +48,7 @@ public class PropertiesCheckListener implements ApplicationListener<ApplicationE
"\n[CHECK] 文件大小: {}" +
"\n[CHECK] 授权时长: {}" +
"\n[CHECK] 重置密码: {}" +
"\n[CHECK] 指定时区: {}" +
"\n[CHECK] ==========================================================================================================================\n\n",
get(env, SpringUtil.PROFILE_ACTION), get(env, "project.base.version"),
get(env, "spring.datasource.url"),
@ -55,7 +58,8 @@ public class PropertiesCheckListener implements ApplicationListener<ApplicationE
get(env, "project.iaas.blos.default-path"),
get(env, "spring.servlet.multipart.max-file-size"),
get(env, "project.auth.clients[0].duration"),
get(env, "project.auth.password-reset")
get(env, "project.auth.password-reset"),
get(env, "project.base.time-zone")
);
String defaultPath = get(env, "project.iaas.blos.default-path");
@ -167,4 +171,15 @@ public class PropertiesCheckListener implements ApplicationListener<ApplicationE
public boolean isNotReceived(String message) {
return message.contains("The driver has not received any packets from the server");
}
private void setTimeZone(ConfigurableEnvironment env) {
String timeZone = get(env, "project.base.time-zone");
if (StrUtil.isBlank(timeZone) || TimeZone.getTimeZone(timeZone) == null) {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
} else {
TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
}
}
}

View File

@ -1,7 +1,7 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.31.99:3306/xzzz-blossom?useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&allowMultiQueries=true&useSSL=false&&serverTimezone=GMT%2B8
url: jdbc:mysql://localhost:3306/blossom?useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&allowMultiQueries=true&useSSL=false&&serverTimezone=GMT%2B8
username: root
password: jasmine888
hikari:
@ -29,6 +29,7 @@ logging:
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ project ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
project:
base:
time-zone: GMT+8
version: @project.version@
ex:
# 异常打印格式 all/project
@ -51,7 +52,7 @@ project:
type: caffeine
default-password: 123456 # 默认密码
password-encoder: bcrypt # 加密方式
password-reset: false # 启动时重置密码
password-reset: true # 启动时重置密码
clients: # 客户端
- client-id: blossom
grant-type: 'password'

View File

@ -20,6 +20,7 @@ logging:
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ project ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
project:
base:
time-zone: GMT+8
version: @project.version@
ex:
# 异常打印格式 all/project

View File

@ -23,6 +23,7 @@ logging:
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ project ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
project:
base:
time-zone: GMT+8
version: @project.version@
ex:
# 异常打印格式 all/project

View File

@ -1,5 +1,6 @@
package com.blossom.common.base;
import com.blossom.common.base.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
@ -22,7 +23,7 @@ public final class BaseConstants {
public static void desc() {
log.info("启动完成" +
"\n=========================================================================" +
"\n启动成功: 可使用客户端登录, 默认用户名/密码: blos/blos" +
"\n启动成功 [" + DateUtils.now() + "], 可使用客户端登录, 默认用户名/密码: blos/blos" +
"\n下载地址: https://github.com/blossom-editor/blossom/releases" +
"\n文档地址: https://www.wangyunf.com/blossom-doc/index" +
"\n博客端访问地址: http://IP:端口(域名)/blog/#/home" +

View File

@ -17,6 +17,11 @@ import org.springframework.context.annotation.Configuration;
@ConfigurationProperties(prefix = "project.base")
public class BaseProperties {
/**
* 指定项目的时区
*/
private String timeZone = "GMT+8";
/**
* 系统版本, 可以使用 @project.version@ 获取 pom 中版本
*/