Просмотр исходного кода

新增 首页获取设备类型统计接口

zhaiyifei 11 месяцев назад
Родитель
Сommit
8cfaf8e675

+ 16 - 8
src/main/java/com/yunfeiyun/agmp/iotm/web/controller/IotHomeController.java

@@ -2,8 +2,8 @@ package com.yunfeiyun.agmp.iotm.web.controller;
 
 import com.yunfeiyun.agmp.common.core.controller.BaseController;
 import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
-import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceGeoLocationService;
+import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotHomeTypeStatResVo;
+import com.yunfeiyun.agmp.iotm.web.service.IIotHomeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,16 +21,24 @@ import java.util.List;
 @RequestMapping("/iot/home")
 public class IotHomeController extends BaseController
 {
-
     @Autowired
-    private IIotDeviceGeoLocationService iotDeviceGeoLocationService;
+    private IIotHomeService iotHomeService;
+
+    /**
+     * 查询设备类型统计列表
+     */
+    @GetMapping("/type/stat")
+    public AjaxResult typeStat() {
+        List<IotHomeTypeStatResVo> dataList = iotHomeService.getDeviceTypeStat();
+        return success(dataList);
+    }
 
     /**
-     * 查询设备类型列表
+     * 查询设备统计
      */
-    @GetMapping("/type/list")
-    public AjaxResult list() {
-        List<IotIndexDevicetypeCountResVo> dataList = iotDeviceGeoLocationService.getDeviceTypeCountList();
+    @GetMapping("/device/stat")
+    public AjaxResult deviceStat() {
+        List<IotHomeTypeStatResVo> dataList = iotHomeService.getDeviceTypeStat();
         return success(dataList);
     }
 }

+ 14 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/domain/resvo/IotHomeDeviceStatResVo.java

@@ -0,0 +1,14 @@
+package com.yunfeiyun.agmp.iotm.web.domain.resvo;
+
+import lombok.Data;
+
+@Data
+public class IotHomeDeviceStatResVo {
+    private static final long serialVersionUID = 1L;
+
+    private int devNum;
+
+    private int offlineNum;
+
+    private int onlineNum;
+}

+ 17 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/domain/resvo/IotHomeTypeStatResVo.java

@@ -0,0 +1,17 @@
+package com.yunfeiyun.agmp.iotm.web.domain.resvo;
+
+import lombok.Data;
+
+@Data
+public class IotHomeTypeStatResVo {
+    private static final long serialVersionUID = 1L;
+
+    private String devtypeBid;
+
+    private int count;
+
+    private String devtypeName;
+
+    /** 型号图示 */
+    private String devtypePreview;
+}

+ 2 - 2
src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotDeviceMapper.java

@@ -1,7 +1,7 @@
 package com.yunfeiyun.agmp.iotm.web.mapper;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
+import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotHomeTypeStatResVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
 
@@ -62,5 +62,5 @@ public interface IotDeviceMapper
 
     public int updateIotDeviceExtInfo(IotDevice iotDevice);
 
-    public List<IotIndexDevicetypeCountResVo> selectDeviceTypeCountList(IotDevice iotDevice);
+    public List<IotHomeTypeStatResVo> selectDeviceTypeStat(IotDevice iotDevice);
 }

+ 0 - 9
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotDeviceGeoLocationService.java

@@ -1,13 +1,4 @@
 package com.yunfeiyun.agmp.iotm.web.service;
 
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
-
-import java.util.List;
-
 public interface IIotDeviceGeoLocationService {
-
-    /**
-     * 获取设备类型数量列表
-     */
-    public List<IotIndexDevicetypeCountResVo> getDeviceTypeCountList();
 }

+ 2 - 2
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotDeviceService.java

@@ -2,7 +2,7 @@ package com.yunfeiyun.agmp.iotm.web.service;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
+import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotHomeTypeStatResVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceAddReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceEditReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
@@ -76,6 +76,6 @@ public interface IIotDeviceService {
 
     public int updateIotDeviceExtInfo(IotDevice iotDevice);
 
-    public List<IotIndexDevicetypeCountResVo> selectDeviceTypeCountList(IotDevice iotDevice);
+    public List<IotHomeTypeStatResVo> selectDeviceTypeStat(IotDevice iotDevice);
 
 }

+ 2 - 2
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotHomeService.java

@@ -1,9 +1,9 @@
 package com.yunfeiyun.agmp.iotm.web.service;
 
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
+import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotHomeTypeStatResVo;
 
 import java.util.List;
 
 public interface IIotHomeService {
-    public List<IotIndexDevicetypeCountResVo> getDeviceTypeCountList();
+    public List<IotHomeTypeStatResVo> getDeviceTypeStat();
 }

+ 0 - 53
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotDeviceGeoLocationServiceImpl.java

@@ -1,67 +1,14 @@
 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;
-    }
 }

+ 3 - 3
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotDeviceServiceImpl.java

@@ -7,7 +7,7 @@ import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.iot.common.constant.mqtt.IotMqttConstant;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
+import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotHomeTypeStatResVo;
 import com.yunfeiyun.agmp.iot.common.enums.IotDeviceDelStatusEnum;
 import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
@@ -420,8 +420,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
     }
 
     @Override
-    public List<IotIndexDevicetypeCountResVo> selectDeviceTypeCountList(IotDevice iotDevice) {
+    public List<IotHomeTypeStatResVo> selectDeviceTypeStat(IotDevice iotDevice) {
         iotDevice.setTid(SecurityUtils.getTid());
-        return iotDeviceMapper.selectDeviceTypeCountList(iotDevice);
+        return iotDeviceMapper.selectDeviceTypeStat(iotDevice);
     }
 }

+ 5 - 3
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotHomeServiceImpl.java

@@ -1,21 +1,23 @@
 package com.yunfeiyun.agmp.iotm.web.service.impl;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
-import com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo;
+import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotHomeTypeStatResVo;
 import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotHomeService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 import java.util.List;
 
+@Service
 public class IotHomeServiceImpl implements IIotHomeService {
 
     @Autowired
     private IIotDeviceService iIotDeviceService;
 
     @Override
-    public List<IotIndexDevicetypeCountResVo> getDeviceTypeCountList() {
+    public List<IotHomeTypeStatResVo> getDeviceTypeStat() {
         IotDevice iotDevice = new IotDevice();
-        return iIotDeviceService.selectDeviceTypeCountList(iotDevice);
+        return iIotDeviceService.selectDeviceTypeStat(iotDevice);
     }
 }

+ 2 - 2
src/main/resources/mapper/IotDeviceMapper.xml

@@ -274,8 +274,8 @@
         where devBid = #{devBid} and devDelstatus = '0'
     </delete>
 
-    <select id="selectDeviceTypeCountList" parameterType="IotDevice"
-            resultType="com.yunfeiyun.agmp.iot.common.domain.resvo.IotIndexDevicetypeCountResVo">
+    <select id="selectDeviceTypeStat" parameterType="IotDevice"
+            resultType="com.yunfeiyun.agmp.iotm.web.domain.resvo.IotHomeTypeStatResVo">
         SELECT d.devtypeBid, COUNT(d.devtypeBid) AS count, dt.devtypeName, dt.devtypePreview
         FROM IotDevice AS d
             LEFT JOIN TosDevicetype AS dt ON dt.devtypeBid = d.devtypeBid