From cc1098fc00a50cb1591d182f04bc37066ff0a9e2 Mon Sep 17 00:00:00 2001 From: 罗元桥 <2376770955@qq.com> Date: 星期四, 05 八月 2021 15:12:39 +0800 Subject: [PATCH] Merge branch 'test' into 'master' --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ScreenWorkServiceImpl.java | 224 ++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 139 insertions(+), 85 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ScreenWorkServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ScreenWorkServiceImpl.java index 236d874..c121e20 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ScreenWorkServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ScreenWorkServiceImpl.java @@ -2,16 +2,22 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.panzhihua.common.model.dtos.partybuilding.ComPbActivityDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.screen.*; import com.panzhihua.common.utlis.DateUtils; import com.panzhihua.common.utlis.StringUtils; import com.panzhihua.service_community.dao.*; +import com.panzhihua.service_community.model.dos.ComActDO; +import com.panzhihua.service_community.model.dos.ComActDynDO; import com.panzhihua.service_community.service.ScreenWorkService; +import org.apache.commons.net.ntp.TimeStamp; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -26,24 +32,25 @@ private static final Integer pageSize = 200; @Resource + private ComActDAO comActDAO; + @Resource private ComActNeighborCircleDAO comActNeighborCircleDAO; - + @Resource + private ComActDynDAO comActDynDAO; @Resource private ComActMicroWishDAO comActMicroWishDAO; - @Resource private ComActActivityDAO actActivityDAO; - @Resource private ComActDiscussDAO comActDiscussDAO; - @Resource private ComPbDynDAO comPbDynDAO; - @Resource private ComActEasyPhotoDAO comActEasyPhotoDAO; private final String moth_format_str = "yyyy-MM"; + + private final String[] monthStr = new String[]{"一","二","三","四","五","六","七","八","九","十","十一","十二"}; @Override public R statisticNeighborCircle(Long communityId) { @@ -51,12 +58,12 @@ ComActNeighborCircleScreenVO comActNeighborCircleScreenVO = new ComActNeighborCircleScreenVO(); String date = DateUtils.getDateFormatString(new Date(),moth_format_str); Map<String,Long> countMap = comActNeighborCircleDAO.countByCommunityId(communityId,date); - comActNeighborCircleScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum")); - comActNeighborCircleScreenVO.setTotalNum(countMap.get("totalNum") == null ? 0L : countMap.get("totalNum")); - Map<String,Long> sumMap = comActNeighborCircleDAO.sumScreenNum(communityId); - comActNeighborCircleScreenVO.setFabulousNum(sumMap.get("fabulousNum") == null ? 0L : sumMap.get("fabulousNum")); - comActNeighborCircleScreenVO.setCommentNum(sumMap.get("commentNum") == null ? 0L : sumMap.get("commentNum")); - comActNeighborCircleScreenVO.setSharedNum(sumMap.get("forwardNum") == null ? 0L : sumMap.get("forwardNum")); + comActNeighborCircleScreenVO.setCurrentNum(countMap.get("currentNum")); + comActNeighborCircleScreenVO.setTotalNum(countMap.get("totalNum")); + Map<String,Object> sumMap = comActNeighborCircleDAO.sumScreenNum(communityId); + comActNeighborCircleScreenVO.setFabulousNum(sumMap.get("fabulousNum") == null?0L:Long.valueOf(sumMap.get("fabulousNum").toString())); + comActNeighborCircleScreenVO.setCommentNum(sumMap.get("commentNum") == null?0L:Long.valueOf(sumMap.get("commentNum").toString())); + comActNeighborCircleScreenVO.setSharedNum(sumMap.get("forwardNum") == null?0L:Long.valueOf(sumMap.get("forwardNum").toString())); //查询最近发布的邻里圈 comActNeighborCircleScreenVO.setList(comActNeighborCircleDAO.screenNeighborCircle(communityId,pageSize)); //查询最近发布的邻里圈图片 @@ -101,6 +108,8 @@ @Override public R activity(Long communityId) { ComActActivityScreenVO comActActivityScreenVO = new ComActActivityScreenVO(); + + comActActivityScreenVO.setImgs(convertStringList(actActivityDAO.listImg(communityId))); //统计本月新增、居民活动,志愿者活动 String date = DateUtils.getDateFormatString(new Date(),moth_format_str); Map<String,Long> countMap = actActivityDAO.countByCommunityId(communityId,date); @@ -156,19 +165,24 @@ List<PbWorkVO> dateList = new ArrayList<>(); Date now = new Date(); for(int i= 6;i>=1;i--){ - Date date = DateUtils.getDateM(now,i); + Date date = DateUtils.getDateM(now,-i); DateTime endDay = DateUtil.endOfMonth(date); - int m = endDay.month();//月份 - int day = DateUtil.dayOfMonth(date); + + int m = DateUtil.month(endDay); + if(m == 0){ + m = 12; + } + m--; + int day = DateUtil.dayOfMonth(endDay); int half = day/2; String month = DateUtil.format(date,moth_format_str); PbWorkVO pbWorkVO = new PbWorkVO(); - pbWorkVO.setMonth(m+"月上旬"); + pbWorkVO.setMonth(monthStr[m]+"月上旬"); pbWorkVO.setStart(month+ "-01 00:00:00"); pbWorkVO.setEnd(month+ "-"+half+" 23:59:58"); dateList.add(pbWorkVO); PbWorkVO pbWorkVO2 = new PbWorkVO(); - pbWorkVO2.setMonth(m+"月下旬"); + pbWorkVO2.setMonth(monthStr[m]+"月下旬"); pbWorkVO2.setStart(month+ "-"+half+" 23:59:58"); pbWorkVO2.setEnd(DateUtils.getDateFormatString(endDay,"yyyy-MM-dd HH:mm:ss")); dateList.add(pbWorkVO2); @@ -180,17 +194,15 @@ @Override public R easyPhoto(Long communityId) { ComActEasyPhotoScreenVO comActEasyPhotoScreenVO = new ComActEasyPhotoScreenVO(); - Map<String,Long> dealMap = comActEasyPhotoDAO.countDeal(communityId); - comActEasyPhotoScreenVO.setDeal(getList(dealMap)); - Map<String,Long> pubMap = comActEasyPhotoDAO.countPub(communityId); - comActEasyPhotoScreenVO.setPub(getList(pubMap)); - Map<String,Long> approvedMap = comActEasyPhotoDAO.countApproved(communityId); - comActEasyPhotoScreenVO.setApproved(getList(approvedMap)); - - Map<String,Long> countMap = comActEasyPhotoDAO.countByCommunityId(communityId); - comActEasyPhotoScreenVO.setNoneDeal(countMap.get("noneDeal") == null ? 0L : countMap.get("noneDeal")); - comActEasyPhotoScreenVO.setPubPoint(countMap.get("pubPoint") == null ? 0L : countMap.get("pubPoint")); - comActEasyPhotoScreenVO.setDealTime(countMap.get("dealTime") == null ? 0L : countMap.get("dealTime")); + comActEasyPhotoScreenVO.setDeal(comActEasyPhotoDAO.countDeal(communityId)); + comActEasyPhotoScreenVO.setPub(comActEasyPhotoDAO.countPub(communityId)); + comActEasyPhotoScreenVO.setApproved(comActEasyPhotoDAO.countApproved(communityId)); + String date = DateUtils.getDateFormatString(new Date(),moth_format_str); + Map<String,Object> countMap = comActEasyPhotoDAO.countByCommunityId(communityId,date); + comActEasyPhotoScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : Long.valueOf(countMap.get("currentNum").toString())); + comActEasyPhotoScreenVO.setNoneDeal(countMap.get("noneDeal") == null ? 0L : Long.valueOf(countMap.get("noneDeal").toString())); + comActEasyPhotoScreenVO.setPubPoint(countMap.get("pubPoint") == null ? 0 : Integer.valueOf(countMap.get("pubPoint").toString())); + comActEasyPhotoScreenVO.setDealTime(countMap.get("dealTime") == null ? 0 : Double.valueOf(countMap.get("dealTime").toString()).intValue()); List<EastPhotoVO> list = new ArrayList<>(); for(PbWorkVO workVO: listHalfYear()){ String nowDate = DateUtils.getDateFormatString(DateUtil.parseDate(workVO.getStart()),moth_format_str); @@ -201,9 +213,6 @@ comActEasyPhotoScreenVO.setList(list); return R.ok(comActEasyPhotoScreenVO); } - - - private List<EasyPhotoPointVO> getList(Map<String, Long> dealMap) { Set<Map.Entry<String,Long>> entrySet = dealMap.entrySet(); @@ -222,63 +231,108 @@ @Override public R workCount(Long communityId) { ComActWorkScreenVO comActWorkScreenVO = new ComActWorkScreenVO(); - comActWorkScreenVO.setAvgTime("1小时"); - comActWorkScreenVO.setTotalCompletedPoint(70); - comActWorkScreenVO.setEveryDayNum("0.3"); - List<ActWorkCountVO> completetPoint = new ArrayList<>(); - ActWorkCountVO easyPhoto = new ActWorkCountVO(); - easyPhoto.setName("随手拍"); - easyPhoto.setNum(10); - completetPoint.add(easyPhoto); - ActWorkCountVO wish = new ActWorkCountVO(); - wish.setName("微心愿"); - wish.setNum(23); - completetPoint.add(wish); - ActWorkCountVO discuss = new ActWorkCountVO(); - discuss.setName("一起议"); - discuss.setNum(33); - completetPoint.add(discuss); - ActWorkCountVO neighbor = new ActWorkCountVO(); - neighbor.setName("邻里圈"); - neighbor.setNum(43); - completetPoint.add(neighbor); - ActWorkCountVO pbWork = new ActWorkCountVO(); - pbWork.setName("党建工作"); - pbWork.setNum(13); - completetPoint.add(pbWork); - ActWorkCountVO activity = new ActWorkCountVO(); - activity.setName("社区活动"); - activity.setNum(63); - completetPoint.add(activity); - comActWorkScreenVO.setCompletetPoint(completetPoint); + //已完成 + comActWorkScreenVO.setCompletetList(comActNeighborCircleDAO.countAllCompletedWorkByCommunityId(communityId)); - List<ActWorkCountVO> completetPoint2 = new ArrayList<>(); - ActWorkCountVO easyPhoto2 = new ActWorkCountVO(); - easyPhoto2.setName("随手拍"); - easyPhoto2.setNum(10); - completetPoint2.add(easyPhoto2); - ActWorkCountVO wish2 = new ActWorkCountVO(); - wish2.setName("微心愿"); - wish2.setNum(23); - completetPoint2.add(wish2); - ActWorkCountVO discuss2 = new ActWorkCountVO(); - discuss2.setName("一起议"); - discuss2.setNum(33); - completetPoint2.add(discuss2); - ActWorkCountVO neighbor2 = new ActWorkCountVO(); - neighbor2.setName("邻里圈"); - neighbor2.setNum(43); - completetPoint2.add(neighbor2); - ActWorkCountVO pbWork2 = new ActWorkCountVO(); - pbWork2.setName("党建工作"); - pbWork2.setNum(13); - completetPoint2.add(pbWork2); - ActWorkCountVO activity2 = new ActWorkCountVO(); - activity2.setName("社区活动"); - activity2.setNum(63); - completetPoint2.add(activity2); - comActWorkScreenVO.setNonePoint(completetPoint2); + //未完成 + comActWorkScreenVO.setNoneList(comActNeighborCircleDAO.countAllNoneCompletedWorkByCommunityId(communityId)); + comActWorkScreenVO.setTotalCompleted(comActWorkScreenVO.getCompletetList().stream().mapToInt(PieElementVO::getNum).sum()); + comActWorkScreenVO.setTotalNoneCompleted(comActWorkScreenVO.getNoneList().stream().mapToInt(PieElementVO::getNum).sum()); + + //统计平均耗时、平均每天完成个数 + Map<String,Object> avgMap = comActNeighborCircleDAO.countAvgByCommunityId(communityId); + comActWorkScreenVO.setAvgTime(avgMap.get("avgTime") == null?"0h":convertTimeStr(Double.valueOf(avgMap.get("avgTime").toString()).intValue())); + + ComActDO comActDO = comActDAO.selectById(communityId); + BigDecimal days = new BigDecimal(DateUtil.betweenDay(comActDO.getCreateAt(),new Date(),false)); + BigDecimal num = new BigDecimal(comActWorkScreenVO.getTotalCompleted()); + BigDecimal rt = num.divide(days,1, RoundingMode.HALF_UP); + comActWorkScreenVO.setEveryDayNum(rt.toString()); return R.ok(comActWorkScreenVO); } + private String convertTimeStr(int minute) { + int hour = minute/60; + int min = minute%60; + StringBuilder timestr = new StringBuilder(); + if(hour > 0){ + timestr.append(hour).append("h"); + } + if(min > 0){ + timestr.append(min).append("min"); + } + return timestr.toString(); + } + + @Override + public R dynamicWork(Long communityId){ + ComDynamicWorkScreenVO workScreenVO = new ComDynamicWorkScreenVO(); + String date = DateUtils.getDateFormatString(new Date(),moth_format_str); + Map<String,Long> countMap = comActDynDAO.countByCommunityId(communityId,date); + if(!countMap.isEmpty()){ + workScreenVO.setTotalNum(countMap.get("dynTotal")== null ? 0L : Long.valueOf(countMap.get("dynTotal").toString())); + workScreenVO.setCurrentNum(countMap.get("currentNum")== null ? 0L : Long.valueOf(countMap.get("currentNum").toString())); + } + + //计算平均每天动态 + DateScreenVO countAvg = comActDynDAO.countByAvgCommunityId(communityId); + if(countAvg != null){ + int day = DateUtils.differentDays(countAvg.getStartTime(),countAvg.getEndTime()); + if(day > 0){ + workScreenVO.setCurrentAvgNum(workScreenVO.getTotalNum().intValue()/day); + } + } + + //查询最新的10条社区动态 + List<String> dynList = new ArrayList<>(); + List<ComActDynDO> actDynDOList = comActDynDAO.selectList(new QueryWrapper<ComActDynDO>().lambda().eq(ComActDynDO::getCommunityId,communityId).orderByDesc(ComActDynDO::getCreateAt).last("limit 10")); + if(!actDynDOList.isEmpty()){ + actDynDOList.forEach(actDyn -> { + dynList.add(actDyn.getTitle()); + }); + } + workScreenVO.setDynList(dynList); + + //统计近半年数据 + List<DynamicWorkVO> list = new ArrayList<>(); + for(DynamicWorkVO dynamicWorkVO: listHalfYearByDyn()){ + DynamicWorkVO result = comActDynDAO.countByTime(dynamicWorkVO.getStart(),dynamicWorkVO.getEnd(),communityId); + result.setMonth(dynamicWorkVO.getMonth()); + list.add(result); + } + workScreenVO.setList(list); + + return R.ok(workScreenVO); + } + + private List<DynamicWorkVO> listHalfYearByDyn() { + List<DynamicWorkVO> dateList = new ArrayList<>(); + Date now = new Date(); + for(int i= 6;i>=1;i--){ + Date date = DateUtils.getDateM(now,-i); + DateTime endDay = DateUtil.endOfMonth(date); + + int m = DateUtil.month(endDay); + m++; + if(m == 12){ + m = 0; + } + int day = DateUtil.dayOfMonth(endDay); + int half = day/2; + String month = DateUtil.format(date,moth_format_str); + DynamicWorkVO dynamicWorkVO = new DynamicWorkVO(); + dynamicWorkVO.setMonth(monthStr[m]+"月上旬"); + dynamicWorkVO.setStart(month+ "-01 00:00:00"); + dynamicWorkVO.setEnd(month+ "-"+half+" 23:59:58"); + dateList.add(dynamicWorkVO); + DynamicWorkVO dynamicWorkVO1 = new DynamicWorkVO(); + dynamicWorkVO1.setMonth(monthStr[m]+"月下旬"); + dynamicWorkVO1.setStart(month+ "-"+half+" 23:59:58"); + dynamicWorkVO1.setEnd(DateUtils.getDateFormatString(endDay,"yyyy-MM-dd HH:mm:ss")); + dateList.add(dynamicWorkVO1); + } + return dateList; + + } + } -- Gitblit v1.7.1