张天森
2022-07-06 0cbbecaafcfdb30d3e7370f85bbe3f3123499309
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java
@@ -5,9 +5,10 @@
import javax.annotation.Resource;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.PageUtil;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.common.ComPbCheckUnitVo;
import com.panzhihua.common.model.vos.PageVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.service_community.service.ComActNeighborCircleTopicService;
import org.apache.commons.lang3.ObjectUtils;
@@ -991,6 +992,7 @@
        ServiceStaticsVO serviceStaticsVO=new ServiceStaticsVO();
        if(serviceStaticDTO.getCheckUnitId()!=null){
            serviceStaticsVO=this.baseMapper.selectStatsCheckUnit(serviceStaticDTO.getCheckUnitId(),serviceStaticDTO.getYear());
            serviceStaticsVO=this.baseMapper.selectStatsCheckUnit(serviceStaticDTO.getCheckUnitId(),serviceStaticDTO.getYear());
            serviceStaticsVO.setServiceProjecList(this.baseMapper.selectListByCheckUnitId(serviceStaticDTO.getCheckUnitId(),serviceStaticDTO.getYear()));
            serviceStaticsVO.setServiceActivityList(comActActivityDAO.selectListByRelationId(serviceStaticDTO.getCheckUnitId(),serviceStaticDTO.getYear()));
        }
