From 6891ae6f2d5313bcebff27e43f40e99c7ce715c8 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 07 五月 2025 17:32:46 +0800
Subject: [PATCH] 分析统计

---
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/AnalyticStatisticsController.java |  223 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 205 insertions(+), 18 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 26587fc..a55aeb8 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
@@ -2,25 +2,26 @@
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.panzhihua.common.controller.BaseController;
 import com.panzhihua.common.model.vos.R;
-import com.panzhihua.common.utlis.DateUtils;
-import com.panzhihua.sangeshenbian.model.entity.Complaint;
+import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo;
+import com.panzhihua.sangeshenbian.model.entity.*;
 import com.panzhihua.sangeshenbian.model.query.AnalyticStatisticsQuery;
-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.service.IComplaintService;
+import com.panzhihua.sangeshenbian.model.vo.*;
+import com.panzhihua.sangeshenbian.service.*;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import javax.validation.Valid;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -33,16 +34,37 @@
 @RestController
 @RequestMapping("/analytic-statistics")
 @Validated
-public class AnalyticStatisticsController {
+public class AnalyticStatisticsController extends BaseController {
 
     @Autowired
     private IComplaintService complaintService;
 
+    @Autowired
+    private ISystemUserLevelService systemUserLevelService;
+
+    @Resource
+    private IBcRegionService bcRegionService;
+
+    @Resource
+    private IComStreetService comStreetService;
+
+    @Resource
+    private IComActService comActService;
+
     @PostMapping("/data")
     @ApiOperation(value = "分析统计", tags = {"三个身边后台-分析统计"})
-    public R<?> data(@Valid @RequestBody AnalyticStatisticsQuery query){
-        // TODO 判断当前账号的层级  如果包含市级 可以查看所有  包含区县多个  包含镇多个 包含村多个
-        LambdaQueryWrapper<Complaint> wrapper = new LambdaQueryWrapper<Complaint>().eq(Complaint::getCityCode, query.getCityCode());
+    public R<AnalyticStatisticsDataVo> data(@Valid @RequestBody AnalyticStatisticsQuery query){
+        SystemUserVo loginUserInfoSanGeShenBian = getLoginUserInfoSanGeShenBian();
+        Integer id = loginUserInfoSanGeShenBian.getId();
+        List<SystemUserLevel> listBySystemUsers = systemUserLevelService.getListBySystemUserId(id);
+        if(listBySystemUsers.size()==0){
+            return R.ok(new AnalyticStatisticsDataVo());
+        }
+
+        LambdaQueryWrapper<Complaint> wrapper = new LambdaQueryWrapper<Complaint>();
+        if(query.getCityCode()!=null){
+            wrapper.eq(Complaint::getCityCode, query.getCityCode());
+        }
         if(query.getDistrictCode()!=null){
             wrapper.eq(Complaint::getDistrictsCode, query.getDistrictCode());
         }
@@ -51,6 +73,44 @@
         }
         if(query.getCommunityId()!=null){
             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<>();
+                List<Long> communityIds=new ArrayList<>();
+                // 不是市级 查看是否是区县账号
+                List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2).collect(Collectors.toList());
+                if(systemUserLevels2.size()>0){
+                    districtsCodes = systemUserLevels2.stream().map(SystemUserLevel::getDistrictsCode).collect(Collectors.toList());
+                }else {
+                    districtsCodes.add("0");
+                }
+
+                List<SystemUserLevel> systemUserLevels3 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3).collect(Collectors.toList());
+                if(systemUserLevels3.size()>0){
+                    streetIds = systemUserLevels3.stream().filter(e -> !systemUserLevels2.contains(e.getDistrictsCode())).map(SystemUserLevel::getStreetId).collect(Collectors.toList());
+                }else {
+                    streetIds.add("0");
+                }
+
+                List<SystemUserLevel> systemUserLevels4 = listBySystemUsers.stream().filter(e -> e.getLevel() == 4).collect(Collectors.toList());
+                if(systemUserLevels4.size()>0){
+                    communityIds = systemUserLevels4.stream().filter(e -> !systemUserLevels3.contains(e.getStreetId()) && !systemUserLevels2.contains(e.getDistrictsCode())).map(SystemUserLevel::getCommunityId).collect(Collectors.toList());
+                }else {
+                    communityIds.add(0L);
+                }
+                List<String> finalDistrictsCodes = districtsCodes;
+                List<String> finalStreetIds = streetIds;
+                List<Long> finalCommunityIds = communityIds;
+                wrapper.and(wrapper1 -> {
+                    wrapper1.in(Complaint::getDistrictsCode, finalDistrictsCodes).or().in(Complaint::getStreetId, finalStreetIds).or().in(Complaint::getCommunityId, finalCommunityIds);
+                });
+
+            }
         }
 
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -64,13 +124,140 @@
         // 第三部分数据
         List<AnalyticStatisticsThreeVo> analyticStatisticsThreeVos =complaintService.analyticStatisticsThree(query,complaints);
 
