LIVE_YE 1 gadu atpakaļ
vecāks
revīzija
37a7a12c3c

+ 37 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanReservatServiceImpl.java

@@ -1,11 +1,14 @@
 package com.ruoyi.system.service.impl;
 
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.BomanReservatConfigTime;
@@ -221,11 +224,42 @@ public class BomanReservatServiceImpl implements IBomanReservatService {
     @Override
     public AjaxResult realTime() {
         // todo
+
+        String configKey = "lyssllsj";
+        String configKey_1 = "lyssllsj_1";
+        String configValue = Convert.toStr(redisCache.getCacheObject(configKey));
+        String configValue_1 = Convert.toStr(redisCache.getCacheObject(configKey_1));
+        if(StringUtils.isEmpty(configValue)){
+            configValue = "0";
+        }
+        if(StringUtils.isEmpty(configValue_1)){
+            configValue_1 = "0";
+        }
+
+
         Map<String, Object> resultMap = new HashMap<>();
 
-        resultMap.put("scale" , "50%");
-        resultMap.put("current" , 5);
-        resultMap.put("total" , 10);
+        if(StringUtils.isEmpty(configValue) || "0".equals(configValue)){
+            resultMap.put("scale" , "0%");
+        }
+        if(StringUtils.isEmpty(configValue_1) || "0".equals(configValue_1)){
+            resultMap.put("scale" , "0%");
+        }
+
+
+        BigDecimal num1 = new BigDecimal("configValue");
+        BigDecimal num2 = new BigDecimal("configValue_1");
+        double result = Double.parseDouble(((num1.divide(num2)).setScale(2,BigDecimal.ROUND_HALF_UP)).toString());
+        DecimalFormat decimalFormat = new DecimalFormat("0%"); // 创建DecimalFormat对象并设置格式化模式为"0%"
+        String percentage = decimalFormat.format((result * 100)); // 使用DecimalFormat对象进行格式化操作
+
+        resultMap.put("scale" , percentage);
+        //今天比昨天新增多少人
+        resultMap.put("addNum" , Long.parseLong(configValue)-Long.parseLong(configValue_1));
+        //昨天人数
+        resultMap.put("current" , configValue_1);
+        //今天人数
+        resultMap.put("total" , configValue);
         return AjaxResult.success(resultMap);
     }