|
|
@@ -111,11 +111,17 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ AddFieldsOperation addFieldsOperation = Aggregation.addFields().addField("numValue")
|
|
|
+ .withValueOfExpression("{$convert: {input: '$eValue', to: 'double', onError: -99, onNull: -99}}").build();
|
|
|
MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
|
GroupOperation groupOperation = Aggregation.group("time")
|
|
|
+ .min("numValue").as("minValue")
|
|
|
.push("$$ROOT").as("data");
|
|
|
|
|
|
+ Criteria criteria2 = new Criteria().and("minValue").gt(-99);
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
+
|
|
|
ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
.and("_id").as("time")
|
|
|
.and("data").as("dataList");
|
|
|
@@ -124,7 +130,9 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
|
|
|
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
matchOperation,
|
|
|
+ addFieldsOperation,
|
|
|
groupOperation,
|
|
|
+ matchOperation2,
|
|
|
projectionOperationResult,
|
|
|
sortOperation
|
|
|
);
|
|
|
@@ -204,19 +212,25 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
|
|
|
.and("eName").as("eName")
|
|
|
.and("eNum").as("eNum")
|
|
|
.and("eKey").as("eKey")
|
|
|
+ .and("time").as("oldTime")
|
|
|
.andExpression("{$convert: {input: '$eValue', to: 'double', onError: -99, onNull: -99}}").as("eValue")
|
|
|
.andExpression("{$dateTrunc: {date: {$toDate: '$time'}, unit:'" + unit + "'}}").as("time");
|
|
|
|
|
|
- GroupOperation groupOperation = Aggregation.group("eName", "eNum", "eKey")
|
|
|
+ GroupOperation groupOperation1 = Aggregation.group("oldTime")
|
|
|
+ .min("eValue").as("minValue")
|
|
|
.push("$$ROOT").as("data");
|
|
|
|
|
|
- UnwindOperation unwindOperation = Aggregation.unwind("$data");
|
|
|
+ Criteria criteria2 = new Criteria().and("minValue").gt(-99);
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
+
|
|
|
+ UnwindOperation unwindOperation1 = Aggregation.unwind("$data");
|
|
|
+
|
|
|
GroupOperation groupOperation2 = Aggregation.group("data.eName", "data.eNum", "data.eKey", "data.time")
|
|
|
- .avg("data.eValue").as("eValue");
|
|
|
+ .avg("data.eValue").as("avgValue");
|
|
|
|
|
|
SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "_id.time");
|
|
|
JSONArray roundArray = new JSONArray();
|
|
|
- roundArray.add("$eValue");
|
|
|
+ roundArray.add("$avgValue");
|
|
|
roundArray.add(2);
|
|
|
Map<String, Object> roundMap = new HashMap<>();
|
|
|
roundMap.put("$round", roundArray);
|
|
|
@@ -227,14 +241,14 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
|
|
|
dateMap.put("$dateSubtract", new HashMap<String, Object>(){{
|
|
|
put("startDate", "$_id.time");
|
|
|
put("unit", "hour");
|
|
|
- put("amount", 8);
|
|
|
+ put("amount", -8);
|
|
|
}});
|
|
|
|
|
|
Map<String, Object> pushMap = new HashMap<>();
|
|
|
pushMap.put("number", pushMapStr);
|
|
|
pushMap.put("time", dateMap);
|
|
|
|
|
|
- GroupOperation groupOperation3 = Aggregation.group("_id.eName", "_id.eNum", "_id.eKey")
|
|
|
+ GroupOperation groupOperation4 = Aggregation.group("_id.eName", "_id.eNum", "_id.eKey")
|
|
|
.push(pushMap).as("dataList");
|
|
|
|
|
|
ProjectionOperation projectionOperation2 = Aggregation.project()
|
|
|
@@ -247,11 +261,12 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
matchOperation,
|
|
|
projectionOperation,
|
|
|
- groupOperation,
|
|
|
- unwindOperation,
|
|
|
+ groupOperation1,
|
|
|
+ matchOperation2,
|
|
|
+ unwindOperation1,
|
|
|
groupOperation2,
|
|
|
sortOperation,
|
|
|
- groupOperation3,
|
|
|
+ groupOperation4,
|
|
|
projectionOperation2,
|
|
|
sortOperation2
|
|
|
);
|
|
|
@@ -291,6 +306,7 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
|
|
|
.addField("eValueNum")
|
|
|
.withValueOfExpression("{$convert: {input: '$eValue', to: 'double', onError: -99, onNull: -99}}")
|
|
|
.build();
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(new Criteria().and("eValueNum").gt(-99));
|
|
|
|
|
|
SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "eValueNum");
|
|
|
|
|
|
@@ -321,6 +337,7 @@ public class IIotQxzCommService extends IotDeviceBaseServiceImpl implements IotD
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
matchOperation,
|
|
|
addFieldsOperation,
|
|
|
+ matchOperation2,
|
|
|
sortOperation,
|
|
|
groupOperation,
|
|
|
sortOperation2,
|