-        return R.ok(analyticStatisticsThreeVos);
+        // 第四部分数据
+        AnalyticStatisticsFourVo analyticStatisticsFourVos =complaintService.analyticStatisticsFour(complaints);
+
+
+        AnalyticStatisticsDataVo analyticStatisticsDataVo = new AnalyticStatisticsDataVo();
+        analyticStatisticsDataVo.setAnalyticStatisticsOneVo(analyticStatisticsOneVo);
+        analyticStatisticsDataVo.setAnalyticStatisticsTwoVos(analyticStatisticsTwoVos);
+        analyticStatisticsDataVo.setAnalyticStatisticsThreeVos(analyticStatisticsThreeVos);
+        analyticStatisticsDataVo.setAnalyticStatisticsFourVo(analyticStatisticsFourVos);
+
+        return R.ok(analyticStatisticsDataVo);
     }
 
 
-    public static void main(String[] args) {
-        String beforeDay = DateUtils.getBeforeDay(6);
-        System.out.println(beforeDay);
+
+
+    @GetMapping("/getRegion")
+    @ApiOperation(value = "分析统计--获取市-区县-街道-社区", tags = {"三个身边后台-分析统计--获取市-区县-街道-社区"})
+    public R<AnalyticStatisticsRegionVo> getRegion(){
+        SystemUserVo loginUserInfoSanGeShenBian = getLoginUserInfoSanGeShenBian();
+        Integer id = loginUserInfoSanGeShenBian.getId();
+        List<SystemUserLevel> listBySystemUsers = systemUserLevelService.getListBySystemUserId(id);
+        // 如果有市级权限  展示所有
+        SystemUserLevel systemUserLevel = listBySystemUsers.stream().filter(e -> e.getLevel() == 1).findFirst().orElse(null);
+
+        AnalyticStatisticsRegionVo analyticStatisticsRegionVo = new AnalyticStatisticsRegionVo();
+        if(systemUserLevel!=null){
+            // 查询所有的县 街道 社区
+            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<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getState,0).eq(ComAct::getAreaCode, 510400));
+            analyticStatisticsRegionVo.setBcRegions(list);
+            analyticStatisticsRegionVo.setComStreets(list1);
+            analyticStatisticsRegionVo.setComActs(list2);
+            return R.ok(analyticStatisticsRegionVo);
+        }
+
+        // 有区县级权限
+        List<SystemUserLevel> systemUserLevels = listBySystemUsers.stream().filter(e -> e.getLevel() == 2).collect(Collectors.toList());
+        // 拥有的区县code
+        List<String> collect = systemUserLevels.stream().map(SystemUserLevel::getDistrictsCode).collect(Collectors.toList());
+        if(collect.size()==0){
+            collect.add("0");
+        }
+        // 找出这个区县的
+        List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400).in(BcRegion::getRegionCode, collect));
+
+        // 区县街道
+        List<ComStreet> list1 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().in(ComStreet::getAreaCode, collect));
+
+        // 区县社区
+        List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().in(ComAct::getAreaCode, collect).eq(ComAct::getState,0));
+
+
+        // 有街道权限 排除上个查询出来的
+        List<SystemUserLevel> systemUserLevels1 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3 && !collect.contains(e.getDistrictsCode())).collect(Collectors.toList());
+        List<String> collect1 = systemUserLevels1.stream().map(SystemUserLevel::getStreetId).collect(Collectors.toList());
+        if(collect1.size()==0){
+            collect1.add("0");
+        }
+        // 区县街道
+        List<ComStreet> list3 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().in(ComStreet::getStreetId, collect1));
+
+        // 区县社区
+        List<ComAct> list4 = comActService.list(new LambdaQueryWrapper<ComAct>().in(ComAct::getStreetId, collect1).eq(ComAct::getState,0));
+
+        list1.addAll(list3);
+        list2.addAll(list4);
+
+        // 有社区权限 排除上个查询出来的
+        List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 4 && !collect.contains(e.getDistrictsCode()) && !collect1.contains(e.getStreetId())).collect(Collectors.toList());
+        List<Long> collect2 = systemUserLevels2.stream().map(SystemUserLevel::getCommunityId).collect(Collectors.toList());
+        if(collect2.size()==0){
+            collect2.add(0l);
+        }
+
+        // 区县社区
+        List<ComAct> list6 = comActService.list(new LambdaQueryWrapper<ComAct>().in(ComAct::getCommunityId, collect2).eq(ComAct::getState,0));
+        list2.addAll(list6);
+
+        analyticStatisticsRegionVo.setBcRegions(list);
+        analyticStatisticsRegionVo.setComStreets(list1);
+        analyticStatisticsRegionVo.setComActs(list2);
+
+        return R.ok(analyticStatisticsRegionVo);
+
+    }
+
+
+    @GetMapping("/getNextRegion")
+    @ApiOperation(value = "分析统计--获取下一级树", tags = {"三个身边后台-分析统计--获取市-区县-街道-社区"})
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "区 传regionCode  街道streetId", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "type", value = "1区  2街道", required = true, dataType = "Integer")
+    })
+    public R<?> getNextRegion(@RequestParam String id, @RequestParam Integer type){
+        if(type==1){
+            List<ComStreet> list3 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getAreaCode, id));
+            return R.ok(list3);
+        }
+        if(type==2){
+            List<ComAct> list3 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getStreetId, id).eq(ComAct::getState,0));
+            return R.ok(list3);
+        }
+        return R.ok();
+    }
+
+    @GetMapping("/getLastRegion")
+    @ApiOperation(value = "分析统计--获取上级回显", tags = {"三个身边后台-分析统计--获取市-区县-街道-社区"})
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "街道streetId 社区 communityId", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "type", value = "2街道 3社区", required = true, dataType = "Integer")
+    })
+    public R<AnalyticStatisticsRegionVo> getLastRegion(@RequestParam String id, @RequestParam Integer type){
+        AnalyticStatisticsRegionVo analyticStatisticsRegionVo = new AnalyticStatisticsRegionVo();
+        if(type==2){
+            ComStreet comStreet = comStreetService.getOne(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getStreetId, id));
+            // 找出这个区县的
+            List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400).eq(BcRegion::getRegionCode, comStreet.getAreaCode()));
+            analyticStatisticsRegionVo.setBcRegions(list);
+            return R.ok(analyticStatisticsRegionVo);
+        }
+        if(type==3){
+            ComAct comAct = comActService.getOne(new LambdaQueryWrapper<ComAct>().eq(ComAct::getCommunityId, id));
+            // 找出这个区县的
+            List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400).eq(BcRegion::getRegionCode, comAct.getAreaCode()));
+            analyticStatisticsRegionVo.setBcRegions(list);
+            List<ComStreet> list3 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getStreetId, comAct.getStreetId()));
+            analyticStatisticsRegionVo.setComStreets(list3);
+            return R.ok(analyticStatisticsRegionVo);
+        }
+        return R.ok();
     }
 
 }

--
Gitblit v1.7.1