|
|
@@ -481,21 +481,29 @@ public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
|
.and("pestrecog.pestrecogNum").as("pestrecogNum")
|
|
|
.and("pestrecog.pestrecogCreatedDate").as("pestrecogCreatedDate");
|
|
|
|
|
|
- SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "pestrecogCreatedDate");
|
|
|
|
|
|
- Map<String, String> dataMap = new HashMap<>();
|
|
|
- dataMap.put("pestrecogNum", "$pestrecogNum");
|
|
|
- dataMap.put("pestrecogCreatedDate", "$pestrecogCreatedDate");
|
|
|
+ GroupOperation groupOperation = Aggregation.group("pestrecogCreatedDate")
|
|
|
+ .sum("pestrecogNum").as("pestrecogNum")
|
|
|
+ .first("$$ROOT").as("data");
|
|
|
|
|
|
- GroupOperation groupOperation = Aggregation.group()
|
|
|
- .first("pestName").as("pestName")
|
|
|
- .push(dataMap).as("dataList");
|
|
|
+ FacetOperation facetOperation = Aggregation.facet()
|
|
|
+ .and(Aggregation.sort(Sort.Direction.ASC, "_id"), Aggregation.limit(1)).as("seeTimesData")
|
|
|
+ .and(Aggregation.sort(Sort.Direction.DESC, "_id"), Aggregation.limit(1)).as("endInPeriodData")
|
|
|
+ .and(Aggregation.sort(Sort.Direction.DESC, "pestrecogNum"), Aggregation.limit(1)).as("fastigiumData");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation3 = Aggregation.project()
|
|
|
+ .andExpression("{'$first': '$seeTimesData'}").as("seeTimesData")
|
|
|
+ .andExpression("{'$first': '$endInPeriodData'}").as("endInPeriodData")
|
|
|
+ .andExpression("{'$first': '$fastigiumData'}").as("fastigiumData");
|
|
|
|
|
|
ProjectionOperation projectionOperationResult = Aggregation.project()
|
|
|
- .and("pestName").as("pestName")
|
|
|
- .andExpression("{'$substrBytes': {{'$first': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("seeTimes")
|
|
|
- .andExpression("{'$substrBytes': {{'$last': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("endInPeriod")
|
|
|
- .andExpression("{'$substrBytes': {{'$max': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("fastigium");
|
|
|
+ .andExpression("{'$substrBytes': {'$seeTimesData.data.pestrecogCreatedDate', 0, 10}}").as("seeTimes")
|
|
|
+ .andExpression("{'$substrBytes': {'$endInPeriodData.data.pestrecogCreatedDate', 0, 10}}").as("endInPeriod")
|
|
|
+ .andExpression("{'$substrBytes': {'$fastigiumData.data.pestrecogCreatedDate', 0, 10}}").as("fastigium")
|
|
|
+ .and("seeTimesData.data.pestrecogNum").as("seeTimesNum")
|
|
|
+ .and("endInPeriodData.data.pestrecogNum").as("endInPeriodNum")
|
|
|
+ .and("fastigiumData.data.pestrecogNum").as("fastigiumNum")
|
|
|
+ .and("seeTimesData.data.pestName").as("pestName");
|
|
|
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
matchOperation,
|
|
|
@@ -503,8 +511,9 @@ public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
|
unwindOperation,
|
|
|
matchOperation2,
|
|
|
projectionOperation2,
|
|
|
- sortOperation,
|
|
|
groupOperation,
|
|
|
+ facetOperation,
|
|
|
+ projectionOperation3,
|
|
|
projectionOperationResult
|
|
|
);
|
|
|
List<IotPestRecogPeriodInfoResVo> infoResVoList = mongoService.aggregate(
|