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

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

parent e94990e4
...@@ -1361,7 +1361,7 @@ public class CylinderInfoController extends BaseController { ...@@ -1361,7 +1361,7 @@ public class CylinderInfoController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "市级为维度,各市的充装次数和累计充装量") @ApiOperation(httpMethod = "GET", value = "市级为维度,各市的充装次数和累计充装量")
@GetMapping(value = "/countFillingTimesAndQuantityByCity") @GetMapping(value = "/countFillingTimesAndQuantityByCity")
public ResponseModel<Object> countFillingTimesAndQuantityByCity() { public ResponseModel<Map<String, Object>> countFillingTimesAndQuantityByCity() {
return ResponseHelper.buildResponse(cylinderInfoServiceImpl.countFillingTimesAndQuantityByCity()); return ResponseHelper.buildResponse(cylinderInfoServiceImpl.countFillingTimesAndQuantityByCity());
} }
} }
...@@ -1260,66 +1260,120 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind ...@@ -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<RegionModel> regionModelList = Systemctl.regionClient.queryByLevel("2").getResult();
// 并行处理每个城市的数据 // 并行处理每个城市的数据
List<CompletableFuture<Map<String, Object>>> futures = regionModelList.stream() List<CompletableFuture<Map<String, Object>>> futures = regionModelList.stream()
.map(regionModel -> CompletableFuture.supplyAsync(() -> esQuery(regionModel))) .map(regionModel -> CompletableFuture.supplyAsync(() -> esQuery(regionModel)))
.collect(Collectors.toList()); .collect(Collectors.toList());
return futures.stream() List<Map<String, Object>> collect = futures.stream()
.map(CompletableFuture::join) .map(CompletableFuture::join)
.collect(Collectors.toList()); .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) { private Map<String, Object> esQuery(RegionModel regionModel) {
SearchRequest searchRequest = new SearchRequest(INDEX_NAME); SearchRequest searchRequest = new SearchRequest(INDEX_NAME);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
// 将 regionModel.getRegionCode() 转换成匹配中间部分的格式 // 将 regionModel.getRegionCode() 转换成匹配中间部分的格式
String regionCodePattern = "*" + regionModel.getRegionCode() + "*"; String regionCodePattern = "*" + regionModel.getRegionCode() + "*";
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.wildcardQuery("regionCode", regionCodePattern)); boolQueryBuilder.must(QueryBuilders.wildcardQuery("regionCode", regionCodePattern));
searchSourceBuilder.query(boolQueryBuilder); searchSourceBuilder.query(boolQueryBuilder);
searchSourceBuilder.aggregation( searchSourceBuilder.aggregation(
AggregationBuilders.cardinality("total_filling_count") AggregationBuilders.cardinality("total_filling_count")
.field("sequenceNbr.keyword") .field("sequenceNbr")
); );
searchSourceBuilder.aggregation( searchSourceBuilder.aggregation(
AggregationBuilders.sum("total_filling_quantity") AggregationBuilders.sum("total_filling_quantity")
.field("fillingQuantity") .field("fillingQuantity")
); );
searchRequest.source(searchSourceBuilder); searchRequest.source(searchSourceBuilder);
System.out.println("Search Request: " + searchRequest); System.out.println("Search Request: " + searchRequest);
try { try {
// 执行搜索请求 // 执行搜索请求
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
// 获取所有聚合结果 // 获取所有聚合结果
Aggregations aggregations = searchResponse.getAggregations(); Aggregations aggregations = searchResponse.getAggregations();
ParsedCardinality cardinalityAgg = aggregations.get("total_filling_count"); ParsedCardinality cardinalityAgg = aggregations.get("total_filling_count");
long uniqueCount = cardinalityAgg.getValue(); long uniqueCount = cardinalityAgg.getValue();
Sum sumAgg = aggregations.get("total_filling_quantity"); Sum sumAgg = aggregations.get("total_filling_quantity");
double totalSum = sumAgg.getValue(); double totalSum = sumAgg.getValue();
System.out.println("填充数量的唯一值数量: " + uniqueCount); System.out.println("填充数量的唯一值数量: " + uniqueCount);
System.out.println("填充量的总和: " + totalSum); System.out.println("填充量的总和: " + totalSum);
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
resultMap.put(REGION_CODE, regionModel.getRegionCode()); resultMap.put(REGION_CODE, regionModel.getRegionCode());
resultMap.put(REGION_NAME, regionModel.getRegionName()); resultMap.put(REGION_NAME, regionModel.getRegionName());
resultMap.put(FILLING_TIMES, uniqueCount); resultMap.put(FILLING_TIMES, uniqueCount);
resultMap.put(FILLING_QUANTITY, totalSum); resultMap.put(FILLING_QUANTITY, totalSum);
return resultMap; return resultMap;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -19,12 +19,12 @@ eureka.client.service-url.defaultZone=http://172.16.10.243:10001/eureka/ ...@@ -19,12 +19,12 @@ eureka.client.service-url.defaultZone=http://172.16.10.243:10001/eureka/
eureka.instance.prefer-ip-address=true eureka.instance.prefer-ip-address=true
management.endpoint.health.show-details=always management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=* 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.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.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.17:${server.port}${server.servlet.context-path}/doc\ eureka.instance.metadata-map.management.api-docs=http://172.16.3.68:${server.port}${server.servlet.context-path}/doc\
.html .html
eureka.instance.ip-address=172.16.3.17 eureka.instance.ip-address=172.16.3.68
## ES properties: ## ES properties:
elasticsearch.username=elastic elasticsearch.username=elastic
elasticsearch.password=a123456 elasticsearch.password=a123456
......
spring.application.name=TZS-CYLINDER spring.application.name=TZS-CYLINDER-htt
server.servlet.context-path=/cylinder server.servlet.context-path=/cylinder
server.port=11003 server.port=11003
spring.profiles.active=cyl 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