Ver Fonte

完成实时预览

sptkw há 2 anos atrás
pai
commit
ec27149815

+ 46 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/RealTimeMonitoringController.java

@@ -0,0 +1,46 @@
+package com.middle.platform.manage.biz.controller;
+
+import com.middle.platform.common.utils.Result;
+import com.middle.platform.manage.biz.domain.req.TypeStatisticsReq;
+import com.middle.platform.manage.biz.domain.vo.TotalStatisticsVo;
+import com.middle.platform.manage.biz.domain.vo.TypeStatisticsVo;
+import com.middle.platform.manage.biz.service.RealTimeMonitoringService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author Aick Spt
+ * @date 2023-12-24 16:26
+ */
+@RestController
+@RequestMapping("/realTimeMonitoring")
+@RequiredArgsConstructor
+@Validated
+public class RealTimeMonitoringController {
+
+    private final RealTimeMonitoringService realTimeMonitoringService;
+
+    /**
+     * 总数统计
+     */
+    @PostMapping("/totalStatistics")
+    public Result<TotalStatisticsVo> totalStatistics() {
+        return Result.ok(realTimeMonitoringService.totalStatistics());
+    }
+
+
+    /**
+     * 分类统计
+     */
+    @PostMapping("/typeStatistics")
+    public Result<List<TypeStatisticsVo>> typeStatistics(@RequestBody @Validated TypeStatisticsReq typeStatisticsReq) {
+        return Result.ok(realTimeMonitoringService.typeStatistics(typeStatisticsReq));
+    }
+
+}

+ 27 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/TypeStatisticsReq.java

@@ -0,0 +1,27 @@
+package com.middle.platform.manage.biz.domain.req;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 实时设备统计
+ * @author Aick Spt
+ * @date 2023-12-24 16:49
+ */
+@Getter
+@Setter
+public class TypeStatisticsReq {
+
+    /**
+     * 产品ID
+     */
+    private Long productId;
+
+    /**
+     * 设备ID
+     */
+    private Long deviceId;
+
+}

+ 35 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/TotalStatisticsVo.java

@@ -0,0 +1,35 @@
+package com.middle.platform.manage.biz.domain.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 实时总数统计
+ *
+ * @author Aick Spt
+ * @date 2023-12-24 16:35
+ */
+@Getter
+@Setter
+public class TotalStatisticsVo {
+
+
+    /**
+     * 产品总数
+     */
+    private Integer totalNumberOfProducts;
+
+
+    /**
+     * 设备总数
+     */
+    private Integer totalNumberOfDevices;
+
+
+    /**
+     * 在线设备
+     */
+    private Integer onlineEquipment;
+
+
+}

+ 59 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/TypeStatisticsVo.java

@@ -0,0 +1,59 @@
+package com.middle.platform.manage.biz.domain.vo;
+
+import com.middle.platform.mybatis.core.dataobject.BaseVO;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * 实时总数统计
+ *
+ * @author Aick Spt
+ * @date 2023-12-24 16:35
+ */
+@Getter
+@Setter
+public class TypeStatisticsVo extends BaseVO {
+
+
+    /**
+     * 设备名称
+     */
+    private String name;
+
+    /**
+     * 设备经度
+     */
+    private BigDecimal lon;
+
+    /**
+     * 设备纬度
+     */
+    private BigDecimal lat;
+
+    /**
+     * 设备所属区域
+     */
+    private String address;
+
+
+    /**
+     * 设备状态
+     */
+    private Integer status;
+
+
+    /**
+     * 设备状态描述
+     */
+    private String statusName;
+
+
+    /**
+     * 所属项目名称
+     */
+    private String projectTitle;
+
+
+}

+ 8 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotDeviceMapper.java

@@ -2,7 +2,9 @@ package com.middle.platform.manage.biz.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.middle.platform.manage.biz.domain.req.DevicePage;
+import com.middle.platform.manage.biz.domain.req.TypeStatisticsReq;
 import com.middle.platform.manage.biz.domain.vo.IotDeviceVo;
+import com.middle.platform.manage.biz.domain.vo.TypeStatisticsVo;
 import com.middle.platform.manage.biz.entity.IotDevice;
 import org.apache.ibatis.annotations.Mapper;
 
