Bläddra i källkod

优化大屏数据

Simon 1 år sedan
förälder
incheckning
db53e9daf2

+ 16 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDataDisplayController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.web.controller.system;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDictData;
@@ -128,12 +129,20 @@ public class TDataDisplayController extends BaseController {
 
     @GetMapping("/deviceView")
     public AjaxResult deviceView() {
-        DeviceViewDto dto = new DeviceViewDto();
-        dto.setDeviceCount(tShouhuanAlarmListService.selectTShouhuanAlarmStatus() + tShouhuanAlarmListService.selectTShouhuanAlarmStatusSolve());
-        dto.setDeviceOnline(tShouhuanAlarmListService.selectTShouhuanAlarmStatus());
-        dto.setUn_deviceOnline(tShouhuanAlarmListService.selectTShouhuanAlarmStatusSolve());
-        dto.setAlarmCount(tShouhuanAlarmListService.selectTShouhuanAlarmListCount());
-        return success(dto);
+        DeviceViewDto deviceViewDto = new DeviceViewDto();
+        /** 总数 deviceCount */
+        Integer deviceCount = itShouhuanInfoService.selectTShouhuanInfoAllCount();
+        deviceViewDto.setDeviceCount(deviceCount == null ? 0 : deviceCount);
+        /** 在线 deviceOnline */
+        Integer deviceOnline = itShouhuanInfoService.selectTShouhuanInfoAllOnlineCount();
+        deviceViewDto.setDeviceOnline(deviceOnline == null ? 0 : deviceOnline);
+        /** 离线 un_deviceOnline */
+        Integer un_deviceOnline = itShouhuanInfoService.selectTShouhuanInfoAllUnOnlineCount();
+        deviceViewDto.setUn_deviceOnline(un_deviceOnline == null ? 0 : un_deviceOnline);
+        /** 告警数 alarmCount */
+        Integer alarmCount = tEarlyWarningService.selectTEarlyWarningUnCompletedAllCount();
+        deviceViewDto.setAlarmCount(alarmCount == null ? 0 : alarmCount);
+        return success(deviceViewDto);
     }
 
     @GetMapping("/deviceType")
@@ -154,7 +163,7 @@ public class TDataDisplayController extends BaseController {
     public AjaxResult userAgeAll() {
         Integer total = userProfileService.selectuserAgeCount();
         List<UserAgeDto> dtoList = userProfileService.selectuserAgeDto();
-        dtoList.removeIf(user -> StringUtils.isNull(user.getAge()));
+        dtoList.removeIf(user -> StringUtils.isNull(user.getAgeGroup()));
         AjaxResult ajax = new AjaxResult();
         ajax.put("list", dtoList);
         ajax.put("total", total);

+ 5 - 5
ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/UserAgeDto.java

@@ -8,18 +8,18 @@ public class UserAgeDto {
 
     /** 名称 */
     @Excel(name = "名称")
-    private String age;
+    private String ageGroup;
 
     /** 数量 */
     @Excel(name = "数量")
     private Integer count;
 
-    public String getAge() {
-        return age;
+    public String getAgeGroup() {
+        return ageGroup;
     }
 
-    public void setAge(String age) {
-        this.age = age;
+    public void setAgeGroup(String ageGroup) {
+        this.ageGroup = ageGroup;
     }
 
     public Integer getCount() {

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TEarlyWarningMapper.java

@@ -89,6 +89,13 @@ public interface TEarlyWarningMapper {
      */
     Integer selectTEarlyWarningUnCompletedCountByType(Integer type);
 
+    /**
+     * 查询类型未完成数量
+     *
+     * @return
+     */
+    Integer selectTEarlyWarningUnCompletedAllCount();
+
     /**
      * 查询类型未完成百分比
      *

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TShouhuanInfoMapper.java

@@ -77,4 +77,10 @@ public interface TShouhuanInfoMapper
     List<TShouhuanInfo> selectTShouhuanInfoListBydeviceIdCode(String deviceIdCode);
 
     Double selectTShouhuanInfoPercentage();
+
+    Integer selectTShouhuanInfoAllCount();
+
+    Integer selectTShouhuanInfoAllOnlineCount();
+
+    Integer selectTShouhuanInfoAllUnOnlineCount();
 }

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ITEarlyWarningService.java

@@ -115,6 +115,13 @@ public interface ITEarlyWarningService {
      */
     Integer selectTEarlyWarningUnCompletedCountByType(Integer type);
 
+    /**
+     * 查询类型未完成总数量
+     *
+     * @return
+     */
+    Integer selectTEarlyWarningUnCompletedAllCount();
+
     /**
      * 查询类型未完成百分比
      *

+ 21 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ITShouhuanInfoService.java

@@ -81,4 +81,25 @@ public interface ITShouhuanInfoService {
      * @return
      */
     Double selectTShouhuanInfoPercentage();
+
+    /**
+     * 查询所有设备
+     *
+     * @return
+     */
+    Integer selectTShouhuanInfoAllCount();
+
+    /**
+     * 查询所有在线设备
+     *
+     * @return
+     */
+    Integer selectTShouhuanInfoAllOnlineCount();
+
+    /**
+     * 查询所有离线设备
+     *
+     * @return
+     */
+    Integer selectTShouhuanInfoAllUnOnlineCount();
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TEarlyWarningServiceImpl.java

@@ -132,6 +132,11 @@ public class TEarlyWarningServiceImpl implements ITEarlyWarningService {
         return tEarlyWarningMapper.selectTEarlyWarningUnCompletedCountByType(type);
     }
 
+    @Override
+    public Integer selectTEarlyWarningUnCompletedAllCount() {
+        return tEarlyWarningMapper.selectTEarlyWarningUnCompletedAllCount();
+    }
+
     @Override
     public Double selectTEarlyWarningUnCompletedPercentageByType(Integer type) {
         return tEarlyWarningMapper.selectTEarlyWarningUnCompletedPercentageByType(type);

+ 29 - 21
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TShouhuanInfoServiceImpl.java

@@ -11,37 +11,34 @@ import com.ruoyi.system.service.ITShouhuanInfoService;
 
 /**
  * 手环信息 实时数据Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2023-09-07
  */
 @Service
-public class TShouhuanInfoServiceImpl implements ITShouhuanInfoService 
-{
+public class TShouhuanInfoServiceImpl implements ITShouhuanInfoService {
     @Autowired
     private TShouhuanInfoMapper tShouhuanInfoMapper;
 
     /**
      * 查询手环信息 实时数据
-     * 
+     *
      * @param id 手环信息 实时数据主键
      * @return 手环信息 实时数据
      */
     @Override
-    public TShouhuanInfo selectTShouhuanInfoById(Long id)
-    {
+    public TShouhuanInfo selectTShouhuanInfoById(Long id) {
         return tShouhuanInfoMapper.selectTShouhuanInfoById(id);
     }
 
     /**
      * 查询手环信息 实时数据列表
-     * 
+     *
      * @param tShouhuanInfo 手环信息 实时数据
      * @return 手环信息 实时数据
      */
     @Override
-    public List<TShouhuanInfo> selectTShouhuanInfoList(TShouhuanInfo tShouhuanInfo)
-    {
+    public List<TShouhuanInfo> selectTShouhuanInfoList(TShouhuanInfo tShouhuanInfo) {
         return tShouhuanInfoMapper.selectTShouhuanInfoList(tShouhuanInfo);
     }
 
@@ -52,49 +49,45 @@ public class TShouhuanInfoServiceImpl implements ITShouhuanInfoService
 
     /**
      * 新增手环信息 实时数据
-     * 
+     *
      * @param tShouhuanInfo 手环信息 实时数据
      * @return 结果
      */
     @Override
-    public int insertTShouhuanInfo(TShouhuanInfo tShouhuanInfo)
-    {
+    public int insertTShouhuanInfo(TShouhuanInfo tShouhuanInfo) {
         return tShouhuanInfoMapper.insertTShouhuanInfo(tShouhuanInfo);
     }
 
     /**
      * 修改手环信息 实时数据
-     * 
+     *
      * @param tShouhuanInfo 手环信息 实时数据
      * @return 结果
      */
     @Override
-    public int updateTShouhuanInfo(TShouhuanInfo tShouhuanInfo)
-    {
+    public int updateTShouhuanInfo(TShouhuanInfo tShouhuanInfo) {
         return tShouhuanInfoMapper.updateTShouhuanInfo(tShouhuanInfo);
     }
 
     /**
      * 批量删除手环信息 实时数据
-     * 
+     *
      * @param ids 需要删除的手环信息 实时数据主键
      * @return 结果
      */
     @Override
-    public int deleteTShouhuanInfoByIds(Long[] ids)
-    {
+    public int deleteTShouhuanInfoByIds(Long[] ids) {
         return tShouhuanInfoMapper.deleteTShouhuanInfoByIds(ids);
     }
 
     /**
      * 删除手环信息 实时数据信息
-     * 
+     *
      * @param id 手环信息 实时数据主键
      * @return 结果
      */
     @Override
-    public int deleteTShouhuanInfoById(Long id)
-    {
+    public int deleteTShouhuanInfoById(Long id) {
         return tShouhuanInfoMapper.deleteTShouhuanInfoById(id);
     }
 
@@ -107,4 +100,19 @@ public class TShouhuanInfoServiceImpl implements ITShouhuanInfoService
     public Double selectTShouhuanInfoPercentage() {
         return tShouhuanInfoMapper.selectTShouhuanInfoPercentage();
     }
+
+    @Override
+    public Integer selectTShouhuanInfoAllCount() {
+        return tShouhuanInfoMapper.selectTShouhuanInfoAllCount();
+    }
+
+    @Override
+    public Integer selectTShouhuanInfoAllOnlineCount() {
+        return tShouhuanInfoMapper.selectTShouhuanInfoAllOnlineCount();
+    }
+
+    @Override
+    public Integer selectTShouhuanInfoAllUnOnlineCount() {
+        return tShouhuanInfoMapper.selectTShouhuanInfoAllUnOnlineCount();
+    }
 }

+ 5 - 0
ruoyi-system/src/main/resources/mapper/system/TEarlyWarningMapper.xml

@@ -201,6 +201,11 @@
         WHERE type = #{type}
           AND state = 0;
     </select>
+    <select id="selectTEarlyWarningUnCompletedAllCount" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM t_early_warning
+        WHERE state = 0;
+    </select>
     <select id="selectTEarlyWarningUnCompletedPercentageByType" parameterType="Integer" resultType="java.lang.Double">
         SELECT (COUNT(CASE WHEN state = 1 THEN 0 END) / COUNT(*) * 100)
         FROM t_early_warning

+ 14 - 0
ruoyi-system/src/main/resources/mapper/system/TShouhuanInfoMapper.xml

@@ -154,6 +154,20 @@
         FROM t_shouhuan_info
         WHERE online_statis = 1;
     </select>
+    <select id="selectTShouhuanInfoAllCount" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM t_device_list;
+    </select>
+    <select id="selectTShouhuanInfoAllOnlineCount" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM t_shouhuan_info
+        WHERE online_statis = 1;
+    </select>
+    <select id="selectTShouhuanInfoAllUnOnlineCount" resultType="java.lang.Integer">
+        SELECT ((SELECT COUNT(*) FROM t_device_list) - COUNT(*))
+        FROM t_shouhuan_info
+        WHERE online_statis = 1;
+    </select>
 
     <insert id="insertTShouhuanInfo" parameterType="TShouhuanInfo" useGeneratedKeys="true" keyProperty="id">
         insert into t_shouhuan_info

+ 14 - 59
ruoyi-system/src/main/resources/mapper/system/TUserProfileMapper.xml

@@ -214,65 +214,20 @@
     </select>
     <select id="selectuserAgeDto" resultType="com.ruoyi.system.domain.dto.UserAgeDto">
         SELECT CASE
-                   WHEN age &lt; 20
-                       THEN
-                       '10'
-                   WHEN age &gt;= 20
-                       AND age &lt; 30 THEN
-                       '20'
-                   WHEN age &gt;= 30
-                       AND age &lt; 40 THEN
-                       '30'
-                   WHEN age &gt;= 40
-                       AND age &lt; 50 THEN
-                       '40'
-                   WHEN age &gt;= 50
-                       AND age &lt; 60 THEN
-                       '50'
-                   WHEN age &gt;= 60
-                       AND age &lt; 70 THEN
-                       '60'
-                   WHEN age &gt;= 70
-                       AND age &lt; 80 THEN
-                       '70'
-                   WHEN age &gt;= 80
-                       AND age &lt; 90 THEN
-                       '80'
-                   WHEN age &gt; 90 THEN
-                       '100以上'
-                   END AS age,
-               count(*) AS count
-        FROM
-            t_user_profile
-        GROUP BY
-            CASE
-            WHEN age &lt; 20
-            THEN
-            '10'
-            WHEN age &gt;= 20
-            AND age &lt; 30 THEN
-            '20'
-            WHEN age &gt;= 30
-            AND age &lt; 40 THEN
-            '30'
-            WHEN age &gt;= 40
-            AND age &lt; 50 THEN
-            '40'
-            WHEN age &gt;= 50
-            AND age &lt; 60 THEN
-            '50'
-            WHEN age &gt;= 60
-            AND age &lt; 70 THEN
-            '60'
-            WHEN age &gt;= 70
-            AND age &lt; 80 THEN
-            '70'
-            WHEN age &gt;= 80
-            AND age &lt; 90 THEN
-            '80'
-            WHEN age &gt; 90 THEN
-            '100以上'
-        END;
+                   WHEN age &lt; 20 THEN '小于20岁'
+                   WHEN age &gt;= 20 AND age &lt; 30 THEN '20~30岁'
+                   WHEN age &gt;= 30 AND age &lt; 40 THEN '30~40岁'
+                   WHEN age &gt;= 40 AND age &lt; 50 THEN '40~50岁'
+                   WHEN age &gt;= 50 AND age &lt; 60 THEN '50~60岁'
+                   WHEN age &gt;= 60 AND age &lt; 70 THEN '60~70岁'
+                   WHEN age &gt;= 70 AND age &lt; 80 THEN '70~80岁'
+                   WHEN age &gt;= 80 AND age &lt; 90 THEN '80~90岁'
+                   WHEN age &gt;= 90 AND age &lt; 100 THEN '90~100岁'
+                   ELSE '100岁以上'
+                   END AS ageGroup,
+               COUNT(*) AS count
+        FROM t_user_profile
+        GROUP BY ageGroup;
     </select>
     <select id="selectuserAgeCount" resultType="java.lang.Integer">
         select IFNULL(count(*), 0)