罗元桥
2021-06-17 a7b550f95172e29d71aa38dca45cacf7f31949b8
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ScreenWorkServiceImpl.java
@@ -1,5 +1,6 @@
package com.panzhihua.service_community.service.impl;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.panzhihua.common.model.dtos.partybuilding.ComPbActivityDTO;
@@ -12,6 +13,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -43,7 +45,14 @@
    @Resource
    private ComActEasyPhotoDAO comActEasyPhotoDAO;
    /**
     * 项目开始时间,超过的不统计
     */
    private final String initMonth = "2020-12";
    private final String moth_format_str = "yyyy-MM";
    private final String moth_format_ch = "yyyy年MM月";
    private final String[] monthStr = new String[]{"一","二","三","四","五","六","七","八","九","十","十一","十二"};
@@ -108,12 +117,12 @@
        //统计本月新增、居民活动,志愿者活动
        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.setTotalNum(comActActivityScreenVO.getCommonNum()+comActActivityScreenVO.getVolunteerNum());
        //最近活动
        comActActivityScreenVO.setList(actActivityDAO.screenActivity(communityId,pageSize));
        return R.ok(comActActivityScreenVO);
@@ -126,11 +135,11 @@
        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.setVoteNum(countMap.get("voteNum") == null ? 0L : countMap.get("voteNum"));
        discussScreenVO.setVotePeopleNum(countMap.get("votePeopleNum") == null ? 0L : countMap.get("votePeopleNum"));
        discussScreenVO.setTotalNum(discussScreenVO.getImgNum()+discussScreenVO.getVoteNum());
        discussScreenVO.setList(comActDiscussDAO.screenDiscuss(communityId,pageSize));
        return R.ok(discussScreenVO);
    }
@@ -145,10 +154,11 @@
        pbWorkScreenVO.setTotalNum(pbWorkScreenVO.getActivityNum() + pbWorkScreenVO.getDynNum());
        pbWorkScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
        //统计近半年数据
        int n = 6;
        List<PbWorkVO> list = new ArrayList<>();
        for(PbWorkVO workVO: listHalfYear()){
            PbWorkVO result = comPbDynDAO.countByTime(workVO.getStart(),workVO.getEnd(),communityId);
            result.setMonth(workVO.getMonth());
        for(Map<String,String> map : listHalfYear(n)){
            PbWorkVO result = comPbDynDAO.countByTime(map.get("start"),map.get("end"),communityId);
            result.setMonth(map.get("name"));
            list.add(result);
        }
        pbWorkScreenVO.setList(list);
@@ -156,10 +166,10 @@
    }
    private List<PbWorkVO> listHalfYear() {
        List<PbWorkVO> dateList = new ArrayList<>();
    private List<Map<String,String>> listHalfYear(int num) {
        List<Map<String,String>> dateList = new ArrayList<>();
        Date now  = new Date();
        for(int i= 6;i>=1;i--){
        for(int i= num;i>=1;i--){
            Date date = DateUtils.getDateM(now,-i);
            DateTime endDay = DateUtil.endOfMonth(date);
@@ -167,16 +177,19 @@
            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);
            if(Objects.equals(month,initMonth)){
                continue;
            }
            Map<String,String> startMap = new HashMap<>();
            startMap.put("name",monthStr[m]+"月上旬");
            startMap.put("start",month+ "-01 00:00:00");
            startMap.put("end",month+ "-"+half+" 23:59:58");
            dateList.add(startMap);
            Map<String,String> endMap = new HashMap<>();
            endMap.put("name",monthStr[m]+"月下旬");
            endMap.put("start",month+ "-"+half+" 23:59:59");
            endMap.put("end",DateUtils.getDateFormatString(endDay,"yyyy-MM-dd HH:mm:ss"));
            dateList.add(endMap);
        }
        return dateList;
@@ -192,39 +205,39 @@
        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.setPubPoint(countMap.get("pubPoint") == null ? 0 : Double.valueOf(countMap.get("pubPoint").toString()).intValue());
        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());
        //统计半年数据
        int n = 6;
        for(Map<String,String> map : listHalfYear(n)){
            String nowDate = DateUtils.getDateFormatString(DateUtil.parseDate(map.get("start")),moth_format_str);
            EastPhotoVO result = comActEasyPhotoDAO.countByTime(map.get("start"),map.get("end"),nowDate,communityId);
            result.setMonth(map.get("name"));
            list.add(result);
        }
        comActEasyPhotoScreenVO.setList(list);
        String fmt = "yyyy-MM-01 00:00:00";
        Date start = DateUtil.parse(DateUtil.format(DateUtils.getDateM(new Date(),-n),new SimpleDateFormat(fmt)));
        Date initTime = DateUtil.parse(initMonth +"-01 00:00:00", DatePattern.NORM_DATETIME_FORMAT);
        if(!DateUtils.before(initTime,start)){
            start = initTime;
        }
        comActEasyPhotoScreenVO.setListTimes(DateUtil.format(start,moth_format_ch)+"-"+DateUtil.format(DateUtils.getDateM(new Date(),-1),moth_format_ch));
        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();
        //已完成
//        Map<String,Long> countMap = comActNeighborCircleDAO.countAllWorkBy(communityId);
        comActWorkScreenVO.setAvgTime("1小时");
        comActWorkScreenVO.setTotalCompletedPoint(70);
        comActWorkScreenVO.setEveryDayNum("0.3");