From b3ad0200bb7dc1d9c2bf75edb14de3f4fde2c40d Mon Sep 17 00:00:00 2001
From: lidongdong <1459917685@qq.com>
Date: 星期二, 04 六月 2024 14:02:14 +0800
Subject: [PATCH] 花城 议事投票评论提交报错

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java |  307 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 287 insertions(+), 20 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java
index 7a98656..08bd230 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java
@@ -1,43 +1,48 @@
 package com.panzhihua.service_community.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.util.PageUtil;
 import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.collection.ListUtil;
-import cn.hutool.core.util.PageUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.panzhihua.common.constants.NeighborCircleConstants;
+import com.panzhihua.common.model.dtos.ExcelDO;
+import com.panzhihua.common.model.dtos.PartyExcelDO;
 import com.panzhihua.common.model.dtos.neighbor.*;
 import com.panzhihua.common.model.vos.PageVO;
 import com.panzhihua.common.model.vos.R;
+import com.panzhihua.common.model.vos.common.PbCheckUnitStatisticsVo;
 import com.panzhihua.common.model.vos.neighbor.*;
 import com.panzhihua.common.model.vos.user.AdministratorsUserVO;
 import com.panzhihua.common.service.user.UserService;
 import com.panzhihua.common.utlis.*;
 import com.panzhihua.service_community.dao.*;
 import com.panzhihua.service_community.entity.ComPbCheckUnit;
+import com.panzhihua.service_community.entity.NewFightNeedProblemClaim;
+import com.panzhihua.service_community.entity.NewFightNeedProblemInventory;
 import com.panzhihua.service_community.entity.SysUser;
 import com.panzhihua.service_community.model.dos.*;
 import com.panzhihua.service_community.service.ComActNeighborCircleBrowseService;
 import com.panzhihua.service_community.service.ComActNeighborCircleService;
 import com.panzhihua.service_community.service.ComActNeighborCircleTopicService;
