liujie
2025-06-09 70d2a5d0f9c6951b2d4cac954041ed73582ff7eb
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java
@@ -1,22 +1,49 @@
package com.panzhihua.service_community.service.impl;
import java.util.Date;
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 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.model.dtos.neighbor.ComActNeighborCircleAdminDTO;
import com.panzhihua.common.model.dtos.neighbor.ComActNeighborCircleAppDTO;
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.neighbor.AddNeighborCircleAdminVO;
import com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAdminVO;
import com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAppVO;
import com.panzhihua.common.model.vos.neighbor.EditNeighborCircleAdminVO;
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.service_community.dao.ComActNeighborCircleDAO;
import com.panzhihua.service_community.model.dos.ComActNeighborCircleDO;
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 javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @auther lyq
@@ -25,23 +52,337 @@
 */
@Slf4j
@Service
public abstract class ComActNeighborCircleServiceImpl extends ServiceImpl<ComActNeighborCircleDAO, ComActNeighborCircleDO> implements ComActNeighborCircleService {
public class ComActNeighborCircleServiceImpl extends ServiceImpl<ComActNeighborCircleDAO, ComActNeighborCircleDO>
    implements ComActNeighborCircleService {
    @Resource
    ComActNeighborCircleFabulousDAO neighborCircleFabulousDAO;
    @Resource
    ComActNeighborCircleBrowseDAO neighborCircleBrowseDAO;
    @Resource
    ComActNeighborCircleCommentDAO neighborCircleCommentDAO;
    @Resource
    ComActNeighborCircleCommentReplyDAO neighborCircleCommentReplyDAO;
    @Resource
    private ComActNeighborCircleBrowseService comActNeighborCircleBrowseService;
    @Resource
    private ComActNeighborCircleCommentDAO comActNeighborCircleCommentDAO;
    @Resource
    private ComActNeighborCircleCommentReplyDAO comActNeighborCircleCommentReplyDAO;
    @Resource
    private ComActNeighborCircleFabulousDAO comActNeighborCircleFabulousDAO;
    @Resource
    private ComActNeighborCircleBrowseDAO comActNeighborCircleBrowseDAO;
    @Resource
    private ComActDAO comActDAO;
    @Resource
    private ComActNeighborCircleTopicMapper comActNeighborCircleTopicMapper;
    @Resource
    private ComActNeighborCircleTopicService comActNeighborCircleTopicService;
    @Resource
    private UserService userService;
    @Resource
    private ComPbMemberDAO comPbMemberDAO;
    @Resource
    private ComActNeighborCircleDAO comActNeighborCircleDAO;
    @Resource
    private ComActActivityDAO comActActivityDAO;
    @Resource
    private ComPbCheckUnitDao comPbCheckUnitDao;
    @Resource
    private SysUserDao sysUserDao;
    @Autowired
    private NewFightNeedProblemClaimMapper newFightNeedProblemClaimMapper;
    @Autowired
    private NewFightNeedProblemInventoryMapper newFightNeedProblemInventoryMapper;
    /**
     * 分页查询邻里圈列表
     * @param neighborCircleAppDTO  请求参数
     * @return  邻里圈列表
     *
     * @param neighborCircleAppDTO
     *            请求参数
     * @return 邻里圈列表
     */
    public R pageNeighborByApp(ComActNeighborCircleAppDTO neighborCircleAppDTO){
    @Override
    public R pageNeighborByApp(ComActNeighborCircleAppDTO neighborCircleAppDTO) {
//        if(neighborCircleAppDTO.getCommunityId()==0L){
//            R<LoginUserInfoVO> loginUserInfoVOR=userService.getUserInfoByUserId(neighborCircleAppDTO.getUserId().toString());
//            if(R.isOk(loginUserInfoVOR)){
//                LoginUserInfoVO loginUserInfoVO=loginUserInfoVOR.getData();
//                if(loginUserInfoVO!=null){
//                 ComPbMemberDO comPbMemberDO=comPbMemberDAO.selectOne(new QueryWrapper<ComPbMemberDO>().lambda().eq(ComPbMemberDO::getIdCard,loginUserInfoVO.getIdCard()));
//                 if(comPbMemberDO!=null){
//                     neighborCircleAppDTO.setCommunityId(comPbMemberDO.getCommunityId());
//                 }
//                }
//            }
//        }
        Long communityId = neighborCircleAppDTO.getCommunityId();
        if(null != communityId){
            List<Long> communityIds = comActDAO.selectIds(communityId);
            if (CollUtil.isEmpty(communityIds)) {
                communityIds = new ArrayList<>();
                communityIds.add(communityId);
            }
            neighborCircleAppDTO.setCommunityIds(communityIds);
        }
        Page userPage = new Page(neighborCircleAppDTO.getPageNum(), neighborCircleAppDTO.getPageSize());
        IPage<ComActNeighborCircleAppVO> doPager = this.baseMapper.pageNeighborByApp(userPage, neighborCircleAppDTO);
        if (!doPager.getRecords().isEmpty()) {
            for (ComActNeighborCircleAppVO circleAppVO : doPager.getRecords()) {
                if (neighborCircleAppDTO.getUserId() != null) {
                    // 查询点赞信息
                    ComActNeighborCircleFabulousDO circleFabulousDO =
                        comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>()
                            .lambda().eq(ComActNeighborCircleFabulousDO::getParentId, circleAppVO.getId())
                            .eq(ComActNeighborCircleFabulousDO::getUserId, neighborCircleAppDTO.getUserId())
                            .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.llq)
                            .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                                ComActNeighborCircleFabulousDO.isEffective.yes));
                    if (circleFabulousDO != null) {
                        circleAppVO.setHaveSign(1);
                    } else {
                        circleAppVO.setHaveSign(2);
                    }
                }
                if (circleAppVO.getType() != null && circleAppVO.getType().equals(ComActNeighborCircleDO.type.admin)) {
                    ComActDO actDO = comActDAO.selectById(circleAppVO.getCommunityId());
                    if (actDO != null) {
                        circleAppVO.setName(actDO.getName());
                    }
                }
            }
        }
        return R.ok(doPager);
    }
    @Override
    public R selectSolve(ComActNeighborCircleAppDTO neighborCircleAppDTO) {
        IPage<ComActNeighborCircleAppVO> doPager=this.baseMapper.selectSolve(new Page<ComActNeighborCircleDO>(neighborCircleAppDTO.getPageNum(),neighborCircleAppDTO.getPageSize()),neighborCircleAppDTO);
        if (!doPager.getRecords().isEmpty()) {
            for (ComActNeighborCircleAppVO circleAppVO : doPager.getRecords()) {
                if (neighborCircleAppDTO.getSolveId() != null) {
                    // 查询点赞信息
                    ComActNeighborCircleFabulousDO circleFabulousDO =
                            comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>()
                                    .lambda().eq(ComActNeighborCircleFabulousDO::getParentId, circleAppVO.getId())
                                    .eq(ComActNeighborCircleFabulousDO::getUserId, neighborCircleAppDTO.getUserId())
                                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.llq)
                                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                                            ComActNeighborCircleFabulousDO.isEffective.yes));
                    if (circleFabulousDO != null) {
                        circleAppVO.setHaveSign(1);
                    } else {
                        circleAppVO.setHaveSign(2);
                    }
                }
                ComActDO actDO = comActDAO.selectById(circleAppVO.getCommunityId());
                if (circleAppVO.getType() != null && circleAppVO.getType().equals(ComActNeighborCircleDO.type.admin)) {
                    if (actDO != null) {
                        circleAppVO.setName(actDO.getName());
                    }
                }
                else {
                    if (actDO != null) {
                        circleAppVO.setCommunityName(actDO.getName());
                    }
                }
            }
        }
        return R.ok(doPager);
    }
    /**
     * 用户发布邻里圈审核
     *
     * @param addNeighborCircleAppDTO
     *            邻里圈请求参数
     * @return 发布结果
     */
    @Override
    public R addNeighborByApp(AddComActNeighborCircleAppDTO addNeighborCircleAppDTO) {
        // 新增邻里圈审核
        ComActNeighborCircleDO neighborCircleDO = new ComActNeighborCircleDO();
        BeanUtils.copyProperties(addNeighborCircleAppDTO, neighborCircleDO);
        if (addNeighborCircleAppDTO.getUserId() != null) {
            neighborCircleDO.setReleaseId(addNeighborCircleAppDTO.getUserId());
        }
        if (addNeighborCircleAppDTO.getCommunityId() != null) {
            neighborCircleDO.setCommunityId(addNeighborCircleAppDTO.getCommunityId());
        }
        if (StringUtils.isNotEmpty(addNeighborCircleAppDTO.getPhone())) {
            neighborCircleDO.setReleasePhone(addNeighborCircleAppDTO.getPhone());
        }
        //判断当前邻里圈是否需要审核
        if(addNeighborCircleAppDTO.getIsExamine().equals(AddComActNeighborCircleAppDTO.isExamine.no)){
            //当邻里圈不需要审核才进入自动审核
            //判断邻里圈自动审核结果
            if(addNeighborCircleAppDTO.getWxExamineResult().equals(AddComActNeighborCircleAppDTO.isExamine.yes)){
                neighborCircleDO.setStatus(ComActNeighborCircleDO.status.xs);
                if(neighborCircleDO.getTopicId() != null){
                    //给邻里圈话题添加邻里圈数量
                    comActNeighborCircleTopicMapper.addCount(neighborCircleDO.getTopicId());
                }
            }else{
                neighborCircleDO.setStatus(ComActNeighborCircleDO.status.bh);
                neighborCircleDO.setRefuseReason("内容违规");
            }
        }
        if(this.baseMapper.insert(neighborCircleDO) > 0){
            return R.ok();
        } else {
            return R.fail("发布失败");
        }
    }
    /**
     * 查看邻里圈详情
     *
     * @param neighborCircleAppDTO
     *            请求参数
     * @return 邻里圈详情
     */
    @Override
    public R neighborDetailByApp(ComActNeighborCircleDetailAppDTO neighborCircleAppDTO) {
        // 查询邻里圈详情
        ComActNeighborCircleDetailAppVO circleDetailAppVO =
            this.baseMapper.neighborDetailByApp(neighborCircleAppDTO.getCircleId());
        if (circleDetailAppVO == null) {
            return R.fail("未找到邻里圈信息");
        }
        if (circleDetailAppVO.getType() != null
            && circleDetailAppVO.getType().equals(ComActNeighborCircleDO.type.admin)) {
            ComActDO actDO = comActDAO.selectById(circleDetailAppVO.getCommunityId());
            if (actDO != null) {
                circleDetailAppVO.setName(actDO.getName());
            }
        }
        if(circleDetailAppVO.getOrderType()!=null){
            if(circleDetailAppVO.getOrderType()==2){
                AdministratorsUserVO user1 = this.baseMapper.selectUserByUserId(circleDetailAppVO.getSolveId());
                circleDetailAppVO.setSolveName(SensitiveUtil.replaceName(user1.getName()));
            }
            if(circleDetailAppVO.getOrderType()==1){
                ComPbCheckUnit comPbCheckUnit=comPbCheckUnitDao.selectById(circleDetailAppVO.getSolveUnitId());
                if(comPbCheckUnit!=null){
                    circleDetailAppVO.setSolveName(comPbCheckUnit.getName());
                }
            }
        }
        if (neighborCircleAppDTO.getUserId() != null) {
            // 查询邻里圈点赞信息
            ComActNeighborCircleFabulousDO circleFabulousDO =
                comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                    .eq(ComActNeighborCircleFabulousDO::getParentId, circleDetailAppVO.getId())
                    .eq(ComActNeighborCircleFabulousDO::getUserId, neighborCircleAppDTO.getUserId())
                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.llq)
                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                        ComActNeighborCircleFabulousDO.isEffective.yes));
            if (circleFabulousDO != null) {
                circleDetailAppVO.setHaveSign(1);
            } else {
                circleDetailAppVO.setHaveSign(2);
            }
        }
        ComActActivityDO comActActivityDO=comActActivityDAO.selectOne(new QueryWrapper<ComActActivityDO>().lambda().eq(ComActActivityDO::getRelationId,neighborCircleAppDTO.getCircleId()));
        if(comActActivityDO!=null){
            circleDetailAppVO.setActivityDate(comActActivityDO.getCreateAt());
            circleDetailAppVO.setActivityId(comActActivityDO.getId());
            circleDetailAppVO.setActivityName(comActActivityDO.getActivityName());
        }
        // 查询邻里圈下评论列表
        IPage<ComActNeighborCircleCommentAppVO> circleCommentAppPage =
            comActNeighborCircleCommentDAO.pageNeighborCommentByApp(
                new Page(neighborCircleAppDTO.getPageNum(), neighborCircleAppDTO.getPageSize()), neighborCircleAppDTO);
        if (!circleCommentAppPage.getRecords().isEmpty()) {
            for (ComActNeighborCircleCommentAppVO circleCommentVo : circleCommentAppPage.getRecords()) {
                if (neighborCircleAppDTO.getUserId() != null) {
                    // 查询点赞信息
                    ComActNeighborCircleFabulousDO circleCommentFabulousDO =
                        comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>()
                            .lambda().eq(ComActNeighborCircleFabulousDO::getParentId, circleCommentVo.getId())
                            .eq(ComActNeighborCircleFabulousDO::getUserId, neighborCircleAppDTO.getUserId())
                            .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.pl)
                            .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                                ComActNeighborCircleFabulousDO.isEffective.yes));
                    if (circleCommentFabulousDO != null) {
                        circleCommentVo.setHaveSign(1);
                    } else {
                        circleCommentVo.setHaveSign(2);
                    }
                }
                // 查询评论下评论回复
                List<ComActNeighborCircleCommentReplyAppVO> commentReplyAppVOS =
                    comActNeighborCircleCommentReplyDAO.getCircleCommentReplyList(circleCommentVo.getId());
                if (!commentReplyAppVOS.isEmpty()) {
                    List<ComActNeighborCircleCommentReplyAppVO> newCommentReplyAppVOS = new ArrayList<>();
                    if (neighborCircleAppDTO.getUserId() != null) {
                        int i = 0;
                        for (ComActNeighborCircleCommentReplyAppVO commentReplyVO : commentReplyAppVOS) {
                            if (i >= 2) {
                                break;
                            }
                            // 查询点赞信息
                            ComActNeighborCircleFabulousDO circleReplyFabulousDO = comActNeighborCircleFabulousDAO
                                .selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                                    .eq(ComActNeighborCircleFabulousDO::getParentId, commentReplyVO.getId())
                                    .eq(ComActNeighborCircleFabulousDO::getUserId, neighborCircleAppDTO.getUserId())
                                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.hf)
                                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                                        ComActNeighborCircleFabulousDO.isEffective.yes));
                            if (circleReplyFabulousDO != null) {
                                commentReplyVO.setHaveSign(1);
                            } else {
                                commentReplyVO.setHaveSign(2);
                            }
                            newCommentReplyAppVOS.add(commentReplyVO);
                            i++;
                        }
                    }
                    circleCommentVo.setCircleCommentReplyAppList(newCommentReplyAppVOS);
                    circleCommentVo.setCommentReplyNum(commentReplyAppVOS.size());
                }
            }
        }
        circleDetailAppVO.setCircleCommentAppList(circleCommentAppPage.getRecords());
        return R.ok(circleDetailAppVO);
    }
    @Override
    public R pageNeighborByAdmin(ComActNeighborCircleAdminDTO neighborCircleAdminDTO) {
        Long communityId = neighborCircleAdminDTO.getCommunityId();
        if(null != communityId){
            List<Long> communityIds = comActDAO.selectIds(communityId);
            if (CollUtil.isEmpty(communityIds)) {
                communityIds = new ArrayList<>();
                communityIds.add(communityId);
            }
            neighborCircleAdminDTO.setCommunityIds(communityIds);
        }
        Page page = new Page(neighborCircleAdminDTO.getPageNum(), neighborCircleAdminDTO.getPageSize());
        IPage<ComActNeighborCircleAdminVO> doPager = this.baseMapper.pageNeighborByAdmin(page, neighborCircleAdminDTO);
        doPager.getRecords().forEach(data -> {
            if(data.getUserType()!=null){
                if (data.getUserType() != 1) {
                    data.setReleaseName(data.getCommunityName());
                }
            }
        });
        return R.ok(doPager);
    }
    @Override
    public R pageNeighborByBigScreen(ComActNeighborCircleAdminDTO neighborCircleAdminDTO) {
        Page page = new Page(neighborCircleAdminDTO.getPageNum(), neighborCircleAdminDTO.getPageSize());
        IPage<ComActNeighborCircleAdminVO> doPager = this.baseMapper.pageNeighborByBigScreen(page, neighborCircleAdminDTO);
        return R.ok(doPager);
    }
