|
@@ -0,0 +1,67 @@
|
|
|
|
|
+package com.yunfeiyun.agmp.iotm.web.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.SecurityUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDeviceGeoLocation;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.TosDevicetype;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceGeoLocationService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.ITosDevicetypeService;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
|
|
+import org.springframework.data.mongodb.core.aggregation.GroupOperation;
|
|
|
|
|
+import org.springframework.data.mongodb.core.aggregation.MatchOperation;
|
|
|
|
|
+import org.springframework.data.mongodb.core.aggregation.ProjectionOperation;
|
|
|
|
|
+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;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class IotDeviceGeoLocationServiceImpl implements IIotDeviceGeoLocationService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MongoService mongoService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ITosDevicetypeService tosDevicetypeService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取设备类型数量列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<IotIndexDevicetypeCountResVo> getDeviceTypeCountList() {
|
|
|
|
|
+ String tid = SecurityUtils.getTid();
|
|
|
|
|
+ List<TosDevicetype> devicetypeList = tosDevicetypeService.selectTosDevicetypeList(null);
|
|
|
|
|
+ Map<String, TosDevicetype> devicetypeMap = new HashMap<>();
|
|
|
|
|
+ for (TosDevicetype devicetype : devicetypeList) {
|
|
|
|
|
+ devicetypeMap.put(devicetype.getDevtypeBid(), devicetype);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Criteria criteria = new Criteria().and("tid").is(tid);
|
|
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group("devtypeBid").count().as("count");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
|
|
+ .and("_id").as("devtypeBid")
|
|
|
|
|
+ .and("count").as("count");
|
|
|
|
|
+
|
|
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+ matchOperation,
|
|
|
|
|
+ groupOperation,
|
|
|
|
|
+ projectionOperationResult
|
|
|
|
|
+ );
|
|
|
|
|
+ List<IotIndexDevicetypeCountResVo> dataList = mongoService.aggregate(IotDeviceGeoLocation.class, aggregation, IotIndexDevicetypeCountResVo.class);
|
|
|
|
|
+ for(IotIndexDevicetypeCountResVo item : dataList) {
|
|
|
|
|
+ String devtypeBid = item.getDevtypeBid();
|
|
|
|
|
+ TosDevicetype devicetype = devicetypeMap.get(devtypeBid);
|
|
|
|
|
+ if (devicetype != null) {
|
|
|
|
|
+ item.setDevtypeName(devicetype.getDevtypeName());
|
|
|
|
|
+ item.setDevtypePreview(devicetype.getDevtypePreview());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return dataList;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|