-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support config timezone locale language region on web ui (#1154)
Co-authored-by: Ceilzcx <1758619238@qq.com>
- Loading branch information
Showing
35 changed files
with
472 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
common/src/main/java/org/dromara/hertzbeat/common/support/event/SystemConfigChangeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.dromara.hertzbeat.common.support.event; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
/** | ||
* the event for system config change | ||
* @author tom | ||
*/ | ||
public class SystemConfigChangeEvent extends ApplicationEvent { | ||
|
||
public SystemConfigChangeEvent(Object source) { | ||
super(source); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
manager/src/main/java/org/dromara/hertzbeat/manager/config/SystemCommandLineRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.dromara.hertzbeat.manager.config; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.dromara.hertzbeat.common.constants.CommonConstants; | ||
import org.dromara.hertzbeat.common.entity.manager.GeneralConfig; | ||
import org.dromara.hertzbeat.manager.dao.GeneralConfigDao; | ||
import org.dromara.hertzbeat.manager.pojo.dto.SystemConfig; | ||
import org.dromara.hertzbeat.manager.service.impl.SystemGeneralConfigServiceImpl; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* @author ceilzcx | ||
* @since 4/7/2023 | ||
*/ | ||
@Component | ||
public class SystemCommandLineRunner implements CommandLineRunner { | ||
|
||
private static final Integer LANG_REGION_LENGTH = 2; | ||
|
||
@Resource | ||
private SystemGeneralConfigServiceImpl systemGeneralConfigService; | ||
|
||
@Resource | ||
protected GeneralConfigDao generalConfigDao; | ||
|
||
@Resource | ||
protected ObjectMapper objectMapper; | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
SystemConfig systemConfig = systemGeneralConfigService.getConfig(); | ||
if (systemConfig != null) { | ||
if (systemConfig.getTimeZoneId() != null) { | ||
TimeZone.setDefault(TimeZone.getTimeZone(systemConfig.getTimeZoneId())); | ||
} | ||
if (systemConfig.getLocale() != null) { | ||
String[] arr = systemConfig.getLocale().split(CommonConstants.LOCALE_SEPARATOR); | ||
if (arr.length == LANG_REGION_LENGTH) { | ||
String language = arr[0]; | ||
String country = arr[1]; | ||
Locale.setDefault(new Locale(language, country)); | ||
} | ||
} | ||
} else { | ||
// init system config data | ||
systemConfig = SystemConfig.builder().timeZoneId(TimeZone.getDefault().getID()) | ||
.locale(Locale.getDefault().getLanguage() + CommonConstants.LOCALE_SEPARATOR | ||
+ Locale.getDefault().getCountry()) | ||
.build(); | ||
String contentJson = objectMapper.writeValueAsString(systemConfig); | ||
GeneralConfig generalConfig2Save = GeneralConfig.builder() | ||
.type(systemGeneralConfigService.type()) | ||
.content(contentJson) | ||
.build(); | ||
generalConfigDao.save(generalConfig2Save); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.