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
7b8750f9
Commit
7b8750f9
authored
Sep 27, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化缓存数据逻辑
parent
c51e1a35
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
36 deletions
+37
-36
StationCacheDataInit.java
.../boot/module/jxiop/biz/initdata/StationCacheDataInit.java
+1
-1
CommonServiceImpl.java
...boot/module/jxiop/biz/service/impl/CommonServiceImpl.java
+36
-35
No files found.
amos-boot-system-jxiop/amos-boot-module-jxiop-monitor-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/initdata/StationCacheDataInit.java
View file @
7b8750f9
...
...
@@ -43,8 +43,8 @@ public class StationCacheDataInit implements CommandLineRunner {
Logger
logger
=
LoggerFactory
.
getLogger
(
StationCacheDataInit
.
class
);
public
void
run
(
String
...
args
)
throws
Exception
{
List
<
StationCacheInfoDto
>
stationCacheInfoDtos
=
new
ArrayList
<>();
redisTemplate
.
delete
(
"station_info_cache"
);
List
<
StationCacheInfoDto
>
stationCacheInfoDtos
=
new
ArrayList
<>();
List
<
Region
>
regionList
=
regionMapper
.
selectList
(
new
QueryWrapper
<
Region
>().
eq
(
"LEVEL"
,
1
));
List
<
MapRegion
>
mapRegionList
=
mapRegionMapper
.
selectList
(
new
QueryWrapper
<
MapRegion
>().
isNotNull
(
"name"
));
List
<
StationBasic
>
stationBasicList
=
stationBasicMapper
.
selectList
(
new
QueryWrapper
<
StationBasic
>().
isNotNull
(
"belong_area"
).
isNotNull
(
"fan_gateway_id"
));
...
...
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 @
7b8750f9
...
...
@@ -18,6 +18,7 @@ import com.yeejoin.amos.boot.module.jxiop.biz.initdata.StationCacheDataInit;
import
com.yeejoin.amos.boot.module.jxiop.biz.mapper2.SjglZsjZsbtzMapper
;
import
com.yeejoin.amos.boot.module.jxiop.biz.repository.ESEquipmentsRepository
;
import
com.yeejoin.amos.component.influxdb.InfluxdbUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.elasticsearch.index.query.*
;
import
org.elasticsearch.script.Script
;
import
org.elasticsearch.script.ScriptType
;
...
...
@@ -44,6 +45,7 @@ import java.util.*;
import
java.util.stream.Collectors
;
@Service
@Slf4j
public
class
CommonServiceImpl
{
@Autowired
...
...
@@ -240,14 +242,14 @@ public class CommonServiceImpl {
queryCondtion
.
put
(
CommonConstans
.
QueryStringEquipmentIndexName
,
Arrays
.
asList
(
indicator
));
queryCondtion
.
put
(
CommonConstans
.
QueryStringGateWayId
,
Arrays
.
asList
(
gatewayId
));
likeQuerCondtion
.
put
(
CommonConstans
.
QueryStringFrontMoudle
,
"逆变器"
);
List
<
ESEquipments
>
result
=
getListDataByCondtions
(
queryCondtion
,
null
,
ESEquipments
.
class
,
likeQuerCondtion
);
List
<
ESEquipments
>
result
=
getListDataByCondtions
(
queryCondtion
,
null
,
ESEquipments
.
class
,
likeQuerCondtion
);
Double
totalvalue
=
0.00
;
try
{
totalvalue
=
result
.
stream
().
filter
(
stringObjectMap
->
!
ObjectUtils
.
isEmpty
(
stringObjectMap
.
getValueF
())).
mapToDouble
(
l
->
Double
.
parseDouble
(
l
.
getValueF
().
toString
())).
sum
();
}
catch
(
Exception
e
)
{
return
totalvalue
;
}
return
Double
.
valueOf
(
String
.
format
(
"%.4f"
,
totalvalue
*
CommonConstans
.
pvGenPoweActor
));
return
Double
.
valueOf
(
String
.
format
(
"%.4f"
,
totalvalue
*
CommonConstans
.
pvGenPoweActor
));
}
public
Double
getTotalByIndicatiorAndParams
(
String
gatewayId
,
String
indicator
,
String
querySql
)
{
...
...
@@ -388,42 +390,42 @@ public class CommonServiceImpl {
* @deprecated 获取缓存场站信息数据
*/
public
List
<
StationCacheInfoDto
>
getListStationCacheInfoDto
()
{
List
<
StationCacheInfoDto
>
stationCacheInfoDto
List
=
redisTemplate
.
opsForList
().
range
(
"station_info_cache"
,
0
,
-
1
);
if
(
ObjectUtils
.
isEmpty
(
stationCacheInfoDtoList
))
{
try
{
List
<
StationCacheInfoDto
>
stationCacheInfoDtos
=
new
ArrayList
<>(
);
List
<
Region
>
regionList
=
regionMapper
.
selectList
(
new
QueryWrapper
<
Region
>().
eq
(
"LEVEL"
,
1
));
List
<
MapRegion
>
mapRegionList
=
mapRegionMapper
.
selectList
(
new
QueryWrapper
<
MapRegion
>().
isNotNull
(
"name
"
));
List
<
StationBasic
>
stationBasicList
=
stationBasicMapper
.
selectList
(
new
QueryWrapper
<
StationBasic
>().
isNotNull
(
"belong_area"
).
isNotNull
(
"fan_gateway_id"
));
stationBasicList
.
forEach
(
stationBasic
->
{
StationCacheInfoDto
stationCacheInfoDto
=
new
StationCacheInfoDto
();
stationCacheInfoDto
.
setStationId
(
stationBasic
.
getSequenceNbr
().
toString
());
stationCacheInfoDto
.
setStationName
(
stationBasic
.
getStationName
());
stationCacheInfoDto
.
setStationType
(
stationBasic
.
getStationType
());
stationCacheInfoDto
.
setBelongProvince
(
regionList
.
stream
().
filter
(
region
->
region
.
getRegionCode
().
toString
().
equals
(
stationBasic
.
getBelongArea
().
replace
(
"["
,
""
).
split
(
","
)[
0
])).
map
(
region
->
region
.
getRegionName
()).
collect
(
Collectors
.
toList
()).
get
(
0
));
stationCacheInfoDto
.
setBelongArea
(
mapRegionList
.
stream
().
filter
(
mapRegion
->
mapRegion
.
getProvince
().
contains
(
stationCacheInfoDto
.
getBelongProvince
().
substring
(
0
,
2
))
||
mapRegion
.
getProvince
().
contains
(
stationCacheInfoDto
.
getBelongProvince
().
substring
(
0
,
3
))).
map
(
mapRegion
->
mapRegion
.
getName
()).
collect
(
Collectors
.
toList
()).
get
(
0
));
stationCacheInfoDto
.
setAreaCode
(
mapRegionList
.
stream
().
filter
(
mapRegion
->
mapRegion
.
getProvince
().
contains
(
stationCacheInfoDto
.
getBelongProvince
().
substring
(
0
,
2
))
||
mapRegion
.
getProvince
().
contains
(
stationCacheInfoDto
.
getBelongProvince
().
substring
(
0
,
3
))).
map
(
mapRegion
->
mapRegion
.
getAreaCode
()).
collect
(
Collectors
.
toList
()).
get
(
0
));
stationCacheInfoDto
.
setInstalledCapacity
(
String
.
format
(
"%.2f"
,
sjglZsjZsbtzMapper
.
getStationCapactityByStationWerks
(
stationBasic
.
getStationNumber
())));
List
<
StationCacheInfoDto
>
stationCacheInfoDto
s
=
new
ArrayList
<>(
);
stationCacheInfoDtos
=
redisTemplate
.
opsForList
().
range
(
"station_info_cache"
,
0
,
-
1
);
if
(
ObjectUtils
.
isEmpty
(
stationCacheInfoDtos
))
{
List
<
Region
>
regionList
=
regionMapper
.
selectList
(
new
QueryWrapper
<
Region
>().
eq
(
"LEVEL"
,
1
)
);
List
<
MapRegion
>
mapRegionList
=
mapRegionMapper
.
selectList
(
new
QueryWrapper
<
MapRegion
>().
isNotNull
(
"name"
));
List
<
StationBasic
>
stationBasicList
=
stationBasicMapper
.
selectList
(
new
QueryWrapper
<
StationBasic
>().
isNotNull
(
"belong_area"
).
isNotNull
(
"fan_gateway_id
"
));
for
(
int
i
=
0
;
i
<
stationBasicList
.
size
();
i
++)
{
StationBasic
stationBasic
=
stationBasicList
.
get
(
i
);
StationCacheInfoDto
stationCacheInfoDto
=
new
StationCacheInfoDto
();
stationCacheInfoDto
.
setStationId
(
stationBasic
.
getSequenceNbr
().
toString
());
stationCacheInfoDto
.
setStationName
(
stationBasic
.
getStationName
());
stationCacheInfoDto
.
setStationType
(
stationBasic
.
getStationType
());
stationCacheInfoDto
.
setBelongProvince
(
regionList
.
stream
().
filter
(
region
->
region
.
getRegionCode
().
toString
().
equals
(
stationBasic
.
getBelongArea
().
replace
(
"["
,
""
).
split
(
","
)[
0
])).
map
(
region
->
region
.
getRegionName
()).
collect
(
Collectors
.
toList
()).
get
(
0
));
stationCacheInfoDto
.
setBelongArea
(
mapRegionList
.
stream
().
filter
(
mapRegion
->
mapRegion
.
getProvince
().
contains
(
stationCacheInfoDto
.
getBelongProvince
().
substring
(
0
,
2
))
||
mapRegion
.
getProvince
().
contains
(
stationCacheInfoDto
.
getBelongProvince
().
substring
(
0
,
3
))).
map
(
mapRegion
->
mapRegion
.
getName
()).
collect
(
Collectors
.
toList
()).
get
(
0
));
stationCacheInfoDto
.
setInstalledCapacity
(
String
.
format
(
"%.2f"
,
sjglZsjZsbtzMapper
.
getStationCapactityByStationWerks
(
stationBasic
.
getStationNumber
())
));
try
{
List
<
QueryDto
>
queryDtoList
=
new
ArrayList
<>();
queryDtoList
.
add
(
new
QueryDto
(
"gatewayId"
,
stationBasic
.
getFanGatewayId
()));
queryDtoList
.
add
(
new
QueryDto
(
"equipmentIndexName.keyword"
,
"有功功率"
));
if
(!
stationBasic
.
getStationType
().
equals
(
"FDZ"
))
{
queryDtoList
.
add
(
new
QueryDto
(
"frontModule"
,
"逆变器"
));
}
stationCacheInfoDto
.
setEquipmentNumbers
(
this
.
getCount
(
queryDtoList
,
"equipmentNumber.Keyword"
,
ESEquipments
.
class
).
toString
());
stationCacheInfoDto
.
setFanGatewayId
(
stationBasic
.
getFanGatewayId
());
stationCacheInfoDto
.
setBoosterGatewayId
(
stationBasic
.
getBoosterGatewayId
());
stationCacheInfoDtos
.
add
(
stationCacheInfoDto
);
});
redisTemplate
.
opsForList
().
leftPushAll
(
"station_info_cache"
,
stationCacheInfoDtos
);
return
stationCacheInfoDtos
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
stationCacheInfoDto
.
setEquipmentNumbers
(
getCount
(
queryDtoList
,
"equipmentNumber.Keyword"
,
ESEquipments
.
class
).
toString
());
}
catch
(
Exception
exception
)
{
log
.
info
(
"--------------------查询ES错误---------------------------"
);
}
stationCacheInfoDto
.
setFanGatewayId
(
stationBasic
.
getFanGatewayId
());
stationCacheInfoDto
.
setBoosterGatewayId
(
stationBasic
.
getBoosterGatewayId
());
stationCacheInfoDtos
.
add
(
stationCacheInfoDto
);
}
redisTemplate
.
opsForList
().
leftPushAll
(
"station_info_cache"
,
stationCacheInfoDtos
);
}
return
stationCacheInfoDto
List
;
return
stationCacheInfoDto
s
;
}
/**
* @param stationId 场站id
* @return 缓存的场站对象
...
...
@@ -494,7 +496,6 @@ public class CommonServiceImpl {
}
/**
* 根据查询条件获取列表信息
*
...
...
@@ -502,7 +503,7 @@ public class CommonServiceImpl {
* @param shouldQuerCondtion
* @param tClass
* @param <T>
* @param likeMap 模糊字段查询 key:不能带.keyWords
* @param likeMap
模糊字段查询 key:不能带.keyWords
* @return
*/
public
<
T
>
List
<
T
>
getListDataByCondtionsAndLike
(
Map
<
String
,
List
<
String
>>
mustQuerCondtion
,
Map
<
String
,
String
>
shouldQuerCondtion
,
Class
<
T
>
tClass
,
Map
<
String
,
String
>
likeMap
)
{
...
...
@@ -539,7 +540,6 @@ public class CommonServiceImpl {
}
public
<
T
>
List
<
T
>
getListDataByCondtions
(
Map
<
String
,
List
<
String
>>
mustQuerCondtion
,
Map
<
String
,
String
>
shouldQuerCondtion
,
Map
<
String
,
String
>
notMustQuerCondtion
,
Class
<
T
>
tClass
)
{
BoolQueryBuilder
queryBuilder
=
QueryBuilders
.
boolQuery
();
if
(!
ObjectUtils
.
isEmpty
(
mustQuerCondtion
))
{
...
...
@@ -571,19 +571,20 @@ public class CommonServiceImpl {
}
return
null
;
}
public
Double
getAvagerByEquipmentIndxName
(
List
<
ESEquipments
>
equipments
,
String
indexName
)
{
Double
result
=
0.00
;
result
=
equipments
.
stream
().
filter
(
esEquipments
->
esEquipments
.
getEquipmentIndexName
().
equals
(
indexName
)).
filter
(
esEquipments
->
esEquipments
.
getValueF
()!=
null
).
mapToDouble
(
ESEquipments:
:
getValueF
).
average
().
getAsDouble
();
result
=
equipments
.
stream
().
filter
(
esEquipments
->
esEquipments
.
getEquipmentIndexName
().
equals
(
indexName
)).
filter
(
esEquipments
->
esEquipments
.
getValueF
()
!=
null
).
mapToDouble
(
ESEquipments:
:
getValueF
).
average
().
getAsDouble
();
return
result
;
}
public
Double
getSumByEquipmentIndxName
(
List
<
ESEquipments
>
equipments
,
String
indexName
)
{
Double
result
=
0.00
;
result
=
equipments
.
stream
().
filter
(
esEquipments
->
esEquipments
.
getEquipmentIndexName
().
equals
(
indexName
)).
filter
(
esEquipments
->
esEquipments
.
getValueF
()!=
null
).
mapToDouble
(
ESEquipments:
:
getValueF
).
sum
();
result
=
equipments
.
stream
().
filter
(
esEquipments
->
esEquipments
.
getEquipmentIndexName
().
equals
(
indexName
)).
filter
(
esEquipments
->
esEquipments
.
getValueF
()
!=
null
).
mapToDouble
(
ESEquipments:
:
getValueF
).
sum
();
return
result
;
}
public
<
T
>
List
<
T
>
getListDataByCondtions
(
Map
<
String
,
List
<
String
>>
mustQuerCondtion
,
Map
<
String
,
String
>
shouldQuerCondtion
,
Class
<
T
>
tClass
,
Map
<
String
,
String
>
likeQuerCondtion
)
{
public
<
T
>
List
<
T
>
getListDataByCondtions
(
Map
<
String
,
List
<
String
>>
mustQuerCondtion
,
Map
<
String
,
String
>
shouldQuerCondtion
,
Class
<
T
>
tClass
,
Map
<
String
,
String
>
likeQuerCondtion
)
{
BoolQueryBuilder
queryBuilder
=
QueryBuilders
.
boolQuery
();
if
(!
ObjectUtils
.
isEmpty
(
mustQuerCondtion
))
{
for
(
String
key
:
mustQuerCondtion
.
keySet
())
{
...
...
@@ -599,7 +600,7 @@ public class CommonServiceImpl {
if
(!
ObjectUtils
.
isEmpty
(
likeQuerCondtion
))
{
for
(
String
key
:
likeQuerCondtion
.
keySet
())
{
queryBuilder
.
must
(
QueryBuilders
.
wildcardQuery
(
key
,
"*"
+
likeQuerCondtion
.
get
(
key
)+
"*"
));
queryBuilder
.
must
(
QueryBuilders
.
wildcardQuery
(
key
,
"*"
+
likeQuerCondtion
.
get
(
key
)
+
"*"
));
}
}
Query
query
=
new
NativeSearchQueryBuilder
()
...
...
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