Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
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
项目统一框架
amos-boot-biz
Commits
0cf773bd
Commit
0cf773bd
authored
Jul 20, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口查询慢问题优化
parent
1301c96e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
41 deletions
+21
-41
CommonServiceImpl.java
...boot/module/jxiop/biz/service/impl/CommonServiceImpl.java
+9
-7
MonitoringServiceImpl.java
.../module/jxiop/biz/service/impl/MonitoringServiceImpl.java
+0
-0
InfluxDButils.java
...ejoin/amos/boot/module/jxiop/biz/utils/InfluxDButils.java
+12
-34
No files found.
amos-boot-system-jxiop/amos-boot-module-jxiop-monitor-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/CommonServiceImpl.java
View file @
0cf773bd
...
...
@@ -7,11 +7,14 @@ import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto;
import
com.yeejoin.amos.boot.module.jxiop.biz.dto.SocialContributionDto
;
import
com.yeejoin.amos.boot.module.jxiop.biz.mapper2.SjglZsjZsbtzMapper
;
import
com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils
;
import
com.yeejoin.amos.component.influxdb.InfluxdbUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.stream.Collectors
;
...
...
@@ -20,7 +23,8 @@ public class CommonServiceImpl {
@Autowired
InfluxDButils
influxDButils
;
@Autowired
InfluxdbUtil
influxdbUtil
;
@Autowired
SjglZsjZsbtzMapper
sjglZsjZsbtzMapper
;
...
...
@@ -33,9 +37,8 @@ public class CommonServiceImpl {
public
Double
getTotalByIndicatior
(
String
gatewayId
,
String
indicator
){
String
sql
=
"SELECT * FROM indicators_"
+
gatewayId
+
" where equipmentIndexName='"
+
indicator
+
"'"
;
Double
totalvalue
=
0.0
;
List
<
IndicatorsDto
>
indicatorsDtoList
=
influxDButils
.
getListData
(
sql
,
IndicatorsDto
.
class
);
List
<
Double
>
doubleList
=
indicatorsDtoList
.
stream
().
map
(
indicatorsDto
->
Double
.
parseDouble
(
indicatorsDto
.
getValue
())).
collect
(
Collectors
.
toList
());
totalvalue
=
doubleList
.
stream
().
mapToDouble
(
Double:
:
doubleValue
).
sum
();
List
<
Map
<
String
,
Object
>>
mapList
=
influxdbUtil
.
query
(
sql
);
totalvalue
=
mapList
.
stream
().
filter
(
stringObjectMap
->
!
ObjectUtils
.
isEmpty
(
stringObjectMap
.
get
(
"value"
))).
mapToDouble
(
l
->
Double
.
parseDouble
((
String
)
l
.
get
(
"value"
))).
sum
();
return
Double
.
valueOf
(
String
.
format
(
"%.2f"
,
totalvalue
));
}
/**
...
...
@@ -47,9 +50,8 @@ public class CommonServiceImpl {
public
Double
getAvgvalueByIndicatior
(
String
gatewayId
,
String
indicator
){
String
sql
=
"SELECT * FROM indicators_"
+
gatewayId
+
" where equipmentIndexName='"
+
indicator
+
"'"
;
Double
avageValue
=
0.0
;
List
<
IndicatorsDto
>
indicatorsDtoList
=
influxDButils
.
getListData
(
sql
,
IndicatorsDto
.
class
);
List
<
Double
>
doubleList
=
indicatorsDtoList
.
stream
().
map
(
indicatorsDto
->
Double
.
parseDouble
(
indicatorsDto
.
getValue
())).
collect
(
Collectors
.
toList
());
avageValue
=
doubleList
.
stream
().
mapToDouble
(
Double:
:
doubleValue
).
average
().
getAsDouble
();
List
<
Map
<
String
,
Object
>>
mapList
=
influxdbUtil
.
query
(
sql
);
avageValue
=
mapList
.
stream
().
filter
(
stringObjectMap
->
!
ObjectUtils
.
isEmpty
(
stringObjectMap
.
get
(
"value"
))).
mapToDouble
(
l
->
Double
.
parseDouble
((
String
)
l
.
get
(
"value"
))).
average
().
getAsDouble
();
return
Double
.
valueOf
(
String
.
format
(
"%.2f"
,
avageValue
));
}
...
...
amos-boot-system-jxiop/amos-boot-module-jxiop-monitor-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/MonitoringServiceImpl.java
View file @
0cf773bd
This diff is collapsed.
Click to expand it.
amos-boot-system-jxiop/amos-boot-module-jxiop-monitor-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/utils/InfluxDButils.java
View file @
0cf773bd
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jxiop
.
biz
.
utils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.squareup.moshi.Json
;
import
com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto
;
import
com.yeejoin.amos.component.influxdb.InfluxDbConnection
;
import
com.yeejoin.amos.component.influxdb.InfluxdbUtil
;
import
org.influxdb.dto.QueryResult
;
import
org.springframework.beans.BeanWrapperImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -10,11 +15,15 @@ import org.springframework.util.ObjectUtils;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@Component
public
class
InfluxDButils
{
@Autowired
InfluxDbConnection
influxDbConnection
;
@Autowired
InfluxdbUtil
influxdbUtil
;
public
<
T
>
List
<
T
>
getListData
(
String
sql
,
Class
<
T
>
clazz
)
{
List
<
T
>
list
=
new
ArrayList
<>();
try
{
...
...
@@ -53,39 +62,8 @@ public class InfluxDButils {
public
<
T
>
List
<
T
>
getListData1
(
String
sql
,
Class
<
T
>
clazz
)
{
List
<
T
>
list
=
new
ArrayList
<>();
try
{
QueryResult
query
=
influxDbConnection
.
query
(
sql
);
List
<
QueryResult
.
Result
>
queryResults
=
query
.
getResults
();
for
(
QueryResult
.
Result
result
:
queryResults
)
{
List
<
QueryResult
.
Series
>
series
=
result
.
getSeries
();
if
(
series
==
null
)
{
continue
;
}
for
(
QueryResult
.
Series
serie
:
series
)
{
List
<
List
<
Object
>>
values
=
serie
.
getValues
();
List
<
String
>
columns
=
serie
.
getColumns
();
for
(
int
i
=
0
;
i
<
values
.
size
();
++
i
)
{
T
object
=
clazz
.
newInstance
();
BeanWrapperImpl
bean
=
new
BeanWrapperImpl
(
object
);
for
(
int
j
=
0
;
j
<
columns
.
size
();
++
j
)
{
String
k
=
columns
.
get
(
j
).
replace
(
"last_"
,
""
);
Object
v
=
values
.
get
(
i
).
get
(
j
);
System
.
out
.
println
(
k
);
System
.
out
.
println
(
v
);
if
(
"time"
.
equals
(
k
))
{
continue
;
}
else
{
// if(ObjectUtils.isEmpty(v)){
// bean.setPropertyValue(k, "");
// }else{
bean
.
setPropertyValue
(
k
,
v
);
// }
}
}
list
.
add
(
object
);
}
}
}
List
<
Map
<
String
,
Object
>>
mapList
=
influxdbUtil
.
query
(
sql
);
list
=
mapList
.
stream
().
map
(
stringObjectMap
->
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
stringObjectMap
),
clazz
)).
collect
(
Collectors
.
toList
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
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