Commit 8032d5fff36a9ee4236d0dc16931b75278a022ce
1 parent
36d70ce8d2
Exists in
master
and in
6 other branches
健康统计-统计
Showing 1 changed file with 25 additions and 6 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AreaCountFacade.java
View file @
8032d5f
... | ... | @@ -36,18 +36,25 @@ |
36 | 36 | import org.springframework.beans.factory.annotation.Qualifier; |
37 | 37 | import org.springframework.data.domain.Sort; |
38 | 38 | import org.springframework.data.mongodb.core.MongoTemplate; |
39 | +import org.springframework.data.mongodb.core.aggregation.Aggregation; | |
40 | +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; | |
41 | +import org.springframework.data.mongodb.core.aggregation.AggregationResults; | |
39 | 42 | import org.springframework.data.mongodb.core.query.Criteria; |
40 | 43 | import org.springframework.data.mongodb.core.query.Query; |
41 | 44 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
42 | 45 | import org.springframework.stereotype.Component; |
43 | 46 | |
44 | 47 | import javax.servlet.http.HttpServletResponse; |
45 | -import java.time.*; | |
48 | +import java.time.Instant; | |
49 | +import java.time.LocalDate; | |
50 | +import java.time.ZoneId; | |
46 | 51 | import java.time.temporal.TemporalAdjusters; |
47 | 52 | import java.util.*; |
48 | 53 | import java.util.concurrent.*; |
49 | 54 | |
55 | +import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; | |
50 | 56 | |
57 | + | |
51 | 58 | /** |
52 | 59 | * |
53 | 60 | * 区域统计 |
... | ... | @@ -1412,7 +1419,7 @@ |
1412 | 1419 | hospitalIds = getCurrentUserHospPermissions(query.getUserId(), StringUtils.isEmpty(provinceId) ? null : provinceId, StringUtils.isEmpty(cityId) ? null : cityId, |
1413 | 1420 | StringUtils.isEmpty(areaId) ? null : areaId); |
1414 | 1421 | } |
1415 | - if (CollectionUtils.isNotEmpty(hospitalIds)){ | |
1422 | + if (CollectionUtils.isEmpty(hospitalIds)){ | |
1416 | 1423 | return baseResponse; |
1417 | 1424 | } |
1418 | 1425 | |
1419 | 1426 | |
1420 | 1427 | |
1421 | 1428 | |
... | ... | @@ -1439,13 +1446,25 @@ |
1439 | 1446 | healthChargeQuery.setHospitalIds(hospitalIds); |
1440 | 1447 | } |
1441 | 1448 | |
1442 | - List<HealthChargeModel> list = healthChargeService.queryHealthChargeList(healthChargeQuery); | |
1449 | + AggregationOperation match = Aggregation.match(healthChargeQuery.convertToQuery().getCriteria()); | |
1450 | + AggregationOperation group = Aggregation.group("day","month","year","healthType").count().as("count"); | |
1451 | + AggregationOperation month = project(). | |
1452 | + andExpression("dayOfMonth(created)").as("day"). | |
1453 | + andExpression("month(created)").as("month"). | |
1454 | + andExpression("year(created)").as("year"). | |
1455 | + andExpression("healthType").as("healthType"); | |
1456 | + Aggregation aggregation = Aggregation.newAggregation(match, month, group ); | |
1457 | + AggregationResults<HashMap> result = mongoTemplate.aggregate(aggregation, "lyms_health_charge", HashMap.class); | |
1458 | + List<HashMap> mappedResults = result.getMappedResults(); | |
1443 | 1459 | |
1460 | + AggregationOperation group2 = Aggregation.group("healthType").count().as("count"); | |
1461 | + Aggregation aggregation2 = Aggregation.newAggregation(match, group2 ); | |
1462 | + AggregationResults<HashMap> result2 = mongoTemplate.aggregate(aggregation2, "lyms_health_charge", HashMap.class); | |
1463 | + List<HashMap> mappedResults2 = result2.getMappedResults(); | |
1444 | 1464 | |
1465 | + baseResponse.setObject(mappedResults2); | |
1445 | 1466 | |
1446 | - | |
1447 | - | |
1448 | - return null; | |
1467 | + return baseResponse; | |
1449 | 1468 | } |
1450 | 1469 | } |