feat(service): 实现国际化支持并优化Service层
重构文件类型相关Service以支持国际化查询 添加findOneByLang辅助方法统一查询逻辑 实现StringConverter支持UI控件显示 优化缓存配置和查询性能 新增UnitStringConverter和CustomerCatalogStringConverter 完善文档和测试用例
This commit is contained in:
@@ -7,85 +7,197 @@ import java.util.function.Consumer;
|
||||
|
||||
import com.ecep.contract.constant.ServiceConstant;
|
||||
|
||||
/**
|
||||
* 参数工具类,用于构建查询条件参数
|
||||
* 提供了一系列静态方法和Builder模式,用于创建各种查询条件
|
||||
*/
|
||||
public class ParamUtils {
|
||||
/**
|
||||
* 创建日期范围查询参数
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param begin 开始日期
|
||||
* @param end 结束日期
|
||||
* @return 包含日期范围的查询参数Map
|
||||
*/
|
||||
public static Map<String, Object> between(String key, LocalDate begin, LocalDate end) {
|
||||
return Map.of(key, Map.of(
|
||||
"begin", begin,
|
||||
"end", end));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建等于条件查询参数
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param value 查询值
|
||||
* @return 包含等于条件的查询参数Map
|
||||
*/
|
||||
public static Map<String, Object> equal(String key, Object value) {
|
||||
return Map.of(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建字符串模糊查询参数
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param value 模糊查询的字符串值
|
||||
* @return 包含模糊查询条件的查询参数Map
|
||||
*/
|
||||
public static Map<String, Object> like(String key, String value) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(key, "%" + value + "%");
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建日期模糊查询参数
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param value 模糊查询的日期值
|
||||
* @return 包含日期模糊查询条件的查询参数Map
|
||||
*/
|
||||
public static Map<String, Object> like(String key, LocalDate value) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(key, "%" + value + "%");
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建非空条件查询参数
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @return 包含非空条件的查询参数Map
|
||||
*/
|
||||
public static Map<String, Object> isNotNull(String key) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(key, Map.of("isNotNull", true));
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建小于条件的日期查询参数
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param value 比较的日期值
|
||||
* @return 包含小于条件的查询参数Map
|
||||
*/
|
||||
public static Map<String, Object> lessThan(String key, LocalDate value) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(key, Map.of("lessThan", value));
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建参数构建器实例
|
||||
*
|
||||
* @return Builder实例,用于链式构建复杂查询条件
|
||||
*/
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数构建器类,使用建造者模式构建复杂查询条件
|
||||
* 支持链式调用,提高代码可读性
|
||||
*/
|
||||
public static class Builder {
|
||||
// 存储构建的查询参数
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 私有构造方法,防止外部直接实例化
|
||||
* 应通过ParamUtils.builder()方法获取实例
|
||||
*/
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加非空条件到构建器
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder isNotNull(String key) {
|
||||
params.put(key, Map.of("isNotNull", true));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加小于条件到构建器(针对日期类型)
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param value 比较的日期值
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder lessThan(String key, LocalDate value) {
|
||||
params.put(key, Map.of("lessThan", value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加大于条件到构建器(针对日期类型)
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param value 比较的日期值
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder greaterThan(String key, LocalDate value) {
|
||||
params.put(key, Map.of("greaterThan", value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加等于条件到构建器
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param value 查询值
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder equals(String key, Object value) {
|
||||
params.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加日期范围条件到构建器
|
||||
*
|
||||
* @param key 查询字段名
|
||||
* @param begin 开始日期
|
||||
* @param end 结束日期
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder between(String key, LocalDate begin, LocalDate end) {
|
||||
params.put(key, Map.of("begin", begin, "end", end));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加全文搜索条件到构建器
|
||||
*
|
||||
* @param searchText 搜索文本
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder search(String searchText) {
|
||||
params.put(ServiceConstant.KEY_SEARCH_TEXT, searchText);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建并返回查询参数Map
|
||||
*
|
||||
* @return 包含所有添加条件的查询参数Map
|
||||
*/
|
||||
public Map<String, Object> build() {
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加AND逻辑条件组到构建器
|
||||
*
|
||||
* @param consumer Builder消费者,用于构建子条件
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder and(Consumer<Builder> consumer) {
|
||||
Builder builder = new Builder();
|
||||
consumer.accept(builder);
|
||||
@@ -93,6 +205,12 @@ public class ParamUtils {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加OR逻辑条件组到构建器
|
||||
*
|
||||
* @param consumer Builder消费者,用于构建子条件
|
||||
* @return 当前Builder实例,支持链式调用
|
||||
*/
|
||||
public Builder or(Consumer<Builder> consumer) {
|
||||
Builder builder = new Builder();
|
||||
consumer.accept(builder);
|
||||
|
||||
Reference in New Issue
Block a user