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
01d6caa2
Commit
01d6caa2
authored
Jul 09, 2025
by
tianyiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 优化统计分析查询逻辑
parent
dc62d3c0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
45 deletions
+45
-45
EquipAdvanceSearchEnum.java
...t/module/statistics/api/enums/EquipAdvanceSearchEnum.java
+2
-2
ComprehensiveStatisticalAnalysisServiceImpl.java
...ice/impl/ComprehensiveStatisticalAnalysisServiceImpl.java
+43
-43
No files found.
amos-boot-system-tzs/amos-boot-module-statistics/amos-boot-module-statistics-api/src/main/java/com/yeejoin/amos/boot/module/statistics/api/enums/EquipAdvanceSearchEnum.java
View file @
01d6caa2
...
...
@@ -26,7 +26,7 @@ public enum EquipAdvanceSearchEnum {
QZ_OR_TANK
(
"是否车用气瓶"
,
"WHETHER_VEHICLE_CYLINDER"
,
null
,
"/statistics/comprehensiveStatisticalAnalysis/select/qzOrTank"
,
null
,
null
),
// IS_SUPERVISORY_CODE("赋码状态", "IS_SUPERVISORY_CODE", null,"/statistics/comprehensiveStatisticalAnalysis/select/queryIsSupervisoryCode",null,null),
DATA_QUALITY_SCORE
(
"数据完整性"
,
"DATA_QUALITY_SCORE"
,
null
,
"/statistics/comprehensiveStatisticalAnalysis/select/queryDataQualityScore"
,
null
,
null
),
US
C_DATE
(
"使用年限"
,
"USC
_DATE"
,
null
,
"/statistics/comprehensiveStatisticalAnalysis/select/queryUscDate"
,
null
,
null
),
US
E_DATE
(
"使用年限"
,
"USE
_DATE"
,
null
,
"/statistics/comprehensiveStatisticalAnalysis/select/queryUscDate"
,
null
,
null
),
// UNIT_TYPE("所属单位类型", "unitType", null,"/statistics/comprehensiveStatisticalAnalysis/select/queryUnitType",null,null),
USC_UNIT_NAME
(
"所属单位名称"
,
"USC_UNIT_NAME"
,
TechnicalParameter
.
ParamType
.
STRING
,
""
,
null
,
null
),
PRODUCE_UNIT_NAME
(
"制造单位名称"
,
"PRODUCE_UNIT_NAME"
,
TechnicalParameter
.
ParamType
.
STRING
,
""
,
null
,
null
),
...
...
@@ -38,7 +38,7 @@ public enum EquipAdvanceSearchEnum {
EQU_TYPE
(
"设备型号"
,
"EQU_TYPE"
,
TechnicalParameter
.
ParamType
.
STRING
,
""
,
null
,
null
),
PRODUCE_DATE
(
"制造日期"
,
"PRODUCE_DATE"
,
TechnicalParameter
.
ParamType
.
DATE
,
""
,
null
,
null
),
designDate
(
"设计日期"
,
"designDate"
,
TechnicalParameter
.
ParamType
.
DATE
,
""
,
null
,
null
),
us
c_date
(
"投用如期"
,
"USC
_DATE"
,
TechnicalParameter
.
ParamType
.
DATE
,
""
,
null
,
null
),
us
e_date
(
"投用如期"
,
"USE
_DATE"
,
TechnicalParameter
.
ParamType
.
DATE
,
""
,
null
,
null
),
ISSUE_DATE
(
"使用登记证日期"
,
"issueDate"
,
TechnicalParameter
.
ParamType
.
DATE
,
""
,
null
,
null
),
JDJY
(
"监督检验日期"
,
"JDJY"
,
TechnicalParameter
.
ParamType
.
DATE
,
""
,
null
,
null
),
DQJY
(
"定期检验日期"
,
"DQJY"
,
TechnicalParameter
.
ParamType
.
DATE
,
""
,
null
,
null
),
...
...
amos-boot-system-tzs/amos-boot-module-statistics/amos-boot-module-statistics-biz/src/main/java/com/yeejoin/amos/boot/module/statistcs/biz/service/impl/ComprehensiveStatisticalAnalysisServiceImpl.java
View file @
01d6caa2
...
...
@@ -17,7 +17,6 @@ import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import
com.yeejoin.amos.boot.module.common.api.dto.TechParamItem
;
import
com.yeejoin.amos.boot.module.common.api.entity.ESEquipmentInfo
;
import
com.yeejoin.amos.boot.module.common.biz.utils.TechParamUtil
;
import
com.yeejoin.amos.boot.module.jg.api.enums.DPMapStatisticsItemEnum
;
import
com.yeejoin.amos.boot.module.statistcs.biz.utils.JsonUtils
;
import
com.yeejoin.amos.boot.module.statistcs.biz.utils.MinioUtils
;
import
com.yeejoin.amos.boot.module.statistcs.factory.DynamicQueryBuilder
;
...
...
@@ -47,6 +46,9 @@ import org.elasticsearch.index.query.NestedQueryBuilder;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.index.query.TermsQueryBuilder
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.aggregations.AggregationBuilders
;
import
org.elasticsearch.search.aggregations.bucket.nested.ParsedNested
;
import
org.elasticsearch.search.aggregations.metrics.ParsedSum
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.sort.FieldSortBuilder
;
import
org.elasticsearch.search.sort.SortBuilders
;
...
...
@@ -504,16 +506,16 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
if
(
v
instanceof
JSONArray
)
{
if
(!((
JSONArray
)
v
).
contains
(
"all"
)
&&
((
JSONArray
)
v
).
size
()
>
0
)
{
String
field
=
k
;
if
(
k
.
equals
(
"unitCategory"
))
{
if
(!
ObjectUtils
.
isEmpty
(
v
)
&&
((
JSONArray
)
v
).
size
()
==
1
)
{
String
category
=
((
JSONArray
)
v
).
get
(
0
).
toString
();
JSONArray
unitTypeByType
=
UnitTypeNewEnum
.
getUnitTypeByType
(
category
);
List
<
String
>
list
=
unitTypeByType
.
stream
().
map
(
e
->
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
e
)).
get
(
"value"
).
toString
()).
collect
(
Collectors
.
toList
());
list
.
forEach
(
item
->
boolMust
.
should
(
QueryBuilders
.
wildcardQuery
(
"unitType.keyword"
,
"*"
+
item
+
"*"
)).
minimumShouldMatch
(
1
));
}
}
else
if
(
k
.
equals
(
"regulatoryLabels"
)
||
k
.
equals
(
"equipCategory"
)
||
k
.
equals
(
"unitType"
))
{
if
(
k
.
equals
(
"regulatoryLabels"
)
||
k
.
equals
(
"equipCategory"
)
||
k
.
equals
(
"unitType"
))
{
boolMust
.
must
(
existsQuery
(
field
));
((
JSONArray
)
v
).
forEach
(
item
->
boolMust
.
should
(
QueryBuilders
.
wildcardQuery
(
field
+
".keyword"
,
"*"
+
item
+
"*"
)).
minimumShouldMatch
(
1
));
EnhancedDynamicQueryBuilder
enhancedDynamicQueryBuilder
=
new
EnhancedDynamicQueryBuilder
();
((
JSONArray
)
v
).
forEach
(
item
->
{
if
(
k
.
equals
(
"unitType"
)
&&
item
.
equals
(
"企业"
))
{
item
=
"使用单位"
;
}
enhancedDynamicQueryBuilder
.
add
(
QueryBuilders
.
wildcardQuery
(
field
+
".keyword"
,
"*"
+
item
+
"*"
),
or
);
});
boolMust
.
should
(
enhancedDynamicQueryBuilder
.
build
()).
minimumShouldMatch
(
1
);
}
else
if
(
k
.
equals
(
"industrySupervisor"
)
||
k
.
equals
(
"operatingStatus"
))
{
boolMust
.
must
(
existsQuery
(
field
));
TermsQueryBuilder
termsQuery
=
QueryBuilders
.
termsQuery
(
field
+
".keyword"
,
((
JSONArray
)
v
).
get
(
0
));
...
...
@@ -564,9 +566,16 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
if
(
k
.
equals
(
"fuzzyInput"
))
{
String
fuzzyValue
=
String
.
valueOf
(
v
);
BoolQueryBuilder
queryBuilder
=
QueryBuilders
.
boolQuery
();
queryBuilder
.
should
(
QueryBuilders
.
wildcardQuery
(
"useUnit"
,
"*"
+
fuzzyValue
+
"*"
));
queryBuilder
.
should
(
QueryBuilders
.
wildcardQuery
(
"useUnit
.keyword
"
,
"*"
+
fuzzyValue
+
"*"
));
queryBuilder
.
minimumShouldMatch
(
1
);
boolMust
.
must
(
queryBuilder
);
}
else
if
(
k
.
equals
(
"unitCategory"
))
{
if
(!
""
.
equals
(
v
)
&&
!
ObjectUtils
.
isEmpty
(
v
))
{
String
category
=
v
.
toString
();
JSONArray
unitTypeByType
=
UnitTypeNewEnum
.
getUnitTypeByType
(
category
);
List
<
String
>
list
=
unitTypeByType
.
stream
().
map
(
e
->
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
e
)).
get
(
"value"
).
toString
()).
collect
(
Collectors
.
toList
());
list
.
forEach
(
item
->
boolMust
.
should
(
QueryBuilders
.
wildcardQuery
(
"unitType.keyword"
,
"*"
+
(
item
.
equals
(
"企业"
)
?
"使用单位"
:
item
)
+
"*"
)).
minimumShouldMatch
(
1
));
}
}
}
});
...
...
@@ -710,7 +719,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
}
});
boolMust
.
must
(
queryBuilder
.
build
());
}
else
if
(
k
.
equals
(
"PRODUCE_DATE"
)
||
k
.
equals
(
"issueDate"
)
||
k
.
equals
(
"designDate"
)
||
k
.
equals
(
"nextInspectDate"
)
||
k
.
equals
(
"US
C
_DATE"
))
{
}
else
if
(
k
.
equals
(
"PRODUCE_DATE"
)
||
k
.
equals
(
"issueDate"
)
||
k
.
equals
(
"designDate"
)
||
k
.
equals
(
"nextInspectDate"
)
||
k
.
equals
(
"US
E
_DATE"
))
{
field
=
k
.
equals
(
"nextInspectDate"
)
?
"NEXT_INSPECT_DATE"
:
k
;
JSONArray
dates
=
(
JSONArray
)
v
;
String
startDate
=
dates
.
getString
(
0
);
...
...
@@ -871,23 +880,15 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
JSONArray
equList
=
(
JSONArray
)
filterParams
.
get
(
"EQU_LIST"
);
if
(
ObjectUtils
.
isEmpty
(
equList
)
||
equList
.
contains
(
"8000"
)
||
equList
.
contains
(
"all"
))
{
// 获取压力管道长度
// 压力管道长度
Map
<
String
,
Object
>
pipeMaps
=
new
HashMap
<>();
stCommonService
.
staticsCenterMapCountDataForPipeline
(
pipeMaps
,
orgCode
,
true
,
false
);
// 获取压力管道长度
// BigDecimal pipeLength = getPipeLength(boolMust, builder);
BigDecimal
pipeLength
=
getPipeLength
(
boolMust
,
builder
);
Map
<
String
,
Object
>
pipeMap
=
new
HashMap
<>();
pipeMap
.
put
(
"name"
,
"压力管道(千米)"
);
pipeMap
.
put
(
"value"
,
pipe
Maps
.
get
(
"pressurePipelines"
));
pipeMap
.
put
(
"value"
,
pipe
Length
.
divide
(
new
BigDecimal
(
1000
),
4
,
BigDecimal
.
ROUND_HALF_UP
));
statics
.
add
(
pipeMap
);
}
if
(
ObjectUtils
.
isEmpty
(
equList
)
||
equList
.
contains
(
"2000"
)
||
equList
.
contains
(
"all"
))
{
// 气瓶数量
Map
<
String
,
Object
>
gasMap
=
new
HashMap
<>();
gasMap
.
put
(
"name"
,
"气瓶(个)"
);
Map
<
String
,
Object
>
gas
=
new
HashMap
<>();
gas
.
put
(
DPMapStatisticsItemEnum
.
GAS
.
getCode
(),
0
);
CountRequest
countRequest
=
new
CountRequest
();
countRequest
.
indices
(
StatisticalAnalysisEnum
.
equip
.
getKey
());
boolMust
.
must
(
QueryBuilders
.
termQuery
(
"EQU_CATEGORY_CODE"
,
"2300"
));
...
...
@@ -898,7 +899,10 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
gasMap
.
put
(
"value"
,
response
.
getCount
());
Map
<
String
,
Object
>
gasMap
=
new
HashMap
<>();
gasMap
.
put
(
"name"
,
"气瓶(个)"
);
gasMap
.
put
(
"value"
,
ObjectUtils
.
isEmpty
(
response
)
?
0
:
response
.
getCount
());
statics
.
add
(
gasMap
);
}
result
.
put
(
"statics"
,
statics
);
...
...
@@ -908,28 +912,24 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
private
BigDecimal
getPipeLength
(
BoolQueryBuilder
boolMust
,
SearchSourceBuilder
builder
)
{
SearchRequest
request
=
new
SearchRequest
();
request
.
indices
(
StatisticalAnalysisEnum
.
equip
.
getKey
());
BigDecimal
pipeLong
=
BigDecimal
.
ZERO
;
builder
.
query
(
boolMust
);
builder
.
from
(
0
);
builder
.
size
(
1000000
);
BigDecimal
pipeLong
;
NestedQueryBuilder
nestedQueryBuilder
=
QueryBuilders
.
nestedQuery
(
"techParams"
,
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
termsQuery
(
"techParams.paramKey"
,
"pipeLength"
)),
ScoreMode
.
None
);
boolMust
.
must
(
nestedQueryBuilder
);
builder
.
query
(
boolMust
).
aggregation
(
AggregationBuilders
.
nested
(
"longPipe"
,
"techParams"
).
subAggregation
(
AggregationBuilders
.
sum
(
"pipeLength"
).
field
(
"techParams.doubleValue"
)
)
);
request
.
source
(
builder
);
try
{
SearchResponse
response
=
restHighLevelClient
.
search
(
request
,
RequestOptions
.
DEFAULT
);
for
(
SearchHit
hit
:
response
.
getHits
().
getHits
())
{
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
hit
);
JSONObject
dto
=
jsonObject
.
getJSONObject
(
"sourceAsMap"
);
if
(
dto
.
get
(
"EQU_LIST_CODE"
).
equals
(
"8000"
))
{
JSONArray
techParams
=
(
JSONArray
)
dto
.
get
(
"techParams"
);
if
(!
ObjectUtils
.
isEmpty
(
techParams
))
{
Object
obj
=
techParams
.
stream
().
filter
(
item
->
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
item
)).
get
(
"paramKey"
).
equals
(
"pipeLength"
)).
findFirst
().
get
();
JSONObject
jsonParam
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
obj
));
if
(
jsonParam
.
containsKey
(
"doubleValue"
))
{
String
pipeLength
=
jsonParam
.
get
(
"doubleValue"
).
toString
();
pipeLong
=
pipeLong
.
add
(
new
BigDecimal
(
pipeLength
));
}
}
}
}
ParsedSum
sumAgg
=
((
ParsedNested
)
response
.
getAggregations
()
.
get
(
"longPipe"
))
.
getAggregations
()
.
get
(
"pipeLength"
);
double
value
=
sumAgg
.
getValue
();
pipeLong
=
new
BigDecimal
(
value
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
@@ -1503,7 +1503,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
builder
.
add
(
QueryBuilders
.
boolQuery
().
filter
(
QueryBuilders
.
rangeQuery
(
field
).
lt
(
LocalDate
.
now
().
plusDays
(
30
).
format
(
formatter
))),
isOr
);
}
}
}
else
if
(
field
.
equals
(
"US
C
_DATE"
))
{
}
else
if
(
field
.
equals
(
"US
E
_DATE"
))
{
if
(
value
.
equals
(
"15"
))
{
// 15年以上:大于当前日期减去15年
if
(
itemCondition
.
equals
(
"eq"
)
||
itemCondition
.
equals
(
"in"
))
{
...
...
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