@@ -49,7 +390,7 @@
    public R addNeighborByAdmin(AddNeighborCircleAdminVO addVO) {
        ComActNeighborCircleDO comActNeighborCircleDO = new ComActNeighborCircleDO();
        AdministratorsUserVO adminUser = this.baseMapper.selectUserByUserId(addVO.getUserId());
        if(adminUser==null){
        if (adminUser == null) {
            return R.fail("请登录重试");
        }
        comActNeighborCircleDO.setReleaseId(addVO.getUserId());
@@ -57,7 +398,8 @@
        comActNeighborCircleDO.setCommunityId(adminUser.getCommunityId());
        comActNeighborCircleDO.setReleaseContent(addVO.getReleaseContent());
        comActNeighborCircleDO.setReleaseImages(addVO.getReleaseImages());
        comActNeighborCircleDO.setStatus(1);
        comActNeighborCircleDO.setType(2);
        comActNeighborCircleDO.setStatus(2);
        comActNeighborCircleDO.setCommentNum(0);
        comActNeighborCircleDO.setFabulousNum(0);
        comActNeighborCircleDO.setForwardNum(0);
@@ -67,6 +409,7 @@
        comActNeighborCircleDO.setLastCommentNum(0);
        comActNeighborCircleDO.setLastFabulousNum(0);
        comActNeighborCircleDO.setLastViewsNum(0);
        comActNeighborCircleDO.setBelongType(addVO.getBelongType());
        this.baseMapper.insert(comActNeighborCircleDO);
        return R.ok();
    }
@@ -74,12 +417,1506 @@
    @Override
    public R changeStatusByAdmin(EditNeighborCircleAdminVO editVO) {
        ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(editVO.getId());
        if(neighborCircleDO==null){
        if (neighborCircleDO == null) {
            return R.fail("id有误!");
        }
        neighborCircleDO.setStatus(editVO.getStatus());
        neighborCircleDO.setRefuseReason(editVO.getRefuseReason());
        if (editVO.getRefuseReason() != null) {
            neighborCircleDO.setRefuseReason(editVO.getRefuseReason());
        }
        this.baseMapper.updateById(neighborCircleDO);
        if(editVO.getStatus().equals(EditNeighborCircleAdminVO.status.xs) && neighborCircleDO.getTopicId() != null){
            //给邻里圈话题添加邻里圈数量
            comActNeighborCircleTopicMapper.addCount(neighborCircleDO.getTopicId());
        }
        return R.ok(neighborCircleDO.getReleaseId());
    }
    /**
     * 用户查询邻里圈列表
     *
     * @param neighborCircleAppDTO
     *            请求参数
     * @return 邻里圈列表
     */
    @Override
    public R neighborExamineByApp(ComActNeighborCircleAppDTO neighborCircleAppDTO) {
        IPage<ComActNeighborCircleAppVO> neighborCircleIPage = this.baseMapper.neighborExamineByApp(
            new Page<>(neighborCircleAppDTO.getPageNum(), neighborCircleAppDTO.getPageSize()),
            neighborCircleAppDTO.getUserId(),neighborCircleAppDTO.getBelongType());
        if (!neighborCircleIPage.getRecords().isEmpty()) {
            for (ComActNeighborCircleAppVO circleAppVO : neighborCircleIPage.getRecords()) {
                // 查询点赞信息
                ComActNeighborCircleFabulousDO circleFabulousDO =
                    comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>()
                        .lambda().eq(ComActNeighborCircleFabulousDO::getParentId, circleAppVO.getId())
                        .eq(ComActNeighborCircleFabulousDO::getUserId, neighborCircleAppDTO.getUserId())
                        .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.llq)
                        .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                            ComActNeighborCircleFabulousDO.isEffective.yes));
                if (circleFabulousDO != null) {
                    circleAppVO.setHaveSign(1);
                } else {
                    circleAppVO.setHaveSign(2);
                }
            }
        }
        return R.ok(neighborCircleIPage);
    }
    /**
     * 邻里圈点赞
     *
     * @param fabulousAppDTO
     *            请求参数
     * @return 点赞结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R neighborFabulousByApp(ComActNeighborFabulousAppDTO fabulousAppDTO) {
        ComActNeighborCircleFabulousDO circleFabulousDO = new ComActNeighborCircleFabulousDO();
        circleFabulousDO.setUserId(fabulousAppDTO.getUserId());
        circleFabulousDO.setType(fabulousAppDTO.getType());
        circleFabulousDO.setParentId(fabulousAppDTO.getServiceId());
        // 判断点赞类型
        if (fabulousAppDTO.getType().equals(ComActNeighborFabulousAppDTO.type.llq)) {
            ComActNeighborCircleFabulousDO oldCircleFabulousDO =
                comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborFabulousAppDTO.type.llq)
                    .eq(ComActNeighborCircleFabulousDO::getParentId, fabulousAppDTO.getServiceId())
                    .eq(ComActNeighborCircleFabulousDO::getIsEffective, ComActNeighborCircleFabulousDO.isEffective.yes)
                    .eq(ComActNeighborCircleFabulousDO::getUserId, fabulousAppDTO.getUserId()));
            if (oldCircleFabulousDO != null) {
                return R.fail("您已点赞");
            }
            // 增加邻里圈点赞数量
            ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(fabulousAppDTO.getServiceId());
            if (neighborCircleDO != null) {
                neighborCircleDO.setFabulousNum(neighborCircleDO.getFabulousNum() + 1);
                neighborCircleDO.setViewsNum(neighborCircleDO.getViewsNum() + 1);
                //计算需要增加的热度值
                Long hotNum = NeighborCircleConstants.FABULOUS_HOT_NUM + NeighborCircleConstants.VIEW_HOT_NUM;
                neighborCircleDO.setHotNum(neighborCircleDO.getHotNum() + hotNum);
                this.baseMapper.updateById(neighborCircleDO);
                comActNeighborCircleTopicMapper.addHotNum(neighborCircleDO.getTopicId(),hotNum);
                circleFabulousDO.setCircleId(neighborCircleDO.getId());
            }
            // 添加邻里圈浏览记录
            comActNeighborCircleBrowseService.addBrowseRecord(fabulousAppDTO.getServiceId(),
                fabulousAppDTO.getUserId());
        } else if (fabulousAppDTO.getType().equals(ComActNeighborFabulousAppDTO.type.pl)) {
            ComActNeighborCircleFabulousDO oldCircleFabulousDO =
                comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborFabulousAppDTO.type.pl)
                    .eq(ComActNeighborCircleFabulousDO::getParentId, fabulousAppDTO.getServiceId())
                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                        ComActNeighborCircleFabulousDO.isEffective.yes));
            if (oldCircleFabulousDO != null) {
                return R.fail("您已点赞");
            }
            // 增加邻里圈评论点赞数量
            ComActNeighborCircleCommentDO circleCommentDO =
                comActNeighborCircleCommentDAO.selectById(fabulousAppDTO.getServiceId());
            if (circleCommentDO != null) {
                circleCommentDO.setFabulousNum(circleCommentDO.getFabulousNum() + 1);
                comActNeighborCircleCommentDAO.updateById(circleCommentDO);
                //计算需要增加的热度值
                Long hotNum = NeighborCircleConstants.FABULOUS_HOT_NUM + NeighborCircleConstants.VIEW_HOT_NUM;
                this.baseMapper.addTopicHotNum(circleCommentDO.getCircleId(),hotNum);
                this.baseMapper.addHotNum(circleCommentDO.getCircleId(),hotNum);
                circleFabulousDO.setCircleId(circleCommentDO.getCircleId());
            }
        } else if (fabulousAppDTO.getType().equals(ComActNeighborFabulousAppDTO.type.hf)) {
            ComActNeighborCircleFabulousDO oldCircleFabulousDO =
                comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborFabulousAppDTO.type.hf)
                    .eq(ComActNeighborCircleFabulousDO::getParentId, fabulousAppDTO.getServiceId())
                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                        ComActNeighborCircleFabulousDO.isEffective.yes));
            if (oldCircleFabulousDO != null) {
                return R.fail("您已点赞");
            }
            // 增加邻里圈评论回复点赞数量
            ComActNeighborCircleCommentReplyDO circleCommentReplyDO =
                comActNeighborCircleCommentReplyDAO.selectById(fabulousAppDTO.getServiceId());
            if (circleCommentReplyDO != null) {
                circleCommentReplyDO.setFabulousNum(circleCommentReplyDO.getFabulousNum() + 1);
                comActNeighborCircleCommentReplyDAO.updateById(circleCommentReplyDO);
                //计算需要增加的热度值
                Long hotNum = NeighborCircleConstants.FABULOUS_HOT_NUM + NeighborCircleConstants.VIEW_HOT_NUM;
                this.baseMapper.addTopicHotNum(circleCommentReplyDO.getCircleId(),hotNum);
                this.baseMapper.addHotNum(circleCommentReplyDO.getCircleId(),hotNum);
                circleFabulousDO.setCircleId(circleCommentReplyDO.getCircleId());
            }
        }
        if (comActNeighborCircleFabulousDAO.insert(circleFabulousDO) > 0) {
            return R.ok();
        } else {
            return R.fail("点赞失败");
        }
    }
    /**
     * 邻里圈转发
     *
     * @param forwardAppDTO
     *            请求参数
     * @return 转发结果
     */
    @Override
    public R neighborForwardByApp(ComActNeighborForwardAppDTO forwardAppDTO) {
        if (forwardAppDTO.getUserId() != null) {
            // 添加邻里圈浏览记录
            comActNeighborCircleBrowseService.addBrowseRecord(forwardAppDTO.getCircleId(), forwardAppDTO.getUserId());
        }
        ComActNeighborCircleDO circleDO = this.baseMapper.selectById(forwardAppDTO.getCircleId());
        if (circleDO == null) {
            return R.fail("没有找到邻里圈");
        }
        circleDO.setForwardNum(circleDO.getForwardNum() + 1);
        if (this.baseMapper.updateById(circleDO) > 0){
            //计算需要增加的热度值
            Long hotNum = NeighborCircleConstants.VIEW_HOT_NUM;
            this.baseMapper.addHotNum(forwardAppDTO.getCircleId(),hotNum);
            this.baseMapper.addTopicHotNum(forwardAppDTO.getCircleId(),hotNum);
            return R.ok();
        } else {
            return R.fail("转发失败");
        }
    }
    /**
     * 邻里圈评论
     *
     * @param commentAppDTO
     *            请求参数
     * @return 评论结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R neighborCommentByApp(ComActNeighborCommentAppDTO commentAppDTO) {
        ComActNeighborCircleCommentDO circleCommentDO = new ComActNeighborCircleCommentDO();
        // 查询邻里圈更新邻里圈评论数量
        ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(commentAppDTO.getCircleId());
        if (neighborCircleDO == null) {
            return R.fail("没有找到邻里圈");
        }
        neighborCircleDO.setCommentNum(neighborCircleDO.getCommentNum() + 1);
        neighborCircleDO.setReplyAt(new Date());
        this.baseMapper.updateById(neighborCircleDO);
        //计算需要增加的热度值
        Long hotNum = NeighborCircleConstants.COMMENT_HOT_NUM;
        this.baseMapper.addHotNum(commentAppDTO.getCircleId(),hotNum);
        this.baseMapper.addTopicHotNum(commentAppDTO.getCircleId(),hotNum);
        circleCommentDO.setCircleId(commentAppDTO.getCircleId());
        circleCommentDO.setUserId(commentAppDTO.getUserId());
        circleCommentDO.setUserPhone(commentAppDTO.getPhone());
        circleCommentDO.setContent(commentAppDTO.getContent());
        if (neighborCircleDO.getReleaseId().equals(commentAppDTO.getUserId())) {
            circleCommentDO.setIsRelease(ComActNeighborCircleCommentDO.isRelease.yes);
        }
        if (comActNeighborCircleCommentDAO.insert(circleCommentDO) > 0) {
            SysUser sysUser=sysUserDao.selectOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserId,neighborCircleDO.getSolveId()));
            if(sysUser!=null) {
                try {
                    WxXCXTempSend util = new WxXCXTempSend();
                    if (neighborCircleDO.getBelongType()==2){
                        WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你有一条新的评价信息",neighborCircleDO.getReleaseContent().length()>10?neighborCircleDO.getReleaseContent().substring(0,10)+"..":neighborCircleDO.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+neighborCircleDO.getId()+"&type=888");
                    }
                    if (neighborCircleDO.getBelongType()==3){
                        WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你有一条新的评价信息",neighborCircleDO.getReleaseContent().length()>10?neighborCircleDO.getReleaseContent().substring(0,10)+"..":neighborCircleDO.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+neighborCircleDO.getId()+"&type=777");
                    }
            } catch (Exception e) {
                e.printStackTrace();
            }
            }
            return R.ok();
        } else {
            return R.fail("评论失败");
        }
    }
    /**
     * 邻里圈回复
     *
     * @param replyAppDTO
     *            请求参数
     * @return 回复结果
     */
    @Override
    public R neighborReplyByApp(ComActNeighborReplyAppDTO replyAppDTO) {
        ComActNeighborCircleCommentReplyDO circleCommentReplyDO = new ComActNeighborCircleCommentReplyDO();
        // 查询邻里圈更新邻里圈评论数量
        ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(replyAppDTO.getCircleId());
        if (neighborCircleDO == null) {
            return R.fail("没有找到邻里圈");
        }
        neighborCircleDO.setCommentNum(neighborCircleDO.getCommentNum() + 1);
        neighborCircleDO.setReplyAt(new Date());
        this.baseMapper.updateById(neighborCircleDO);
        //计算需要增加的热度值
        Long hotNum = NeighborCircleConstants.COMMENT_HOT_NUM;
        this.baseMapper.addHotNum(replyAppDTO.getCircleId(),hotNum);
        this.baseMapper.addTopicHotNum(replyAppDTO.getCircleId(),hotNum);
        circleCommentReplyDO.setCircleId(replyAppDTO.getCircleId());
        circleCommentReplyDO.setUserId(replyAppDTO.getUserId());
        circleCommentReplyDO.setReplyContent(replyAppDTO.getContent());
        if (neighborCircleDO.getReleaseId().equals(replyAppDTO.getUserId())) {
            circleCommentReplyDO.setIsRelease(1);
        }
        // 判断回复类型
        if (replyAppDTO.getType().equals(ComActNeighborReplyAppDTO.type.pl)) {
            // 查询评论信息
            ComActNeighborCircleCommentDO circleCommentDO =
                comActNeighborCircleCommentDAO.selectById(replyAppDTO.getServiceId());
            if (circleCommentDO != null) {
                circleCommentReplyDO.setCommentId(replyAppDTO.getServiceId());
                circleCommentReplyDO.setParentId(0L);
                circleCommentReplyDO.setParentUserId(circleCommentDO.getUserId());
            }
        } else if (replyAppDTO.getType().equals(ComActNeighborReplyAppDTO.type.hf)) {
            // 查询上级回复信息
            ComActNeighborCircleCommentReplyDO parentCommentReplyDO =
                comActNeighborCircleCommentReplyDAO.selectById(replyAppDTO.getServiceId());
            if (parentCommentReplyDO != null) {
                circleCommentReplyDO.setCommentId(parentCommentReplyDO.getCommentId());
                circleCommentReplyDO.setParentId(parentCommentReplyDO.getId());
                circleCommentReplyDO.setParentUserId(parentCommentReplyDO.getUserId());
            }
        }
        if (comActNeighborCircleCommentReplyDAO.insert(circleCommentReplyDO) > 0) {
            return R.ok();
        } else {
            return R.fail("回复失败");
        }
    }
    @Override
    public R timeTaskCircleFlow() {
        Date oldDate = DateUtils.addDay(new Date(), -3);
        // 查询所有状态正常的邻里圈
        List<ComActNeighborCircleDO> circleDOList =
            this.baseMapper.selectList(new QueryWrapper<ComActNeighborCircleDO>().lambda()
                .eq(ComActNeighborCircleDO::getStatus, ComActNeighborCircleDO.status.xs));
        if (!circleDOList.isEmpty()) {
            // 遍历查询到的邻里圈,更新邻里圈内近3天的评论数,点赞数,浏览量
            for (ComActNeighborCircleDO neighborCircleDO : circleDOList) {
                // 查询邻里圈近3天的评论数
                int commentCount =
                    comActNeighborCircleCommentDAO.selectCount(new QueryWrapper<ComActNeighborCircleCommentDO>()
                        .lambda().eq(ComActNeighborCircleCommentDO::getCircleId, neighborCircleDO.getId()));
                // 查询邻里圈近3天的评论回复数
                int commentReplyCount = comActNeighborCircleCommentReplyDAO
                    .selectCount(new QueryWrapper<ComActNeighborCircleCommentReplyDO>().lambda()
                        .eq(ComActNeighborCircleCommentReplyDO::getCircleId, neighborCircleDO.getId()));
                // 查询邻里圈近3天的点赞数
                int fabulousCount =
                    comActNeighborCircleFabulousDAO.selectCount(new QueryWrapper<ComActNeighborCircleFabulousDO>()
                        .lambda().eq(ComActNeighborCircleFabulousDO::getCircleId, neighborCircleDO.getId())
                        .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                            ComActNeighborCircleFabulousDO.isEffective.yes));
                // 查询邻里圈近3天的浏览量
                int browseCount =
                    comActNeighborCircleBrowseDAO.selectCount(new QueryWrapper<ComActNeighborCircleBrowseDO>().lambda()
                        .eq(ComActNeighborCircleBrowseDO::getNeighborId, neighborCircleDO.getId()));
                // 更新邻里圈信息
                neighborCircleDO.setLastCommentNum(commentCount + commentReplyCount);
                neighborCircleDO.setLastFabulousNum(fabulousCount);
                neighborCircleDO.setLastViewsNum(browseCount);
                this.baseMapper.updateById(neighborCircleDO);
            }
        }
        return R.ok();
    }
    @Override
    public R deleteByAdmin(Long id) {
        ComActNeighborCircleDO comActNeighborCircleDO = this.baseMapper.selectById(id);
        if (comActNeighborCircleDO == null) {
            return R.fail();
        }
        if (comActNeighborCircleDO.getStatus() == 1) {
            return R.fail("待审核的数据不能删除");
        }
        // 邻里圈删除
        this.baseMapper.deleteById(id);
        // 邻里圈评论删除
        neighborCircleCommentDAO.delete(
            new LambdaQueryWrapper<ComActNeighborCircleCommentDO>().eq(ComActNeighborCircleCommentDO::getCircleId, id));
        // 邻里圈回复删除
        neighborCircleCommentReplyDAO.delete(new LambdaQueryWrapper<ComActNeighborCircleCommentReplyDO>()
            .eq(ComActNeighborCircleCommentReplyDO::getCircleId, id));
        // 邻里圈浏览器记录
        neighborCircleBrowseDAO.delete(
            new LambdaQueryWrapper<ComActNeighborCircleBrowseDO>().eq(ComActNeighborCircleBrowseDO::getNeighborId, id));
        // 邻里圈点赞删除
        neighborCircleFabulousDAO.delete(new LambdaQueryWrapper<ComActNeighborCircleFabulousDO>()
            .eq(ComActNeighborCircleFabulousDO::getCircleId, id));
        return R.ok();
    }
    @Override
    public R detailNeighborByAdmin(Long id) {
        ComActNeighborCircleDetailAppVO comActNeighborCircleDO = baseMapper.neighborDetailByApp(id);
        if (comActNeighborCircleDO == null) {
            return R.fail("id有误");
        }
        AdministratorsUserVO user = this.baseMapper.selectUserByUserId(comActNeighborCircleDO.getReleaseId());
        DetailNeighborCircleAdminVO vo = new DetailNeighborCircleAdminVO();
        BeanUtils.copyProperties(comActNeighborCircleDO, vo);
        if(user!=null){
            vo.setReleaseName(user.getName());
            vo.setImageUrl(user.getImageUrl());
        }
        if(comActNeighborCircleDO.getOrderType()!=null){
            if(comActNeighborCircleDO.getOrderType()==2){
                AdministratorsUserVO user1 = this.baseMapper.selectUserByUserId(comActNeighborCircleDO.getSolveId());
                vo.setSolveName(user1.getName());
            }
            if(comActNeighborCircleDO.getOrderType()==1){
                ComPbCheckUnit comPbCheckUnit=comPbCheckUnitDao.selectById(comActNeighborCircleDO.getSolveUnitId());
                if(comPbCheckUnit!=null){
                    vo.setSolveName(comPbCheckUnit.getName());
                }
            }
        }
        // 查询话题名称
        if (comActNeighborCircleDO.getTopicId() != null) {
            ComActNeighborCircleTopicDO circleTopicDO =
                comActNeighborCircleTopicMapper.selectById(comActNeighborCircleDO.getTopicId());
            if(circleTopicDO!=null && !StringUtils.isEmpty(circleTopicDO.getName()))
            {
                vo.setTopicName(circleTopicDO.getName());
            }
        }
        return R.ok(vo);
    }
    @Override
    public R detailNeighborAllCommentByAdmin(DetailNeighborAllCommentByAdminDTO dto) {
        ComActNeighborCircleDO comActNeighborCircleDO = this.baseMapper.selectById(dto.getId());
        if (comActNeighborCircleDO == null) {
            return R.fail("id有误");
        }
        Page<ComActNeighborCircleCommentDO> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        // 1、先查询所有该邻里圈_的评论
        IPage<ComActNeighborCommentByAdminVO> commentDOIPage =
            neighborCircleCommentDAO.selectPageDetailNeighborComment(page, dto);
        return R.ok(commentDOIPage);
    }
    @Override
    public R changeCommentStatusByAdmin(ChangeCommentStatusByAdminVO dto) {
        ComActNeighborCircleCommentDO commentDO = neighborCircleCommentDAO.selectById(dto.getId());
        if (commentDO == null) {
            return R.fail("id有误!");
        }
        commentDO.setStatus(dto.getStatus());
        neighborCircleCommentDAO.updateById(commentDO);
        // 查询邻里圈更新邻里圈评论数量
        ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(commentDO.getCircleId());
        if (neighborCircleDO != null) {
            if (dto.getStatus().equals(2)) {
                neighborCircleDO.setCommentNum(neighborCircleDO.getCommentNum() - 1);
            } else {
                neighborCircleDO.setCommentNum(neighborCircleDO.getCommentNum() + 1);
            }
            this.baseMapper.updateById(neighborCircleDO);
        }
        return R.ok();
    }
    @Override
    public R detailNeighborCommentByAdmin(Long id) {
        ComActNeighborCircleCommentDO commentDO = neighborCircleCommentDAO.selectById(id);
        if (commentDO == null) {
            return R.fail("id有误!");
        }
        AdministratorsUserVO user = this.baseMapper.selectUserByUserId(commentDO.getUserId());
        ComActNeighborCommentByAdminVO vo = new ComActNeighborCommentByAdminVO();
        BeanUtils.copyProperties(commentDO, vo);
        String name = user.getName() == null ? user.getNickName() : user.getName();
        vo.setUserName(name);
        vo.setUserPhone(user.getPhone());
        return R.ok(vo);
    }
    @Override
    public R detailNeighborCommentAllReply(DetailNeighborCommentReplyByAdminDTO dto) {
        Page<ComActNeighborCircleCommentReplyDO> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        Page<ComActNeighborCommentReplyByAdminVO> replyPage =
            neighborCircleCommentReplyDAO.selectListByComment(page, dto);
        replyPage.getRecords().forEach(reply -> {
        });
        return R.ok(replyPage);
    }
    @Override
    public R detailNeighborCommentReply(Long id) {
        ComActNeighborCircleCommentReplyDO replyDO = neighborCircleCommentReplyDAO.selectById(id);
        if (replyDO == null) {
            return R.fail("id有误!");
        }
        AdministratorsUserVO user = this.baseMapper.selectUserByUserId(replyDO.getUserId());
        ComActNeighborCommentReplyByAdminVO vo = new ComActNeighborCommentReplyByAdminVO();
        BeanUtils.copyProperties(replyDO, vo);
        vo.setUserName(user.getName());
        vo.setUserPhone(user.getPhone());
        return R.ok(vo);
    }
    @Override
    public R changeCommentReplyStatusByAdmin(ChangeCommentReplyStatusByAdminVO changeStatusReplyVO) {
        ComActNeighborCircleCommentReplyDO replyDO =
            neighborCircleCommentReplyDAO.selectById(changeStatusReplyVO.getId());
        if (replyDO == null) {
            return R.fail("id有误!");
        }
        replyDO.setStatus(changeStatusReplyVO.getStatus());
        neighborCircleCommentReplyDAO.updateById(replyDO);
        return R.ok();
    }
    /**
     * 邻里圈取消点赞
     *
     * @param fabulousAppDTO
     *            请求参数
     * @return 取消点赞结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R neighborFabulousCancelByApp(ComActNeighborFabulousAppDTO fabulousAppDTO) {
        ComActNeighborCircleFabulousDO circleFabulousDO = null;
        // 查询邻里圈点赞信息
        if (fabulousAppDTO.getType().equals(ComActNeighborFabulousAppDTO.type.llq)) {
            // 查询点赞信息
            circleFabulousDO =
                comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                    .eq(ComActNeighborCircleFabulousDO::getParentId, fabulousAppDTO.getServiceId())
                    .eq(ComActNeighborCircleFabulousDO::getUserId, fabulousAppDTO.getUserId())
                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.llq)
                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                        ComActNeighborCircleFabulousDO.isEffective.yes));
            if (circleFabulousDO == null) {
                return R.fail("未查询到点赞信息");
            }
            // 减少邻里圈点赞数量
            ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(fabulousAppDTO.getServiceId());
            if (neighborCircleDO != null) {
                neighborCircleDO.setFabulousNum(neighborCircleDO.getFabulousNum() - 1);
                this.baseMapper.updateById(neighborCircleDO);
                //计算需要增加的热度值
                Long hotNum = NeighborCircleConstants.FABULOUS_HOT_NUM;
                this.baseMapper.addHotNum(neighborCircleDO.getId(),-hotNum);
                this.baseMapper.addTopicHotNum(neighborCircleDO.getId(),-hotNum);
            }
        } else if (fabulousAppDTO.getType().equals(ComActNeighborFabulousAppDTO.type.pl)) {
            circleFabulousDO =
                comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                    .eq(ComActNeighborCircleFabulousDO::getParentId, fabulousAppDTO.getServiceId())
                    .eq(ComActNeighborCircleFabulousDO::getUserId, fabulousAppDTO.getUserId())
                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.pl)
                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                        ComActNeighborCircleFabulousDO.isEffective.yes));
            if (circleFabulousDO == null) {
                return R.fail("未查询到点赞信息");
            }
            // 减少邻里圈评论点赞数量
            ComActNeighborCircleCommentDO circleCommentDO =
                comActNeighborCircleCommentDAO.selectById(fabulousAppDTO.getServiceId());
            if (circleCommentDO != null) {
                circleCommentDO.setFabulousNum(circleCommentDO.getFabulousNum() - 1);
                comActNeighborCircleCommentDAO.updateById(circleCommentDO);
                //计算需要增加的热度值
                Long hotNum = NeighborCircleConstants.FABULOUS_HOT_NUM;
                this.baseMapper.addHotNum(circleCommentDO.getCircleId(),-hotNum);
                this.baseMapper.addTopicHotNum(circleCommentDO.getCircleId(),-hotNum);
            }
        } else if (fabulousAppDTO.getType().equals(ComActNeighborFabulousAppDTO.type.hf)) {
            circleFabulousDO =
                comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>().lambda()
                    .eq(ComActNeighborCircleFabulousDO::getParentId, fabulousAppDTO.getServiceId())
                    .eq(ComActNeighborCircleFabulousDO::getUserId, fabulousAppDTO.getUserId())
                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.hf)
                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                        ComActNeighborCircleFabulousDO.isEffective.yes));
            if (circleFabulousDO == null) {
                return R.fail("未查询到点赞信息");
            }
            // 减少邻里圈评论回复点赞数量
            ComActNeighborCircleCommentReplyDO circleCommentReplyDO =
                comActNeighborCircleCommentReplyDAO.selectById(fabulousAppDTO.getServiceId());
            if (circleCommentReplyDO != null) {
                circleCommentReplyDO.setFabulousNum(circleCommentReplyDO.getFabulousNum() - 1);
                comActNeighborCircleCommentReplyDAO.updateById(circleCommentReplyDO);
                //计算需要增加的热度值
                Long hotNum = NeighborCircleConstants.FABULOUS_HOT_NUM;
                this.baseMapper.addHotNum(circleCommentReplyDO.getCircleId(),-hotNum);
                this.baseMapper.addTopicHotNum(circleCommentReplyDO.getCircleId(),-hotNum);
            }
        }
        if (circleFabulousDO != null) {
            circleFabulousDO.setIsEffective(ComActNeighborCircleFabulousDO.isEffective.no);
            comActNeighborCircleFabulousDAO.updateById(circleFabulousDO);
        }
        return R.ok();
    }
    /**
     * 添加邻里圈浏览记录
     *
     * @param addBrowseAppDTO
     *            请求参数
     * @return 返回参数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R neighborAddBrowseByApp(ComActNeighborAddBrowseAppDTO addBrowseAppDTO) {
        // 添加邻里圈浏览记录
        comActNeighborCircleBrowseService.addBrowseRecord(addBrowseAppDTO.getCircleId(), addBrowseAppDTO.getUserId());
        // 更新邻里圈记录
        ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(addBrowseAppDTO.getCircleId());
        if (neighborCircleDO != null) {
            neighborCircleDO.setViewsNum(neighborCircleDO.getViewsNum() + 1);
            this.baseMapper.updateById(neighborCircleDO);
            //计算需要增加的热度值
            Long hotNum = NeighborCircleConstants.FABULOUS_HOT_NUM;
            this.baseMapper.addHotNum(neighborCircleDO.getId(),hotNum);
            this.baseMapper.addTopicHotNum(neighborCircleDO.getId(),hotNum);
        }
        return R.ok();
    }
    /**
     * 分页查询评论下所有回复
     *
     * @param commentReplyAppDTO
     *            请求参数
     * @return 回复列表
     */
    @Override
    public R neighborCommentReplyByApp(ComActNeighborCommentReplyAppDTO commentReplyAppDTO) {
        IPage<ComActNeighborCommentReplyAppVO> neighborCircleIPage = this.baseMapper.neighborCommentReplyByApp(
            new Page<>(commentReplyAppDTO.getPageNum(), commentReplyAppDTO.getPageSize()),
            commentReplyAppDTO.getCommentId());
        if (!neighborCircleIPage.getRecords().isEmpty()) {
            for (ComActNeighborCommentReplyAppVO commentReplyAppVO : neighborCircleIPage.getRecords()) {
                if (commentReplyAppDTO.getUserId() != null) {
                    // 查询点赞信息
                    ComActNeighborCircleFabulousDO circleFabulousDO =
                        comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>()
                            .lambda().eq(ComActNeighborCircleFabulousDO::getParentId, commentReplyAppVO.getId())
                            .eq(ComActNeighborCircleFabulousDO::getUserId, commentReplyAppDTO.getUserId())
                            .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.hf)
                            .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                                ComActNeighborCircleFabulousDO.isEffective.yes));
                    if (circleFabulousDO != null) {
                        commentReplyAppVO.setHaveSign(1);
                    } else {
                        commentReplyAppVO.setHaveSign(2);
                    }
                }
            }
        }
        return R.ok(neighborCircleIPage);
    }
    /**
     * 小程序-删除邻里圈
     * @param circleTopicAppDTO 请求参数
     * @return  删除结果
     */
    @Override
    public R deleteNeighborByApp(DeleteNeighborCircleAppDTO circleTopicAppDTO){
        ComActNeighborCircleDO neighborCircleDO = new ComActNeighborCircleDO();
        neighborCircleDO.setId(circleTopicAppDTO.getId());
        neighborCircleDO.setIsDel(ComActNeighborCircleDO.isDel.yes);
        if(this.baseMapper.updateById(neighborCircleDO) > 0){
            return R.ok();
        }
        return R.fail();
    }
    @Override
    public R orderAndSolve(EditNeighborCircleAdminVO editNeighborCircleAdminVO) {
        ComActNeighborCircleDO comActNeighborCircleDO=new ComActNeighborCircleDO();
        BeanUtils.copyProperties(editNeighborCircleAdminVO,comActNeighborCircleDO);
        if(comActNeighborCircleDO.getSolveStatus()!=null && comActNeighborCircleDO.getSolveStatus() == 3){
            comActNeighborCircleDO.setSolveTime(new Date());
        }
        if(comActNeighborCircleDO.getOrderStatus()!=null){
            comActNeighborCircleDO.setOrderTime(new Date());
        }
        if(StringUtils.isNotEmpty(comActNeighborCircleDO.getComment())){
            comActNeighborCircleDO.setCommentTime(new Date());
        }
        int result=this.baseMapper.updateById(comActNeighborCircleDO);
        if(result>0){
            ComActNeighborCircleDO comActNeighborCircleDO1=this.baseMapper.selectById(comActNeighborCircleDO.getId());
            if(comActNeighborCircleDO.getOrderStatus()!=null){
                SysUser sysUser=sysUserDao.selectOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserId,comActNeighborCircleDO1.getReleaseId()));
                if(sysUser!=null) {
                    try {
                        WxXCXTempSend util = new WxXCXTempSend();
                        if (comActNeighborCircleDO1.getBelongType()==2){
                            WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你反馈的问题已被人认领",comActNeighborCircleDO1.getReleaseContent().length()>10?comActNeighborCircleDO1.getReleaseContent().substring(0,10)+"..":comActNeighborCircleDO1.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+comActNeighborCircleDO.getId()+"&type=888");
                        }
                        if (comActNeighborCircleDO1.getBelongType()==3){
                            WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你反馈的需求已被人认领",comActNeighborCircleDO1.getReleaseContent().length()>10?comActNeighborCircleDO1.getReleaseContent().substring(0,10)+"..":comActNeighborCircleDO1.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+comActNeighborCircleDO.getId()+"&type=777");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            if(comActNeighborCircleDO.getSolveStatus()==3){
                SysUser sysUser=sysUserDao.selectOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserId,comActNeighborCircleDO1.getReleaseId()));
                if(sysUser!=null) {
                    try {
                        WxXCXTempSend util = new WxXCXTempSend();
                        if (comActNeighborCircleDO1.getBelongType()==2){
                            WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你反馈的问题已被人处理",comActNeighborCircleDO1.getReleaseContent().length()>10?comActNeighborCircleDO1.getReleaseContent().substring(0,10)+"..":comActNeighborCircleDO1.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+comActNeighborCircleDO.getId()+"&type=888");
                        }
                        if (comActNeighborCircleDO1.getBelongType()==3){
                            WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你反馈的需求已被人处理",comActNeighborCircleDO1.getReleaseContent().length()>10?comActNeighborCircleDO1.getReleaseContent().substring(0,10)+"..":comActNeighborCircleDO1.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+comActNeighborCircleDO.getId()+"&type=777");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            if(comActNeighborCircleDO.getSolveStatus()==4){
                SysUser sysUser=sysUserDao.selectOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserId,comActNeighborCircleDO1.getSolveId()));
                if(sysUser!=null) {
                    try {
                        WxXCXTempSend util = new WxXCXTempSend();
                        if (comActNeighborCircleDO1.getBelongType()==2){
                            WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你有一条新的评价信息",comActNeighborCircleDO1.getReleaseContent().length()>10?comActNeighborCircleDO1.getReleaseContent().substring(0,10)+"..":comActNeighborCircleDO1.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+comActNeighborCircleDO.getId()+"&type=888");
                        }
                        if (comActNeighborCircleDO1.getBelongType()==3){
                            WxUtil.sendLongTimeTemplate(sysUser.getOpenid(),util.getAccessToken(),"你有一条新的评价信息",comActNeighborCircleDO1.getReleaseContent().length()>10?comActNeighborCircleDO1.getReleaseContent().substring(0,10)+"..":comActNeighborCircleDO1.getReleaseContent(),"packageB/pages/partySecond/problemDetails/index?id="+comActNeighborCircleDO.getId()+"&type=777");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            return R.ok(result);
        }
        return R.fail();
    }
    @Override
    public R serviceStatic(ServiceStaticDTO serviceStaticDTO) {
        ServiceStaticsVO serviceStaticsVO = new ServiceStaticsVO();
        if (serviceStaticDTO.getCheckUnitId() != null && serviceStaticDTO.getCheckUnitId()> 0)
        {
            //单位服务统计
            serviceStaticsVO =
                this.baseMapper.selectStatsCheckUnit(serviceStaticDTO.getCheckUnitId(), serviceStaticDTO.getYear());
            List<ServiceDetailStaticsVO> serviceDetailStaticsVOList=this.baseMapper.selectServiceDetailList(serviceStaticDTO.getCheckUnitId(),
                    serviceStaticDTO.getYear(), serviceStaticDTO.getServiceType());
           if(serviceStaticDTO.getServiceType()==null  || serviceStaticDTO.getServiceType()==1)
           {
               List<NewFightNeedProblemClaim> list=baseMapper.getNewServiceNum("",serviceStaticDTO.getCheckUnitId()+"");
               if(list.size()>0)
               {
                   //设置次数
                   int timeNum=serviceStaticsVO.getTimes()+list.size();
                   serviceStaticsVO.setTimes(timeNum);
                   //设置服务时间
                   double hours=serviceStaticsVO.getHours();
                   for (NewFightNeedProblemClaim item:list)
                   {
                       ServiceDetailStaticsVO newItem=new ServiceDetailStaticsVO();
                       String Ltime=item.getServiceTime();
                       if(!StringUtils.isEmpty(Ltime))
                       {
                           double time=(Double.valueOf(Ltime)/3600000);
                           DecimalFormat df = new DecimalFormat("#.##");
                           String formattedNumber = df.format(time);
                           double result = Double.parseDouble(formattedNumber);
                           hours=hours+result;
                           newItem.setServiceTime(result);
                           item.setServiceTime(result+"");
                       }
                       newItem.setIsNew("2");
                       newItem.setServiceId(Long.valueOf(item.getTaskId()));
                       newItem.setServiceType(1);
                       newItem.setServiceAt(item.getCreationTime());
                       serviceDetailStaticsVOList.add(newItem);
                   }
                   DecimalFormat df = new DecimalFormat("#.##");
                   String formattedNumber = df.format(hours);
                   double result = Double.parseDouble(formattedNumber);
                   serviceStaticsVO.setHours(result);
               }
           }
            serviceStaticsVO.setServiceDetailStaticsList(serviceDetailStaticsVOList);
        }
        else
        {
            //个人服务统计
            ComPbMemberDO comPbMemberDO = comPbMemberDAO.selectOne(new QueryWrapper<ComPbMemberDO>().lambda()
                    .eq(ComPbMemberDO::getPhone, serviceStaticDTO.getPhone()).last("limit 1"));
            Long checkUnitId = null;
            if (comPbMemberDO != null) {
                checkUnitId = comPbMemberDO.getCheckUnitId();
            }
            serviceStaticsVO = this.baseMapper.selectStatsUser(serviceStaticDTO.getPhone(),checkUnitId+"", serviceStaticDTO.getYear());
            List<ServiceDetailStaticsVO> serviceDetailStaticsVOList=this.baseMapper.selectServiceDetailListForPersonal(checkUnitId, serviceStaticDTO.getPhone(),
                    serviceStaticDTO.getYear(), serviceStaticDTO.getServiceType());
            if(serviceStaticDTO.getServiceType()==null  || serviceStaticDTO.getServiceType()==1)
            {
                //获取新需求服务列表
                List<NewFightNeedProblemClaim> list=baseMapper.getNewServiceNum(serviceStaticDTO.getPhone(),"");
                if(list.size()>0)
                {
                    //设置次数
                    int timeNum=serviceStaticsVO.getTimes()+list.size();
                    //设置服务时间
                    double hours=serviceStaticsVO.getHours();
                    serviceStaticsVO.setTimes(timeNum);
                    for (NewFightNeedProblemClaim item:list)
                    {
                        ServiceDetailStaticsVO newItem=new ServiceDetailStaticsVO();
                        String Ltime=item.getServiceTime();
                        if(!StringUtils.isEmpty(Ltime))
                        {
                            double time=(Double.valueOf(Ltime)/3600000);
                            DecimalFormat df = new DecimalFormat("#.##");
                            String formattedNumber = df.format(time);
                            double result = Double.parseDouble(formattedNumber);
                            hours=hours+result;
                            newItem.setServiceTime(result);
                            item.setServiceTime(result+"");
                        }
                        newItem.setIsNew("2");
                        newItem.setServiceId(Long.valueOf(item.getTaskId()));
                        newItem.setServiceType(1);
                        newItem.setServiceAt(item.getCreationTime());
                        serviceDetailStaticsVOList.add(newItem);
                    }
                    DecimalFormat df = new DecimalFormat("#.##");
                    String formattedNumber = df.format(hours);
                    double result = Double.parseDouble(formattedNumber);
                    serviceStaticsVO.setHours(result);
                }
            }
            serviceStaticsVO.setServiceDetailStaticsList(serviceDetailStaticsVOList);
        }
        return R.ok(serviceStaticsVO);
    }
    @Override
    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;
        if (null != year){
            //设置开始,截止时间
            beginTime=year.toString().concat("-01-01");
            endTime=year.toString().concat("-12-31");
        }
        //统计党员,单位总数
        activityVO.setPartyMemberCount(comActDAO.selectUnitCount());
        activityVO.setUnitCount(comActDAO.selectMemberCount());
        //获取单位活动统计数据(邻里圈)
        List<UnitActivityAnalysisVO> unitActivityAnalysisVOS = comActNeighborCircleDAO.institutionalUnitServiceAnalysis(beginTime, endTime, belongTo,communityId,unitId);
        //获取单位活动统计数据(活动)
        List<UnitActivityAnalysisVO> unitActivityAnalysisVOS1 = comActNeighborCircleDAO.institutionalUnitActivityAnalysis(beginTime, endTime, belongTo,communityId,unitId);
        //获取新双挣双评清单任务
        List<UnitActivityAnalysisVO> newTaskList=comActNeighborCircleDAO.getNewTaskList(beginTime, endTime, belongTo,communityId);
        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(unitActivityAnalysisVO.getCommunityId())){
                        unitActivityAnalysisVO.setCommunityName(comActDAO.selectById(unitActivityAnalysisVO.getCommunityId()).getName());
                    }
                }
            }
        }
        if (newTaskList.size()>0){
            for (UnitActivityAnalysisVO item : newTaskList){
                if (ObjectUtils.isNotEmpty(item)){
                    if (ObjectUtils.isNotEmpty(item.getUnitId())){
                        //设置单位名称
                        item.setUnitName(comActDAO.selectUnitName(item.getUnitId()));
                        //统计活动表中的活动信息
                    }
                    if (ObjectUtils.isNotEmpty(item.getCommunityId())){
                        item.setCommunityName(comActDAO.selectById(item.getCommunityId()).getName());
                    }
                    Double time=(item.getServiceTime()/3600000);
                    DecimalFormat df = new DecimalFormat("#.##");
                    String formattedNumber = df.format(time);
                    Double result = Double.parseDouble(formattedNumber);
                    item.setServiceTime(result);
                }
            }
        }
        //活动表数据处理
        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){
                            //已有数据,将时长,次数相加
                            Double 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);
                        }
                    }
                }
            }
        }
        if (newTaskList.size()>0){
            for (UnitActivityAnalysisVO item : newTaskList){
                if (ObjectUtils.isNotEmpty(item)){
                    if (ObjectUtils.isNotEmpty(item.getUnitId())){
                        //判断邻里圈统计中是否已有该单位数据
                        Map<String, Integer> param = alreadyAnalysis(item.getUnitId(), unitActivityAnalysisVOS);
                        if (param.get("flag")==1){
                            //已有数据,将时长,次数相加
                            Double serviceTime = unitActivityAnalysisVOS.get(param.get("index")).getServiceTime()+item.getServiceTime();
                            Integer serviceTimes = item.getServiceTimes();
                            DecimalFormat df2 = new DecimalFormat("#.##");
                            String formattedNumber2 = df2.format(serviceTime);
                            Double result2 = Double.parseDouble(formattedNumber2);
                            unitActivityAnalysisVOS.get(param.get("index")).setServiceTime(result2);
                            unitActivityAnalysisVOS.get(param.get("index")).setServiceTimes(unitActivityAnalysisVOS.get(param.get("index")).getServiceTimes()+serviceTimes);
                        }else {
                            //新数据,获取单位,社区名
                            item.setUnitName(comActDAO.selectUnitName(item.getUnitId()));
                            if (ObjectUtils.isNotEmpty(item.getCommunityId()))
                            {
                                ComActDO actDO=comActDAO.selectById(item.getCommunityId());
                                if(actDO!=null && !StringUtils.isEmpty(actDO.getName()))
                                {
                                    item.setCommunityName(actDO.getName());
                                }
                            }
                            unitActivityAnalysisVOS.add(item);
                        }
                    }
                }
            }
        }
        //获取党员活动统计数据
        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS = comActNeighborCircleDAO.institutionalPartyMemberServiceAnalysis(beginTime, endTime, belongTo,communityId,unitId,searchContent);
        List<PartyMemberAnalysisVO> partyMemberAnalysisVOS1 = comActNeighborCircleDAO.institutionalPartyMemberActAnalysis(beginTime, endTime, belongTo,communityId,unitId,searchContent);
        //获取新双挣双评清单任务
        List<PartyMemberAnalysisVO> newPartyMemberList = comActNeighborCircleDAO.getNewPartyMemberTaskList(beginTime, endTime, belongTo,communityId,unitId,searchContent);
        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){
                            Double 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);
                        }
                    }
                }
            }
        }
        if (newPartyMemberList.size()>0){
            for (PartyMemberAnalysisVO item : newPartyMemberList)
            {
                Double time=(item.getServiceTime()/3600000);
                DecimalFormat df = new DecimalFormat("#.##");
                String formattedNumber = df.format(time);
                Double result = Double.parseDouble(formattedNumber);
                item.setServiceTime(result);
                if (ObjectUtils.isNotEmpty(item)){
                    if (ObjectUtils.isNotEmpty(item.getMemberId())){
                        Map<String, Integer> param = memberAlreadyAnalysis(item.getMemberId(), partyMemberAnalysisVOS);
                        if (param.get("flag")==1){
                            Double serviceTime = partyMemberAnalysisVOS.get(param.get("index")).getServiceTime()+item.getServiceTime();
                            Integer serviceTimes = item.getServiceTimes();
                            DecimalFormat df1 = new DecimalFormat("#.##");
                            String formattedNumber1 = df1.format(serviceTime);
                            Double result1 = Double.parseDouble(formattedNumber1);
                            partyMemberAnalysisVOS.get(param.get("index")).setServiceTime(result1);
                            partyMemberAnalysisVOS.get(param.get("index")).setServiceTimes(partyMemberAnalysisVOS.get(param.get("index")).getServiceTimes()+serviceTimes);
                        }else{
                            partyMemberAnalysisVOS.add(item);
                        }
                    }
                }
            }
        }
        //报道单位统计积分
        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)
            {
                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);
                if(!StringUtils.isEmpty(award) )
                {
                    long i = Long.parseLong(award) * count;
                    sum = sum + i;
                }
            }
            unitVO.setAwardSum(sum);
        }
        //报道党员统计积分
        for (PartyMemberAnalysisVO memberAnalysisVO : partyMemberAnalysisVOS)
        {
            if(memberAnalysisVO!=null)
            {
                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)
                {
                    sumAward=memberAnalysisVO.getPartyCount();
                }
                for (NewFightNeedProblemClaim inventory : newFightNeedProblemInventories) {
                    String taskId = inventory.getTaskId();
                    NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId);
                    if(newFightNeedProblemInventory!=null && !StringUtils.isEmpty(newFightNeedProblemInventory.getAward()))
                    {
                        String award = newFightNeedProblemInventory.getAward();
                        if(!StringUtils.isEmpty(award) )
                        {
                            sumAward = Long.parseLong(award) + sumAward;
                        }
                    }
                }
                memberAnalysisVO.setPartyCount(sumAward);
            }
        }
        //统计总时长和总次数
        Integer unitServiceCount=0;
        Double unitServiceTotalTime=0.0;
        Integer memberServiceCount=0;
        Double memberServiceTotalTome=0.0;
        long awardSumCount=0L;
        long partySumCount=0L;
        for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) {
            //避免空指针
            if (ObjectUtils.isNotEmpty(vo)){
                if (ObjectUtils.isNotEmpty(vo.getServiceTime())){
                    unitServiceTotalTime+=vo.getServiceTime();
                }
                if (ObjectUtils.isNotEmpty(vo.getServiceTimes())){
                    unitServiceCount+=vo.getServiceTimes();
                }
            }
        }
        for (PartyMemberAnalysisVO vo : partyMemberAnalysisVOS) {
            //避免空指针
            if (ObjectUtils.isNotEmpty(vo)){
                if (ObjectUtils.isNotEmpty(vo.getServiceTime())){
                    memberServiceTotalTome+=vo.getServiceTime();
                }
                if (ObjectUtils.isNotEmpty(vo.getServiceTimes())){
                    memberServiceCount+=vo.getServiceTimes();
                }
            }
        }
        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");
                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,"");
            }
        }
        else
        {
            //按时长排序
            ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTime");
            ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTime");
            ListUtil.reverse(unitActivityAnalysisVOS);
            ListUtil.reverse(partyMemberAnalysisVOS);
        }
        //处理分页
        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);
        //党员数据 聚合
        Map<String, Double> map = new HashMap<>();
        partyMemberAnalysisVOS.forEach(vo->{
            String name = vo.getBelongTo();
            Double time = 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,null);
        //获取单位活动统计数据(活动)
        List<UnitActivityAnalysisVO> unitActivityAnalysisVOS1 = comActNeighborCircleDAO.institutionalUnitActivityAnalysis(beginTime, endTime, belongTo,communityId,null);
        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){
                            //已有数据,将时长,次数相加
                            Double 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){
                            Double 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) {
        return null;
    }
    @Override
    public R selectCount(Integer type, String phone,Long communityId) {
        return R.ok(this.baseMapper.selectCount(type,phone,communityId));
    }
    /**
     * 分页查询可关联清单列表
     * @param neighborCircleAppDTO
     * @return
     */
    @Override
    public R pageRelationList(ComActNeighborCircleAppDTO neighborCircleAppDTO) {
        Page userPage = new Page(neighborCircleAppDTO.getPageNum(), neighborCircleAppDTO.getPageSize());
        IPage<ComActNeighborCircleAppVO> doPager = this.baseMapper.pageRelationList(userPage, neighborCircleAppDTO);
        if (!doPager.getRecords().isEmpty()) {
            for (ComActNeighborCircleAppVO circleAppVO : doPager.getRecords()) {
                if (neighborCircleAppDTO.getUserId() != null) {
                    // 查询点赞信息
                    ComActNeighborCircleFabulousDO circleFabulousDO =
                            comActNeighborCircleFabulousDAO.selectOne(new QueryWrapper<ComActNeighborCircleFabulousDO>()
                                    .lambda().eq(ComActNeighborCircleFabulousDO::getParentId, circleAppVO.getId())
                                    .eq(ComActNeighborCircleFabulousDO::getUserId, neighborCircleAppDTO.getUserId())
                                    .eq(ComActNeighborCircleFabulousDO::getType, ComActNeighborCircleFabulousDO.type.llq)
                                    .eq(ComActNeighborCircleFabulousDO::getIsEffective,
                                            ComActNeighborCircleFabulousDO.isEffective.yes));
                    if (circleFabulousDO != null) {
                        circleAppVO.setHaveSign(1);
                    } else {
                        circleAppVO.setHaveSign(2);
                    }
                }
                if (circleAppVO.getType() != null && circleAppVO.getType().equals(ComActNeighborCircleDO.type.admin)) {
                    ComActDO actDO = comActDAO.selectById(circleAppVO.getCommunityId());
                    if (actDO != null) {
                        circleAppVO.setName(actDO.getName());
                    }
                }
            }
        }
        return R.ok(doPager);
    }
    /**
     * 判断活动统计列表中是否已有该单位的数据
     * */
    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;
        }
    }
    /**
     * 判断党员的统计是是否已存在
     * */
    public Map<String,Integer> memberAlreadyAnalysis(Long memberId,List<PartyMemberAnalysisVO> list){
        Map<String,Integer> map=new HashMap<>();
        if (memberId != null && list.size() > 0){
            for (int i=0;i<list.size();i++) {
                PartyMemberAnalysisVO vo = list.get(i);
                if (ObjectUtils.isNotEmpty(vo)){
                    if (ObjectUtils.isNotEmpty(vo.getMemberId())){
                        if (memberId.equals(vo.getMemberId())){
                            map.put("index",i );
                            map.put("flag",1 );
                            return map;
                        }
                    }
                }
            }
        }
        map.put("flag",0 );
        return map;
    }
}