From cec12ff6e380e6be36cc78d0cbe22cedb72f00bf Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期一, 12 五月 2025 11:37:49 +0800 Subject: [PATCH] 分析统计修改 --- springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/AnalyticStatisticsController.java | 48 +++++++++++++++- springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java | 74 ++++++++++++------------ 2 files changed, 82 insertions(+), 40 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/AnalyticStatisticsController.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/AnalyticStatisticsController.java index a55aeb8..52f3f87 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/AnalyticStatisticsController.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/AnalyticStatisticsController.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.panzhihua.common.controller.BaseController; +import com.panzhihua.common.exceptions.ServiceException; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo; import com.panzhihua.sangeshenbian.model.entity.*; @@ -51,6 +52,8 @@ @Resource private IComActService comActService; + + @PostMapping("/data") @ApiOperation(value = "分析统计", tags = {"三个身边后台-分析统计"}) public R<AnalyticStatisticsDataVo> data(@Valid @RequestBody AnalyticStatisticsQuery query){ @@ -62,22 +65,61 @@ } LambdaQueryWrapper<Complaint> wrapper = new LambdaQueryWrapper<Complaint>(); + SystemUserLevel systemUserLevel = listBySystemUsers.stream().filter(e -> e.getLevel() == 1).findFirst().orElse(null); if(query.getCityCode()!=null){ + // 判断是否有市级权限 + if(systemUserLevel==null){ + throw new ServiceException("没有市级权限"); + } wrapper.eq(Complaint::getCityCode, query.getCityCode()); } if(query.getDistrictCode()!=null){ + // 判断是否有区县权限 + List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2 && e.getDistrictsCode().equals(query.getDistrictCode().toString())).collect(Collectors.toList()); + // 没有市权限 也没有该区权限 + if(systemUserLevels2.size()==0 && systemUserLevel==null){ + throw new ServiceException("没有该区县权限"); + } wrapper.eq(Complaint::getDistrictsCode, query.getDistrictCode()); } if(query.getStreetId()!=null){ + // 获取街道上一级查看是否有上级权限 + ComStreet comStreet = comStreetService.getById(query.getStreetId()); + if(comStreet==null){ + throw new ServiceException("没有该街道权限"); + } + List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2 && e.getDistrictsCode().equals(comStreet.getAreaCode().toString())).collect(Collectors.toList()); + // 判断是否有街道权限 + List<SystemUserLevel> systemUserLevels3 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3 && e.getStreetId().equals(query.getStreetId().toString())).collect(Collectors.toList()); + // 没有市级 上级区县 本级街道权限 + if(systemUserLevels3.size()==0 && systemUserLevel==null && systemUserLevels2.size()==0){ + throw new ServiceException("没有该街道权限"); + } wrapper.eq(Complaint::getStreetId, query.getStreetId()); } if(query.getCommunityId()!=null){ + + ComAct comAct = comActService.getById(query.getCommunityId()); + if (comAct == null) { + throw new ServiceException("没有该社区权限"); + } + // 查看是否有上级街道权限 + List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3 && e.getStreetId().equals(comAct.getStreetId().toString())).collect(Collectors.toList()); + + // 查看是否有上级区权限 + List<SystemUserLevel> systemUserLevels3 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2 && e.getDistrictsCode().equals(comAct.getAreaCode())).collect(Collectors.toList()); + + // 查看是否有本级权限 + List<SystemUserLevel> systemUserLevels4 = listBySystemUsers.stream().filter(e -> e.getLevel() == 4 && e.getCommunityId().equals(query.getCommunityId())).collect(Collectors.toList()); + // 判断是否有上面的4个权限 + if(systemUserLevels4.size()==0 && systemUserLevels3.size()==0 && systemUserLevels2.size()==0 && systemUserLevel==null){ + throw new ServiceException("没有该社区权限"); + } wrapper.eq(Complaint::getCommunityId, query.getCommunityId()); } // 都为空 查他有的 if(query.getCityCode()==null && query.getDistrictCode()==null && query.getStreetId()==null && query.getCommunityId()==null){ // 看是否直接是市级账号 - SystemUserLevel systemUserLevel = listBySystemUsers.stream().filter(e -> e.getLevel() == 1).findFirst().orElse(null); if(systemUserLevel==null){ List<String> districtsCodes=new ArrayList<>(); List<String> streetIds=new ArrayList<>(); @@ -154,9 +196,9 @@ // 查询所有的县 街道 社区 List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400)); - List<ComStreet> list1 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getAreaCode, 510400)); + List<ComStreet> list1 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getCityCode, 510400)); - List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getState,0).eq(ComAct::getAreaCode, 510400)); + List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getState,0).eq(ComAct::getCityCode, 510400)); analyticStatisticsRegionVo.setBcRegions(list); analyticStatisticsRegionVo.setComStreets(list1); analyticStatisticsRegionVo.setComActs(list2); diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java index dd0f12a..0f4afa9 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java @@ -563,8 +563,6 @@ // } - - // //已办结,显示评价按钮 // int count = complaintCommentService.count(new LambdaQueryWrapper<ComplaintComment>().eq(ComplaintComment::getComplaintId, detail.getId()).eq(ComplaintComment::getDelFlag, 0)); // if(detail.getStatus() == 3 && 0 == count){ @@ -1240,8 +1238,8 @@ complaintVO.setComplaintComment(comment); ArrayList<String> voiceFileList = new ArrayList<>(); String voiceFile = complaint.getVoiceFile(); - if(StringUtils.isNotEmpty(voiceFile)){ - for (String file :voiceFile.split(",")) { + if (StringUtils.isNotEmpty(voiceFile)) { + for (String file : voiceFile.split(",")) { voiceFileList.add(file); } } @@ -1428,7 +1426,7 @@ public void updateProgress(ComplaintProcessUpdateDto dto) { complaintProgressService.update(new LambdaUpdateWrapper<ComplaintProgress>().eq(ComplaintProgress::getId, dto.getId()) .set(ComplaintProgress::getDescribe, dto.getDescribe()).set(ComplaintProgress::getImgUrl, dto.getImgUrl()) - .set(ComplaintProgress::getVideo, dto.getVideo()) ) ; + .set(ComplaintProgress::getVideo, dto.getVideo())); } /** @@ -1437,23 +1435,23 @@ */ @Override public void delProgress(Long id) { - complaintProgressService.removeById(id); + complaintProgressService.removeById(id); } @Override - public AnalyticStatisticsOneVo analyticStatisticsOne(AnalyticStatisticsQuery query,List<Complaint> complaints, SimpleDateFormat simpleDateFormat) { + public AnalyticStatisticsOneVo analyticStatisticsOne(AnalyticStatisticsQuery query, List<Complaint> complaints, SimpleDateFormat simpleDateFormat) { String nowYearMonth; String lastYearMonth; int value = LocalDate.now().getMonth().getValue(); - if(value<10){ + if (value < 10) { nowYearMonth = LocalDate.now().getYear() + "-0" + LocalDate.now().getMonth().getValue(); - }else { + } else { nowYearMonth = LocalDate.now().getYear() + "-" + LocalDate.now().getMonth().getValue(); } int value1 = LocalDate.now().minusMonths(1).getMonth().getValue(); - if(value1<10){ + if (value1 < 10) { lastYearMonth = LocalDate.now().minusMonths(1).getYear() + "-0" + LocalDate.now().minusMonths(1).getMonth().getValue(); - }else { + } else { lastYearMonth = LocalDate.now().minusMonths(1).getYear() + "-" + LocalDate.now().minusMonths(1).getMonth().getValue(); } @@ -1464,12 +1462,12 @@ vo.setAllTotal(complaints.size()); // 诉求单量本月 - int thisMonthTotal = (int)complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(nowYearMonth)).count(); - vo.setThisMonthTotal( thisMonthTotal); + int thisMonthTotal = (int) complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(nowYearMonth)).count(); + vo.setThisMonthTotal(thisMonthTotal); // 诉求单量同比上月 - int lastMonthTotal = (int)complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(lastYearMonth)).count(); - vo.setLastMonthCompareTotal(thisMonthTotal- lastMonthTotal); + int lastMonthTotal = (int) complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(lastYearMonth)).count(); + vo.setLastMonthCompareTotal(thisMonthTotal - lastMonthTotal); // 正在办理 int nowTransactTotal = (int) complaints.stream().filter(e -> e.getStatus() == 0).count(); @@ -1497,25 +1495,25 @@ // 超时办理同比上月 int lastMonthOvertimeTransactTotal = (int) overtimeComplaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(lastYearMonth)).count(); - vo.setLastMonthOvertimeTransactCompareTotal(thisMonthOvertimeTransactTotal-lastMonthOvertimeTransactTotal); + vo.setLastMonthOvertimeTransactCompareTotal(thisMonthOvertimeTransactTotal - lastMonthOvertimeTransactTotal); // 平均处理时长 - if(complaints.size()>0) { + if (complaints.size() > 0) { double averageDay = complaints.stream().mapToDouble(v -> v.getHandlingDay() == null ? 0 : v.getHandlingDay()).average().getAsDouble(); averageDay = BigDecimal.valueOf(averageDay).setScale(2, RoundingMode.HALF_UP).doubleValue(); vo.setAverageTime(averageDay); List<Complaint> thisMonthAverageTimeComplaints = complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(nowYearMonth)).collect(Collectors.toList()); - if(thisMonthAverageTimeComplaints.size()>0){ + if (thisMonthAverageTimeComplaints.size() > 0) { double thisMonthAverageTime = thisMonthAverageTimeComplaints.stream().mapToDouble(v -> v.getHandlingDay() == null ? 0 : v.getHandlingDay()).average().getAsDouble(); thisMonthAverageTime = BigDecimal.valueOf(thisMonthAverageTime).setScale(2, RoundingMode.HALF_UP).doubleValue(); vo.setThisMonthAverageTime(thisMonthAverageTime); } List<Complaint> lastMonthAverageTimeComplaints = complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(lastYearMonth)).collect(Collectors.toList()); - if(lastMonthAverageTimeComplaints.size()>0){ + if (lastMonthAverageTimeComplaints.size() > 0) { double lastMonthAverageTime = lastMonthAverageTimeComplaints.stream().mapToDouble(v -> v.getHandlingDay() == null ? 0 : v.getHandlingDay()).average().getAsDouble(); lastMonthAverageTime = BigDecimal.valueOf(lastMonthAverageTime).setScale(2, RoundingMode.HALF_UP).doubleValue(); - vo.setAverageTime(vo.getThisMonthAverageTime() - lastMonthAverageTime); + vo.setLastMonthCompareAverageTime(vo.getThisMonthAverageTime() - lastMonthAverageTime); } } @@ -1523,7 +1521,7 @@ List<Complaint> commentRateComplaints = complaints.stream().filter(e -> e.getCommentRate() != null).collect(Collectors.toList()); long count = commentRateComplaints.stream().filter(e -> e.getCommentRate() > 1).count(); int size = commentRateComplaints.size(); - if(size>0){ + if (size > 0) { BigDecimal multiply = BigDecimal.valueOf(count).divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")); vo.setSatisfactionRate(multiply.doubleValue()); @@ -1532,19 +1530,19 @@ long count1 = nowMonth.stream().filter(e -> e.getCommentRate() > 1).count(); // 当月的评价数 int nowMonthSize = nowMonth.size(); - if(nowMonthSize>0){ + if (nowMonthSize > 0) { BigDecimal multiply1 = BigDecimal.valueOf(count1).divide(new BigDecimal(nowMonthSize), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")); vo.setThisMonthSatisfactionRate(multiply1.doubleValue()); } - List<Complaint> lastMonth = commentRateComplaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(nowYearMonth)).collect(Collectors.toList()); + List<Complaint> lastMonth = commentRateComplaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(lastYearMonth)).collect(Collectors.toList()); // 当月满意 long count2 = lastMonth.stream().filter(e -> e.getCommentRate() > 1).count(); // 当月的评价数 int lastMonthSize = lastMonth.size(); - if(lastMonthSize>0){ + if (lastMonthSize > 0) { BigDecimal multiply2 = BigDecimal.valueOf(count2).divide(new BigDecimal(lastMonthSize), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")); - vo.setLastMonthCompareSatisfactionRate(vo.getThisMonthSatisfactionRate()-multiply2.doubleValue()); + vo.setLastMonthCompareSatisfactionRate(vo.getThisMonthSatisfactionRate() - multiply2.doubleValue()); } } return vo; @@ -1560,20 +1558,21 @@ Date parse1 = simpleDateFormat.parse(split[1] + " 23:59:59"); complaints = complaints.stream().filter(e -> e.getCreateTime().getTime() <= parse1.getTime() && e.getCreateTime().getTime() >= parse.getTime()).collect(Collectors.toList()); int day = DateUtils.getDay(parse, parse1); - if(day>30){ + + if (day > 30) { throw new ServiceException("时间范围不能超过30天"); } for (int i = 0; i <= day; i++) { AnalyticStatisticsTwoVo analyticStatisticsTwoVo = new AnalyticStatisticsTwoVo(); - if(i==0){ + if (i == 0) { List<Complaint> collect = complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(split[0])).collect(Collectors.toList()); analyticStatisticsTwoVo.setTime(split[0]); analyticStatisticsTwoVo.setAllTotal(collect.size()); int count = (int) collect.stream().filter(e -> e.getStatus() == 3).count(); analyticStatisticsTwoVo.setCompleteTotal(count); list.add(analyticStatisticsTwoVo); - }else { + } else { String nextDay = DateUtils.getNextDay(parse, i); List<Complaint> collect = complaints.stream().filter(e -> simpleDateFormat.format(e.getCreateTime()).contains(nextDay)).collect(Collectors.toList()); analyticStatisticsTwoVo.setTime(nextDay); @@ -1622,11 +1621,11 @@ }) .collect(Collectors.toList()); analyticStatisticsThreeVos = analyticStatisticsThreeVos.stream().sorted(Comparator.comparing(AnalyticStatisticsThreeVo::getAllTotal).reversed()).collect(Collectors.toList()); - if(query.getRank()==null){ + if (query.getRank() == null) { return analyticStatisticsThreeVos; - }else if(query.getRank()==5){ - return analyticStatisticsThreeVos.stream().limit(5).collect(Collectors.toList()); - }else if(query.getRank()==10){ + } else if (query.getRank() == 5) { + return analyticStatisticsThreeVos.stream().limit(5).collect(Collectors.toList()); + } else if (query.getRank() == 10) { return analyticStatisticsThreeVos.stream().limit(10).collect(Collectors.toList()); } return Collections.emptyList(); @@ -1640,11 +1639,12 @@ long count1 = complaints.stream().filter(e -> e.getCommentRate() != null && e.getCommentRate() == 1).count(); long count2 = complaints.stream().filter(e -> e.getCommentRate() != null && e.getCommentRate() == 2).count(); long count3 = complaints.stream().filter(e -> e.getCommentRate() != null && e.getCommentRate() == 3).count(); - vo.setDissatisfactionRate(BigDecimal.valueOf(count).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); - vo.setGeneralSatisfactionRate(BigDecimal.valueOf(count1).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); - vo.setSatisfactionRate(BigDecimal.valueOf(count2).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); - vo.setGreatSatisfactionRate(BigDecimal.valueOf(count3).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); - + if (complaints.size() > 0) { + vo.setDissatisfactionRate(BigDecimal.valueOf(count).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); + vo.setGeneralSatisfactionRate(BigDecimal.valueOf(count1).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); + vo.setSatisfactionRate(BigDecimal.valueOf(count2).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); + vo.setGreatSatisfactionRate(BigDecimal.valueOf(count3).divide(BigDecimal.valueOf(complaints.size()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).doubleValue()); + } return vo; } -- Gitblit v1.7.1