diff --git a/boot/platform/src/main/java/com/plate/boot/commons/base/BaseEntity.java b/boot/platform/src/main/java/com/plate/boot/commons/base/BaseEntity.java index 9e47a419..4dff77e0 100644 --- a/boot/platform/src/main/java/com/plate/boot/commons/base/BaseEntity.java +++ b/boot/platform/src/main/java/com/plate/boot/commons/base/BaseEntity.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.plate.boot.commons.utils.ContextUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; +import com.plate.boot.commons.utils.query.QueryHelper; import org.springframework.data.domain.Persistable; import org.springframework.data.relational.core.query.Criteria; import org.springframework.util.ObjectUtils; @@ -60,6 +60,6 @@ default boolean isNew() { */ default Criteria criteria(Collection skipKeys) { // 调用CriteriaUtils的静态方法build来创建Criteria对象,并传入当前对象和要忽略的属性键集合。 - return CriteriaUtils.build(this, skipKeys); + return QueryHelper.build(this, skipKeys); } } \ No newline at end of file diff --git a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/ParamSql.java b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryFragment.java similarity index 81% rename from boot/platform/src/main/java/com/plate/boot/commons/utils/query/ParamSql.java rename to boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryFragment.java index a740e467..b0047d19 100644 --- a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/ParamSql.java +++ b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryFragment.java @@ -15,21 +15,21 @@ * @param params A {@link Map} mapping parameter names to their respective values, * which are intended to replace placeholders in the SQL query. */ -public record ParamSql(StringJoiner sql, Map params) implements Serializable { +public record QueryFragment(StringJoiner sql, Map params) implements Serializable { /** - * Creates a new instance of {@link ParamSql} with the provided conditional SQL + * Creates a new instance of {@link QueryFragment} with the provided conditional SQL * fragment and parameters map. * * @param sql A {@link StringJoiner} object containing the dynamically * constructed WHERE clause segments of a SQL query, concatenated by 'and'. * @param params A {@link Map} of parameter names to values, which will be * substituted for placeholders within the SQL query to prevent SQL injection. - * @return A new {@link ParamSql} instance encapsulating the given SQL fragment + * @return A new {@link QueryFragment} instance encapsulating the given SQL fragment * and parameters map, ready for use in preparing a parameterized SQL statement. */ - public static ParamSql of(StringJoiner sql, Map params) { - return new ParamSql(sql, params); + public static QueryFragment of(StringJoiner sql, Map params) { + return new QueryFragment(sql, params); } /** diff --git a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/CriteriaUtils.java b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryHelper.java similarity index 92% rename from boot/platform/src/main/java/com/plate/boot/commons/utils/query/CriteriaUtils.java rename to boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryHelper.java index 993d3ddc..66b6c545 100644 --- a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/CriteriaUtils.java +++ b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryHelper.java @@ -18,7 +18,7 @@ * This is particularly useful for dynamically constructing SQL queries * with bind variables in a structured manner. */ -public final class CriteriaUtils { +public final class QueryHelper { public static final Set SKIP_CRITERIA_KEYS = Set.of("extend", "createdTime", "updatedTime"); @@ -64,7 +64,7 @@ public static String applySort(Sort sort, String prefix) { if (sort == null || sort.isUnsorted()) { return " order by id desc "; } - sort = QueryJson.sortJson(sort, prefix); + sort = QueryJsonHelper.transformSortForJson(sort, prefix); StringJoiner sortSql = new StringJoiner(", "); for (Sort.Order order : sort) { String sortedPropertyName = order.getProperty(); @@ -97,15 +97,15 @@ public static String applySort(Sort sort, String prefix) { * (joined by 'and') and a map of parameters for prepared statement binding. */ @SuppressWarnings("unchecked") - public static ParamSql buildParamSql(Object object, Collection skipKeys, String prefix) { + public static QueryFragment buildParamSql(Object object, Collection skipKeys, String prefix) { Map objectMap = BeanUtils.beanToMap(object, false, true); if (ObjectUtils.isEmpty(objectMap)) { - return ParamSql.of(new StringJoiner(" and "), Maps.newHashMap()); + return QueryFragment.of(new StringJoiner(" and "), Maps.newHashMap()); } - ParamSql jsonParamSql = QueryJson.queryJson((Map) objectMap.get("query"), prefix); - Map params = jsonParamSql.params(); - StringJoiner sql = jsonParamSql.sql(); + QueryFragment jsonQueryFragment = QueryJsonHelper.queryJson((Map) objectMap.get("query"), prefix); + Map params = jsonQueryFragment.params(); + StringJoiner sql = jsonQueryFragment.sql(); String securityCodeKey = "securityCode"; if (!skipKeys.contains(securityCodeKey) && !ObjectUtils.isEmpty(objectMap.get(securityCodeKey))) { String key = "tenant_code"; @@ -124,10 +124,10 @@ public static ParamSql buildParamSql(Object object, Collection skipKeys, } objectMap = Maps.filterKeys(objectMap, key -> !removeKeys.contains(key)); - ParamSql entityParamSql = buildParamSql(objectMap, prefix); - params.putAll(entityParamSql.params()); - sql.merge(entityParamSql.sql()); - return ParamSql.of(sql, params); + QueryFragment entityQueryFragment = buildParamSql(objectMap, prefix); + params.putAll(entityQueryFragment.params()); + sql.merge(entityQueryFragment.sql()); + return QueryFragment.of(sql, params); } /** @@ -147,7 +147,7 @@ public static ParamSql buildParamSql(Object object, Collection skipKeys, * statement binding, where keys correspond to named parameters * and values are the user-provided filter values. */ - public static ParamSql buildParamSql(Map objectMap, String prefix) { + public static QueryFragment buildParamSql(Map objectMap, String prefix) { StringJoiner whereSql = new StringJoiner(" and "); for (Map.Entry entry : objectMap.entrySet()) { String column = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey()); @@ -166,7 +166,7 @@ public static ParamSql buildParamSql(Map objectMap, String prefi whereSql.add(column + " = " + paramName); } } - return ParamSql.of(whereSql, objectMap); + return QueryFragment.of(whereSql, objectMap); } /** diff --git a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryJson.java b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryJsonHelper.java similarity index 76% rename from boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryJson.java rename to boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryJsonHelper.java index e37c2be6..b59de555 100644 --- a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryJson.java +++ b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryJsonHelper.java @@ -10,46 +10,48 @@ import java.util.*; /** - * Searches for a keyword within the provided key and returns the keyword along with its SQL equivalent. - * If no keyword match is found, returns null. + * Utility class providing helper methods to facilitate querying and sorting JSON data within SQL statements. + * This class maps operation keywords to their SQL equivalents and offers functionality to translate + * query parameters and sorting instructions into SQL-compatible formats, especially handy when working + * with JSON data stored in relational databases. */ -public class QueryJson { +public final class QueryJsonHelper { - private final static Map KEYWORDS = Maps.newHashMap(); + private final static Map SQL_OPERATION_MAPPING = Maps.newHashMap(); static { - KEYWORDS.put("EQ", "="); - KEYWORDS.put("Equal", "="); - KEYWORDS.put("After", ">"); - KEYWORDS.put("GreaterThanEqual", ">="); - KEYWORDS.put("GTE", ">="); - KEYWORDS.put("GreaterThan", ">"); - KEYWORDS.put("GT", ">"); - KEYWORDS.put("Before", "<"); - KEYWORDS.put("LessThanEqual", "<="); - KEYWORDS.put("LTE", "<="); - KEYWORDS.put("LessThan", "<"); - KEYWORDS.put("LT", "<"); - KEYWORDS.put("Between", "between"); - KEYWORDS.put("NotBetween", "not between"); - KEYWORDS.put("NotIn", "not in"); - KEYWORDS.put("In", "in"); - KEYWORDS.put("IsNotNull", "is not null"); - KEYWORDS.put("NotNull", "is not null"); - KEYWORDS.put("IsNull", "is null"); - KEYWORDS.put("Null", "is null"); - KEYWORDS.put("NotLike", "not like"); - KEYWORDS.put("Like", "like"); - KEYWORDS.put("StartingWith", "like"); - KEYWORDS.put("EndingWith", "like"); - KEYWORDS.put("IsNotLike", "not like"); - KEYWORDS.put("Containing", "like"); - KEYWORDS.put("NotContaining", "not like"); - KEYWORDS.put("Not", "!="); - KEYWORDS.put("IsTrue", "is true"); - KEYWORDS.put("True", "is true"); - KEYWORDS.put("IsFalse", "is false"); - KEYWORDS.put("False", "is false"); + SQL_OPERATION_MAPPING.put("EQ", "="); + SQL_OPERATION_MAPPING.put("Equal", "="); + SQL_OPERATION_MAPPING.put("After", ">"); + SQL_OPERATION_MAPPING.put("GreaterThanEqual", ">="); + SQL_OPERATION_MAPPING.put("GTE", ">="); + SQL_OPERATION_MAPPING.put("GreaterThan", ">"); + SQL_OPERATION_MAPPING.put("GT", ">"); + SQL_OPERATION_MAPPING.put("Before", "<"); + SQL_OPERATION_MAPPING.put("LessThanEqual", "<="); + SQL_OPERATION_MAPPING.put("LTE", "<="); + SQL_OPERATION_MAPPING.put("LessThan", "<"); + SQL_OPERATION_MAPPING.put("LT", "<"); + SQL_OPERATION_MAPPING.put("Between", "between"); + SQL_OPERATION_MAPPING.put("NotBetween", "not between"); + SQL_OPERATION_MAPPING.put("NotIn", "not in"); + SQL_OPERATION_MAPPING.put("In", "in"); + SQL_OPERATION_MAPPING.put("IsNotNull", "is not null"); + SQL_OPERATION_MAPPING.put("NotNull", "is not null"); + SQL_OPERATION_MAPPING.put("IsNull", "is null"); + SQL_OPERATION_MAPPING.put("Null", "is null"); + SQL_OPERATION_MAPPING.put("NotLike", "not like"); + SQL_OPERATION_MAPPING.put("Like", "like"); + SQL_OPERATION_MAPPING.put("StartingWith", "like"); + SQL_OPERATION_MAPPING.put("EndingWith", "like"); + SQL_OPERATION_MAPPING.put("IsNotLike", "not like"); + SQL_OPERATION_MAPPING.put("Containing", "like"); + SQL_OPERATION_MAPPING.put("NotContaining", "not like"); + SQL_OPERATION_MAPPING.put("Not", "!="); + SQL_OPERATION_MAPPING.put("IsTrue", "is true"); + SQL_OPERATION_MAPPING.put("True", "is true"); + SQL_OPERATION_MAPPING.put("IsFalse", "is false"); + SQL_OPERATION_MAPPING.put("False", "is false"); } /** @@ -65,7 +67,7 @@ public class QueryJson { * @param prefix An optional prefix to prepend to each sorting property, useful for aliasing in SQL queries. * @return A new Sort object with transformed sorting properties, ready for sorting queries that involve JSON columns. */ - public static Sort sortJson(Sort sort, String prefix) { + public static Sort transformSortForJson(Sort sort, String prefix) { if (sort == null || sort.isEmpty()) { return Sort.unsorted(); } @@ -99,15 +101,15 @@ public static Sort sortJson(Sort sort, String prefix) { * @param params A map where each key represents a JSON path to a value that should be used in query conditions. * The value associated with each key is the target value for comparison or range (for Between/NotBetween). * @param prefix An optional prefix to prepend to column names, useful when querying nested or aliased tables/views. - * @return A {@link ParamSql} object containing a {@link StringJoiner} with concatenated WHERE clause conditions + * @return A {@link QueryFragment} object containing a {@link StringJoiner} with concatenated WHERE clause conditions * and a map of bind parameters to be used in a prepared statement. */ - public static ParamSql queryJson(Map params, String prefix) { + public static QueryFragment queryJson(Map params, String prefix) { Map bindParams = Maps.newHashMap(); StringJoiner whereSql = new StringJoiner(" and "); if (ObjectUtils.isEmpty(params)) { - return ParamSql.of(whereSql, bindParams); + return QueryFragment.of(whereSql, bindParams); } for (Map.Entry entry : params.entrySet()) { @@ -122,7 +124,7 @@ public static ParamSql queryJson(Map params, String prefix) { bindParams.put(exps.getValue().getFirst(), entry.getValue()); } } - return ParamSql.of(whereSql, bindParams); + return QueryFragment.of(whereSql, bindParams); } /** @@ -209,7 +211,7 @@ private static StringBuilder appendIntermediateKeys(String[] joinKeys) { * or null if no match is found. */ private static Map.Entry findKeyWord(String inputStr) { - return KEYWORDS.entrySet().stream() + return SQL_OPERATION_MAPPING.entrySet().stream() .filter(entry -> StringUtils.endsWithIgnoreCase(inputStr, entry.getKey())) .max((entry1, entry2) -> { int entry1Length = entry1.getKey().length(); diff --git a/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggerRequest.java b/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggerRequest.java index df36c490..ff56e4c7 100644 --- a/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggerRequest.java +++ b/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggerRequest.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -42,8 +42,9 @@ public static LoggerRequest of(String tenantCode, String operator, String prefix public Logger toLogger() { return BeanUtils.copyProperties(this, Logger.class); } - public ParamSql bindParamSql() { - return CriteriaUtils.buildParamSql(this, List.of(), null); + + public QueryFragment bindParamSql() { + return QueryHelper.buildParamSql(this, List.of(), null); } public Criteria toCriteria() { diff --git a/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggersService.java b/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggersService.java index 6d3a034e..9bf3ffb9 100644 --- a/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggersService.java +++ b/boot/platform/src/main/java/com/plate/boot/relational/logger/LoggersService.java @@ -2,7 +2,7 @@ import com.plate.boot.commons.base.AbstractDatabase; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; import org.springframework.data.domain.Page; @@ -28,7 +28,7 @@ public class LoggersService extends AbstractDatabase { public Flux search(LoggerRequest request, Pageable pageable) { String querySql = "select * from se_loggers"; var paramSql = request.bindParamSql(); - var query = this.databaseClient.sql(() -> querySql + paramSql.whereSql() + CriteriaUtils.applyPage(pageable)) + var query = this.databaseClient.sql(() -> querySql + paramSql.whereSql() + QueryHelper.applyPage(pageable)) .bindValues(paramSql.params()) .map((row, rowMetadata) -> r2dbcConverter.read(Logger.class, row, rowMetadata)).all(); return this.queryWithCache(BeanUtils.cacheKey(request, pageable), query); diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupRequest.java b/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupRequest.java index 66510f8b..78102f0f 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupRequest.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupRequest.java @@ -1,8 +1,8 @@ package com.plate.boot.security.core.group; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -31,7 +31,7 @@ public Group toGroup() { return BeanUtils.copyProperties(this, Group.class); } - public ParamSql bindParamSql() { - return CriteriaUtils.buildParamSql(this, List.of(), null); + public QueryFragment bindParamSql() { + return QueryHelper.buildParamSql(this, List.of(), null); } } \ No newline at end of file diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupsService.java b/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupsService.java index 75801870..c87f5ce4 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupsService.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/group/GroupsService.java @@ -2,8 +2,8 @@ import com.plate.boot.commons.base.AbstractDatabase; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -22,16 +22,16 @@ public class GroupsService extends AbstractDatabase { private final GroupsRepository groupsRepository; public Flux search(GroupRequest request, Pageable pageable) { - ParamSql paramSql = request.bindParamSql(); - String query = "select * from se_groups" + paramSql.whereSql() + CriteriaUtils.applyPage(pageable); - return super.queryWithCache(BeanUtils.cacheKey(request, pageable), query, paramSql.params(), Group.class); + QueryFragment QueryFragment = request.bindParamSql(); + String query = "select * from se_groups" + QueryFragment.whereSql() + QueryHelper.applyPage(pageable); + return super.queryWithCache(BeanUtils.cacheKey(request, pageable), query, QueryFragment.params(), Group.class); } public Mono> page(GroupRequest request, Pageable pageable) { var searchMono = this.search(request, pageable).collectList(); - ParamSql paramSql = request.bindParamSql(); - String query = "select count(*) from se_groups" + paramSql.whereSql(); - var countMono = this.countWithCache(BeanUtils.cacheKey(request), query, paramSql.params()); + QueryFragment QueryFragment = request.bindParamSql(); + String query = "select count(*) from se_groups" + QueryFragment.whereSql(); + var countMono = this.countWithCache(BeanUtils.cacheKey(request), query, QueryFragment.params()); return searchMono.zipWith(countMono) .map(tuple2 -> new PageImpl<>(tuple2.getT1(), pageable, tuple2.getT2())); diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMemberRequest.java b/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMemberRequest.java index 48f8f47b..6f8d9b82 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMemberRequest.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMemberRequest.java @@ -1,8 +1,8 @@ package com.plate.boot.security.core.group.member; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -35,11 +35,11 @@ public Criteria toCriteria() { return criteria(Set.of("users", "username")); } - public ParamSql toParamSql() { - ParamSql paramSql = CriteriaUtils.buildParamSql(this, List.of("users", "username"), "a"); + public QueryFragment toParamSql() { + QueryFragment QueryFragment = QueryHelper.buildParamSql(this, List.of("users", "username"), "a"); - StringJoiner criteria = paramSql.sql(); - Map params = paramSql.params(); + StringJoiner criteria = QueryFragment.sql(); + Map params = QueryFragment.params(); if (!ObjectUtils.isEmpty(this.getUsers())) { criteria.add("a.user_code in :users"); @@ -51,7 +51,7 @@ public ParamSql toParamSql() { params.put("username", this.getUsername()); } - return ParamSql.of(criteria, params); + return QueryFragment.of(criteria, params); } } \ No newline at end of file diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMembersService.java b/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMembersService.java index 1cdd6715..741d8a91 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMembersService.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/group/member/GroupMembersService.java @@ -2,8 +2,8 @@ import com.plate.boot.commons.base.AbstractDatabase; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -34,17 +34,17 @@ select count(*) from se_group_members a private final GroupMembersRepository memberRepository; public Flux search(GroupMemberRequest request, Pageable pageable) { - ParamSql paramSql = request.toParamSql(); - String query = QUERY_SQL + paramSql.whereSql() + CriteriaUtils.applyPage(pageable); + QueryFragment QueryFragment = request.toParamSql(); + String query = QUERY_SQL + QueryFragment.whereSql() + QueryHelper.applyPage(pageable); return super.queryWithCache(BeanUtils.cacheKey(request, pageable), query, - paramSql.params(), GroupMemberResponse.class); + QueryFragment.params(), GroupMemberResponse.class); } public Mono> page(GroupMemberRequest request, Pageable pageable) { var searchMono = this.search(request, pageable).collectList(); - ParamSql paramSql = request.toParamSql(); - String query = COUNT_SQL + paramSql.whereSql(); - var countMono = this.countWithCache(BeanUtils.cacheKey(request), query, paramSql.params()); + QueryFragment QueryFragment = request.toParamSql(); + String query = COUNT_SQL + QueryFragment.whereSql(); + var countMono = this.countWithCache(BeanUtils.cacheKey(request), query, QueryFragment.params()); return searchMono.zipWith(countMono) .map(tuple2 -> new PageImpl<>(tuple2.getT1(), pageable, tuple2.getT2())); } diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantRequest.java b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantRequest.java index fbaf37d9..dc6bdf77 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantRequest.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantRequest.java @@ -1,8 +1,8 @@ package com.plate.boot.security.core.tenant; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -24,7 +24,7 @@ public Tenant toTenant() { return BeanUtils.copyProperties(this, Tenant.class); } - public ParamSql bindParamSql() { - return CriteriaUtils.buildParamSql(this, List.of(), null); + public QueryFragment bindParamSql() { + return QueryHelper.buildParamSql(this, List.of(), null); } } \ No newline at end of file diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantsService.java b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantsService.java index 8e7ebc6a..5e65399b 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantsService.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/TenantsService.java @@ -2,8 +2,8 @@ import com.plate.boot.commons.base.AbstractDatabase; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import com.plate.boot.security.core.tenant.member.TenantMembersRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -25,16 +25,16 @@ public class TenantsService extends AbstractDatabase { private final TenantMembersRepository membersRepository; public Flux search(TenantRequest request, Pageable pageable) { - ParamSql paramSql = request.bindParamSql(); - String query = "select * from se_tenants" + paramSql.whereSql() + CriteriaUtils.applyPage(pageable); - return super.queryWithCache(BeanUtils.cacheKey(request, pageable), query, paramSql.params(), Tenant.class); + QueryFragment QueryFragment = request.bindParamSql(); + String query = "select * from se_tenants" + QueryFragment.whereSql() + QueryHelper.applyPage(pageable); + return super.queryWithCache(BeanUtils.cacheKey(request, pageable), query, QueryFragment.params(), Tenant.class); } public Mono> page(TenantRequest request, Pageable pageable) { var searchMono = this.search(request, pageable).collectList(); - ParamSql paramSql = request.bindParamSql(); - String query = "select count(*) from se_tenants" + paramSql.whereSql() + CriteriaUtils.applyPage(pageable); - var countMono = this.countWithCache(BeanUtils.cacheKey(request), query, paramSql.params()); + QueryFragment QueryFragment = request.bindParamSql(); + String query = "select count(*) from se_tenants" + QueryFragment.whereSql() + QueryHelper.applyPage(pageable); + var countMono = this.countWithCache(BeanUtils.cacheKey(request), query, QueryFragment.params()); return searchMono.zipWith(countMono) .map(tuple2 -> new PageImpl<>(tuple2.getT1(), pageable, tuple2.getT2())); diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMemberRequest.java b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMemberRequest.java index 994fe5a4..3a8ed634 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMemberRequest.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMemberRequest.java @@ -1,8 +1,8 @@ package com.plate.boot.security.core.tenant.member; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -42,12 +42,12 @@ public Criteria toCriteria() { return criteria(Set.of("securityCode", "users", "username")); } - public ParamSql toParamSql() { - ParamSql paramSql = CriteriaUtils + public QueryFragment toParamSql() { + QueryFragment QueryFragment = QueryHelper .buildParamSql(this, List.of("users", "securityCode", "username"), "a"); - StringJoiner criteria = paramSql.sql(); - Map params = paramSql.params(); + StringJoiner criteria = QueryFragment.sql(); + Map params = QueryFragment.params(); if (!ObjectUtils.isEmpty(this.getUsers())) { criteria.add("a.user_code in :users"); params.put("users", this.getUsers()); @@ -63,6 +63,6 @@ public ParamSql toParamSql() { params.put("username", this.getUsername()); } - return ParamSql.of(criteria, params); + return QueryFragment.of(criteria, params); } } \ No newline at end of file diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMembersService.java b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMembersService.java index e188083e..56604ec7 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMembersService.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/tenant/member/TenantMembersService.java @@ -2,8 +2,8 @@ import com.plate.boot.commons.base.AbstractDatabase; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -37,17 +37,17 @@ select count(*) from se_tenant_members a private final TenantMembersRepository tenantMembersRepository; public Flux search(TenantMemberRequest request, Pageable pageable) { - ParamSql paramSql = request.toParamSql(); - String query = QUERY_SQL + paramSql.whereSql() + CriteriaUtils.applyPage(pageable, "a"); + QueryFragment QueryFragment = request.toParamSql(); + String query = QUERY_SQL + QueryFragment.whereSql() + QueryHelper.applyPage(pageable, "a"); return super.queryWithCache(BeanUtils.cacheKey(request, pageable), query, - paramSql.params(), TenantMemberResponse.class); + QueryFragment.params(), TenantMemberResponse.class); } public Mono> page(TenantMemberRequest request, Pageable pageable) { var searchMono = this.search(request, pageable).collectList(); - ParamSql paramSql = request.toParamSql(); - String query = COUNT_SQL + paramSql.whereSql(); - Mono countMono = this.countWithCache(BeanUtils.cacheKey(request), query, paramSql.params()); + QueryFragment QueryFragment = request.toParamSql(); + String query = COUNT_SQL + QueryFragment.whereSql(); + Mono countMono = this.countWithCache(BeanUtils.cacheKey(request), query, QueryFragment.params()); return searchMono.zipWith(countMono) .map(tuple2 -> new PageImpl<>(tuple2.getT1(), pageable, tuple2.getT2())); } diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/user/UserRequest.java b/boot/platform/src/main/java/com/plate/boot/security/core/user/UserRequest.java index e3270c8d..fdc719d9 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/user/UserRequest.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/user/UserRequest.java @@ -1,8 +1,8 @@ package com.plate.boot.security.core.user; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -31,7 +31,7 @@ public User toUser() { return BeanUtils.copyProperties(this, User.class); } - public ParamSql bindParamSql() { - return CriteriaUtils.buildParamSql(this, List.of(), null); + public QueryFragment bindParamSql() { + return QueryHelper.buildParamSql(this, List.of(), null); } } \ No newline at end of file diff --git a/boot/platform/src/main/java/com/plate/boot/security/core/user/UsersService.java b/boot/platform/src/main/java/com/plate/boot/security/core/user/UsersService.java index 8b322559..c3588e97 100644 --- a/boot/platform/src/main/java/com/plate/boot/security/core/user/UsersService.java +++ b/boot/platform/src/main/java/com/plate/boot/security/core/user/UsersService.java @@ -3,8 +3,8 @@ import com.plate.boot.commons.base.AbstractDatabase; import com.plate.boot.commons.exception.RestServerException; import com.plate.boot.commons.utils.BeanUtils; -import com.plate.boot.commons.utils.query.CriteriaUtils; -import com.plate.boot.commons.utils.query.ParamSql; +import com.plate.boot.commons.utils.query.QueryFragment; +import com.plate.boot.commons.utils.query.QueryHelper; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -26,17 +26,17 @@ public class UsersService extends AbstractDatabase { private final UsersRepository usersRepository; public Flux search(UserRequest request, Pageable pageable) { - ParamSql paramSql = request.bindParamSql(); - String query = "select * from se_users" + paramSql.whereSql() + CriteriaUtils.applyPage(pageable); + QueryFragment QueryFragment = request.bindParamSql(); + String query = "select * from se_users" + QueryFragment.whereSql() + QueryHelper.applyPage(pageable); return super.queryWithCache(BeanUtils.cacheKey(request, pageable), query, - paramSql.params(), UserResponse.class); + QueryFragment.params(), UserResponse.class); } public Mono> page(UserRequest request, Pageable pageable) { var searchMono = this.search(request, pageable).collectList(); - ParamSql paramSql = request.bindParamSql(); - String query = "select count(*) from se_users" + paramSql.whereSql(); - var countMono = super.countWithCache(BeanUtils.cacheKey(request), query, paramSql.params()); + QueryFragment QueryFragment = request.bindParamSql(); + String query = "select count(*) from se_users" + QueryFragment.whereSql(); + var countMono = super.countWithCache(BeanUtils.cacheKey(request), query, QueryFragment.params()); return searchMono.zipWith(countMono) .map(tuple2 -> new PageImpl<>(tuple2.getT1(), pageable, tuple2.getT2())); }