|
@@ -22,6 +22,10 @@ public class NamedTable {
|
|
|
|
|
|
List<String> fields = new ArrayList<>();
|
|
|
|
|
|
+ List<String> groups = new ArrayList<>();
|
|
|
+
|
|
|
+ List<String> orders = new ArrayList<>();
|
|
|
+
|
|
|
Function<String, String> rowMapColumnMapper;
|
|
|
|
|
|
Object defaultPrimaryValue;
|
|
@@ -83,6 +87,28 @@ public class NamedTable {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ @Comment("拼接`order by xxx asc/desc`")
|
|
|
+ public NamedTable orderBy(@Comment("要排序的列") String column, @Comment("`asc`或`desc`") String sort) {
|
|
|
+ this.orders.add(column + " " + sort);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Comment("拼接`order by xxx asc`")
|
|
|
+ public NamedTable orderBy(@Comment("要排序的列") String column) {
|
|
|
+ return orderBy(column, "asc");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Comment("拼接`order by xxx desc`")
|
|
|
+ public NamedTable orderByDesc(@Comment("要排序的列") String column) {
|
|
|
+ return orderBy(column, "desc");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Comment("拼接`group by`")
|
|
|
+ public NamedTable groupBy(@Comment("要分组的列") String ... columns) {
|
|
|
+ this.groups.addAll(Arrays.asList(columns));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
private List<Map.Entry<String, Object>> filterNotBlanks() {
|
|
|
return this.columns.entrySet().stream()
|
|
|
.filter(it -> StringUtils.isNotBlank(Objects.toString(it.getValue(), "")))
|
|
@@ -170,6 +196,14 @@ public class NamedTable {
|
|
|
builder.append(where.getSql());
|
|
|
params.addAll(where.getParams());
|
|
|
}
|
|
|
+ if(!orders.isEmpty()){
|
|
|
+ builder.append(" order by ");
|
|
|
+ builder.append(String.join(",", orders));
|
|
|
+ }
|
|
|
+ if(!groups.isEmpty()){
|
|
|
+ builder.append(" group by ");
|
|
|
+ builder.append(String.join(",", groups));
|
|
|
+ }
|
|
|
return new BoundSql(builder.toString(), params, sqlModule);
|
|
|
}
|
|
|
|