From 7c38a8639974436095dc914e94c855f403f8ffc0 Mon Sep 17 00:00:00 2001 From: 张天森 <1292933220@qq.com> Date: 星期五, 08 七月 2022 10:52:35 +0800 Subject: [PATCH] 双争后台统计范围修改,新数据看板 --- springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 150 insertions(+), 3 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 177601c..9e94005 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 @@ -4,12 +4,18 @@ import static java.util.Objects.nonNull; import static org.apache.commons.lang3.StringUtils.isNotBlank; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.annotation.Resource; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.NumberUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.model.dtos.community.microCommercialStreet.BindUserPhoneDTO; @@ -149,6 +155,7 @@ public static final Integer ALLCOUNTY=1; public static final Integer ALLSTREET=2; public static final Integer ALLCOMMUNITY=3; + public static final Integer BYSTREET=4; // @Resource // private GridService gridService; @@ -3296,12 +3303,152 @@ @Override public R newIndexData(Integer type, Long streetId) { IndexDataKanbanVO indexDataKanbanVO = userDao.selectIndexDataKanban(null); - //判断数据范围 - if (type.equals(ALLCOUNTY)){ - //数据范围:全部区县 + IndexDataAnalysisVO vo=new IndexDataAnalysisVO(); + if (ObjectUtils.isEmpty(type)){ + //不传默认为所有区县 + type=ALLCOUNTY; + } + if (type.equals(ALLCOUNTY) || type.equals(ALLCOMMUNITY) || type.equals(ALLSTREET)){ + BeanUtils.copyProperties(indexDataKanbanVO,vo); + }else { + IndexDataKanbanVO indexDataVO = userDao.dataKanBanStreet(streetId); + BeanUtils.copyProperties(indexDataVO,vo); + } + List<UserProportion> userProportionsTotal = userDao.userAnalysis(type, null, streetId); + Integer streetUser = userDao.streetUserCount(streetId); + for (UserProportion userProportion : userProportionsTotal) { + if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(userProportion)){ + if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(userProportion.getUser())){ + //计算占比 + //userProportion.setAreaCode(null); + if (type.equals(BYSTREET)){ + userProportion.setRate(getRate(streetUser,userProportion.getUser())); + } + userProportion.setRate(getRate(vo.getAllUser(),userProportion.getUser())); + } + } + } + List<UserProportion> userProportionsMonth = userDao.userAnalysis(type, DateUtil.beginOfMonth(new Date()).toString(), streetId); + for (UserProportion userProportion : userProportionsMonth) { + if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(userProportion)){ + if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(userProportion.getUser())){ + //计算占比 + //userProportion.setAreaCode(null); + if (type.equals(BYSTREET)){ + userProportion.setRate(getRate(streetUser,userProportion.getUser())); + } + userProportion.setRate(getRate(vo.getAllUser(),userProportion.getUser())); + } + } + } + vo.setUserProportionTotal(userProportionsTotal); + vo.setUserProportionMonth(userProportionsMonth); + List<RealUser> realUsersTotal = userDao.realUserCount(type, null, streetId); + List<RealUser> realUsersMonth = userDao.realUserCount(type, DateUtil.beginOfMonth(new Date()).toString(), streetId); + vo.setRealUsersTotal(realUsersTotal); + vo.setRealUsersMonth(realUsersMonth); + vo.setRealUser(getStreetRealUser(realUsersTotal)); + vo.setRealUserRate(getRate(vo.getAllUser(),vo.getRealUser())); + vo.setUserActivityXAll(getTwentyDays()); + vo.setUserActivityXMonth(getMonthTwentyDays()); + List<String> addUserYAll=new ArrayList<>(); + List<String> addUserYMonth=new ArrayList<>(); + List<String> activeUserYAll=new ArrayList<>(); + List<String> activeUserYMonth=new ArrayList<>(); + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); + //获取用户行为Y轴 + for (Date date : vo.getUserActivityXAll()) { + //查询当天的新增和日活 + Map<String, Long> map = userDao.getDailyAddAndActive(DateUtil.parse(sdf.format(date)), streetId); + addUserYAll.add(map.get("addUser").toString()); + activeUserYAll.add(map.get("activeUser").toString()); + } + for (Date date : vo.getUserActivityXMonth()) { + Map<String, Long> map = userDao.getDailyAddAndActive(DateUtil.parse(sdf.format(date)), streetId); + addUserYMonth.add(map.get("addUser").toString()); + activeUserYMonth.add(map.get("activeUser").toString()); + } + vo.setAddUserYAll(addUserYAll); + vo.setAddUserYWeek(addUserYMonth); + vo.setActiveUserYAll(activeUserYAll); + vo.setActiveUserYMonth(activeUserYMonth); + if (type.equals(BYSTREET) || type.equals(ALLCOMMUNITY) || type.equals(ALLSTREET)){ + //获取其他用户 + vo.setOtherUser(indexDataKanbanVO.getAllUser()-vo.getAllUser()); + vo.setOtherUserRate(getRate(indexDataKanbanVO.getAllUser(),vo.getAllUser())); + } + return R.ok(vo); + } + + /** + * 获取最近20天数据 + * + * @return + */ + private List<Date> getTwentyDays() { + List<Date> dates = new ArrayList<>(); + Date date = new Date(); + for (int i = 19; i >= 0; i--) { + Date date1 = DateUtils.addDays(date, -i); + dates.add(date1); + } + return dates; + } + + /** + * 获取最近本月20天数据 + * + * @return + */ + private List<Date> getMonthTwentyDays() { + List<Date> dates = new ArrayList<>(); + Date date = new Date(); + Long offset = DateUtil.between(new Date(), DateUtil.beginOfMonth(date), DateUnit.DAY); + if (offset>=20){ + for (int i = 19; i >= 0; i--) { + Date date1 = DateUtils.addDays(date, -i); + dates.add(date1); + } + }else{ + //距离月初不足20天 + for (int i = offset.intValue(); i >= 0; i--) { + Date date1 = DateUtils.addDays(date, -i); + dates.add(date1); + } + } + return dates; + } + + + /** + * 计算占比 + * */ + private Double getRate(Integer total,Integer count){ + if (0 != total && null != total){ + if (0 != count && null != count){ + BigDecimal div = NumberUtil.div(count.toString(), total.toString(),1); + return div.doubleValue(); + } } return null; } + /** + * 计算街道实名用户总数 + * */ + private Integer getStreetRealUser(List<RealUser> list){ + Integer count=0; + if (list.size()>0){ + for (RealUser realUser : list) { + if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(realUser)){ + if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(realUser.getCount())){ + count+=realUser.getCount(); + } + } + } + + } + return count; + } } -- Gitblit v1.7.1