From ad2201f809f45cbbe2e63a829e4c93a9c7b7f67c Mon Sep 17 00:00:00 2001
From: yanghui <2536613402@qq.com>
Date: 星期五, 11 十一月 2022 10:00:19 +0800
Subject: [PATCH] #feat 修改
---
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ScreenWorkServiceImpl.java | 359 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 325 insertions(+), 34 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 5ff7cd5..e978d53 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
@@ -1,14 +1,25 @@
package com.panzhihua.service_community.service.impl;
-import com.panzhihua.common.model.vos.R;
-import com.panzhihua.common.model.vos.screen.ComActNeighborCircleScreenVO;
-import com.panzhihua.common.utlis.DateUtils;
-import com.panzhihua.service_community.dao.ComActNeighborCircleDAO;
-import com.panzhihua.service_community.service.ScreenWorkService;
-import org.springframework.stereotype.Service;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
import javax.annotation.Resource;
-import java.util.*;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+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 cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
/**
* @author xyh
@@ -17,40 +28,320 @@
@Service
public class ScreenWorkServiceImpl implements ScreenWorkService {
- private static final Integer neighborSize = 200;
-
+ private static final Integer pageSize = 200;
+ private final String moth_format_str = "yyyy-MM";
+ private final String[] monthStr = new String[] {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
+ @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;
@Override
public R statisticNeighborCircle(Long communityId) {
ComActNeighborCircleScreenVO comActNeighborCircleScreenVO = new ComActNeighborCircleScreenVO();
- String date = DateUtils.getDateFormatString(new Date(),"yyyy-MM-dd");
- Long currentNeighborCircles = comActNeighborCircleDAO.countCurrentNeighborCircles(communityId,date);
- comActNeighborCircleScreenVO.setCurrentNum(currentNeighborCircles == null?0:currentNeighborCircles);
- Long totalNum = comActNeighborCircleDAO.countByCommunityId(communityId);
- comActNeighborCircleScreenVO.setTotalNum(totalNum == null?0L: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.setNeighborCircles(comActNeighborCircleDAO.screenNeighborCircle(communityId,neighborSize));
- //查询最近发布的邻里圈图片
- List<String> imsg = new ArrayList<>();
- List<String> imgList = comActNeighborCircleDAO.screenNeighborCircleImgs(communityId,neighborSize);
- for(String img:imgList){
- String[] imgarr = img.split(",");
- if(imgarr.length > 1){
- for(String arr: imgarr){
- imsg.add(arr);
- }
- }else{
- imsg.add(img);
- }
- }
- comActNeighborCircleScreenVO.setImgs(imsg);
+ String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
+ Map<String, Long> countMap = comActNeighborCircleDAO.countByCommunityId(communityId, date);
+ 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));
+ // 查询最近发布的邻里圈图片
+ comActNeighborCircleScreenVO
+ .setImgs(convertStringList(comActNeighborCircleDAO.screenNeighborCircleImgs(communityId, pageSize)));
return R.ok(comActNeighborCircleScreenVO);
}
+
+ @Override
+ public R wish(Long communityId) {
+ ComActMicroWishScreenVO wishScreenVO = new ComActMicroWishScreenVO();
+ String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
+ // 统计本月新增,累计实现,待实现
+ Map<String, Long> countMap = comActMicroWishDAO.countByCommunityId(communityId, date);
+ wishScreenVO.setCompletedNum(countMap.get("completedNum") == null ? 0L : countMap.get("completedNum"));
+ wishScreenVO.setWillNum(countMap.get("willNum") == null ? 0L : countMap.get("willNum"));
+ wishScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
+ // 微心愿轮播图片
+ wishScreenVO.setImgs(convertStringList(comActMicroWishDAO.getAllImgs(communityId, pageSize)));
+ return R.ok(wishScreenVO);
+ }
+
+ private List<String> convertStringList(List<String> imgList) {
+ List<String> imgs = new ArrayList<>();
+ for (String img : imgList) {
+ if (StringUtils.isEmpty(img)) {
+ continue;
+ }
+ String[] arrs = img.split(",");
+ if (arrs.length > 1) {
+ for (String arr : arrs) {
+ imgs.add(arr);
+ }
+ } else {
+ imgs.add(img);
+ }
+ }
+ return imgs;
+ }
+
+ @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);
+ comActActivityScreenVO.setTotalNum(countMap.get("totalNum") == null ? 0L : countMap.get("totalNum"));
+ comActActivityScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
+ comActActivityScreenVO.setCommonNum(countMap.get("commonNum") == null ? 0L : countMap.get("commonNum"));
+ comActActivityScreenVO
+ .setCommonPeopleNum(countMap.get("commonPeopleNum") == null ? 0L : countMap.get("commonPeopleNum"));
+ comActActivityScreenVO
+ .setVolunteerNum(countMap.get("volunteerNum") == null ? 0L : countMap.get("volunteerNum"));
+ comActActivityScreenVO.setVolunteerPeopleNum(
+ countMap.get("volunteerPeopleNum") == null ? 0L : countMap.get("volunteerPeopleNum"));
+ // 最近活动
+ comActActivityScreenVO.setList(actActivityDAO.screenActivity(communityId, pageSize));
+ return R.ok(comActActivityScreenVO);
+ }
+
+ @Override
+ public R discuss(Long communityId) {
+ ComActDiscussScreenVO discussScreenVO = new ComActDiscussScreenVO();
+ // 统计本月新增,总共,图文,投票
+ String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
+ Map<String, Long> countMap = comActDiscussDAO.countByCommunityId(communityId, date);
+ discussScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
+ discussScreenVO.setTotalNum(countMap.get("totalNum") == null ? 0L : countMap.get("totalNum"));
+ discussScreenVO.setImgNum(countMap.get("imgNum") == null ? 0L : countMap.get("imgNum"));
+ discussScreenVO.setImgPeopleNum(countMap.get("imgPeopleNum") == null ? 0L : countMap.get("imgPeopleNum"));
+ discussScreenVO.setVoteNum(discussScreenVO.getTotalNum() - discussScreenVO.getImgNum());
+ discussScreenVO.setVotePeopleNum(countMap.get("votePeopleNum") == null ? 0L : countMap.get("votePeopleNum"));
+ discussScreenVO.setList(comActDiscussDAO.screenDiscuss(communityId, pageSize));
+ return R.ok(discussScreenVO);
+ }
+
+ @Override
+ public R pbWork(Long communityId) {
+ ComPbWorkScreenVO pbWorkScreenVO = new ComPbWorkScreenVO();
+ String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
+ Map<String, Long> countMap = comPbDynDAO.countByCommunityId(communityId, date);
+ pbWorkScreenVO.setActivityNum(countMap.get("activityNum") == null ? 0L : countMap.get("activityNum"));
+ pbWorkScreenVO.setDynNum(countMap.get("dynNum") == null ? 0L : countMap.get("dynNum"));
+ pbWorkScreenVO.setTotalNum(pbWorkScreenVO.getActivityNum() + pbWorkScreenVO.getDynNum());
+ pbWorkScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
+ // 统计近半年数据
+ List<PbWorkVO> list = new ArrayList<>();
+ for (PbWorkVO workVO : listHalfYear()) {
+ PbWorkVO result = comPbDynDAO.countByTime(workVO.getStart(), workVO.getEnd(), communityId);
+ result.setMonth(workVO.getMonth());
+ list.add(result);
+ }
+ pbWorkScreenVO.setList(list);
+ return R.ok(pbWorkScreenVO);
+ }
+
+ private List<PbWorkVO> listHalfYear() {
+ List<PbWorkVO> 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);
+ 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(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(monthStr[m] + "月下旬");
+ pbWorkVO2.setStart(month + "-" + half + " 23:59:58");
+ pbWorkVO2.setEnd(DateUtils.getDateFormatString(endDay, "yyyy-MM-dd HH:mm:ss"));
+ dateList.add(pbWorkVO2);
+ }
+ return dateList;
+
+ }
+
+ @Override
+ public R easyPhoto(Long communityId) {
+ ComActEasyPhotoScreenVO comActEasyPhotoScreenVO = new ComActEasyPhotoScreenVO();
+ 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);
+ EastPhotoVO result =
+ comActEasyPhotoDAO.countByTime(workVO.getStart(), workVO.getEnd(), nowDate, communityId);
+ result.setMonth(workVO.getMonth());
+ list.add(result);
+ }
+ comActEasyPhotoScreenVO.setList(list);
+ return R.ok(comActEasyPhotoScreenVO);
+ }
+
+ private List<EasyPhotoPointVO> getList(Map<String, Long> dealMap) {
+ Set<Map.Entry<String, Long>> entrySet = dealMap.entrySet();
+
+ List<EasyPhotoPointVO> list = new ArrayList<>();
+ for (Map.Entry<String, Long> en : entrySet) {
+ EasyPhotoPointVO easyPhotoPointVO = new EasyPhotoPointVO();
+ easyPhotoPointVO.setTypeName(en.getKey());
+ easyPhotoPointVO.setPoint(en.getValue().intValue());
+ list.add(easyPhotoPointVO);
+ }
+ return list;
+
+ }
+
+ @Override
+ public R workCount(Long communityId) {
+ ComActWorkScreenVO comActWorkScreenVO = new ComActWorkScreenVO();
+ // 已完成
+ comActWorkScreenVO.setCompletetList(comActNeighborCircleDAO.countAllCompletedWorkByCommunityId(communityId));
+
+ // 未完成
+ 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 = 5; i >= 0; i--) {
+ Date date = DateUtils.getDateM(now, -i);
+ DateTime endDay = DateUtil.endOfMonth(date);
+
+ int m = DateUtil.month(endDay);
+ m++;
+ 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-1] + "月上旬");
+ 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-1] + "月下旬");
+ 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