From cf60a875646dbaaa7932f93286d8e708ed79c6dc Mon Sep 17 00:00:00 2001 From: 张天森 <1292933220@qq.com> Date: 星期一, 18 七月 2022 17:39:33 +0800 Subject: [PATCH] update --- springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java | 106 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 93 insertions(+), 13 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..3753f8e 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 @@ -13,6 +13,8 @@ import javax.annotation.Resource; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; @@ -41,6 +43,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -3445,28 +3448,35 @@ for (UserProportion userProportion : userProportions) { if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(userProportion)){ UserRateAnalysisVO vo=new UserRateAnalysisVO(); - vo.setName(typeToName(type,userProportion )); if (monthRange){ + if (userProportion.getCommunityId().equals("11")){ + continue; + } //获取本月的用户总数作为计算占比的用户总数 - IndexDataKanbanVO data = userDao.dataKanBanStreet(streetId, areaCode, date); - vo.setRate(getRate(data.getAllUser(),userProportion.getUser())); + //IndexDataKanbanVO data = userDao.dataKanBanStreet(streetId, areaCode, date); + Integer monthUsers = userDao.getMonthUsers(streetId, areaCode, date); + vo.setRate(getRate(monthUsers,userProportion.getUser())); }else{ vo.setRate(getRate(analysisVO.getAllUser(),userProportion.getUser())); } + vo.setName(typeToName(type,userProportion )); vo.setCount(userProportion.getUser()); userRateAnalysisVOList.add(vo); } } } - //计算其他用户占比 - 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)){ + //查看累计数据时才计算其他用户的比例 || type.equals(BYSTREET) || type.equals(BYAREA)) + final Boolean flag=(type.equals(ALLSTREET) || type.equals(ALLCOMMUNITY)); + 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); @@ -3496,14 +3506,44 @@ List<RealUser> realUsers = userDao.realUserCount(type, date, streetId, areaCode); List<RealUserAnalysisVO> realUserList=new ArrayList<>(); realUserVO.setRealUserCount(getStreetRealUser(realUsers)); - realUserVO.setRealUserRate(NumberUtil.div(realUserVO.getRealUserCount(), analysisVO.getAllUser()).doubleValue()); + Integer rate = getRate(analysisVO.getAllUser(), realUserVO.getRealUserCount()); + if (null == rate){ + realUserVO.setRealUserRate(0.0); + }else{ + realUserVO.setRealUserRate(rate.doubleValue()); + } for (RealUser realUser : realUsers) { + if (!(type.equals(ALLCOUNTY))){ + if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(realUser)){ + if (realUser.getCommunityId().equals("11")){ + continue; + } + } + } RealUserAnalysisVO vo=new RealUserAnalysisVO(); vo.setCount(realUser.getCount()); vo.setName(typeToNameRealUser(type, realUser)); 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); } @@ -3561,6 +3601,40 @@ } } return R.ok(); + } + + @Override + public R getCommunityList(Integer type) { + List<Integer> areaList = areaCodeList(); + List<AreaVOS> areaVOList=new ArrayList<>(); + for (Integer code : areaList) { + AreaVOS areaVO=new AreaVOS(); + areaVO.setId(code); + areaVO.setName(areaCodeToName(code.longValue())); + List<StreetVO> streetVOS = userDao.selectStreetByAreaCode(code); + Iterator<StreetVO> iterator = streetVOS.listIterator(); + while (iterator.hasNext()){ + StreetVO vo = iterator.next(); + List<CommunityVO> communityVOS = userDao.selectCommunityByStreetId(vo.getId(), type); + vo.setCommunityList(communityVOS); + if (type!=3){ + if (communityVOS==null || communityVOS.size()==0){ + iterator.remove(); + } + } + } + List<StreetVOS> list=new ArrayList<>(); + for (StreetVO streetVO : streetVOS) { + StreetVOS vo=new StreetVOS(); + vo.setId(streetVO.getId()); + vo.setName(streetVO.getName()); + vo.setChildList(streetVO.getCommunityList()); + list.add(vo); + } + areaVO.setChildList(list); + areaVOList.add(areaVO); + } + return R.ok(areaVOList); } @Override @@ -3692,6 +3766,7 @@ break; case "510402": name="东区"; + break; case "510411": name="仁和区"; break; @@ -3701,6 +3776,9 @@ case "510422": name="盐边县"; break; + case "510424": + name="钒钛新区"; + break; } return name; } @@ -3709,6 +3787,7 @@ *根据type选择要设置的名称 * */ private String typeToName(Integer type,UserProportion proportion){ + log.info("当前code"+proportion.getAreaCode()); String name=""; if (type.equals(ALLCOUNTY)){ name=areaCodeToName(proportion.getAreaCode()); @@ -3740,11 +3819,12 @@ * */ private List<Integer> areaCodeList(){ List<Integer> list=new ArrayList<>(); - list.add(510423); list.add(510402); + list.add(510423); list.add(510411); list.add(510421); list.add(510422); + list.add(510424); return list; } -- Gitblit v1.7.1