-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore-ISelectAbility-加入支持复杂条件拼接的post查询
- Loading branch information
Showing
7 changed files
with
339 additions
and
7 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
my-core/src/main/java/net/ximatai/muyun/ability/curd/std/IQueryAbility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.ximatai.muyun.ability.curd.std; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
import net.ximatai.muyun.model.PageResult; | ||
import net.ximatai.muyun.model.QueryItem; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public interface IQueryAbility extends ISelectAbility { | ||
|
||
List<QueryItem> queryItemList(); | ||
|
||
@GET | ||
@Path("/queryFields") | ||
default List<QueryItem> queryFields() { | ||
return queryItemList().stream().filter(item -> !item.isHide()).collect(Collectors.toList()); | ||
} | ||
|
||
@POST | ||
@Path("/view") | ||
default PageResult view(@QueryParam("page") int page, | ||
@QueryParam("limit") int limit, | ||
@QueryParam("orderField") String orderField, | ||
@QueryParam("orderType") String orderType, | ||
Map<String, Object> queryBody) { | ||
return ISelectAbility.super.view(page, limit, orderField, orderType, queryBody, queryItemList()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
my-core/src/main/java/net/ximatai/muyun/core/exception/QueryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.ximatai.muyun.core.exception; | ||
|
||
public class QueryException extends RuntimeException { | ||
|
||
public QueryException(String message) { | ||
super(message); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
my-core/src/main/java/net/ximatai/muyun/core/tool/DateTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.ximatai.muyun.core.tool; | ||
|
||
import java.sql.Date; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class DateTool { | ||
|
||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
public static Date stringToSqlDate(String dateString) { | ||
if (dateString == null || dateString.isEmpty()) { | ||
throw new IllegalArgumentException("Date string cannot be null or empty."); | ||
} | ||
dateString = dateString.substring(0, 10); | ||
LocalDate localDate = LocalDate.parse(dateString, DATE_FORMATTER); | ||
return Date.valueOf(localDate); | ||
} | ||
|
||
public static Date stringToSqlTime(String dateString) { | ||
if (dateString == null || dateString.isEmpty()) { | ||
throw new IllegalArgumentException("Date string cannot be null or empty."); | ||
} | ||
if (dateString.length() == 10) { | ||
dateString += " 00:00:00"; | ||
} | ||
LocalDateTime localDateTime = LocalDateTime.parse(dateString, TIME_FORMATTER); | ||
return Date.valueOf(localDateTime.toLocalDate()); | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...net/ximatai/muyun/domain/OrderColumn.java → .../net/ximatai/muyun/model/OrderColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package net.ximatai.muyun.domain; | ||
package net.ximatai.muyun.model; | ||
|
||
public class OrderColumn { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../net/ximatai/muyun/domain/PageResult.java → ...a/net/ximatai/muyun/model/PageResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package net.ximatai.muyun.domain; | ||
package net.ximatai.muyun.model; | ||
|
||
import java.util.List; | ||
|
||
|
159 changes: 159 additions & 0 deletions
159
my-core/src/main/java/net/ximatai/muyun/model/QueryItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package net.ximatai.muyun.model; | ||
|
||
public class QueryItem { | ||
|
||
private String field; | ||
private String label; | ||
private String alias; | ||
|
||
private SymbolType symbolType; | ||
|
||
private boolean isMain = true; //ui | ||
private boolean isReference = false; | ||
private boolean isDate = false; | ||
private boolean isTime = false; | ||
private boolean isDatetime = false; | ||
private boolean isBoolean = false; | ||
private boolean isHide = false; //ui | ||
private boolean isNotNull = false; | ||
|
||
private Object defaultValue; //ui | ||
|
||
public QueryItem of(String field) { | ||
QueryItem item = new QueryItem(); | ||
item.field = field; | ||
item.alias = field; | ||
item.symbolType = SymbolType.EQUAL; | ||
|
||
if (field.startsWith("t_")) { | ||
item.isDatetime = true; | ||
} else if (field.startsWith("d_")) { | ||
item.isDate = true; | ||
} else if (field.startsWith("b_")) { | ||
item.isBoolean = true; | ||
} | ||
|
||
return item; | ||
} | ||
|
||
public enum SymbolType { | ||
EQUAL, NOT_EQUAL, LIKE, IN, NOT_IN, RANGE | ||
} | ||
|
||
public QueryItem setField(String field) { | ||
this.field = field; | ||
return this; | ||
} | ||
|
||
public QueryItem setLabel(String label) { | ||
this.label = label; | ||
return this; | ||
} | ||
|
||
public QueryItem setAlias(String alias) { | ||
this.alias = alias; | ||
return this; | ||
} | ||
|
||
public QueryItem setSymbolType(SymbolType symbolType) { | ||
this.symbolType = symbolType; | ||
return this; | ||
} | ||
|
||
public QueryItem setMain(boolean main) { | ||
isMain = main; | ||
return this; | ||
} | ||
|
||
public QueryItem setReference(boolean reference) { | ||
isReference = reference; | ||
return this; | ||
} | ||
|
||
public QueryItem setDate(boolean date) { | ||
isDate = date; | ||
return this; | ||
} | ||
|
||
public QueryItem setTime(boolean time) { | ||
isTime = time; | ||
return this; | ||
} | ||
|
||
public QueryItem setDatetime(boolean datetime) { | ||
isDatetime = datetime; | ||
return this; | ||
} | ||
|
||
public QueryItem setBoolean(boolean aBoolean) { | ||
isBoolean = aBoolean; | ||
return this; | ||
} | ||
|
||
public QueryItem setHide(boolean hide) { | ||
isHide = hide; | ||
return this; | ||
} | ||
|
||
public QueryItem setNotNull(boolean notNull) { | ||
isNotNull = notNull; | ||
return this; | ||
} | ||
|
||
public QueryItem setDefaultValue(Object defaultValue) { | ||
this.defaultValue = defaultValue; | ||
return this; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
public SymbolType getSymbolType() { | ||
return symbolType; | ||
} | ||
|
||
public boolean isMain() { | ||
return isMain; | ||
} | ||
|
||
public boolean isReference() { | ||
return isReference; | ||
} | ||
|
||
public boolean isDate() { | ||
return isDate; | ||
} | ||
|
||
public boolean isTime() { | ||
return isTime; | ||
} | ||
|
||
public boolean isDatetime() { | ||
return isDatetime; | ||
} | ||
|
||
public boolean isBoolean() { | ||
return isBoolean; | ||
} | ||
|
||
public boolean isHide() { | ||
return isHide; | ||
} | ||
|
||
public boolean isNotNull() { | ||
return isNotNull; | ||
} | ||
|
||
public Object getDefaultValue() { | ||
return defaultValue; | ||
} | ||
} |