@@ -1008,32 +1010,184 @@
    }
    @Override
    public R institutionalUnitServiceAnalysis(Integer year,Long communityId) {
        //根据年份获取一年的开始和结束时间
    public R institutionalUnitServiceAnalysis(Integer year, Integer type, Integer range, Long communityId,Integer page,Integer size,String belongTo) {
        ActivityAnalysisVO activityVO=new ActivityAnalysisVO();
        String beginTime=null;
        String endTime=null;
        if (null != year && 0 !=year){
            beginTime= year.toString()+"-01-01" ;
            endTime=year.toString()+"-12-31";
        if (null != year){
            //设置开始,截止时间
            beginTime=year.toString().concat("-01-01");
            endTime=year.toString().concat("-12-31");
        }
        //根据communityId分组获取活动时长,活动次数
        List<ComActNeighborCircleAnalysisVO> comActNeighborCircleAnalysisVOS = comActNeighborCircleDAO.institutionalUnitServiceAnalysis(beginTime,endTime,communityId);
        //填充单位,社区信息
        if (comActNeighborCircleAnalysisVOS.size()>0){
            for (ComActNeighborCircleAnalysisVO vo : comActNeighborCircleAnalysisVOS) {
                if (ObjectUtils.isNotEmpty(vo)){
                    if (ObjectUtils.isNotEmpty(vo.getCommunityId())){
                        vo.setCommunityName(comActDAO.selectById(vo.getCommunityId()).getName());
        //统计党员,单位总数
        activityVO.setPartyMemberCount(comActDAO.selectUnitCount());
        activityVO.setUnitCount(comActDAO.selectMemberCount());
        //获取单位活动统计数据(邻里圈)
        List<UnitActivityAnalysisVO> unitActivityAnalysisVOS = comActNeighborCircleDAO.institutionalUnitServiceAnalysis(beginTime, endTime, belongTo);
        //获取单位活动统计数据(活动)
        List<UnitActivityAnalysisVO> unitActivityAnalysisVOS1 = comActNeighborCircleDAO.institutionalUnitActivityAnalysis(beginTime, endTime, belongTo);
        if (unitActivityAnalysisVOS.size()>0){
            for (UnitActivityAnalysisVO unitActivityAnalysisVO : unitActivityAnalysisVOS){
                if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO)){
                    if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO.getUnitId())){
                        //设置单位名称
                        unitActivityAnalysisVO.setUnitName(comActDAO.selectUnitName(unitActivityAnalysisVO.getUnitId()));
                        //统计活动表中的活动信息
                    }
                    if (ObjectUtils.isNotEmpty(vo.getUnitId())){
                        vo.setUnitName(comActDAO.getUnitName(vo.getUnitId()));
                    if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO.getCommunityId())){
                        unitActivityAnalysisVO.setCommunityName(comActDAO.selectById(unitActivityAnalysisVO.getCommunityId()).getName());
                    }
                }
            }
        }
        ActivityAnalysisVO activityAnalysisVO=new ActivityAnalysisVO();
        activityAnalysisVO.setDataList(comActNeighborCircleAnalysisVOS);
        activityAnalysisVO.setUnitCount(comActDAO.getUnitCount());
        return R.ok(activityAnalysisVO);
        //活动表数据处理
        if (unitActivityAnalysisVOS1.size()>0){
            for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS1) {
                if(ObjectUtils.isNotEmpty(vo)){
                    if (ObjectUtils.isNotEmpty(vo.getUnitId())){
                        //判断邻里圈统计中是否已有该单位数据
                        Map<String, Integer> param = alreadyAnalysis(vo.getUnitId(), unitActivityAnalysisVOS);
                        if (param.get("flag")==1){
                            //已有数据,将时长,次数相加
                            Integer serviceTime = vo.getServiceTime();
                            Integer serviceTimes = vo.getServiceTimes();
                            unitActivityAnalysisVOS.get(param.get("index")).setServiceTime(unitActivityAnalysisVOS.get(param.get("index")).getServiceTime()+serviceTime);
                            unitActivityAnalysisVOS.get(param.get("index")).setServiceTimes(unitActivityAnalysisVOS.get(param.get("index")).getServiceTimes()+serviceTimes);
                        }else {
                            //新数据,获取单位,社区名
                            vo.setUnitName(comActDAO.selectUnitName(vo.getUnitId()));
                            if (ObjectUtils.isNotEmpty(vo.getCommunityId())) {
                                vo.setCommunityName(comActDAO.selectById(vo.getCommunityId()).getName());
                            }
                            unitActivityAnalysisVOS.add(vo);
                        }
                    }
                }
            }
        }
        //获取党员活动统计数据
        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS = comActNeighborCircleDAO.institutionalPartyMemberServiceAnalysis(beginTime, endTime, belongTo);
        //统计总时长和总次数
        Integer unitServiceCount=0;
        Integer unitServiceTotalTime=0;
        Integer memberServiceCount=0;
        Integer memberServiceTotalTome=0;
        for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) {
            unitServiceCount+=vo.getServiceTime();
            unitServiceTotalTime+=vo.getServiceTimes();
        }
        for (PartyMemberAnalysisVO vo : partyMemberAnalysisVOS) {
            memberServiceCount+=vo.getServiceTime();
            memberServiceTotalTome+=vo.getServiceTimes();
        }
        activityVO.setUnitServiceTotalCount(unitServiceCount);
        activityVO.setUnitServiceTotalTime(unitServiceTotalTime);
        activityVO.setPartyMemberServiceTotalCount(memberServiceCount);
        activityVO.setPartyMemberServiceTotalTime(memberServiceTotalTome);
        //处理排序
        if (null != type){
            if (type.equals(1)){
                //按时长排序
                ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTime");
                ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTime");
            }else if (type.equals(2)){
                //按次数排序
                ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTimes");
                ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTimes");
            }
        }
        //处理分页
        PageVO<List<UnitActivityAnalysisVO>> unitPage=new PageVO<>();
        PageVO<List<PartyMemberAnalysisVO>> memberPage=new PageVO<>();
        if (ObjectUtils.isNotEmpty(page) && ObjectUtils.isNotEmpty(size)){
            //分页处理
            unitPage.setRecordsCount(unitActivityAnalysisVOS.size());
            unitPage.setPage(page);
            unitPage.setPages(getPages(unitPage.getRecordsCount(),size ));
            memberPage.setPage(page);
            memberPage.setRecordsCount(partyMemberAnalysisVOS.size());
            memberPage.setPages(getPages(memberPage.getRecordsCount(), size));
            //处理分页的结果
            unitPage.setRecords(subUnitList((ArrayList) unitActivityAnalysisVOS, page,size));
            memberPage.setRecords(subUnitList((ArrayList)partyMemberAnalysisVOS,page ,size));
        }else {
            unitPage.setRecords(unitActivityAnalysisVOS);
            memberPage.setRecords(partyMemberAnalysisVOS);
        }
        activityVO.setUnitList(unitPage);
        activityVO.setPartyMemberList(memberPage);
        return R.ok(activityVO);
    }
    @Override
    public R serviceStaticBackstage(ServiceStaticBackstageDTO serviceStaticDTO) {
        return null;
    }
    /**
     * 判断活动统计列表中是否已有该单位的数据
     * */
    public Map<String,Integer> alreadyAnalysis(Long unitId,List<UnitActivityAnalysisVO> list){
        Map<String,Integer> map=new HashMap<>();
        if (list.size()>0){
            for (int i=0;i<list.size();i++) {
                UnitActivityAnalysisVO vo = list.get(i);
                if (ObjectUtils.isNotEmpty(vo)){
                    if (ObjectUtils.isNotEmpty(vo.getUnitId())){
                        if (unitId.equals(vo.getUnitId())){
                            map.put("index",i );
                            map.put("flag",1 );
                            return map;
                        }
                    }
                }
            }
        }
        map.put("flag",0 );
        return map;
    }
    /**
     * 计算总页数
     * */
    public Integer getPages(Integer record,Integer size){
        if (null != record && null != size){
            int pages = PageUtil.totalPage(record, size);
            return pages;
        }
        return 0;
    }
    /**
     * 分页截取
     * */
    public List<Object> subUnitList(List<Object> list, int page, int size){
        try {
            //计算endIndex是否超出List大小
            final Boolean flag=((page-1)*size+size) > list.size();
            if (1 == page || 0 == page){
                //第一页
                return list.subList(0,size);
            }else if (flag){
                return ListUtil.sub(list, (page-1)*size-1, list.size()-1);
            }
            else {
                return list.subList((page-1)*size, (page-1)*size+size);
            }
        }catch (Exception e){
            //返回原集合
            return list;
        }
    }
}