LIVE_YE 1 year ago
parent
commit
3110a6bc8b

+ 11 - 16
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BomanReservatServiceImpl.java

@@ -229,31 +229,26 @@ public class BomanReservatServiceImpl implements IBomanReservatService {
         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)){
+        if(StringUtils.isEmpty(configValue) || "0".equals(configValue)){
             configValue = "0";
         }
-        if(StringUtils.isEmpty(configValue_1)){
+        if(StringUtils.isEmpty(configValue_1) || "0".equals(configValue_1)){
             configValue_1 = "0";
         }
 
 
         Map<String, Object> resultMap = new HashMap<>();
-
-        if(StringUtils.isEmpty(configValue) || "0".equals(configValue)){
-            resultMap.put("scale" , "0%");
+        resultMap.put("scale" , "0%");
+
+        if(!"0".equals(configValue) && !"0".equals(configValue_1)){
+            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);
         }
-        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));
         //昨天人数