Browse Source

数据大屏优化

zhengjie 1 year ago
parent
commit
d96a3d8a96

+ 26 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDataDisplayController.java

@@ -20,6 +20,8 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -72,7 +74,7 @@ public class TDataDisplayController extends BaseController
     @GetMapping("/count")
     public AjaxResult count()
     {
-        return success(tShouhuanAlarmListService.selectTShouhuanAlarmListCount());
+        return success(userProfileService.selectuserAgeCount());
     }
 
     @GetMapping("/alarm")
@@ -139,6 +141,7 @@ public class TDataDisplayController extends BaseController
     {
         Integer total = userProfileService.selectuserAgeCount();
         List<UserAgeDto> dtoList = userProfileService.selectuserAgeDto();
+        dtoList.removeIf(user -> StringUtils.isNull(user.getAge()));
         AjaxResult ajax = new AjaxResult();
         ajax.put("list",dtoList);
         ajax.put("total", total);
@@ -197,6 +200,28 @@ public class TDataDisplayController extends BaseController
     public AjaxResult addDevice()
     {
         List<AddDeviceDto> dtoList = tDeviceListService.selectAddDevice();
+        LocalDate currentDate = LocalDate.now();
+        LocalDate lastMonthDate = currentDate.minusMonths(1);
+        int year= currentDate.getYear();
+        if (dtoList.size() == 2){
+            int lastMonth = lastMonthDate.getMonthValue()-1;
+            AddDeviceDto dto = new AddDeviceDto();
+            dto.setMonth(year + "-0" + lastMonth);
+            dto.setCount(0);
+            dtoList.add(dto);
+        }else if (dtoList.size() == 1){
+            int lastMonth = lastMonthDate.getMonthValue();
+            int lastlastMonth = lastMonthDate.getMonthValue()-1;
+            AddDeviceDto dto = new AddDeviceDto();
+            dto.setMonth(year + "-0" + lastMonth);
+            dto.setCount(0);
+            dtoList.add(dto);
+            AddDeviceDto dto1 = new AddDeviceDto();
+            dto1.setMonth(year + "-0" + lastlastMonth);
+            dto1.setCount(0);
+            dtoList.add(dto1);
+        }
+        dtoList = dtoList.stream().sorted(Comparator.comparing(AddDeviceDto::getMonth)).collect(Collectors.toList());
         return success(dtoList);
     }
 

+ 4 - 4
ruoyi-admin/src/main/resources/application-test.yml

@@ -9,9 +9,9 @@ spring:
         druid:
             # 主库数据源
             master:
-                url: jdbc:mysql://192.168.56.10:3306/yyky?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+                url: jdbc:mysql://42.193.106.113:3306/yyky?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                 username: root
-                password: root
+                password: zhonghui0123
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭
@@ -66,13 +66,13 @@ spring:
     # redis 配置
     redis:
         # 地址
-        host: 192.168.56.10
+        host: localhost
         # 端口,默认为6379
         port: 6379
         # 数据库索引
         database: 0
         # 密码
-        password: redis
+        password:
         # 连接超时时间
         timeout: 10s
         lettuce:

+ 2 - 2
ruoyi-admin/src/main/resources/application.yml

@@ -54,11 +54,11 @@ spring:
     basename: i18n/messages
   profiles:
     # 测试环境
-    #    active: test
+        active: test
     # 开发环境
 #    active: dev
     # 生产环境
-    active: druid
+#    active: druid
 
   # 文件上传
   servlet:

+ 3 - 1
ruoyi-system/src/main/resources/mapper/system/TDeviceListMapper.xml

@@ -109,7 +109,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select IFNULL(count(*),0) from t_device_list
     </select>
     <select id="selectAddDevice" resultType="com.ruoyi.system.domain.dto.AddDeviceDto">
-        SELECT DATE_FORMAT(createtime, '%Y-%m') AS month, COUNT(*) AS count FROM t_device_list GROUP BY month;
+        SELECT DATE_FORMAT(createtime, '%Y-%m') AS month, COUNT(*) AS count FROM t_device_list
+        WHERE createtime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
+        GROUP BY month;
     </select>
     <select id="selectTDeviceListBandUser" resultType="java.lang.Integer">
         select count(distinct userid) from t_device_list

+ 4 - 8
ruoyi-system/src/main/resources/mapper/system/TUserProfileMapper.xml

@@ -146,10 +146,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectuserAgeDto" resultType="com.ruoyi.system.domain.dto.UserAgeDto">
         SELECT
         CASE
-        WHEN age IS NULL THEN
-        '未知'
-        WHEN age &gt;= 10
-        AND age &lt; 20 THEN
+        WHEN age &lt; 20
+        THEN
         '10'
         WHEN age &gt;= 20
         AND age &lt; 30 THEN
@@ -180,10 +178,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         t_user_profile
         GROUP BY
         CASE
-        WHEN age IS NULL THEN
-        '未知'
-        WHEN age &gt;= 10
-        AND age &lt; 20 THEN
+        WHEN age &lt; 20
+        THEN
         '10'
         WHEN age &gt;= 20
         AND age &lt; 30 THEN