diff --git a/system-dict-examples/examples-refresh-dict/build.gradle b/system-dict-examples/examples-refresh-dict/build.gradle new file mode 100644 index 0000000..fef224d --- /dev/null +++ b/system-dict-examples/examples-refresh-dict/build.gradle @@ -0,0 +1,11 @@ +plugins { + id 'java' +} + +dependencies { + implementation project(":common") +} + +test { + useJUnitPlatform() +} diff --git a/system-dict-examples/examples-refresh-dict/src/main/java/com/examples/Application.java b/system-dict-examples/examples-refresh-dict/src/main/java/com/examples/Application.java new file mode 100644 index 0000000..8caa15f --- /dev/null +++ b/system-dict-examples/examples-refresh-dict/src/main/java/com/examples/Application.java @@ -0,0 +1,70 @@ +package com.examples; + +import com.houkunlin.system.dict.starter.DictUtil; +import com.houkunlin.system.dict.starter.SystemDictScan; +import com.houkunlin.system.dict.starter.bean.DictTypeVo; +import com.houkunlin.system.dict.starter.bean.DictValueVo; +import com.houkunlin.system.dict.starter.notice.RefreshDictEvent; +import com.houkunlin.system.dict.starter.notice.RefreshDictTypeEvent; +import com.houkunlin.system.dict.starter.notice.RefreshDictValueEvent; +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * SystemDictScan 是必须加的一个注解 + * + * @author HouKunLin + */ +@SpringBootApplication +@SystemDictScan +@RestController +@RequestMapping +@Component +@RequiredArgsConstructor +public class Application implements CommandLineRunner { + private static final Logger logger = LoggerFactory.getLogger(Application.class); + private final ApplicationEventPublisher publisher; + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Override + public void run(final String... args) throws Exception { + final String dictType = UserType.class.getSimpleName(); + logger.info("用户类型:{}", DictUtil.getDictType(dictType)); + logger.info("用户类型:UserType(1) = {}", DictUtil.getDictText(dictType, "1")); + System.out.println(); + + publisher.publishEvent(new RefreshDictValueEvent(DictValueVo.builder() + .dictType(dictType) + .value(1) + .title("刷新单个字典值") + .build())); + logger.info("用户类型:{}", DictUtil.getDictType(dictType)); + logger.info("用户类型:UserType(1) = {}", DictUtil.getDictText(dictType, "1")); + System.out.println(); + + publisher.publishEvent(new RefreshDictTypeEvent(DictTypeVo.newBuilder(dictType, "刷新一个完整的字典类型") + .add(0, "刷新一个完整的字典类型0") + .add(1, "刷新一个完整的字典类型1") + .add(2, "刷新一个完整的字典类型2") + .build())); + logger.info("用户类型:{}", DictUtil.getDictType(dictType)); + logger.info("用户类型:UserType(1) = {}", DictUtil.getDictText(dictType, "1")); + System.out.println(); + + publisher.publishEvent(new RefreshDictEvent("从系统中重新读取字典信息,所有系统字典信息将被还原成系统启动时的最初版本", true, true)); + logger.info("用户类型:{}", DictUtil.getDictType(dictType)); + logger.info("用户类型:UserType(1) = {}", DictUtil.getDictText(dictType, "1")); + System.out.println(); + } +} diff --git a/system-dict-examples/examples-refresh-dict/src/main/resources/application.properties b/system-dict-examples/examples-refresh-dict/src/main/resources/application.properties new file mode 100644 index 0000000..a1bdee8 --- /dev/null +++ b/system-dict-examples/examples-refresh-dict/src/main/resources/application.properties @@ -0,0 +1,4 @@ +# \u8BBE\u7F6E\u4E24\u6B21\u5237\u65B0\u5B57\u5178\u7684\u95F4\u9694\uFF0C\u5C0F\u4E8E\u95F4\u9694\u7684\u5237\u65B0\u4E8B\u4EF6\u5C06\u88AB\u5FFD\u7565\uFF0C\u6B64\u53C2\u6570\u53EA\u9002\u7528 RefreshDictEvent \u4E8B\u4EF6 +system.dict.refresh-dict-interval=0 +# \u8BFB\u53D6\u5B57\u5178\u6570\u636E\u4F1A\u9ED8\u8BA4\u4F7F\u7528\u7F13\u5B58\u4FE1\u606F\uFF0C\u7981\u7528\u7F13\u5B58\u540E\u5C06\u4F1A\u76F4\u63A5\u4ECE store \u4E2D\u8BFB\u53D6\u5B57\u5178\u4FE1\u606F +system.dict.cache.enabled=false diff --git a/system-dict-examples/settings.gradle b/system-dict-examples/settings.gradle index 0b549af..f5e9282 100644 --- a/system-dict-examples/settings.gradle +++ b/system-dict-examples/settings.gradle @@ -1,4 +1,5 @@ rootProject.name = 'system-dict-examples' include 'examples-basic' include 'examples-provider' +include 'examples-refresh-dict' include 'common'