Commit 236c5212 authored by 韩桐桐's avatar 韩桐桐

fix(cyl):市级为维度,各市的充装次数和累计充装量

parent e94990e4
......@@ -1361,7 +1361,7 @@ public class CylinderInfoController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "市级为维度,各市的充装次数和累计充装量")
@GetMapping(value = "/countFillingTimesAndQuantityByCity")
public ResponseModel<Object> countFillingTimesAndQuantityByCity() {
public ResponseModel<Map<String, Object>> countFillingTimesAndQuantityByCity() {
return ResponseHelper.buildResponse(cylinderInfoServiceImpl.countFillingTimesAndQuantityByCity());
}
}
......@@ -1260,66 +1260,120 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
public List<Map<String, Object>> countFillingTimesAndQuantityByCity() {
public Map<String, Object> countFillingTimesAndQuantityByCity() {
// 查询所有的市级城市
List<RegionModel> regionModelList = Systemctl.regionClient.queryByLevel("2").getResult();
// 并行处理每个城市的数据
List<CompletableFuture<Map<String, Object>>> futures = regionModelList.stream()
.map(regionModel -> CompletableFuture.supplyAsync(() -> esQuery(regionModel)))
.collect(Collectors.toList());
return futures.stream()
List<Map<String, Object>> collect = futures.stream()
.map(CompletableFuture::join)
.collect(Collectors.toList());
return assemblingHistogramData(collect);
// Map<String, Object> stringObjectMap = esQuery(regionModelList.get(3));
// ArrayList<Map<String, Object>> ss = new ArrayList<>();
// ss.add(stringObjectMap);
// return assemblingHistogramData(ss);
}
private static Map<String, Object> assemblingHistogramData(List<Map<String, Object>> collect) {
// 组装数据
// {
// "seriesData": [
// {
// "data": [
// 3,
// 2,
// 2,
// 3,
// 1
// ],
// "name": "正常点",
// "stack": "正常点"
// },
// {
// "data": [
// 1,
// 1,
// 2,
// 1,
// 2
// ],
// "name": "异常点",
// "stack": "巡检点"
// }
// ],
// "axisData": [
// "A",
// "B",
// "C",
// "D",
// "E"
// ]
// }
Map<String, Object> result = new HashMap<>();
List<Map<String, Object>> seriesData = new ArrayList<>();
List<String> axisData = new ArrayList<>();
List<String> seriesFillingTimesDataList = new ArrayList<>();
List<String> seriesCumulativeFillingQuantityDataList = new ArrayList<>();
collect.forEach(x->{
axisData.add(String.valueOf(x.get("regionName")));
seriesFillingTimesDataList.add(String.valueOf(x.get("fillingTimes")));
seriesCumulativeFillingQuantityDataList.add(String.valueOf(x.get("fillingQuantity")));
});
HashMap<String, Object> temMap1 = new HashMap<>();
temMap1.put("data",seriesFillingTimesDataList);
temMap1.put("name","充装次数");
temMap1.put("stack","充装次数");
HashMap<String, Object> temMap2 = new HashMap<>();
temMap2.put("data",seriesCumulativeFillingQuantityDataList);
temMap2.put("name","累计充装量");
temMap2.put("stack","累计充装量");
seriesData.add(temMap1);
seriesData.add(temMap2);
result.put("seriesData",seriesData);
result.put("axisData",axisData);
return result;
}
private Map<String, Object> esQuery(RegionModel regionModel) {
SearchRequest searchRequest = new SearchRequest(INDEX_NAME);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
// 将 regionModel.getRegionCode() 转换成匹配中间部分的格式
String regionCodePattern = "*" + regionModel.getRegionCode() + "*";
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.wildcardQuery("regionCode", regionCodePattern));
searchSourceBuilder.query(boolQueryBuilder);
searchSourceBuilder.aggregation(
AggregationBuilders.cardinality("total_filling_count")
.field("sequenceNbr.keyword")
.field("sequenceNbr")
);
searchSourceBuilder.aggregation(
AggregationBuilders.sum("total_filling_quantity")
.field("fillingQuantity")
);
searchRequest.source(searchSourceBuilder);
System.out.println("Search Request: " + searchRequest);
try {
// 执行搜索请求
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
// 获取所有聚合结果
Aggregations aggregations = searchResponse.getAggregations();
ParsedCardinality cardinalityAgg = aggregations.get("total_filling_count");
long uniqueCount = cardinalityAgg.getValue();
Sum sumAgg = aggregations.get("total_filling_quantity");
double totalSum = sumAgg.getValue();
System.out.println("填充数量的唯一值数量: " + uniqueCount);
System.out.println("填充量的总和: " + totalSum);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put(REGION_CODE, regionModel.getRegionCode());
resultMap.put(REGION_NAME, regionModel.getRegionName());
resultMap.put(FILLING_TIMES, uniqueCount);
resultMap.put(FILLING_QUANTITY, totalSum);
return resultMap;
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -19,12 +19,12 @@ eureka.client.service-url.defaultZone=http://172.16.10.243:10001/eureka/
eureka.instance.prefer-ip-address=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*
eureka.instance.health-check-url=http://172.16.3.17:${server.port}${server.servlet.context-path}/actuator/health
eureka.instance.health-check-url=http://172.16.3.68:${server.port}${server.servlet.context-path}/actuator/health
eureka.instance.metadata-map.management.context-path=${server.servlet.context-path}/actuator
eureka.instance.status-page-url=http://172.16.3.17:${server.port}${server.servlet.context-path}/actuator/info
eureka.instance.metadata-map.management.api-docs=http://172.16.3.17:${server.port}${server.servlet.context-path}/doc\
eureka.instance.status-page-url=http://172.16.3.68:${server.port}${server.servlet.context-path}/actuator/info
eureka.instance.metadata-map.management.api-docs=http://172.16.3.68:${server.port}${server.servlet.context-path}/doc\
.html
eureka.instance.ip-address=172.16.3.17
eureka.instance.ip-address=172.16.3.68
## ES properties:
elasticsearch.username=elastic
elasticsearch.password=a123456
......
spring.application.name=TZS-CYLINDER
spring.application.name=TZS-CYLINDER-htt
server.servlet.context-path=/cylinder
server.port=11003
spring.profiles.active=cyl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment