Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
asset-distribution
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data-spider
asset-distribution
Commits
e5a934f2
Commit
e5a934f2
authored
Apr 03, 2020
by
zhengjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
6.6-2
parent
2c052e2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
0 deletions
+136
-0
Range.java
...uantgroup/asset/distribution/util/ruleRelation/Range.java
+38
-0
SetRelationUtil.java
...asset/distribution/util/ruleRelation/SetRelationUtil.java
+98
-0
No files found.
src/main/java/com/quantgroup/asset/distribution/util/ruleRelation/Range.java
0 → 100644
View file @
e5a934f2
package
com
.
quantgroup
.
asset
.
distribution
.
util
.
ruleRelation
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author jian.zheng
*/
public
class
Range
<
T
>
{
private
RangeType
rangeType
;
private
List
<
T
>
items
;
private
Aggregation
aggregation
;
/**
* @author jian.zheng
*/
public
enum
RangeType
{
/**
* 数字
*/
NUMERIC
,
/**
* 数组
*/
ARRAY
;
}
@Data
public
static
class
Aggregation
{
private
Number
start
;
private
boolean
startClosed
;
private
Number
end
;
private
boolean
endClosed
;
}
}
src/main/java/com/quantgroup/asset/distribution/util/ruleRelation/SetRelationUtil.java
0 → 100644
View file @
e5a934f2
package
com
.
quantgroup
.
asset
.
distribution
.
util
.
ruleRelation
;
import
com.quantgroup.asset.distribution.enums.RuleOperator
;
import
com.quantgroup.asset.distribution.exception.QGException
;
import
com.quantgroup.asset.distribution.exception.QGExceptionType
;
import
org.apache.commons.lang3.RandomUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
SetRelationUtil
{
public
static
<
T
>
Range
<
T
>
getRange
(
String
operator
,
String
value
){
Class
<?>
clazz
=
getType
(
value
);
return
null
;
}
private
static
String
getValue
(
String
operator
,
String
value
){
Class
<?>
clazz
=
getType
(
value
);
switch
(
RuleOperator
.
fromCode
(
operator
))
{
case
Equal:
return
value
;
case
NotEqual:
if
(
clazz
.
isAssignableFrom
(
BigDecimal
.
class
))
{
return
new
BigDecimal
(
value
).
add
(
new
BigDecimal
(
1
)).
toString
();
}
else
if
(
clazz
.
isAssignableFrom
(
Boolean
.
class
)){
return
Boolean
.
toString
(!
Boolean
.
valueOf
(
value
));
}
else
{
if
(
value
.
length
()
==
1
){
return
String
.
valueOf
((
char
)
(
value
.
charAt
(
0
)
+
1
));
}
else
{
return
value
.
substring
(
0
,
value
.
length
()
-
1
)
+
String
.
valueOf
((
char
)
(
value
.
charAt
(
value
.
length
()
-
1
)
+
1
));
}
}
case
In:
if
(
value
.
contains
(
","
)){
List
<
String
>
list
=
Arrays
.
asList
(
value
.
split
(
","
));
return
list
.
get
(
RandomUtils
.
nextInt
(
0
,
list
.
size
()-
1
));
}
else
{
return
value
;
}
case
NotIn:
if
(
value
.
contains
(
","
)){
List
<
String
>
list
=
Arrays
.
asList
(
value
.
split
(
","
));
if
(
BigDecimal
.
class
.
isAssignableFrom
(
list
.
get
(
0
).
getClass
())){
Integer
num
=
1
;
while
(
list
.
contains
(
String
.
valueOf
(
num
))){
num
++;
}
return
num
.
toString
();
}
else
{
String
start
=
getValue
(
operator
,
list
.
get
(
0
));
while
(
list
.
contains
(
start
)){
start
=
getValue
(
operator
,
start
);
}
return
start
;
}
}
else
{
return
value
;
}
case
LessThan:
if
(
BigDecimal
.
class
.
isAssignableFrom
(
clazz
)){
if
(
new
BigDecimal
(
value
).
doubleValue
()
<
1
&&
new
BigDecimal
(
value
).
doubleValue
()
>
0
){
return
new
BigDecimal
(
value
).
divide
(
new
BigDecimal
(
10
),
value
.
split
(
"."
)[
1
].
length
(),
RoundingMode
.
HALF_UP
).
toString
();
}
else
{
return
new
BigDecimal
(
value
).
subtract
(
new
BigDecimal
(
1
)).
toString
();
}
}
else
{
throw
new
QGException
(
QGExceptionType
.
CRATE_RULE_VO_ERROR
);
}
case
GreaterThan:
if
(
BigDecimal
.
class
.
isAssignableFrom
(
clazz
)){
return
new
BigDecimal
(
value
).
add
(
new
BigDecimal
(
1
)).
toString
();
}
else
{
throw
new
QGException
(
QGExceptionType
.
CRATE_RULE_VO_ERROR
);
}
case
LessThanOrEqual:
return
getValue
(
"<"
,
value
);
case
GreaterThanOrEqual:
return
getValue
(
">"
,
value
);
default
:
throw
new
QGException
(
QGExceptionType
.
RULE_OPERATOR_NOT_EXIST
);
}
}
private
static
Class
<?>
getType
(
String
value
){
if
(
StringUtils
.
isNumeric
(
value
)){
return
BigDecimal
.
class
;
}
if
(
"true"
.
equals
(
value
)
||
"false"
.
equals
(
value
)){
return
Boolean
.
class
;
}
return
String
.
class
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment