lidongdong
2024-07-11 eef6d2bcdb29348efe4ef17bc45a4c6886b487b1
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActEasyPhotoServiceImpl.java
@@ -1,14 +1,19 @@
package com.panzhihua.service_community.service.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.DesensitizedUtil;
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.common.model.dtos.common.PageComActEasyPhotoEvaluateDto;
import com.panzhihua.common.model.vos.common.ComActEasyPhotoHandlerVo;
import com.panzhihua.common.model.vos.community.acid.ComActAcidColorChartsVO;
import com.panzhihua.common.model.vos.community.easyPhoto.BannerVO;
import com.panzhihua.service_community.entity.ComActEasyPhotoEvaluate;
import com.panzhihua.service_community.entity.ComActEasyPhotoHandler;
@@ -146,6 +151,51 @@
        return R.ok(iPage);
    }
    @Override
    public R pageEasyPhotoAdminLC(Long pageNum,Long pageSize) {
        Page page = new Page<>();
        if (null == pageNum || 0 == pageNum) {
            pageNum = 1l;
        }
        if (null == pageSize || 0 == pageSize) {
            pageSize = 10l;
        }
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        IPage<ComActEasyPhotoVO> iPage = comActEasyPhotoDAO.pageEasyPhotoAdminLC(page);
        List<ComActEasyPhotoVO> records = iPage.getRecords();
        if (!ObjectUtils.isEmpty(records)) {
            records.forEach(comActEasyPhotoVO1 -> {
                Long id = comActEasyPhotoVO1.getId();
                if (comActEasyPhotoVO1.getActivityId() != null
                        && comActEasyPhotoVO1.getStatus().equals(ComActEasyPhotoDO.status.dpj)) {
                    // 查询随手拍活动
                    ComActEasyPhotoActivityDO photoActivityDO =
                            comActEasyPhotoActivityMapper.selectById(comActEasyPhotoVO1.getActivityId());
                    if (photoActivityDO != null) {
                        if (comActEasyPhotoVO1.getActivityType() != null) {
                            if (comActEasyPhotoVO1.getActivityType().equals(ComActEasyPhotoDO.activityType.yz)) {
                                comActEasyPhotoVO1.setActivityMoney(photoActivityDO.getGoodReward());
                            } else if (comActEasyPhotoVO1.getActivityType().equals(ComActEasyPhotoDO.activityType.jl)) {
                                comActEasyPhotoVO1.setActivityMoney(photoActivityDO.getExcellentReward());
                            } else if (comActEasyPhotoVO1.getActivityType().equals(ComActEasyPhotoDO.activityType.pt)) {
                                comActEasyPhotoVO1.setActivityMoney(photoActivityDO.getOrdinaryReward());
                            } else if (comActEasyPhotoVO1.getActivityType().equals(ComActEasyPhotoDO.activityType.yb)) {
                                comActEasyPhotoVO1.setActivityMoney(photoActivityDO.getCommonlyReward());
                            } else if (comActEasyPhotoVO1.getActivityType().equals(ComActEasyPhotoDO.activityType.wu)) {
                                comActEasyPhotoVO1.setActivityMoney(BigDecimal.ZERO);
                            }
                        }
                    }
                }
            });
            iPage.setRecords(records);
        }
        return R.ok(iPage);
    }
    /**
     * 随手拍详情
     *
@@ -180,7 +230,8 @@
        // }
        // 查询反馈信息
        List<ComActEasyPhotoFeedbackVO> photoFeedbackList = comActEasyPhotoFeedbackMapper.getPhotoFeedbackList(id);
        List<ComActEasyPhotoFeedbackVO> photoFeedbackList =
                comActEasyPhotoFeedbackMapper.getPhotoFeedbackList(id);
        if (!photoFeedbackList.isEmpty()) {
            comActEasyPhotoVO.setPhotoFeedbackList(photoFeedbackList);
        }
@@ -193,6 +244,66 @@
        if (comActEasyPhotoVO.getActivityId() != null) {
            ComActEasyPhotoActivityDO photoActivityDO =
                comActEasyPhotoActivityMapper.selectById(comActEasyPhotoVO.getActivityId());
            if (photoActivityDO != null) {
                ComActEasyPhotoActivityVO easyPhotoActivityVO = new ComActEasyPhotoActivityVO();
                BeanUtils.copyProperties(photoActivityDO, easyPhotoActivityVO);
                comActEasyPhotoVO.setEasyPhotoActivityVO(easyPhotoActivityVO);
            }
        }
        PageComActEasyPhotoEvaluateDto evaluateDto = new PageComActEasyPhotoEvaluateDto();
        evaluateDto.setServiceId(id);
        evaluateDto.setServiceType(ComActEasyPhotoEvaluate.ServiceType.SSP);
        comActEasyPhotoVO.setEvaluateList(comActEasyPhotoEvaluateMapper.queryAllByList(evaluateDto));
        return R.ok(comActEasyPhotoVO);
    }
    /**
     * 随手拍详情 - 脱敏
     *
     * @param id
     *            随手拍主键
     * @param userId
     * @return 详情内容
     */
    @Override
    public R detailEasyPhotoDesensitize(Long id, Long userId) {
        ComActEasyPhotoVO comActEasyPhotoVO = comActEasyPhotoDAO.detailEasyPhoto(id);
        Integer status = comActEasyPhotoVO.getStatus();
        if (ObjectUtils.isEmpty(comActEasyPhotoVO) || null == status) {
            return R.fail("随手拍不存在");
        }
        if (!userId.equals(0L)) {
            ComActEasyPhotoUserDO comActEasyPhotoUserDO =
                    comActEasyPhotoUserDAO.selectOne(new QueryWrapper<ComActEasyPhotoUserDO>().lambda()
                            .eq(ComActEasyPhotoUserDO::getEasyPhotoId, id).eq(ComActEasyPhotoUserDO::getUserId, userId));
            if (ObjectUtils.isEmpty(comActEasyPhotoUserDO)) {
                comActEasyPhotoVO.setHaveGiveThumbsUp(0);
            } else {
                comActEasyPhotoVO.setHaveGiveThumbsUp(1);
            }
        }
        comActEasyPhotoVO.setSponsorName(DesensitizedUtil.chineseName(comActEasyPhotoVO.getSponsorName()));
        comActEasyPhotoVO.setHandlerName(DesensitizedUtil.chineseName(comActEasyPhotoVO.getHandlerName()));
        comActEasyPhotoVO.setCompleteName(DesensitizedUtil.chineseName(comActEasyPhotoVO.getCompleteName()));
        comActEasyPhotoVO.setPhone(DesensitizedUtil.mobilePhone(comActEasyPhotoVO.getPhone()));
        // 查询反馈信息
        List<ComActEasyPhotoFeedbackVO> photoFeedbackList = comActEasyPhotoFeedbackMapper.getPhotoFeedbackList(id);
        if (!photoFeedbackList.isEmpty()) {
            if (CollUtil.isNotEmpty(photoFeedbackList)){
                for (ComActEasyPhotoFeedbackVO comActEasyPhotoFeedbackVO : photoFeedbackList) {
                    comActEasyPhotoFeedbackVO.setCreateByName(DesensitizedUtil.chineseName(comActEasyPhotoFeedbackVO.getCreateByName()));
                }
            }
            comActEasyPhotoVO.setPhotoFeedbackList(photoFeedbackList);
        }
        if (comActEasyPhotoVO.getAddrRemark() == null) {
            comActEasyPhotoVO.setAddrRemark("");
        }
        if (comActEasyPhotoVO.getActivityId() != null) {
            ComActEasyPhotoActivityDO photoActivityDO =
                    comActEasyPhotoActivityMapper.selectById(comActEasyPhotoVO.getActivityId());
            if (photoActivityDO != null) {
                ComActEasyPhotoActivityVO easyPhotoActivityVO = new ComActEasyPhotoActivityVO();
                BeanUtils.copyProperties(photoActivityDO, easyPhotoActivityVO);
@@ -233,7 +344,9 @@
        }
        int insert = comActEasyPhotoDAO.insert(comActEasyPhotoDO);
        if (insert > 0) {
            return R.ok();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id",comActEasyPhotoDO.getId());
            return R.ok(jsonObject);
        }
        return R.fail();
    }
@@ -298,6 +411,7 @@
            case 1:
                if (!cmActEasyPhotoDO.getStatus().equals(ComActEasyPhotoDO.status.dsh)) {
                    return R.fail("该随手拍已处理,不可重复操作");
//                    return R.ok();
                }
                cmActEasyPhotoDO.setStatus(2);// 进行中
                cmActEasyPhotoDO.setIsNeedFeedBack(1);
@@ -467,6 +581,65 @@
    }
    /**
     * 小程序分页查询随手拍 脱敏
     *
     * @param comActEasyPhotoVO
     *            查询参数
     * @return 返回结果
     */
    @Override
    public R pageEasyPhotoAppletsDesensitize(ComActEasyPhotoVO comActEasyPhotoVO) {
        Page page = new Page<>();
        Long pageNum = comActEasyPhotoVO.getPageNum();
        Long pageSize = comActEasyPhotoVO.getPageSize();
        Long userId = comActEasyPhotoVO.getLogInUserId();
        if (null == pageNum || 0 == pageNum) {
            pageNum = 1l;
        }
        if (null == pageSize || 0 == pageSize) {
            pageSize = 10l;
        }
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        IPage<ComActEasyPhotoVO> iPage = comActEasyPhotoDAO.pageEasyPhotoApplets(page, comActEasyPhotoVO);
        List<ComActEasyPhotoVO> records = iPage.getRecords();
        if (userId != null) {
            if (!ObjectUtils.isEmpty(records)) {
                records.forEach(comActEasyPhotoVO1 -> {
                    Long id = comActEasyPhotoVO1.getId();
                    Integer status = comActEasyPhotoVO1.getStatus();
                    Date feedbackAt = comActEasyPhotoVO1.getFeedbackAt();
                    comActEasyPhotoVO1.setSponsorName(DesensitizedUtil.chineseName(comActEasyPhotoVO1.getSponsorName()));
                    comActEasyPhotoVO1.setHandlerName(DesensitizedUtil.chineseName(comActEasyPhotoVO1.getHandlerName()));
                    comActEasyPhotoVO1.setCompleteName(DesensitizedUtil.chineseName(comActEasyPhotoVO1.getCompleteName()));
                    comActEasyPhotoVO1.setPhone(DesensitizedUtil.mobilePhone(comActEasyPhotoVO1.getPhone()));
                    List<ComActEasyPhotoUserDO> comActEasyPhotoUserDO = comActEasyPhotoUserDAO.selectList(
                            new QueryWrapper<ComActEasyPhotoUserDO>().lambda().eq(ComActEasyPhotoUserDO::getEasyPhotoId, id)
                                    .eq(ComActEasyPhotoUserDO::getUserId, userId));
                    if (comActEasyPhotoUserDO == null || comActEasyPhotoUserDO.size() == 0) {
                        comActEasyPhotoVO1.setHaveGiveThumbsUp(0);
                    } else {
                        comActEasyPhotoVO1.setHaveGiveThumbsUp(1);
                    }
                    if (status.intValue() == 4 && null == feedbackAt) {
                        comActEasyPhotoVO1.setFeedbackAt(comActEasyPhotoVO1.getExamineAt());
                    }
                    //反馈信息列表
                    List<ComActEasyPhotoFeedbackVO> photoFeedbackList = comActEasyPhotoVO1.getPhotoFeedbackList();
                    if (CollUtil.isNotEmpty(photoFeedbackList)){
                        for (ComActEasyPhotoFeedbackVO comActEasyPhotoFeedbackVO : photoFeedbackList) {
                            comActEasyPhotoFeedbackVO.setCreateByName(DesensitizedUtil.chineseName(comActEasyPhotoFeedbackVO.getCreateByName()));
                        }
                    }
                    comActEasyPhotoVO1.setPhotoFeedbackList(photoFeedbackList);
                });
                iPage.setRecords(records);
            }
        }
        return R.ok(iPage);
    }
    /**
     * 随手拍评论分页查询
     *
     * @param pageComActEasyPhotoCommentDTO
@@ -490,6 +663,39 @@
            comActEasyPhotoCommentDAO.pageComActEasyPhotoComment(page, pageComActEasyPhotoCommentDTO);
        if (!iPage.getRecords().isEmpty()) {
            for (ComActEasyPhotoCommentVO commentVO : iPage.getRecords()) {
                if (StringUtils.isEmpty(commentVO.getName())) {
                    commentVO.setName(commentVO.getNickName());
                }
            }
        }
        return R.ok(iPage);
    }
    /**
     * 随手拍评论分页查询 - 脱敏
     *
     * @param pageComActEasyPhotoCommentDTO
     *            查询参数
     * @return 查询结果
     */
    @Override
    public R pageComActEasyPhotoCommentDesensitize(PageComActEasyPhotoCommentDTO pageComActEasyPhotoCommentDTO) {
        Page page = new Page<>();
        Long pageNum = pageComActEasyPhotoCommentDTO.getPageNum();
        Long pageSize = pageComActEasyPhotoCommentDTO.getPageSize();
        if (null == pageNum || 0 == pageNum) {
            pageNum = 1l;
        }
        if (null == pageSize || 0 == pageSize) {
            pageSize = 10l;
        }
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        IPage<ComActEasyPhotoCommentVO> iPage =
                comActEasyPhotoCommentDAO.pageComActEasyPhotoComment(page, pageComActEasyPhotoCommentDTO);
        if (!iPage.getRecords().isEmpty()) {
            for (ComActEasyPhotoCommentVO commentVO : iPage.getRecords()) {
                commentVO.setNickName(DesensitizedUtil.chineseName(commentVO.getNickName()));
                if (StringUtils.isEmpty(commentVO.getName())) {
                    commentVO.setName(commentVO.getNickName());
                }
@@ -925,4 +1131,97 @@
        return R.fail();
    }
    /**
     * 获取社区置顶动态banner
     * @param communityId
     * */
    @Override
    public R getUserRewardNew(Long userId, Long communityId) {
        ComActEasyPhotoRewardVO easyPhotoRewardVO=new ComActEasyPhotoRewardVO();
        List<BannerVO> bannerVOS=this.comActEasyPhotoDAO.getBanner(communityId);
        if(!bannerVOS.isEmpty()){
            easyPhotoRewardVO.setBannerVOS(bannerVOS);
        }
        return R.ok(easyPhotoRewardVO);
    }
    @Override
    public R selectStatisticsPhoto(){
        //所有分组
        List<StatisticsPhotoVO> statisticsPhotoVOS = this.baseMapper.selectPhotoAll();
        int all = statisticsPhotoVOS.stream().mapToInt(StatisticsPhotoVO::getCountNum).sum();
        for (StatisticsPhotoVO statisticsPhotoVO : statisticsPhotoVOS) {
            if (0!=all){
                BigDecimal countNum = new BigDecimal(statisticsPhotoVO.getCountNum());
                BigDecimal allDecimal = new BigDecimal(all);
                BigDecimal percent = countNum.divide(allDecimal,4, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(100));
                statisticsPhotoVO.setPercent(percent);
            }
        }
//        Map<String, StatisticsPhotoVO> circleMap = statisticsPhotoVOS
//                .stream()
//                .collect(Collectors.toMap(StatisticsPhotoVO::getCountName, Function.identity()));
        //按月份查询
        List<StatisticsPhotoVO> statisticsPhotoVOS1 = this.baseMapper.selectPhotoByMonth();
        //按类型分组求和
        Map<String, IntSummaryStatistics> statusCollect = statisticsPhotoVOS1
                .stream()
                .collect(Collectors.groupingBy(StatisticsPhotoVO::getCountName,
                        Collectors.summarizingInt(StatisticsPhotoVO::getCountNum)));
        for (StatisticsPhotoVO statisticsPhotoVO : statisticsPhotoVOS1) {
            String countName = statisticsPhotoVO.getCountName();
            if (statusCollect.containsKey(countName)){
                IntSummaryStatistics intSummaryStatistics = statusCollect.get(countName);
                long sum = intSummaryStatistics.getSum();
                if (0L!=sum) {
                    BigDecimal countNum = new BigDecimal(statisticsPhotoVO.getCountNum());
                    BigDecimal sumDecimal = new BigDecimal(sum);
                    BigDecimal percent = countNum.divide(sumDecimal, 4, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(100));
                    statisticsPhotoVO.setPercent(percent);
                }
            }
        }
        Map<String, Map<String, StatisticsPhotoVO>> chartMap = statisticsPhotoVOS1.stream().collect(Collectors.groupingBy(StatisticsPhotoVO::getStatisticsDate, Collectors.toMap(StatisticsPhotoVO::getCountName, Function.identity())));
        // 状态 1待处理   2进行中 3已驳回 4待评价 5.已完成
        String[] statusArr = {"待处理","进行中","已驳回","待评价","已完成"};
        List<String> latest12Month = DateUtils.getLatest12Month(LocalDate.now(), 10);
        for (String month : latest12Month) {
            Map<String, StatisticsPhotoVO> map1;
            if(chartMap.containsKey(month)){
                map1 = chartMap.get(month);
            }else {
                map1 = new HashMap<>();
            }
            for (String status : statusArr) {
                if (!map1.containsKey(status)){
                    StatisticsPhotoVO statisticsPhotoVO = new StatisticsPhotoVO();
                    statisticsPhotoVO.setCountNum(0);
                    statisticsPhotoVO.setStatisticsDate(month);
                    statisticsPhotoVO.setCountName(status);
                    statisticsPhotoVOS1.add(statisticsPhotoVO);
                    map1.put(status,statisticsPhotoVO);
                }
            }
            chartMap.put(month,map1);
        }
        Map<String, List<StatisticsPhotoVO>> stringListMap = statisticsPhotoVOS1
                .stream()
                .sorted(Comparator.comparing(StatisticsPhotoVO::getStatisticsDate))
                .collect(Collectors.groupingBy(StatisticsPhotoVO::getCountName));
        Map<String,Object> retMap = new HashMap<>();
        retMap.put("statisticsPhotoVOS",statisticsPhotoVOS);
        retMap.put("monthMap",stringListMap);
        return R.ok(retMap);
    }
}