Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
indicators
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangkb
indicators
Commits
672c2c97
Commit
672c2c97
authored
Jul 31, 2020
by
zhangkb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加新增基础项或者指标判断公式合法性代码
parent
0d6df2dc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
2 deletions
+37
-2
BaseIndDefService.java
...obile/indicators/service/hytobacco/BaseIndDefService.java
+6
-0
DriveIndDefService.java
...bile/indicators/service/hytobacco/DriveIndDefService.java
+5
-0
CalculateUtils.java
...n/java/com/keymobile/indicators/utils/CalculateUtils.java
+26
-2
No files found.
src/main/java/com/keymobile/indicators/service/hytobacco/BaseIndDefService.java
View file @
672c2c97
...
...
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import
com.keymobile.indicators.model.entity.indicators.BaseIndDef
;
import
com.keymobile.indicators.model.mapper.indicators.BaseIndDefMapper
;
import
com.keymobile.indicators.utils.CalculateUtils
;
@Service
public
class
BaseIndDefService
{
...
...
@@ -27,6 +28,11 @@ public class BaseIndDefService {
public
String
saveOrUpdate
(
BaseIndDef
baseIndDef
,
Integer
catalogId
,
String
catalogIdPath
,
String
user
,
String
isUpdate
,
String
code
)
throws
Exception
{
//判断公式合法性
if
(
StringUtils
.
isNotBlank
(
baseIndDef
.
getIndFormat
())
&&
!
CalculateUtils
.
isValidformula
(
baseIndDef
.
getIndFormat
()))
{
return
"formula is not valid"
;
}
if
(
StringUtils
.
isBlank
(
baseIndDef
.
getIndId
()))
{
return
"indId can not be null"
;
}
...
...
src/main/java/com/keymobile/indicators/service/hytobacco/DriveIndDefService.java
View file @
672c2c97
...
...
@@ -40,6 +40,11 @@ public class DriveIndDefService {
public
String
saveOrUpdate
(
DriveIndDef
driveIndDef
,
String
code
,
Integer
catalogId
,
String
catalogIdPath
,
String
user
,
String
isUpdate
,
String
shortboardIds
)
throws
Exception
{
//判断公式合法性
if
(
StringUtils
.
isNotBlank
(
driveIndDef
.
getIndFormat
())
&&
!
CalculateUtils
.
isValidformula
(
driveIndDef
.
getIndFormat
()))
{
return
"formula is not valid"
;
}
if
(
StringUtils
.
isBlank
(
driveIndDef
.
getIndId
()))
{
return
"indId can not be null"
;
}
...
...
src/main/java/com/keymobile/indicators/utils/CalculateUtils.java
View file @
672c2c97
...
...
@@ -10,6 +10,8 @@ import java.util.LinkedHashMap;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -244,7 +246,6 @@ public class CalculateUtils {
}
else
{
result
.
put
(
"rankMap"
,
rankMap
);
}
System
.
out
.
println
(
result
);
return
result
;
}
...
...
@@ -327,6 +328,29 @@ public class CalculateUtils {
}
}
//判断公式合法性
public
static
boolean
isValidformula
(
String
formula
)
{
List
<
String
>
indIdList
=
new
ArrayList
<>();
Pattern
p
=
Pattern
.
compile
(
"(\\[[^\\]]*\\])"
);
Matcher
m
=
p
.
matcher
(
formula
);
while
(
m
.
find
()){
indIdList
.
add
(
m
.
group
().
substring
(
1
,
m
.
group
().
length
()-
1
));
}
if
(
indIdList
.
isEmpty
())
{
return
false
;
}
else
{
for
(
int
i
=
0
;
i
<
indIdList
.
size
();
i
++)
{
formula
=
formula
.
replace
(
"["
+
indIdList
.
get
(
i
)+
"]"
,
(
i
+
1
)+
""
);
}
try
{
AviatorEvaluator
.
execute
(
formula
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
}
public
static
void
main
(
String
[]
args
)
{
// Map<String,String> map = new HashMap<>();
// map.put("1001", "12");
...
...
@@ -338,7 +362,7 @@ public class CalculateUtils {
// map.put("1007", "0");
// map.put("1008", "-6");
CalculateUtils
cal
=
new
CalculateUtils
();
cal
.
rankByObjSort
(
new
HashMap
<
String
,
Integer
>(),
new
HashMap
<
String
,
Integer
>(
));
System
.
out
.
println
(
cal
.
isValidformula
(
"([1001]+[1002])-[1004]"
));
// Map<String,Integer> result = cal.rankValue(map, "0");
// result = cal.sortMapByValue(result,1);
// System.out.println(result);
...
...
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