Skip to content

Commit

Permalink
feat: 增加刷新字典值示例代码
Browse files Browse the repository at this point in the history
  • Loading branch information
houkunlin committed Dec 12, 2021
1 parent a72bc17 commit 6692659
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
11 changes: 11 additions & 0 deletions system-dict-examples/examples-refresh-dict/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'java'
}

dependencies {
implementation project(":common")
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions system-dict-examples/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
rootProject.name = 'system-dict-examples'
include 'examples-basic'
include 'examples-provider'
include 'examples-refresh-dict'
include 'common'

0 comments on commit 6692659

Please sign in to comment.