|
@@ -17,10 +17,12 @@ import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceBaseService;
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceBaseService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.impl.IotDeviceBaseServiceImpl;
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.impl.IotDeviceBaseServiceImpl;
|
|
|
import com.yunfeiyun.agmp.iotm.device.qxz.domain.IotDeviceQxzDataListReqVo;
|
|
import com.yunfeiyun.agmp.iotm.device.qxz.domain.IotDeviceQxzDataListReqVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.qxz.domain.QxzDataLast24hDto;
|
|
|
import com.yunfeiyun.agmp.iotm.util.MongoUtil;
|
|
import com.yunfeiyun.agmp.iotm.util.MongoUtil;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDevicefactorService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDevicefactorService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.mongodb.core.aggregation.*;
|
|
import org.springframework.data.mongodb.core.aggregation.*;
|
|
@@ -200,4 +202,90 @@ public class IotYfQxzServiceImpl extends IotDeviceBaseServiceImpl implements Iot
|
|
|
List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzChartProcessData(dataList, factorList, findDevice, false);
|
|
List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzChartProcessData(dataList, factorList, findDevice, false);
|
|
|
return iotQxzDataListRseVoList;
|
|
return iotQxzDataListRseVoList;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取24小时数据列表接口
|
|
|
|
|
+ * @param reqVo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<IotQxzDataListRseVo> dataList24h(IotDeviceQxzDataListReqVo reqVo){
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+ long endTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.dateNow()).getTime();
|
|
|
|
|
+ long begintime = endTime-86400000;
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
|
|
+
|
|
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
|
|
+ criteria = criteria.andOperator(
|
|
|
|
|
+ Criteria.where("time").gte(new Date(begintime)),
|
|
|
|
|
+ Criteria.where("time").lte(new Date(endTime))
|
|
|
|
|
+ );
|
|
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
+ AddFieldsOperation addFieldsOperation = Aggregation.addFields()
|
|
|
|
|
+ .addField("eValueNum")
|
|
|
|
|
+ .withValueOfExpression("{$convert: {input: '$eValue', to: 'double', onError: -99, onNull: -99}}")
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "eValueNum");
|
|
|
|
|
+
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group("eNum", "eName", "eKey")
|
|
|
|
|
+ .push("$$ROOT").as("data");
|
|
|
|
|
+ SortOperation sortOperation2 = Aggregation.sort(Sort.Direction.ASC, "data.eValueNum")
|
|
|
|
|
+ .and(Sort.Direction.ASC, "data.time");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
|
|
+ .and("_id").as("elem")
|
|
|
|
|
+ .andExpression("{$last: '$data'}").as("max_data")
|
|
|
|
|
+ .andExpression("{$first: '$data'}").as("min_data");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperationResult2 = Aggregation.project("_id")
|
|
|
|
|
+ .and("elem").as("elem")
|
|
|
|
|
+ .and("elem.eNum").as("eNum")
|
|
|
|
|
+ .and("elem.eName").as("eName")
|
|
|
|
|
+ .and("elem.eKey").as("eKey")
|
|
|
|
|
+ .and("max_data.eValue").as("maxVal")
|
|
|
|
|
+ .and("max_data.time").as("maxValdate")
|
|
|
|
|
+ .and("min_data.eValue").as("minVal")
|
|
|
|
|
+ .and("min_data.time").as("minValdate");
|
|
|
|
|
+
|
|
|
|
|
+ SortOperation sortOperation3 = Aggregation.sort(Sort.Direction.ASC, "eNum")
|
|
|
|
|
+ .and(Sort.Direction.ASC, "eName")
|
|
|
|
|
+ .and(Sort.Direction.ASC, "eKey");
|
|
|
|
|
+
|
|
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+ matchOperation,
|
|
|
|
|
+ addFieldsOperation,
|
|
|
|
|
+ sortOperation,
|
|
|
|
|
+ groupOperation,
|
|
|
|
|
+ sortOperation2,
|
|
|
|
|
+ projectionOperationResult,
|
|
|
|
|
+ projectionOperationResult2,
|
|
|
|
|
+ sortOperation3
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ List<QxzDataLast24hDto> qxzDataLast24hDtoList = mongoService.aggregate(IotYfqxzdata.class, aggregation, QxzDataLast24hDto.class);
|
|
|
|
|
+ //查出该设备的“自定义要素信息列表”
|
|
|
|
|
+ IotDevicefactor param = new IotDevicefactor();
|
|
|
|
|
+ param.setDevBid(devBid);
|
|
|
|
|
+ List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
|
|
+ Map<String, QxzDataLast24hDto> iotXphLast24hDtoMap = new HashMap<>();
|
|
|
|
|
+ List<QxzDataDto> dataList = new ArrayList<>();
|
|
|
|
|
+ for(QxzDataLast24hDto item: qxzDataLast24hDtoList){
|
|
|
|
|
+ String key = ElementFactorUtil.getAddress(item.getEName(), item.getEKey());
|
|
|
|
|
+ iotXphLast24hDtoMap.put(key, item);
|
|
|
|
|
+ QxzDataDto dto = new QxzDataDto();
|
|
|
|
|
+ BeanUtils.copyProperties(item, dto);
|
|
|
|
|
+ dataList.add(dto);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzListProcessData(dataList, factorList, findDevice, false);
|
|
|
|
|
+ for(IotQxzDataListRseVo item: iotQxzDataListRseVoList){
|
|
|
|
|
+ QxzDataLast24hDto qxzDataLast24hDto = iotXphLast24hDtoMap.get(item.getAddress());
|
|
|
|
|
+ item.setMinVal(qxzDataLast24hDto.getMinVal());
|
|
|
|
|
+ item.setMinValdate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, qxzDataLast24hDto.getMinValdate()));
|
|
|
|
|
+ item.setMaxVal(qxzDataLast24hDto.getMaxVal());
|
|
|
|
|
+ item.setMaxValdate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, qxzDataLast24hDto.getMaxValdate()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return iotQxzDataListRseVoList;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|