From 77deb8621aac83c40b2140611852380c9e123899 Mon Sep 17 00:00:00 2001
From: 张天森 <1292933220@qq.com>
Date: 星期三, 13 七月 2022 17:19:11 +0800
Subject: [PATCH] 用户占比统计规则修改

---
 springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
index 1f41811..ad63772 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -3458,15 +3458,18 @@
                 }
             }
         }
-        //计算其他用户占比
-        final Boolean flag=(type.equals(ALLSTREET) || type.equals(ALLCOMMUNITY) || type.equals(BYSTREET) || type.equals(BYAREA));
-        if (flag){
-            UserRateAnalysisVO vo=new UserRateAnalysisVO();
-            vo.setName(OTHERUSER);
-            vo.setCount(analysisVO.getAllUser()-countUser(userRateAnalysisVOList));
-            vo.setRate(getRate(analysisVO.getAllUser(), vo.getCount()));
-            userRateAnalysisVOList.add(vo);
+        if (ObjectUtils.isEmpty(range)){
+            //查看累计数据时才计算其他用户的比例
+            final Boolean flag=(type.equals(ALLSTREET) || type.equals(ALLCOMMUNITY) || type.equals(BYSTREET) || type.equals(BYAREA));
+            if (flag){
+                UserRateAnalysisVO vo=new UserRateAnalysisVO();
+                vo.setName(OTHERUSER);
+                vo.setCount(analysisVO.getAllUser()-countUser(userRateAnalysisVOList));
+                vo.setRate(getRate(analysisVO.getAllUser(), vo.getCount()));
+                userRateAnalysisVOList.add(vo);
+            }
         }
+        //计算其他用户占比
         UserRateVO userRate=new UserRateVO();
         userRate.setUserList(userRateAnalysisVOList);
         return R.ok(userRate);
@@ -3504,6 +3507,24 @@
             realUserList.add(vo);
         }
         realUserVO.setRealUserList(realUserList);
+        //使用索引迭代避免从列表移除数据后出现空指针异常
+        if (type.equals(BYSTREET) || type.equals(ALLCOMMUNITY)){
+            for (int i = 0; i < realUserList.size() ; i++) {
+                RealUserAnalysisVO realUserAnalysisVO = realUserList.get(i);
+                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(realUserAnalysisVO)){
+                    if (StringUtils.isNotEmpty(realUserAnalysisVO.getName())){
+                        if (realUserAnalysisVO.getName().equals("请选择社区")){
+                            realUserList.remove(i);
+                        }
+                    }
+                }
+            }
+        }else {
+            //只保留十条
+            if (realUserList.size()>=11){
+                realUserList.remove(10);
+            }
+        }
         return R.ok(realUserVO);
     }
 

--
Gitblit v1.7.1