|
|
@@ -1,6 +1,11 @@
|
|
|
package com.yunfeiyun.agmp.iotm.device.qxz.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
+import com.yunfeiyun.agmp.common.core.page.PageDomain;
|
|
|
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
|
|
|
+import com.yunfeiyun.agmp.common.core.page.TableSupport;
|
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
@@ -12,21 +17,23 @@ 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.impl.IotDeviceBaseServiceImpl;
|
|
|
import com.yunfeiyun.agmp.iotm.device.qxz.domain.IotDeviceQxzDataListReqVo;
|
|
|
-import com.yunfeiyun.agmp.iotm.device.qxz.domain.YfQxzChartDataDto;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.qxz.domain.QxzDataLast24hDto;
|
|
|
import com.yunfeiyun.agmp.iotm.util.MongoUtil;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDevicefactorService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.mongodb.core.aggregation.*;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service(value = ServiceNameConst.SERVICE_YF_QXZ)
|
|
|
+@Slf4j
|
|
|
public class IotYfQxzServiceImpl extends IotDeviceBaseServiceImpl implements IotDeviceBaseService {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -39,6 +46,72 @@ public class IotYfQxzServiceImpl extends IotDeviceBaseServiceImpl implements Iot
|
|
|
private IIotDeviceService iotDeviceService;
|
|
|
|
|
|
/**
|
|
|
+ * 获取数据列表接口
|
|
|
+ * @param reqVo
|
|
|
+ */
|
|
|
+ public TableDataInfo dataList(IotDeviceQxzDataListReqVo reqVo) throws ParseException {
|
|
|
+ TableDataInfo rspData = new TableDataInfo();
|
|
|
+ rspData.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
+ rspData.setMsg(ErrorCode.SUCCESS.getMessage());
|
|
|
+ rspData.setData(new ArrayList<>());
|
|
|
+ rspData.setTotal(0);
|
|
|
+
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
+
|
|
|
+ String devBid = findDevice.getDevBid();
|
|
|
+ Date startDate = null;
|
|
|
+ Date endDate = null;
|
|
|
+ try{
|
|
|
+ startDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, reqVo.getStartTime());
|
|
|
+ endDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, reqVo.getEndTime());
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("时间格式错误", e);
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "请输入正确的起止时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
+ criteria = criteria.andOperator(
|
|
|
+ Criteria.where("time").gte(startDate),
|
|
|
+ Criteria.where("time").lte(endDate)
|
|
|
+ );
|
|
|
+
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("time")
|
|
|
+ .push("$$ROOT").as("data");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
+ .and("_id").as("time")
|
|
|
+ .and("data").as("dataList");
|
|
|
+
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "time");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperationResult,
|
|
|
+ sortOperation
|
|
|
+ );
|
|
|
+
|
|
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
|
+ IPage<QxzDataListDto> qxzDataListDtoIPage = mongoService.aggregate(IotYfqxzdata.class, aggregation, QxzDataListDto.class, pageDomain);
|
|
|
+ //查出该设备的“自定义要素信息列表”
|
|
|
+ IotDevicefactor param = new IotDevicefactor();
|
|
|
+ param.setDevBid(devBid);
|
|
|
+ List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
+
|
|
|
+ List<List<IotQxzDataListRseVo>> rest = new ArrayList<>();
|
|
|
+ for(QxzDataListDto item: qxzDataListDtoIPage.getRecords()){
|
|
|
+ List<QxzDataDto> dataList = item.getDataList();
|
|
|
+ List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzListProcessData(dataList, factorList, findDevice, false);
|
|
|
+ rest.add(iotQxzDataListRseVoList);
|
|
|
+ }
|
|
|
+ rspData.setData(rest);
|
|
|
+ rspData.setTotal(qxzDataListDtoIPage.getTotal());
|
|
|
+ return rspData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取折线图数据列表接口
|
|
|
* @param reqVo
|
|
|
*/
|
|
|
@@ -120,13 +193,99 @@ public class IotYfQxzServiceImpl extends IotDeviceBaseServiceImpl implements Iot
|
|
|
projectionOperation2,
|
|
|
sortOperation2
|
|
|
);
|
|
|
- List<QxzChartDataDto> dataList = mongoService.aggregate(IotYfqxzdata.class, aggregation, YfQxzChartDataDto.class);
|
|
|
+ List<QxzDataDto> dataList = mongoService.aggregate(IotYfqxzdata.class, aggregation, QxzDataDto.class);
|
|
|
+
|
|
|
+ //查出该设备的“自定义要素信息列表”
|
|
|
+ IotDevicefactor param = new IotDevicefactor();
|
|
|
+ param.setDevBid(devBid);
|
|
|
+ List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
+ List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzChartProcessData(dataList, factorList, findDevice, false);
|
|
|
+ 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);
|
|
|
- List<IotQxzDataListRseVo> iotXphChartListResVoList = ElementFactorUtil.qxzChartProcessData(dataList, factorList, findDevice, false);
|
|
|
- return iotXphChartListResVoList;
|
|
|
+ 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;
|
|
|
}
|
|
|
}
|