Skip to content

Commit

Permalink
增加utf8LengthBetween,修正length比较算符的文档
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Oct 11, 2024
1 parent 9d050f5 commit 4705e8d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public interface FilterBeanConstants {
String FILTER_OP_DATE_BETWEEN = "dateBetween";
String FILTER_OP_DATETIME_BETWEEN = "dateTimeBetween";
String FILTER_OP_LENGTH_BETWEEN = "lengthBetween";
String FILTER_OP_UTF8_LENGTH_BETWEEN = "utf8LengthBetween";

/**
* 字符串长度为指定值,或者在指定区间内
*/
String FILTER_OP_LENGTH = "length";
String FILTER_OP_UTF8_LENGTH = "utf8Length";

String FILTER_OP_STARTS_WITH = "startsWith";
String FILTER_OP_ENDS_WITH = "endsWith";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_NOT_EMPTY;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_NOT_IN;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_NOT_NULL;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_UTF8_LENGTH_BETWEEN;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_TAG_NAME;

@SuppressWarnings("PMD.TooManyStaticImports")
Expand Down Expand Up @@ -125,6 +126,12 @@ public static TreeBean lengthBetween(String name, Integer min, Integer max) {
return bean;
}

public static TreeBean utf8LengthBetween(String name, Integer min, Integer max) {
TreeBean bean = new TreeBean(FILTER_OP_UTF8_LENGTH_BETWEEN).attr(FILTER_ATTR_NAME, name);
bean.attrIgnoreNull(FILTER_ATTR_MIN, min).attrIgnoreNull(FILTER_ATTR_MAX, max);
return bean;
}

public static TreeBean eq(String name, Object value) {
return compareOp(FILTER_OP_EQ, name, value);
}
Expand Down
13 changes: 9 additions & 4 deletions nop-core/src/main/java/io/nop/core/model/query/FilterOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_OR;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_REGEX;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_STARTS_WITH;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_UTF8_LENGTH;
import static io.nop.api.core.beans.FilterBeanConstants.FILTER_OP_UTF8_LENGTH_BETWEEN;
import static io.nop.commons.util.CollectionHelper.buildImmutableList;

public class FilterOp extends EnumLike<FilterOp> implements IJsonSerializable {
Expand Down Expand Up @@ -328,12 +330,13 @@ public String getMathSymbol() {
public static final FilterOp NOT_CONTAINS = compareOp(FILTER_OP_NOT_CONTAINS, 41, FilterOpHelper::notContains);

public static final FilterOp LENGTH = compareOp(FILTER_OP_LENGTH, 42, FilterOpHelper::length);
public static final FilterOp REGEX = compareOp(FILTER_OP_REGEX, 43, FilterOpHelper::regex);
public static final FilterOp ICONTAINS = compareOp(FILTER_OP_ICONTAINS, 44, FilterOpHelper::icontains);
public static final FilterOp LIKE = compareOp(FILTER_OP_LIKE, 45, FilterOpHelper::like);
public static final FilterOp UTF8_LENGTH = compareOp(FILTER_OP_UTF8_LENGTH, 43, FilterOpHelper::length);
public static final FilterOp REGEX = compareOp(FILTER_OP_REGEX, 44, FilterOpHelper::regex);
public static final FilterOp ICONTAINS = compareOp(FILTER_OP_ICONTAINS, 45, FilterOpHelper::icontains);
public static final FilterOp LIKE = compareOp(FILTER_OP_LIKE, 46, FilterOpHelper::like);

public static final List<FilterOp> DEFAULT_COMPARE_OPS = buildImmutableList(EQ, NE, GT, GE, LT, LE, IN, NOT_IN,
STARTS_WITH, ENDS_WITH, CONTAINS, NOT_CONTAINS, LENGTH, REGEX, ICONTAINS, LIKE);
STARTS_WITH, ENDS_WITH, CONTAINS, NOT_CONTAINS, LENGTH, UTF8_LENGTH, REGEX, ICONTAINS, LIKE);

public static final FilterOp BETWEEN = betweenOp(FILTER_OP_BETWEEN, 50, FilterOpHelper::between);

Expand All @@ -343,4 +346,6 @@ public String getMathSymbol() {
FilterOpHelper::dateTimeBetween);
public static final FilterOp LENGTH_BETWEEN = betweenOp(FILTER_OP_LENGTH_BETWEEN, 54,
FilterOpHelper::lengthBetween);
public static final FilterOp UTF8_LENGTH_BETWEEN = betweenOp(FILTER_OP_UTF8_LENGTH_BETWEEN, 55,
FilterOpHelper::lengthBetween);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public static boolean length(Object value, Object length) {
return str.length() == len;
}

public static boolean utf8Length(Object value, Object length) {
Integer len = ConvertHelper.toInt(length, NopException::new);
if (len == null)
return true;
String str = ConvertHelper.toString(value, "");
return StringHelper.utf8Length(str) == len;
}

public static boolean regex(Object value, Object pattern) {
String s1 = ConvertHelper.toString(value, "");
String s2 = ConvertHelper.toString(pattern, "");
Expand Down Expand Up @@ -275,7 +283,28 @@ public static boolean lengthBetween(Object value, Object min, Object max, boolea
int d1 = ConvertHelper.toString(value, "").length();

Integer m1 = ConvertHelper.toInt(min, NopException::new);
Integer m2 = ConvertHelper.toInt(min, NopException::new);
Integer m2 = ConvertHelper.toInt(max, NopException::new);

if (m1 != null) {
int cmp1 = Integer.compare(d1, m1);
if (excludeMin ? cmp1 <= 0 : cmp1 < 0) {
return false;
}
}
if (m2 != null) {
int cmp1 = Integer.compare(d1, m2);
if (excludeMax ? cmp1 >= 0 : cmp1 > 0) {
return false;
}
}
return true;
}

public static boolean utf8LengthBetween(Object value, Object min, Object max, boolean excludeMin, boolean excludeMax) {
int d1 = StringHelper.utf8Length(ConvertHelper.toString(value, ""));

Integer m1 = ConvertHelper.toInt(min, NopException::new);
Integer m2 = ConvertHelper.toInt(max, NopException::new);

if (m1 != null) {
int cmp1 = Integer.compare(d1, m1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,12 @@
/nop/schema/query/group-by.xdef
/nop/schema/query/order-by.xdef
/nop/schema/query/query.xdef
/nop/schema/record/packet-codec.xdef
/nop/schema/record/record-definitions.xdef
/nop/schema/record/record-field.xdef
/nop/schema/record/record-file.xdef
/nop/schema/record/record-object.xdef
/nop/schema/record/record-param.xdef
/nop/schema/record/record-simple-field.xdef
/nop/schema/register-model.xdef
/nop/schema/registry.xdef
Expand Down Expand Up @@ -1237,6 +1241,8 @@
/nop/wf/xlib/dingflow-gen/impl_GenComponents.xpl
/nop/wf/xlib/dingflow-gen/impl_GenFlowEditorPage.xpl
/nop/wf/xlib/dingflow-gen/impl_GenFlowEditorSchema.xpl
/nop/wf/xlib/dingflow-tran.xlib
/nop/wf/xlib/dingflow-tran/impl_GenWorkflow.xpl
/nop/wf/xlib/oa.xlib
/nop/wf/xlib/wf-actor.xlib
/nop/wf/xlib/wf-gen.xlib
Expand Down
9 changes: 9 additions & 0 deletions nop-demo/nop-spring-demo/src/main/resources/nop-vfs-index.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/_delta/default/nop/spring/beans/spring-demo.beans.xml
/_delta/default/nop/spring/mapper/SysUser.mapper.xml
/dict/auth/gender.dict.yaml
/dict/auth/login-status.dict.yaml
/dict/auth/login-type.dict.yaml
Expand Down Expand Up @@ -385,8 +387,12 @@
/nop/schema/query/group-by.xdef
/nop/schema/query/order-by.xdef
/nop/schema/query/query.xdef
/nop/schema/record/packet-codec.xdef
/nop/schema/record/record-definitions.xdef
/nop/schema/record/record-field.xdef
/nop/schema/record/record-file.xdef
/nop/schema/record/record-object.xdef
/nop/schema/record/record-param.xdef
/nop/schema/record/record-simple-field.xdef
/nop/schema/register-model.xdef
/nop/schema/registry.xdef
Expand Down Expand Up @@ -428,6 +434,9 @@
/nop/schema/xui/xview.xdef
/nop/spring/_module
/nop/spring/beans/spring-base.beans.xml
/nop/spring/beans/spring-demo.beans.xml
/nop/spring/mapper/SysUser.mapper.xml
/nop/spring/mapper/_gen/_SysUser.mapper.xml
/nop/spring/schema/mapper.xdef
/nop/sys/_module
/nop/sys/auth/_nop-sys.action-auth.xml
Expand Down
10 changes: 8 additions & 2 deletions nop-xdefs/src/main/resources/_vfs/nop/schema/query/filter.xdef
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,19 @@
xdef:allow-multiple="true" xdef:bean-tag-prop="$type"/>

<!-- 字段值的长度在指定范围之内 -->
<length name="!string" owner="string" min="#int" max="#int" excludeMin="boolean" excludeMax="boolean"
<lengthBetween name="!string" owner="string" min="#int" max="#int" excludeMin="boolean" excludeMax="boolean"
xdef:allow-multiple="true" minName="string" maxName="string" xdef:bean-tag-prop="$type"/>

<!-- 文本字段值的utf8编码后的长度在指定范围之内 -->
<utf8Length name="!string" owner="string" min="#int" max="#int" excludeMin="boolean" excludeMax="boolean"
<utf8LengthBetween name="!string" owner="string" min="#int" max="#int" excludeMin="boolean" excludeMax="boolean"
xdef:allow-multiple="true" minName="string" maxName="string" xdef:bean-tag-prop="$type"/>

<length name="!string" owner="string" value="int" valueName="string"
xdef:allow-multiple="true" xdef:bean-tag-prop="$type"/>

<utf8Length name="!string" owner="string" value="int" valueName="string"
xdef:allow-multiple="true" xdef:bean-tag-prop="$type"/>

<sql value="!sql-obj" xdef:allow-multiple="true" xdef:bean-tag-prop="$type"/>

<expr xdef:value="expr" xdef:allow-multiple="true" xdef:bean-tag-prop="$type"/>
Expand Down

0 comments on commit 4705e8d

Please sign in to comment.