@@ -29,4 +31,10 @@ public interface IotDeviceMapper extends BaseMapper<IotDevice> {
      * @return
      */
     List<IotDeviceVo> pageQuery(DevicePage devicePage);
+
+    int queryTotalNumberOfDevices();
+
+    int queryOnlineEquipment();
+
+    List<TypeStatisticsVo> queryTypeStatistics(TypeStatisticsReq typeStatisticsReq);
 }

+ 4 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProductMapper.java

@@ -21,4 +21,8 @@ public interface IotProductMapper extends BaseMapper<IotProduct> {
      * @return
      */
     List<IotProductVo> pageQuery(ProductPage devicePage);
+
+
+    int queryTotalNumberOfProducts();
+
 }

+ 54 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/RealTimeMonitoringService.java

@@ -0,0 +1,54 @@
+package com.middle.platform.manage.biz.service;
+
+import com.middle.platform.manage.biz.domain.req.TypeStatisticsReq;
+import com.middle.platform.manage.biz.domain.vo.TotalStatisticsVo;
+import com.middle.platform.manage.biz.domain.vo.TypeStatisticsVo;
+import com.middle.platform.manage.biz.mapper.IotDeviceMapper;
+import com.middle.platform.manage.biz.mapper.IotProductMapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author Aick Spt
+ * @date 2023-12-24 16:38
+ */
+@Service
+@RequiredArgsConstructor
+public class RealTimeMonitoringService {
+
+    private final IotProductMapper iotProductMapper;
+
+    private final IotDeviceMapper iotDeviceMapper;
+
+    /**
+     * 总数统计
+     */
+    public TotalStatisticsVo totalStatistics() {
+        TotalStatisticsVo totalStatisticsVo = new TotalStatisticsVo();
+
+        int tnp = iotProductMapper.queryTotalNumberOfProducts();
+        totalStatisticsVo.setTotalNumberOfProducts(tnp);//产品总数
+
+        int tnd = iotDeviceMapper.queryTotalNumberOfDevices();
+        totalStatisticsVo.setTotalNumberOfDevices(tnd);//设备总数
+
+        int oe = iotDeviceMapper.queryOnlineEquipment();
+        totalStatisticsVo.setOnlineEquipment(oe);//在线设备
+
+        return totalStatisticsVo;
+    }
+
+
+    /**
+     * 分类统计
+     */
+    public List<TypeStatisticsVo> typeStatistics(TypeStatisticsReq typeStatisticsReq) {
+        List<TypeStatisticsVo> typeStatisticsVos = iotDeviceMapper.queryTypeStatistics(typeStatisticsReq);
+        typeStatisticsVos.forEach(e -> {
+            e.setStatusName(e.getStatus().equals(1) ? "在线" : "离线");
+        });
+        return typeStatisticsVos;
+    }
+}

+ 94 - 60
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotDeviceMapper.xml

