fix: repair decompiled sources and add exhaustive documentation
- restore generic signatures, scoped variables and missing code from original bytecode - remove decompiler artifacts and document classes, methods, fields and packages - restore resources, add Batik/BouncyCastle dependencies and build/runtime docs
This commit is contained in:
1 parent
9d7e42eda8
commit
10aa1829f5
346 files changed
+42404
-622
No files matched your search
@@ -12,11 +12,40 @@ import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
|
||||
/**
|
||||
* 【Spring 配置类】{@code AppConfig}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>向 Spring 容器装配 Bean、读取外部配置并控制初始化顺序。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code mongoTemplate}(MongoTemplate):MongoDB模板</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code MongoTemplate}。
|
||||
*
|
||||
* 学习提示:先看 @Bean 方法与 @Value 配置项,再对照 application.properties 和启动日志。
|
||||
*/
|
||||
@Configuration
|
||||
public class AppConfig {
|
||||
/**
|
||||
* MongoDB模板;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
/**
|
||||
* 处理multipart配置Element。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);主要调用:findOne、new MultipartConfigFactory。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@Bean
|
||||
public MultipartConfigElement multipartConfigElement() {
|
||||
SystemSetting setting = (SystemSetting)this.mongoTemplate.findOne(Query.query(Criteria.where("_id").is("files.maxUploadSize")), SystemSetting.class);
|
||||
|
||||
@@ -11,17 +11,56 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* 【Spring 配置类】{@code AsyncConfig}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>向 Spring 容器装配 Bean、读取外部配置并控制初始化顺序。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code TASK_CORE_POOL_SIZE}(int):字段 TASK_CORE_POOL_SIZE</li>
|
||||
* <li>{@code TASK_MAX_POOL_SIZE}(int):字段 TASK_MAX_POOL_SIZE</li>
|
||||
* <li>{@code TASK_QUEUE_CAPACITY}(int):字段 TASK_QUEUE_CAPACITY</li>
|
||||
* <li>{@code asyncExceptionHandler}(AsyncUncaughtExceptionHandler):异步异常Handler</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code AsyncUncaughtExceptionHandler}。
|
||||
*
|
||||
* 学习提示:先看 @Bean 方法与 @Value 配置项,再对照 application.properties 和启动日志。
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class AsyncConfig implements AsyncConfigurer {
|
||||
/**
|
||||
* 字段 TASK_CORE_POOL_SIZE。
|
||||
*/
|
||||
private static final int TASK_CORE_POOL_SIZE = 10;
|
||||
/**
|
||||
* 字段 TASK_MAX_POOL_SIZE。
|
||||
*/
|
||||
private static final int TASK_MAX_POOL_SIZE = 20;
|
||||
/**
|
||||
* 字段 TASK_QUEUE_CAPACITY。
|
||||
*/
|
||||
private static final int TASK_QUEUE_CAPACITY = 100;
|
||||
/**
|
||||
* 异步异常Handler。
|
||||
*/
|
||||
private AsyncUncaughtExceptionHandler asyncExceptionHandler = new AsyncUncaughtExceptionHandler() {
|
||||
public void handleUncaughtException(Throwable ex, Method method, Object... params) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取 {@code asyncExecutor}。
|
||||
*
|
||||
* 实现要点:主要调用:new ThreadPoolTaskExecutor。
|
||||
* @return 字段/派生属性 {@code asyncExecutor} 的值
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
public Executor getAsyncExecutor() {
|
||||
@@ -34,10 +73,20 @@ public class AsyncConfig implements AsyncConfigurer {
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 {@code asyncUncaughtExceptionHandler}。
|
||||
* @return 字段/派生属性 {@code asyncUncaughtExceptionHandler} 的值
|
||||
*/
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return this.asyncExceptionHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 {@code taskScheduler}。
|
||||
*
|
||||
* 实现要点:主要调用:new ThreadPoolTaskScheduler。
|
||||
* @return 字段/派生属性 {@code taskScheduler} 的值
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
public ThreadPoolTaskScheduler getTaskScheduler() {
|
||||
@@ -46,6 +95,12 @@ public class AsyncConfig implements AsyncConfigurer {
|
||||
return taskScheduler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 {@code taskExcutor}。
|
||||
*
|
||||
* 实现要点:主要调用:new ThreadPoolTaskExecutor。
|
||||
* @return 字段/派生属性 {@code taskExcutor} 的值
|
||||
*/
|
||||
@Bean
|
||||
public ThreadPoolTaskExecutor getTaskExcutor() {
|
||||
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
|
||||
|
||||
@@ -11,13 +11,53 @@ import org.springframework.data.util.Pair;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code BasicAuthInterceptor}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code deviceKeyService}(DeviceKeyService):设备密钥服务</li>
|
||||
* <li>{@code settingsService}(SettingsService):设置列表服务</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code DeviceKeyService、SettingsService}。
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class BasicAuthInterceptor implements HandlerInterceptor {
|
||||
/**
|
||||
* 设备密钥服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
DeviceKeyService deviceKeyService;
|
||||
/**
|
||||
* 设置列表服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
SettingsService settingsService;
|
||||
|
||||
/**
|
||||
* 处理pre处理。
|
||||
*
|
||||
* 实现要点:包含 2 个条件分支、0 个循环。
|
||||
*
|
||||
* @param request HTTP 请求({@code HttpServletRequest})
|
||||
* @param response HTTP 响应({@code HttpServletResponse})
|
||||
* @param handler 参数 {@code handler}({@code Object})
|
||||
* @return 条件成立返回 {@code true},否则返回 {@code false}
|
||||
* @throws Exception 当 Exception 条件不满足或底层调用失败时抛出。
|
||||
*/
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String serialNo = request.getHeader("serialNo");
|
||||
if (Strings.isNullOrEmpty(serialNo)) {
|
||||
@@ -35,6 +75,15 @@ public class BasicAuthInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理响应错误。
|
||||
*
|
||||
* 实现要点:包含异常捕获与降级/回滚分支。
|
||||
*
|
||||
* @param response HTTP 响应({@code HttpServletResponse})
|
||||
* @param code 状态码/业务码({@code int})
|
||||
* @param message 消息内容({@code String})
|
||||
*/
|
||||
private void responseError(HttpServletResponse response, int code, String message) {
|
||||
response.setStatus(code);
|
||||
response.setContentType("application/json");
|
||||
|
||||
@@ -47,33 +47,83 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
|
||||
@EnableMongoRepositories({"com.midm.repository"})
|
||||
public class DbConfig extends AbstractMongoClientConfiguration {
|
||||
|
||||
/**
|
||||
* 数据库Servers;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.servers:}")}。
|
||||
*/
|
||||
@Value("${mongo.servers:}")
|
||||
private String dbServers;
|
||||
|
||||
/**
|
||||
* 数据库URI;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.uri:}")}。
|
||||
*/
|
||||
@Value("${mongo.uri:}")
|
||||
private String dbUri;
|
||||
|
||||
/**
|
||||
* 数据库Scheme;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.scheme:mongodb}")}。
|
||||
*/
|
||||
@Value("${mongo.scheme:mongodb}")
|
||||
private String dbScheme;
|
||||
|
||||
/**
|
||||
* 数据库Host;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.host:127.0.0.1}")}。
|
||||
*/
|
||||
@Value("${mongo.host:127.0.0.1}")
|
||||
private String dbHost;
|
||||
|
||||
/**
|
||||
* 数据库Port;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.port:27017}")}。
|
||||
*/
|
||||
@Value("${mongo.port:27017}")
|
||||
private Integer dbPort;
|
||||
|
||||
/**
|
||||
* 数据库名称;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.dbname:db_midm}")}。
|
||||
*/
|
||||
@Value("${mongo.dbname:db_midm}")
|
||||
private String dbName;
|
||||
|
||||
/**
|
||||
* 数据库用户;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.username:}")}。
|
||||
*/
|
||||
@Value("${mongo.username:}")
|
||||
private String dbUser;
|
||||
|
||||
/**
|
||||
* 数据库Password;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.password:}")}。
|
||||
*/
|
||||
@Value("${mongo.password:}")
|
||||
private String dbPassword;
|
||||
|
||||
/**
|
||||
* SSLEnabled;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.ssl:false}")}。
|
||||
*/
|
||||
@Value("${mongo.ssl:false}")
|
||||
private boolean sslEnabled;
|
||||
|
||||
/**
|
||||
* 是否keepAlive;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.keep_alive:true}")}。
|
||||
*/
|
||||
@Value("${mongo.keep_alive:true}")
|
||||
private boolean keepAlive;
|
||||
|
||||
@@ -81,24 +131,59 @@ public class DbConfig extends AbstractMongoClientConfiguration {
|
||||
@Value("${mongo.maxPoolSize:1000}")
|
||||
private int maxPoolSize;
|
||||
|
||||
/**
|
||||
* 字段 connectionsPerHost;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.connectionsPerHost: 1000}")}。
|
||||
*/
|
||||
@Value("${mongo.connectionsPerHost: 1000}")
|
||||
private int connectionsPerHost;
|
||||
|
||||
/**
|
||||
* 字段 connectionMultiplier;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.connection_multiplier:200}")}。
|
||||
*/
|
||||
@Value("${mongo.connection_multiplier:200}")
|
||||
private int connectionMultiplier;
|
||||
|
||||
/**
|
||||
* 字段 connectTimeout;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.connect_timeout:5000}")}。
|
||||
*/
|
||||
@Value("${mongo.connect_timeout:5000}")
|
||||
private int connectTimeout;
|
||||
|
||||
/**
|
||||
* 字段 waitTimeout;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.wait_timeout:5000}")}。
|
||||
*/
|
||||
@Value("${mongo.wait_timeout:5000}")
|
||||
private int waitTimeout;
|
||||
|
||||
/**
|
||||
* 字段 socketTimeout;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.socket_timeout:0}")}。
|
||||
*/
|
||||
@Value("${mongo.socket_timeout:0}")
|
||||
private int socketTimeout;
|
||||
|
||||
/**
|
||||
* 字段 idleTimeout;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.idle_timeout:30000}")}。
|
||||
*/
|
||||
@Value("${mongo.idle_timeout:30000}")
|
||||
private int idleTimeout;
|
||||
|
||||
/**
|
||||
* 数据库Replica设置;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${mongo.replica_set:rs0}")}。
|
||||
*/
|
||||
@Value("${mongo.replica_set:rs0}")
|
||||
private String dbReplicaSet;
|
||||
|
||||
@@ -188,11 +273,17 @@ public class DbConfig extends AbstractMongoClientConfiguration {
|
||||
if (!params.contains("waitqueuetimeoutms")) {
|
||||
uriBuilder.setParameter("waitqueuetimeoutms", String.valueOf(this.waitTimeout));
|
||||
}
|
||||
if (!params.contains("connectTimeoutMS")) {
|
||||
uriBuilder.setParameter("connectTimeoutMS", String.valueOf(this.connectTimeout));
|
||||
}
|
||||
|
||||
boolean isSrv = uriBuilder.getScheme().endsWith("+srv");
|
||||
if (!isSrv && !params.contains("ssl")) {
|
||||
uriBuilder.setParameter("ssl", String.valueOf(this.sslEnabled));
|
||||
}
|
||||
if (this.socketTimeout > 0 && !params.contains("socketTimeoutMS")) {
|
||||
uriBuilder.setParameter("", "");
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(this.dbReplicaSet) && !params.contains("replicaSet")) {
|
||||
uriBuilder.setParameter("replicaSet", this.dbReplicaSet);
|
||||
@@ -220,6 +311,12 @@ public class DbConfig extends AbstractMongoClientConfiguration {
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 {@code databaseName}。
|
||||
*
|
||||
* 框架注解:{@code @Override}。
|
||||
* @return 字符串结果
|
||||
*/
|
||||
@Override
|
||||
protected String getDatabaseName() {
|
||||
return this.dbName;
|
||||
|
||||
@@ -57,25 +57,84 @@ import org.springframework.data.mongodb.core.schema.JsonSchemaObject;
|
||||
import org.springframework.data.mongodb.core.schema.JsonSchemaObject.Type;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code DbInitialize}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code DB_SCHEME_VER_2}(long):字段 DB_SCHEME_VER_2</li>
|
||||
* <li>{@code DB_SCHEME_VER_3}(long):字段 DB_SCHEME_VER_3</li>
|
||||
* <li>{@code DB_SCHEME_VER_4}(long):字段 DB_SCHEME_VER_4</li>
|
||||
* <li>{@code DB_SCHEME_VER_5}(long):字段 DB_SCHEME_VER_5</li>
|
||||
* <li>{@code DB_SCHEME_VER_6}(long):字段 DB_SCHEME_VER_6</li>
|
||||
* <li>{@code KEY_DB_SCHEME}(String):字段 KEY_DB_SCHEME</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code MongoTemplate、RestoreService}。
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class DbInitialize {
|
||||
/**
|
||||
* 字段 DB_SCHEME_VER_2。
|
||||
*/
|
||||
private static final long DB_SCHEME_VER_2 = 20092901L;
|
||||
/**
|
||||
* 字段 DB_SCHEME_VER_3。
|
||||
*/
|
||||
private static final long DB_SCHEME_VER_3 = 22111002L;
|
||||
/**
|
||||
* 字段 DB_SCHEME_VER_4。
|
||||
*/
|
||||
private static final long DB_SCHEME_VER_4 = 23072101L;
|
||||
/**
|
||||
* 字段 DB_SCHEME_VER_5。
|
||||
*/
|
||||
private static final long DB_SCHEME_VER_5 = 23082501L;
|
||||
/**
|
||||
* 字段 DB_SCHEME_VER_6。
|
||||
*/
|
||||
private static final long DB_SCHEME_VER_6 = 24022701L;
|
||||
/**
|
||||
* 字段 KEY_DB_SCHEME。
|
||||
*/
|
||||
private String KEY_DB_SCHEME = "db.scheme";
|
||||
/**
|
||||
* MongoDB模板;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
/**
|
||||
* restore服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private RestoreService restoreService;
|
||||
|
||||
/**
|
||||
* 处理contextRefreshed事件。
|
||||
*/
|
||||
@EventListener({ContextRefreshedEvent.class})
|
||||
public void contextRefreshedEvent() {
|
||||
this.initializeDb();
|
||||
this.updateScheme();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理initialize数据库。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);包含 7 个条件分支、1 个循环;主要调用:findOne、save、new SystemSetting、new Update、updateMulti、new Document。
|
||||
*/
|
||||
private void initializeDb() {
|
||||
MongoCollection<Document> resourceMessageCollection = this.mongoTemplate.getCollection("resourceMessage");
|
||||
if (resourceMessageCollection == null || resourceMessageCollection.countDocuments() == 0L) {
|
||||
@@ -147,7 +206,16 @@ public class DbInitialize {
|
||||
this.ensureIndex(MidmLog.class, false, "category", "loggedAt");
|
||||
}
|
||||
|
||||
private void ensureIndex(Class entityClass, boolean unique, String... keys) {
|
||||
/**
|
||||
* 处理ensureIndex。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);包含异常捕获与降级/回滚分支;包含 2 个条件分支、1 个循环;主要调用:new Document、new CompoundIndexDefinition。
|
||||
*
|
||||
* @param entityClass 参数 {@code entityClass}({@code Class<?>})
|
||||
* @param unique 参数 {@code unique}({@code boolean})
|
||||
* @param keys 参数 {@code keys}({@code String[]})
|
||||
*/
|
||||
private void ensureIndex(Class<?> entityClass, boolean unique, String... keys) {
|
||||
try {
|
||||
if (keys.length > 0) {
|
||||
Document indexDefinition = new Document();
|
||||
@@ -168,7 +236,15 @@ public class DbInitialize {
|
||||
|
||||
}
|
||||
|
||||
private void dropIndex(Class entityClass, String... keys) {
|
||||
/**
|
||||
* 处理dropIndex。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);包含 2 个条件分支、1 个循环;主要调用:dropIndex。
|
||||
*
|
||||
* @param entityClass 参数 {@code entityClass}({@code Class<?>})
|
||||
* @param keys 参数 {@code keys}({@code String[]})
|
||||
*/
|
||||
private void dropIndex(Class<?> entityClass, String... keys) {
|
||||
if (this.mongoTemplate.collectionExists(entityClass)) {
|
||||
MongoCollection<Document> collection = this.getCollection(entityClass);
|
||||
ListIndexesIterable<Document> indexes = collection.listIndexes();
|
||||
@@ -187,14 +263,16 @@ public class DbInitialize {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理ensure设备序列Index。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);包含 5 个条件分支、2 个循环;主要调用:dropIndex、new Document、new CompoundIndexDefinition。
|
||||
*/
|
||||
private void ensureDeviceSerialIndex() {
|
||||
MongoCollection<Document> collection = this.getCollection(Device.class);
|
||||
ListIndexesIterable<Document> indexes = collection.listIndexes();
|
||||
boolean isConfigured = false;
|
||||
MongoCursor indexDefinition = indexes.iterator();
|
||||
|
||||
while(indexDefinition.hasNext()) {
|
||||
Document index = (Document)indexDefinition.next();
|
||||
for(Document index : collection.listIndexes()) {
|
||||
Document keys = (Document)index.get("key", Document.class);
|
||||
if (keys.containsKey("profile.hardware_info.serial_no") && keys.containsKey("siteUuid")) {
|
||||
if (!index.containsKey("collation")) {
|
||||
@@ -214,11 +292,8 @@ public class DbInitialize {
|
||||
}
|
||||
|
||||
collection = this.getCollection(DeviceLicense.class);
|
||||
indexes = collection.listIndexes();
|
||||
indexDefinition = indexes.iterator();
|
||||
|
||||
while(indexDefinition.hasNext()) {
|
||||
Document index = (Document)indexDefinition.next();
|
||||
for(Document index : collection.listIndexes()) {
|
||||
Document keys = (Document)index.get("key", Document.class);
|
||||
if (keys.size() == 1 && keys.containsKey("plan")) {
|
||||
collection.dropIndex(index.getString("name"));
|
||||
@@ -227,6 +302,11 @@ public class DbInitialize {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Scheme。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);包含异常捕获与降级/回滚分支;包含 30 个条件分支、4 个循环;主要调用:new MongoNamespace、new Update、updateMulti、new Query、new Criteria、find。
|
||||
*/
|
||||
private void updateScheme() {
|
||||
if (this.mongoTemplate.collectionExists("siteReport")) {
|
||||
MongoCollection<Document> collection = this.mongoTemplate.getCollection("siteReport");
|
||||
@@ -438,15 +518,35 @@ public class DbInitialize {
|
||||
|
||||
}
|
||||
|
||||
private MongoCollection getCollection(Class entityClass) {
|
||||
/**
|
||||
* 获取Collection。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合)。
|
||||
*
|
||||
* @param entityClass 参数 {@code entityClass}({@code Class<?>})
|
||||
* @return 字段/派生属性 {@code collection} 的值
|
||||
*/
|
||||
private MongoCollection<Document> getCollection(Class<?> entityClass) {
|
||||
return this.mongoTemplate.getCollection(this.mongoTemplate.getCollectionName(entityClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 {@code dbScheme}。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);主要调用:findOne。
|
||||
* @return 数量/长度
|
||||
*/
|
||||
private long getDbScheme() {
|
||||
SystemSetting setting = (SystemSetting)this.mongoTemplate.findOne(Query.query(Criteria.where("_id").is(this.KEY_DB_SCHEME)), SystemSetting.class);
|
||||
return setting != null ? setting.getAsLong() : -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 {@code standalone}。
|
||||
*
|
||||
* 实现要点:通过 MongoTemplate 访问 MongoDB(查询/写入/聚合);主要调用:findOne。
|
||||
* @return 字段/派生属性 {@code standalone} 的值
|
||||
*/
|
||||
private boolean isStandalone() {
|
||||
HostLicense license = (HostLicense)this.mongoTemplate.findOne(Query.query(Criteria.where("isPrimary").is(true)), HostLicense.class);
|
||||
return license != null && license.isStandalone();
|
||||
|
||||
@@ -19,34 +19,113 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* 【Web 控制器】{@code GlobalController}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>接收 HTTP 请求、做参数绑定/鉴权,并把业务委托给 Service。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code excludeBindingPrefixes}(String[]):字段 excludeBindingPrefixes</li>
|
||||
* <li>{@code buildProperties}(BuildProperties):构建Properties</li>
|
||||
* <li>{@code localeService}(LocaleService):语言区域服务</li>
|
||||
* <li>{@code settingsService}(SettingsService):设置列表服务</li>
|
||||
* <li>{@code licenseService}(HostLicenseService):许可证服务</li>
|
||||
* <li>{@code siteService}(SiteService):站点服务</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code String[]、BuildProperties、LocaleService、SettingsService、HostLicenseService、SiteService}。
|
||||
*
|
||||
* 学习提示:先看类上的 @RequestMapping 路径,再沿 public 方法里的 service 调用链阅读。
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public final class GlobalController {
|
||||
/**
|
||||
* 字段 excludeBindingPrefixes。
|
||||
*/
|
||||
private static final String[] excludeBindingPrefixes = new String[]{"/api/", "/img/", "/profile/", "/client/", "/icon/", "/store/", "/logo/", "/device/", "/file/", "/must/", "/userfile/", "/barcode/", "/dpc/"};
|
||||
/**
|
||||
* 构建Properties;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private BuildProperties buildProperties;
|
||||
/**
|
||||
* 语言区域服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
protected LocaleService localeService;
|
||||
/**
|
||||
* 设置列表服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private SettingsService settingsService;
|
||||
/**
|
||||
* 许可证服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private HostLicenseService licenseService;
|
||||
/**
|
||||
* 站点服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
protected SiteService siteService;
|
||||
/**
|
||||
* 帮助消息服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private HelpMessageService helpMessageService;
|
||||
/**
|
||||
* servletContext路径;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("#{servletContext.contextPath}")}。
|
||||
*/
|
||||
@Value("#{servletContext.contextPath}")
|
||||
private String servletContextPath;
|
||||
|
||||
/**
|
||||
* 构建版本。
|
||||
* @return 字符串结果
|
||||
*/
|
||||
@ModelAttribute("buildVersion")
|
||||
public String buildVersion() {
|
||||
return this.buildProperties.getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建时间。
|
||||
* @return 字符串结果
|
||||
*/
|
||||
@ModelAttribute("buildTime")
|
||||
public String buildTime() {
|
||||
return Date.from(this.buildProperties.getTime()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理用户。
|
||||
*
|
||||
* 实现要点:包含 2 个条件分支、0 个循环。
|
||||
*
|
||||
* @param request HTTP 请求({@code HttpServletRequest})
|
||||
* @param authentication Spring Security 认证信息({@code Authentication})
|
||||
* @param language 参数 {@code language}({@code String})
|
||||
* @return 处理结果
|
||||
*/
|
||||
@ModelAttribute("user")
|
||||
public Object user(HttpServletRequest request, Authentication authentication, @RequestParam(required = false) String language) {
|
||||
if (this.bindModel(request)) {
|
||||
@@ -61,41 +140,78 @@ public final class GlobalController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设置列表。
|
||||
* @return 结果集合,可能为空
|
||||
*/
|
||||
@ModelAttribute("settings")
|
||||
public SettingsService settings() {
|
||||
return this.settingsService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理locales。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@ModelAttribute("locales")
|
||||
public LocaleService locales() {
|
||||
return this.localeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理帮助服务。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@ModelAttribute("helpService")
|
||||
public HelpMessageService helpService() {
|
||||
return this.helpMessageService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 {@code hostValid}。
|
||||
* @return 字段/派生属性 {@code hostValid} 的值
|
||||
*/
|
||||
@ModelAttribute("isHostValid")
|
||||
public boolean isHostValid() {
|
||||
return this.licenseService.isValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设备Limit。
|
||||
* @return 数量/长度
|
||||
*/
|
||||
@ModelAttribute("deviceLimit")
|
||||
public int deviceLimit() {
|
||||
return this.licenseService.getDeviceLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理站点服务。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@ModelAttribute("siteService")
|
||||
public SiteService siteService() {
|
||||
return this.siteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理context路径。
|
||||
* @return 字符串结果
|
||||
*/
|
||||
@ModelAttribute("contextPath")
|
||||
public String contextPath() {
|
||||
return this.servletContextPath + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理guest。
|
||||
*
|
||||
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new User。
|
||||
*
|
||||
* @param request HTTP 请求({@code HttpServletRequest})
|
||||
* @param localeTag 参数 {@code localeTag}({@code String})
|
||||
* @return 用户对象;未找到时返回 {@code null}
|
||||
*/
|
||||
private User guest(HttpServletRequest request, String localeTag) {
|
||||
User user = new User();
|
||||
user.setName("Guest");
|
||||
@@ -113,6 +229,14 @@ public final class GlobalController {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理bind模型。
|
||||
*
|
||||
* 实现要点:包含 1 个条件分支、1 个循环。
|
||||
*
|
||||
* @param request HTTP 请求({@code HttpServletRequest})
|
||||
* @return 条件成立返回 {@code true},否则返回 {@code false}
|
||||
*/
|
||||
public boolean bindModel(HttpServletRequest request) {
|
||||
String uri = request.getRequestURI();
|
||||
|
||||
|
||||
@@ -5,11 +5,41 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* 【Spring 配置类】{@code InterceptorConfig}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>向 Spring 容器装配 Bean、读取外部配置并控制初始化顺序。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code basicAuthInterceptor}(BasicAuthInterceptor):basicAuth拦截器</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code BasicAuthInterceptor}。
|
||||
*
|
||||
* 学习提示:先看 @Bean 方法与 @Value 配置项,再对照 application.properties 和启动日志。
|
||||
*/
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
/**
|
||||
* basicAuth拦截器;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private BasicAuthInterceptor basicAuthInterceptor;
|
||||
|
||||
/**
|
||||
* 添加Interceptors。
|
||||
*
|
||||
* 实现要点:包含异常捕获与降级/回滚分支。
|
||||
*
|
||||
* @param registry 参数 {@code registry}({@code InterceptorRegistry})
|
||||
*/
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(this.basicAuthInterceptor).addPathPatterns(new String[]{"/api/**"});
|
||||
}
|
||||
|
||||
@@ -13,8 +13,24 @@ import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
import org.thymeleaf.TemplateEngine;
|
||||
import org.thymeleaf.templateresolver.StringTemplateResolver;
|
||||
|
||||
/**
|
||||
* 【Spring 配置类】{@code LocaleConfig}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>向 Spring 容器装配 Bean、读取外部配置并控制初始化顺序。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 学习提示:先看 @Bean 方法与 @Value 配置项,再对照 application.properties 和启动日志。
|
||||
*/
|
||||
@Configuration
|
||||
public class LocaleConfig {
|
||||
/**
|
||||
* 处理string模板Engine。
|
||||
*
|
||||
* 实现要点:主要调用:new TemplateEngine、new StringTemplateResolver。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@Bean({"stringTemplateEngine"})
|
||||
public TemplateEngine stringTemplateEngine() {
|
||||
TemplateEngine templateEngine = new TemplateEngine();
|
||||
@@ -22,6 +38,12 @@ public class LocaleConfig {
|
||||
return templateEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理语言区域解析器。
|
||||
*
|
||||
* 实现要点:主要调用:new SessionLocaleResolver。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
|
||||
@@ -29,15 +51,51 @@ public class LocaleConfig {
|
||||
return localeResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理消息Source。
|
||||
*
|
||||
* 实现要点:主要调用:new ResourceMessageSource。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@Bean
|
||||
public MessageSource messageSource() {
|
||||
return new ResourceMessageSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* 【基础设施】{@code ResourceMessageSource}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>提供该包内的可复用能力。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code localeService}(LocaleService):语言区域服务</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code LocaleService}。
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
private class ResourceMessageSource extends AbstractMessageSource {
|
||||
/**
|
||||
* 语言区域服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private LocaleService localeService;
|
||||
|
||||
/**
|
||||
* 解析代码。
|
||||
*
|
||||
* @param code 状态码/业务码({@code String})
|
||||
* @param locale 参数 {@code locale}({@code Locale})
|
||||
* @return 处理结果
|
||||
*/
|
||||
protected MessageFormat resolveCode(String code, Locale locale) {
|
||||
String msg = this.localeService.getMessage(locale, code);
|
||||
return this.createMessageFormat(msg, locale);
|
||||
|
||||
@@ -15,8 +15,24 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* 【Spring 配置类】{@code PropertiesConfig}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>向 Spring 容器装配 Bean、读取外部配置并控制初始化顺序。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 学习提示:先看 @Bean 方法与 @Value 配置项,再对照 application.properties 和启动日志。
|
||||
*/
|
||||
@Configuration
|
||||
public class PropertiesConfig {
|
||||
/**
|
||||
* 处理properties。
|
||||
*
|
||||
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new PropertySourcesPlaceholderConfigurer、new ArrayList、new File、exists、new FileSystemResource。
|
||||
* @return 处理结果
|
||||
*/
|
||||
@Bean
|
||||
public static PropertySourcesPlaceholderConfigurer properties() {
|
||||
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
|
||||
@@ -31,6 +47,13 @@ public class PropertiesConfig {
|
||||
return ppc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化Properties。
|
||||
*
|
||||
* 实现要点:包含异常捕获与降级/回滚分支;主要调用:new Properties、new FileOutputStream、close。
|
||||
*
|
||||
* @param file 文件({@code File})
|
||||
*/
|
||||
private static void initProperties(File file) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("mongo.uri", "mongodb://username:password@127.0.0.1:27017/dbname");
|
||||
@@ -45,6 +68,12 @@ public class PropertiesConfig {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 {@code configFolder}。
|
||||
*
|
||||
* 实现要点:主要调用:new OsInfo。
|
||||
* @return 字段/派生属性 {@code configFolder} 的值
|
||||
*/
|
||||
private static File getConfigFolder() {
|
||||
return (new OsInfo()).getConfigFolder("MiDM");
|
||||
}
|
||||
|
||||
@@ -44,9 +44,19 @@ import org.springframework.web.filter.ForwardedHeaderFilter;
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
/**
|
||||
* 构建Properties;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private BuildProperties buildProperties;
|
||||
|
||||
/**
|
||||
* 判断是否Debug;从配置注入。
|
||||
*
|
||||
* 注解:{@code @Value("${spring.thymeleaf.cache: true}")}。
|
||||
*/
|
||||
@Value("${spring.thymeleaf.cache: true}")
|
||||
private boolean isDebug;
|
||||
|
||||
@@ -91,7 +101,7 @@ public class SecurityConfig {
|
||||
* 反向代理转发头过滤器(保障真实 IP 提取)
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean forwardedHeaderFilter() {
|
||||
public FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() {
|
||||
FilterRegistrationBean<ForwardedHeaderFilter> filterRegistrationBean = new FilterRegistrationBean();
|
||||
filterRegistrationBean.setFilter(new ForwardedHeaderFilter());
|
||||
filterRegistrationBean.setOrder(Integer.MIN_VALUE);
|
||||
|
||||
@@ -16,29 +16,107 @@ import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code StartupKeeper}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 核心字段(按声明顺序):
|
||||
* <ul>
|
||||
* <li>{@code hostLicenseService}(HostLicenseService):host许可证服务</li>
|
||||
* <li>{@code deviceService}(DeviceService):设备服务</li>
|
||||
* <li>{@code settingsService}(SettingsService):设置列表服务</li>
|
||||
* <li>{@code localeService}(LocaleService):语言区域服务</li>
|
||||
* <li>{@code userService}(UserService):用户服务</li>
|
||||
* <li>{@code helpMessageService}(HelpMessageService):帮助消息服务</li>
|
||||
* </ul>
|
||||
*
|
||||
* 协作对象:{@code HostLicenseService、DeviceService、SettingsService、LocaleService、UserService、HelpMessageService}。
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class StartupKeeper {
|
||||
/**
|
||||
* host许可证服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private HostLicenseService hostLicenseService;
|
||||
/**
|
||||
* 设备服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
/**
|
||||
* 设置列表服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private SettingsService settingsService;
|
||||
/**
|
||||
* 语言区域服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private LocaleService localeService;
|
||||
/**
|
||||
* 用户服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
/**
|
||||
* 帮助消息服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private HelpMessageService helpMessageService;
|
||||
/**
|
||||
* 新闻消息服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private NewsMessageService newsMessageService;
|
||||
/**
|
||||
* 报表服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private ReportService reportService;
|
||||
/**
|
||||
* 站点服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private SiteService siteService;
|
||||
/**
|
||||
* restore服务;Spring 自动注入的依赖。
|
||||
*
|
||||
* 注解:{@code @Autowired}。
|
||||
*/
|
||||
@Autowired
|
||||
private RestoreService restoreService;
|
||||
|
||||
/**
|
||||
* 处理contextRefreshed事件。
|
||||
*
|
||||
* 实现要点:包含 2 个条件分支、0 个循环。
|
||||
*/
|
||||
@EventListener({ContextRefreshedEvent.class})
|
||||
private void contextRefreshedEvent() {
|
||||
this.setDefaultTimeZone();
|
||||
@@ -63,6 +141,9 @@ public class StartupKeeper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Default时间Zone。
|
||||
*/
|
||||
private void setDefaultTimeZone() {
|
||||
TimeZone defaultTimeZone = TimeZone.getTimeZone("UTC");
|
||||
System.setProperty("user.timezone", defaultTimeZone.getID());
|
||||
|
||||
@@ -6,8 +6,26 @@ import org.joda.time.DateTime;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code DateConverter}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class DateConverter implements Converter {
|
||||
public class DateConverter implements Converter<String, Date> {
|
||||
/**
|
||||
* 处理转换。
|
||||
*
|
||||
* 实现要点:包含异常捕获与降级/回滚分支;包含 2 个条件分支、0 个循环;主要调用:new DateTime、new Date、parse。
|
||||
*
|
||||
* @param source 参数 {@code source}({@code String})
|
||||
* @return 处理结果
|
||||
*/
|
||||
public Date convert(String source) {
|
||||
DateTime date = null;
|
||||
|
||||
|
||||
@@ -5,8 +5,24 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code DirectionConverter}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class DirectionConverter implements Converter {
|
||||
public class DirectionConverter implements Converter<String, Sort.Direction> {
|
||||
/**
|
||||
* 处理转换。
|
||||
*
|
||||
* @param source 参数 {@code source}({@code String})
|
||||
* @return 处理结果
|
||||
*/
|
||||
public Sort.Direction convert(String source) {
|
||||
return Direction.valueOf(source.toUpperCase());
|
||||
}
|
||||
|
||||
@@ -7,8 +7,27 @@ import java.nio.charset.Charset;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code JsonElementConverter}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class JsonElementConverter implements Converter<String, JsonElement> {
|
||||
/**
|
||||
* 处理转换。
|
||||
*
|
||||
* 实现要点:包含异常捕获与降级/回滚分支;主要调用:new RuntimeException。
|
||||
*
|
||||
* @param source 参数 {@code source}({@code String})
|
||||
* @return 处理结果
|
||||
* @throws RuntimeException 当 RuntimeException 条件不满足或底层调用失败时抛出。
|
||||
*/
|
||||
public JsonElement convert(String source) {
|
||||
try {
|
||||
source = URLDecoder.decode(source, Charset.defaultCharset());
|
||||
|
||||
@@ -7,8 +7,27 @@ import java.nio.charset.Charset;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code JsonObjectConverter}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class JsonObjectConverter implements Converter<String, JsonObject> {
|
||||
/**
|
||||
* 处理转换。
|
||||
*
|
||||
* 实现要点:包含异常捕获与降级/回滚分支;主要调用:new RuntimeException。
|
||||
*
|
||||
* @param source 参数 {@code source}({@code String})
|
||||
* @return 处理结果
|
||||
* @throws RuntimeException 当 RuntimeException 条件不满足或底层调用失败时抛出。
|
||||
*/
|
||||
public JsonObject convert(String source) {
|
||||
try {
|
||||
source = URLDecoder.decode(source, Charset.defaultCharset());
|
||||
|
||||
@@ -4,8 +4,26 @@ import com.mitac.cell.internet.http.UserAgent;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 【Spring 组件】{@code UserAgentConverter}
|
||||
*
|
||||
* 类职责:
|
||||
* <ul>
|
||||
* <li>作为 Spring 组件参与依赖注入或生命周期回调。</li>
|
||||
* </ul>
|
||||
*
|
||||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||||
*/
|
||||
@Component
|
||||
public class UserAgentConverter implements Converter {
|
||||
public class UserAgentConverter implements Converter<String, UserAgent> {
|
||||
/**
|
||||
* 处理转换。
|
||||
*
|
||||
* 实现要点:主要调用:new UserAgent。
|
||||
*
|
||||
* @param source 参数 {@code source}({@code String})
|
||||
* @return 处理结果
|
||||
*/
|
||||
public UserAgent convert(String source) {
|
||||
return new UserAgent(source);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Spring MVC 参数类型转换器:把请求中的字符串转换为日期、方向、JSON、User-Agent 等对象。
|
||||
*
|
||||
* <p>本包主要类型:
|
||||
* <ul>
|
||||
* <li>{@link DateConverter}</li>
|
||||
* <li>{@link DirectionConverter}</li>
|
||||
* <li>{@link JsonElementConverter}</li>
|
||||
* <li>{@link JsonObjectConverter}</li>
|
||||
* <li>{@link UserAgentConverter}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
|
||||
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
|
||||
*/
|
||||
package com.midm.app.converter;
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 应用启动与基础设施配置包:Mongo、Security、WebSocket、Locale、启动初始化等。
|
||||
*
|
||||
* <p>本包主要类型:
|
||||
* <ul>
|
||||
* <li>{@link AppConfig}</li>
|
||||
* <li>{@link AsyncConfig}</li>
|
||||
* <li>{@link BasicAuthInterceptor}</li>
|
||||
* <li>{@link DbConfig}</li>
|
||||
* <li>{@link DbInitialize}</li>
|
||||
* <li>{@link GlobalController}</li>
|
||||
* <li>{@link InterceptorConfig}</li>
|
||||
* <li>{@link LocaleConfig}</li>
|
||||
* <li>{@link PropertiesConfig}</li>
|
||||
* <li>{@link SecurityConfig}</li>
|
||||
* <li>{@link StartupKeeper}</li>
|
||||
* <li>{@link WebSocketConfig}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
|
||||
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
|
||||
*/
|
||||
package com.midm.app;
|
||||
Reference in new issue
Block a user