From bc91619c854cc2dbb01b20d0c47d76c4881e9ee8 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期二, 20 五月 2025 23:52:21 +0800
Subject: [PATCH] Merge remote-tracking branch '喜望/dev-2.0.1' into dev-2.0.1

---
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/StaticsService.java |  173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 173 insertions(+), 0 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/StaticsService.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/StaticsService.java
index 2ec8758..0d41c72 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/StaticsService.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/StaticsService.java
@@ -1,13 +1,34 @@
 package com.panzhihua.sangeshenbian.service.impl;
 
+import com.panzhihua.common.exceptions.ServiceException;
+import com.panzhihua.common.model.vos.LoginUserInfoVO;
+import com.panzhihua.common.utlis.DateUtils;
+import com.panzhihua.sangeshenbian.dao.SystemUserMapper;
+import com.panzhihua.sangeshenbian.model.entity.ComAct;
+import com.panzhihua.sangeshenbian.model.entity.ComStreet;
+import com.panzhihua.sangeshenbian.model.entity.Complaint;
+import com.panzhihua.sangeshenbian.model.entity.SystemUserLevel;
+import com.panzhihua.sangeshenbian.model.query.AppStaticsQuery;
+import com.panzhihua.sangeshenbian.model.vo.AnalyticStatisticsFourVo;
+import com.panzhihua.sangeshenbian.model.vo.AnalyticStatisticsOneVo;
+import com.panzhihua.sangeshenbian.model.vo.AnalyticStatisticsThreeVo;
+import com.panzhihua.sangeshenbian.model.vo.AnalyticStatisticsTwoVo;
+import com.panzhihua.sangeshenbian.model.vo.RegionVO;
 import com.panzhihua.sangeshenbian.service.IBcRegionService;
 import com.panzhihua.sangeshenbian.service.IComActService;
 import com.panzhihua.sangeshenbian.service.IComStreetService;
 import com.panzhihua.sangeshenbian.service.IComplaintService;
 import com.panzhihua.sangeshenbian.service.IdentityInformationService;