@@ -1,70 +1,104 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.middle.platform.manage.biz.mapper.IotDeviceMapper">
-  <resultMap id="BaseResultMap" type="com.middle.platform.manage.biz.entity.IotDevice">
-    <!--@mbg.generated-->
-    <!--@Table iot_device-->
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="product_id" jdbcType="BIGINT" property="productId" />
-    <result column="name" jdbcType="VARCHAR" property="name" />
-    <result column="sn" jdbcType="VARCHAR" property="sn" />
-    <result column="guid" jdbcType="VARCHAR" property="guid" />
-    <result column="subtitle" jdbcType="VARCHAR" property="subtitle" />
-    <result column="lon" jdbcType="DECIMAL" property="lon" />
-    <result column="lat" jdbcType="DECIMAL" property="lat" />
-    <result column="address" jdbcType="VARCHAR" property="address" />
-    <result column="online_time" jdbcType="TIMESTAMP" property="onlineTime" />
-    <result column="status" jdbcType="TINYINT" property="status" />
-    <result column="enable_flag" jdbcType="TINYINT" property="enableFlag" />
-    <result column="remark" jdbcType="VARCHAR" property="remark" />
-    <result column="create_by" jdbcType="BIGINT" property="createBy" />
-    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
-    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
-    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
-    <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime" />
-    <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
-  </resultMap>
-  <sql id="Base_Column_List">
-      <!--@mbg.generated-->
-      id,
-      product_id,
-      `name`,
-      sn,
-      guid,
-      subtitle,
-      lon,
-      lat,
-      address,
-      online_time,
-      `status`,
-      enable_flag,
-      remark,
-      create_by,
-      create_time,
-      update_by,
-      update_time,
-      delete_time,
-      del_flag
-  </sql>
+    <resultMap id="BaseResultMap" type="com.middle.platform.manage.biz.entity.IotDevice">
+        <!--@mbg.generated-->
+        <!--@Table iot_device-->
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="product_id" jdbcType="BIGINT" property="productId"/>
+        <result column="name" jdbcType="VARCHAR" property="name"/>
+        <result column="sn" jdbcType="VARCHAR" property="sn"/>
+        <result column="guid" jdbcType="VARCHAR" property="guid"/>
+        <result column="subtitle" jdbcType="VARCHAR" property="subtitle"/>
+        <result column="lon" jdbcType="DECIMAL" property="lon"/>
+        <result column="lat" jdbcType="DECIMAL" property="lat"/>
+        <result column="address" jdbcType="VARCHAR" property="address"/>
+        <result column="online_time" jdbcType="TIMESTAMP" property="onlineTime"/>
+        <result column="status" jdbcType="TINYINT" property="status"/>
+        <result column="enable_flag" jdbcType="TINYINT" property="enableFlag"/>
+        <result column="remark" jdbcType="VARCHAR" property="remark"/>
+        <result column="create_by" jdbcType="BIGINT" property="createBy"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+        <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime"/>
+        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        <!--@mbg.generated-->
+        id,
+        product_id,
+        `name`,
+        sn,
+        guid,
+        subtitle,
+        lon,
+        lat,
+        address,
+        online_time,
+        `status`,
+        enable_flag,
+        remark,
+        create_by,
+        create_time,
+        update_by,
+        update_time,
+        delete_time,
+        del_flag
+    </sql>
 
-  <select id="queryByProduct" resultType="java.lang.Long">
-    select count(1)
-    from iot_device id
-    <where>
-      id.product_id = #{id,jdbcType=BIGINT}
-    </where>
+    <select id="queryByProduct" resultType="java.lang.Long">
+        select count(1)
+        from iot_device id
+        <where>
+            id.product_id = #{id,jdbcType=BIGINT}
+        </where>
     </select>
 
-  <select id="pageQuery" resultType="com.middle.platform.manage.biz.domain.vo.IotDeviceVo">
-      select *
-      from iot_device id
-      <where>
-          <if test="keywords != null and keywords != ''">
-              and id.name like concat('%', #{keywords,jdbcType=VARCHAR}, '%')
-          </if>
-      </where>
-  </select>
+    <select id="pageQuery" resultType="com.middle.platform.manage.biz.domain.vo.IotDeviceVo">
+        select *
+        from iot_device id
+        <where>
+            <if test="keywords != null and keywords != ''">
+                and id.name like concat('%', #{keywords,jdbcType=VARCHAR}, '%')
+            </if>
+        </where>
+    </select>
 
+    <select id="queryTotalNumberOfDevices" resultType="int">
+        select count(id) as num
+        from iot_device
+        <where>
+            del_flag = 0
+              and enable_flag = 1
+        </where>
+    </select>
 
+    <select id="queryOnlineEquipment" resultType="int">
+        select count(id) as num
+        from iot_device
+        <where>
+            del_flag = 0
+              and status = 1
+              and enable_flag = 1
+        </where>
+    </select>
 
+    <select id="queryTypeStatistics" resultType="com.middle.platform.manage.biz.domain.vo.TypeStatisticsVo">
+        select ide.*,
+               ipr.title projectTitle
+        from iot_device ide
+                 left join iot_project_device ipd on ipd.device_id = ide.id
+                 left join iot_project ipr on ipr.id = ipd.project_id
+        <where>
+            ide.del_flag = 0
+              and ide.enable_flag = 1
+            <if test="deviceId != null">
+                and id = #{deviceId,jdbcType=BIGINT}
+            </if>
+            <if test="productId != null">
+                and product_id = #{productId,jdbcType=BIGINT}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 8 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProductMapper.xml

@@ -57,4 +57,12 @@
             and ip.del_flag = 0
         </where>
     </select>
+
+    <select id="queryTotalNumberOfProducts" resultType="int">
+        select count(id) as num
+        from iot_product
+        <where>
+            del_flag = 0
+        </where>
+    </select>
 </mapper>