+import com.panzhihua.service_community.util.ExcelUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.time.LocalDateTime;
+import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
-import static com.panzhihua.common.utlis.PayUtil.makeUUID;
 
 /**
  * @auther lyq
@@ -85,6 +90,10 @@
     private ComPbCheckUnitDao comPbCheckUnitDao;
     @Resource
     private SysUserDao sysUserDao;
+    @Autowired
+    private NewFightNeedProblemClaimMapper newFightNeedProblemClaimMapper;
+    @Autowired
+    private NewFightNeedProblemInventoryMapper newFightNeedProblemInventoryMapper;
     /**
      * 分页查询邻里圈列表
      *
@@ -1145,7 +1154,8 @@
     }
 
     @Override
-    public R institutionalUnitServiceAnalysis(Integer year, Integer type, Integer range, Long communityId,Integer page,Integer size,String belongTo,Long unitId) {
+    public R institutionalUnitServiceAnalysis(Integer year, Integer type, Integer range, Long communityId,
+                                              Integer page,Integer size,String belongTo,Long unitId,String searchContent) {
         ActivityAnalysisVO activityVO=new ActivityAnalysisVO();
         String beginTime=null;
         String endTime=null;
@@ -1206,8 +1216,8 @@
             }
         }
         //获取党员活动统计数据
-        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS = comActNeighborCircleDAO.institutionalPartyMemberServiceAnalysis(beginTime, endTime, belongTo,communityId,unitId);
-        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS1 = comActNeighborCircleDAO.institutionalPartyMemberActAnalysis(beginTime, endTime, belongTo,communityId,unitId);
+        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS = comActNeighborCircleDAO.institutionalPartyMemberServiceAnalysis(beginTime, endTime, belongTo,communityId,unitId,searchContent);
+        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS1 = comActNeighborCircleDAO.institutionalPartyMemberActAnalysis(beginTime, endTime, belongTo,communityId,unitId,searchContent);
         if (partyMemberAnalysisVOS1.size()>0){
             for (PartyMemberAnalysisVO vo : partyMemberAnalysisVOS1) {
                 if (ObjectUtils.isNotEmpty(vo)){
@@ -1225,11 +1235,64 @@
                 }
             }
         }
+        //报道单位统计积分
+        List<NewFightNeedProblemInventory> allList = newFightNeedProblemInventoryMapper.selectAll();
+        Map<Long, String> awardMap = allList.stream().filter(Objects::nonNull).collect(Collectors.toMap(NewFightNeedProblemInventory::getId, NewFightNeedProblemInventory::getAward));
+        for (UnitActivityAnalysisVO unitVO : unitActivityAnalysisVOS) {
+
+            Long unitId1 = unitVO.getUnitId();
+            LambdaQueryWrapper<NewFightNeedProblemClaim> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(NewFightNeedProblemClaim::getUnitId,String.valueOf(unitId1));
+            List<NewFightNeedProblemClaim> inventories = newFightNeedProblemClaimMapper.selectList(wrapper);
+            Map<String, Long> collectMap = inventories.stream()
+                    .collect(Collectors.groupingBy(NewFightNeedProblemClaim::getTaskId, Collectors.counting()));
+            long sum = 0l;
+            if(unitVO.getAwardSum()!=null || unitVO.getAwardSum()!=0l )
+            {
+                sum=unitVO.getAwardSum();
+            }
+            //任务id集合
+            List<String> taskIds = inventories.stream().map(NewFightNeedProblemClaim::getTaskId).distinct().collect(Collectors.toList());
+            for (String taskId : taskIds) {
+//                NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId);
+//                String award = newFightNeedProblemInventory.getAward();
+                String award = awardMap.get(Long.parseLong(taskId));
+                Long count = collectMap.get(taskId);
+                long i = Long.parseLong(award) * count;
+                sum = sum + i;
+            }
+            unitVO.setAwardSum(sum);
+        }
+
+        //报道党员统计积分
+        for (PartyMemberAnalysisVO memberAnalysisVO : partyMemberAnalysisVOS) {
+            Long userId = memberAnalysisVO.getMemberId();
+            LambdaQueryWrapper<NewFightNeedProblemClaim> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(NewFightNeedProblemClaim::getUserId,userId);
+            List<NewFightNeedProblemClaim> newFightNeedProblemInventories = newFightNeedProblemClaimMapper.selectList(wrapper);
+            long sumAward = 0l;
+
+            if(memberAnalysisVO.getPartyCount()!=null || memberAnalysisVO.getPartyCount()!=0l )
+            {
+                sumAward=memberAnalysisVO.getPartyCount();
+            }
+
+            for (NewFightNeedProblemClaim inventory : newFightNeedProblemInventories) {
+                String taskId = inventory.getTaskId();
+                NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId);
+                String award = newFightNeedProblemInventory.getAward();
+                sumAward = Long.parseLong(award) + sumAward;
+            }
+            memberAnalysisVO.setPartyCount(sumAward);
+        }
+
         //统计总时长和总次数
         Integer unitServiceCount=0;
         Integer unitServiceTotalTime=0;
         Integer memberServiceCount=0;
         Integer memberServiceTotalTome=0;
+        long awardSumCount=0L;
+        long partySumCount=0L;
         for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) {
             //避免空指针
             if (ObjectUtils.isNotEmpty(vo)){
@@ -1252,22 +1315,50 @@
                 }
             }
         }
+        for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) {
+            if(ObjectUtils.isNotEmpty(vo)){
+                if(ObjectUtils.isNotEmpty(vo.getAwardSum())){
+                    awardSumCount += vo.getAwardSum();
+                }
+            }
+        }
+        for (PartyMemberAnalysisVO memberAnalysisVO : partyMemberAnalysisVOS) {
+            if(ObjectUtils.isNotEmpty(memberAnalysisVO)){
+                if(ObjectUtils.isNotEmpty(memberAnalysisVO.getPartyCount())){
+                    partySumCount += memberAnalysisVO.getPartyCount();
+                }
+            }
+        }
+        activityVO.setAwardSumCount(awardSumCount);
+        activityVO.setPartySumCount(partySumCount);
         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");
-//            }
-//        }
+        if (null != type){
+            if (type.equals(1)){
+                //按时长排序
+                ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTime");
+                ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTime");
+
+                ListUtil.reverse(unitActivityAnalysisVOS);
+                ListUtil.reverse(partyMemberAnalysisVOS);
+
+            }else if (type.equals(2)){
+                //按次数排序
+                ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTimes");
+                ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTimes");
+
+                ListUtil.reverse(unitActivityAnalysisVOS);
+                ListUtil.reverse(partyMemberAnalysisVOS);
+            }else if(type.equals(3)){
+                //按积分排序
+                ListUtil.sortByProperty(unitActivityAnalysisVOS,"awardSum");
+                ListUtil.reverse(unitActivityAnalysisVOS);
+             //   ListUtil.sortByProperty(unitActivityAnalysisVOS,"");
+            }
+        }
         //处理分页
         PageVO<List<UnitActivityAnalysisVO>> unitPage=new PageVO<>();
         PageVO<List<PartyMemberAnalysisVO>> memberPage=new PageVO<>();
@@ -1289,10 +1380,186 @@
         }
         activityVO.setUnitList(unitPage);
         activityVO.setPartyMemberList(memberPage);
+
+        //党员数据 聚合
+        Map<String, Long> map = new HashMap<>();
+        partyMemberAnalysisVOS.forEach(vo->{
+            String name = vo.getBelongTo();
+            Long time = Long.valueOf(vo.getServiceTime());
+            if (map.containsKey(name)) {
+                time += map.get(name);
+            }
+            map.put(name, time);
+        });
+        if(CollectionUtil.isNotEmpty(map)){
+            List<PbCheckUnitStatisticsVo> list = new ArrayList<>();
+            map.keySet().forEach(vo->{
+                PbCheckUnitStatisticsVo dto = new PbCheckUnitStatisticsVo();
+                dto.setBelongTo(vo);
+                dto.setServiceTime(map.get(vo));
+                list.add(dto);
+            });
+            activityVO.setGroupPartyCount(list);
+        }
         return R.ok(activityVO);
 
     }
 
+    @Override
+    public List<ExcelDO> export(Integer year, String belongTo, Long communityId) throws Exception {
+        List<ExcelDO> excelDOList = new ArrayList<>();
+        String beginTime=null;
+        String endTime=null;
+        if (null != year){
+            //设置开始,截止时间
+            beginTime=year.toString().concat("-01-01");
+            endTime=year.toString().concat("-12-31");
+        }
+        //获取单位活动统计数据(邻里圈)
+        List<UnitActivityAnalysisVO> unitActivityAnalysisVOS = comActNeighborCircleDAO.institutionalUnitServiceAnalysis(beginTime, endTime, belongTo,communityId);
+        //获取单位活动统计数据(活动)
+        List<UnitActivityAnalysisVO> unitActivityAnalysisVOS1 = comActNeighborCircleDAO.institutionalUnitActivityAnalysis(beginTime, endTime, belongTo,communityId);
+        if (!unitActivityAnalysisVOS.isEmpty()){
+            for (UnitActivityAnalysisVO unitActivityAnalysisVO : unitActivityAnalysisVOS){
+                if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO)){
+                    if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO.getUnitId())){
+                        //设置单位名称
+                        unitActivityAnalysisVO.setUnitName(comActDAO.selectUnitName(unitActivityAnalysisVO.getUnitId()));
+                        //统计活动表中的活动信息
+                    }
+                    if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO.getCommunityId())){
+                        unitActivityAnalysisVO.setCommunityName(comActDAO.selectById(unitActivityAnalysisVO.getCommunityId()).getName());
+                    }
+                }
+            }
+        }
+        //活动表数据处理
+        if (!unitActivityAnalysisVOS1.isEmpty()){
+            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()))
+                            {
+                                ComActDO actDO=comActDAO.selectById(vo.getCommunityId());
+                                if(actDO!=null && !StringUtils.isEmpty(actDO.getName()))
+                                {
+                                    vo.setCommunityName(actDO.getName());
+                                }
+                            }
+                            unitActivityAnalysisVOS.add(vo);
+                        }
+                    }
+                }
+            }
+        }
+        List<NewFightNeedProblemInventory> allList = newFightNeedProblemInventoryMapper.selectAll();
+        Map<Long, String> awardMap = allList.stream().filter(Objects::nonNull).collect(Collectors.toMap(NewFightNeedProblemInventory::getId, NewFightNeedProblemInventory::getAward));
+        for (UnitActivityAnalysisVO unitVO : unitActivityAnalysisVOS) {
+
+            Long unitId1 = unitVO.getUnitId();
+            LambdaQueryWrapper<NewFightNeedProblemClaim> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(NewFightNeedProblemClaim::getUnitId,String.valueOf(unitId1));
+            List<NewFightNeedProblemClaim> inventories = newFightNeedProblemClaimMapper.selectList(wrapper);
+            Map<String, Long> collectMap = inventories.stream()
+                    .collect(Collectors.groupingBy(NewFightNeedProblemClaim::getTaskId, Collectors.counting()));
+            long sum = 0L;
+            //任务id集合
+            List<String> taskIds = inventories.stream().map(NewFightNeedProblemClaim::getTaskId).distinct().collect(Collectors.toList());
+            for (String taskId : taskIds) {
+//                NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId);
+//                String award = newFightNeedProblemInventory.getAward();
+                String award = awardMap.get(Long.parseLong(taskId));
+                Long count = collectMap.get(taskId);
+                long i = Long.parseLong(award) * count;
+                sum = sum + i;
+            }
+            unitVO.setAwardSum(sum);
+        }
+        for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) {
+            ExcelDO excelDO = new ExcelDO();
+            excelDO.setBelongTo(vo.getBelongTo());
+            excelDO.setOrgName(vo.getOrgName());
+            excelDO.setUnitName(vo.getUnitName());
+            excelDO.setCommunityName(vo.getCommunityName());
+            excelDO.setServiceTime(vo.getServiceTime());
+            excelDO.setAwardSum(vo.getAwardSum());
+            excelDOList.add(excelDO);
+        }
+        return excelDOList;
+    }
+
+    @Override
+    public List<PartyExcelDO> partyExcel(Integer year, String belongTo, Long communityId,Long unitId) {
+        String beginTime=null;
+        String endTime=null;
+        if (null != year){
+            //设置开始,截止时间
+            beginTime=year.toString().concat("-01-01");
+            endTime=year.toString().concat("-12-31");
+        }
+        //获取党员活动统计数据
+        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS = comActNeighborCircleDAO.institutionalPartyMemberServiceAnalysis(beginTime, endTime, belongTo,communityId,unitId,null);
+        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS1 = comActNeighborCircleDAO.institutionalPartyMemberActAnalysis(beginTime, endTime, belongTo,communityId,unitId,null);
+        if (partyMemberAnalysisVOS1.size()>0){
+            for (PartyMemberAnalysisVO vo : partyMemberAnalysisVOS1) {
+                if (ObjectUtils.isNotEmpty(vo)){
+                    if (ObjectUtils.isNotEmpty(vo.getMemberId())){
+                        Map<String, Integer> param = memberAlreadyAnalysis(vo.getMemberId(), partyMemberAnalysisVOS);
+                        if (param.get("flag")==1){
+                            Integer serviceTime = vo.getServiceTime();
+                            Integer serviceTimes = vo.getServiceTimes();
+                            partyMemberAnalysisVOS.get(param.get("index")).setServiceTime(partyMemberAnalysisVOS.get(param.get("index")).getServiceTime()+serviceTime);
+                            partyMemberAnalysisVOS.get(param.get("index")).setServiceTimes(partyMemberAnalysisVOS.get(param.get("index")).getServiceTimes()+serviceTimes);
+                        }else{
+                            partyMemberAnalysisVOS.add(vo);
+                        }
+                    }
+                }
+            }
+        }
+
+        //报道党员统计积分
+        for (PartyMemberAnalysisVO memberAnalysisVO : partyMemberAnalysisVOS) {
+            Long userId = memberAnalysisVO.getMemberId();
+            LambdaQueryWrapper<NewFightNeedProblemClaim> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(NewFightNeedProblemClaim::getUserId,userId);
+            List<NewFightNeedProblemClaim> newFightNeedProblemInventories = newFightNeedProblemClaimMapper.selectList(wrapper);
+            long sumAward = 0L;
+            for (NewFightNeedProblemClaim inventory : newFightNeedProblemInventories) {
+                String taskId = inventory.getTaskId();
+                NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId);
+                String award = newFightNeedProblemInventory.getAward();
+                sumAward = Long.parseLong(award) + sumAward;
+            }
+            memberAnalysisVO.setPartyCount(sumAward);
+        }
+        List<PartyExcelDO> list = new ArrayList<>();
+        for (PartyMemberAnalysisVO memberAnalysisVO : partyMemberAnalysisVOS) {
+            PartyExcelDO partyExcelDO = new PartyExcelDO();
+            partyExcelDO.setBelongTo(memberAnalysisVO.getBelongTo());
+            partyExcelDO.setOrgName(memberAnalysisVO.getOrgName());
+            partyExcelDO.setUnitName(memberAnalysisVO.getUnitName());
+            partyExcelDO.setMemberName(memberAnalysisVO.getMemberName());
+            partyExcelDO.setBelongCommunity(memberAnalysisVO.getBelongCommunity());
+            partyExcelDO.setServiceTimes(memberAnalysisVO.getServiceTimes());
+            partyExcelDO.setServiceTime(memberAnalysisVO.getServiceTime());
+            partyExcelDO.setPartyCount(memberAnalysisVO.getPartyCount());
+            list.add(partyExcelDO);
+        }
+        return list;
+    }
+
 
     @Override
     public R serviceStaticBackstage(ServiceStaticBackstageDTO serviceStaticDTO) {

--
Gitblit v1.7.1