+import com.panzhihua.sangeshenbian.warpper.IdentityInformation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
 
 /**
  * @author mitao
@@ -21,5 +42,157 @@
     private final IBcRegionService bcRegionService;
     private final IComStreetService comStreetService;
     private final IComActService comActService;
+    private final SystemUserMapper systemUserMapper;
+    private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    public List<RegionVO> queryRegionTree(LoginUserInfoVO loginUserInfo) {
+        IdentityInformation currentIdentityInformation = identityInformationService.getCurrentIdentityInformation(loginUserInfo);
+        if (!Integer.valueOf(2).equals(currentIdentityInformation.getIdentity())) {
+            throw new ServiceException("当前账号无权限");
+        }
 
+        SystemUserLevel userLevel = currentIdentityInformation.getSystemUserLevel();
+        Integer level = userLevel.getLevel();
+
+        switch (level) {
+            case 1:
+                return buildCityLevelTree("510400");
+            case 2:
+                return buildDistrictLevelTree(userLevel.getDistrictsCode());
+            case 3:
+                return buildStreetLevelTree(userLevel.getStreetId());
+            case 4:
+                return buildCommunityLevelTree(userLevel.getCommunityId());
+            default:
+                throw new ServiceException("不支持的用户等级");
+        }
+    }
+    /**
+     * 构建市级区域树结构(市 -> 区/县 -> 街道 -> 社区)
+     * @param cityCode 市级行政区划代码,例如 "510400"
+     * @return 区域树列表,每个区包含下属街道和社区
+     */
+    private List<RegionVO> buildCityLevelTree(String cityCode) {
+        List<RegionVO> districts = systemUserMapper.getRegion(cityCode);
+        districts.forEach(district -> {
+            district.setTier(2);
+            List<RegionVO> streets = systemUserMapper.getStreet(district.getId());
+            district.setChildren(streets);
+            streets.forEach(street -> {
+                street.setTier(3);
+                List<RegionVO> communities = systemUserMapper.getCommunity(street.getId());
+                communities.forEach(c -> c.setTier(4));
+                street.setChildren(communities);
+            });
+        });
+        return districts;
+    }
+    /**
+     * 构建区级区域树结构(区/县 -> 街道 -> 社区)
+     * @param districtCode 区级行政区划代码
+     * @return 街道列表,每个街道包含其下属社区
+     */
+    private List<RegionVO> buildDistrictLevelTree(String districtCode) {
+        List<RegionVO> streets = systemUserMapper.getStreet(districtCode);
+        streets.forEach(street -> {
+            street.setTier(2);
+            List<RegionVO> communities = systemUserMapper.getCommunity(street.getId());
+            communities.forEach(c -> c.setTier(4));
+            street.setChildren(communities);
+        });
+        return streets;
+    }
+    /**
+     * 构建街道级区域树结构(街道 -> 社区)
+     * @param streetId 街道ID
+     * @return 包含一个街道及其下属社区的列表
+     */
+    private List<RegionVO> buildStreetLevelTree(String streetId) {
+        ComStreet street = comStreetService.getById(streetId);
+        RegionVO streetVO = new RegionVO();
+        streetVO.setId(String.valueOf(street.getStreetId()));
+        streetVO.setName(street.getName());
+        streetVO.setTier(3);
+        List<RegionVO> communities = systemUserMapper.getCommunity(streetId);
+        communities.forEach(c -> c.setTier(4));
+        streetVO.setChildren(communities);
+        return Collections.singletonList(streetVO);
+    }
+    /**
+     * 构建社区级区域(只返回当前社区信息)
+     * @param communityId 社区ID
+     * @return 仅包含一个社区节点的列表
+     */
+    private List<RegionVO> buildCommunityLevelTree(Long communityId) {
+        ComAct community = comActService.getById(communityId);
+        RegionVO regionVO = new RegionVO();
+        regionVO.setId(String.valueOf(community.getCommunityId()));
+        regionVO.setName(community.getName());
+        regionVO.setTier(4);
+        return Collections.singletonList(regionVO);
+    }
+
+    /**
+     * 统计分析-第一部分
+     * @param query
+     * @param loginUserInfo
+     * @return
+     */
+    public AnalyticStatisticsOneVo queryStaticsPartOne(AppStaticsQuery query, LoginUserInfoVO loginUserInfo) {
+        List<Complaint> complaints = complaintService.queryCompliantList(query,loginUserInfo);
+        return  complaintService.analyticStatisticsOne(null, complaints, simpleDateFormat);
+    }
+
+    /**
+     *获取统计分析-第二部分(诉求单量统计柱状图)
+     * @param query
+     * @param loginUserInfo
+     * @return
+     */
+    public List<AnalyticStatisticsTwoVo> queryStaticsPartTwo(AppStaticsQuery query, LoginUserInfoVO loginUserInfo) {
+        List<Complaint> complaints = complaintService.queryCompliantList(query,loginUserInfo);
+        //时间范围
+        String time = "";
+        if (Objects.nonNull(query.getTimeType())) {
+            Date now = new Date();
+            Date start = null;
+            switch (query.getTimeType()) {
+                case 2:
+                    start = DateUtils.addDay(now, -15);
+                    break;
+                case 3:
+                    start = DateUtils.addDay(now, -30);
+                    break;
+                default:
+                    start = DateUtils.addDay(now, -7);
+                    break;
+            }
+            //格式化
+            String startStr = DateUtils.format(start, DateUtils.yyyyMMdd_format);
+            String endStr = DateUtils.format(now, DateUtils.yyyyMMdd_format);
+            time = startStr + " - " + endStr;
+        }
+        return complaintService.analyticStatisticsTwo(time, complaints, simpleDateFormat);
+    }
+
+    /**
+     *获取统计分析-第三部分(问题类型排名)
+     * @param query
+     * @param loginUserInfo
+     * @return
+     */
+    public List<AnalyticStatisticsThreeVo> queryStaticsPartThree(AppStaticsQuery query, LoginUserInfoVO loginUserInfo) {
+        List<Complaint> complaints = complaintService.queryCompliantList(query,loginUserInfo);
+        return complaintService.analyticStatisticsThree(query.getRank(), complaints);
+    }
+
+    /**
+     * 获取统计分析-第四部分(评价占比)
+     * @param query
+     * @param loginUserInfo
+     * @return
+     */
+    public AnalyticStatisticsFourVo queryStaticsPartFour(AppStaticsQuery query, LoginUserInfoVO loginUserInfo) {
+        List<Complaint> complaints = complaintService.queryCompliantList(query,loginUserInfo);
+        return complaintService.analyticStatisticsFour(complaints);
+    }
 }

--
Gitblit v1.7.1