From fad1b886464f52e88dd9b99a62b9cd89fd5bb8c2 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期二, 13 五月 2025 09:33:22 +0800
Subject: [PATCH] 用户端统计分析接口

---
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/resources/mapper/ComplaintMapper.xml                                              |   35 ++++++--
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/StaticsController.java                |   24 +++++
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java |    1 
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/StaticsService.java                 |  101 +++++++++++++++++++++++++
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/vo/AppComplaintRejectVO.java               |    2 
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/HomeController.java                   |   20 ++++
 6 files changed, 170 insertions(+), 13 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/HomeController.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/HomeController.java
index 72dbb0a..799fbc0 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/HomeController.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/HomeController.java
@@ -5,9 +5,11 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.panzhihua.common.controller.BaseController;
+import com.panzhihua.common.exceptions.ServiceException;
 import com.panzhihua.common.model.vos.LoginUserInfoVO;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.redis.RedisUtils;
+import com.panzhihua.sangeshenbian.model.dto.UserIdentityDTO;
 import com.panzhihua.sangeshenbian.model.entity.Banner;
 import com.panzhihua.sangeshenbian.model.entity.PartyMember;
 import com.panzhihua.sangeshenbian.model.entity.SystemUser;
@@ -20,6 +22,8 @@
 import com.panzhihua.sangeshenbian.warpper.IdentityInformation;
 import com.panzhihua.sangeshenbian.warpper.IdentityInformationVO;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
@@ -141,9 +145,21 @@
      */
     @GetMapping("/change-identity")
     @ApiOperation("切换身份")
-    public R<?> changeIdentity(Integer identity) {
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "identity", value = "身份 1:党员 2:管理员", required = true, dataType = "Integer"),
+            @ApiImplicitParam(name = "levelId", value = "身份层级id,党员身份不传,管理员必传", required = true, dataType = "Integer")
+    })
+    public R<?> changeIdentity(@RequestParam(value = "identity", required = true) Integer identity,
+                               @RequestParam(value = "levelId", required = false) Integer levelId) {
         LoginUserInfoVO loginUserInfo = getLoginUserInfo();
-        redisUtils.set("identity:" + loginUserInfo.getPhone(), identity);
+        if (identity.equals(2) && Objects.isNull(levelId)) {
+            throw new ServiceException("管理员所属层级id不能为空");
+        }
+        // 存储到Redis
+        redisUtils.set("identity:" + loginUserInfo.getPhone(), UserIdentityDTO.builder()
+                .identity(identity)
+                .levelId(levelId)
+                .build());
         return R.ok();
     }
 
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/StaticsController.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/StaticsController.java
index 8bde110..bcd311a 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/StaticsController.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/StaticsController.java
@@ -1,11 +1,25 @@
 package com.panzhihua.sangeshenbian.controller;
 
+import com.beust.jcommander.internal.Lists;
+import com.panzhihua.common.controller.BaseController;
+import com.panzhihua.common.exceptions.ServiceException;
+import com.panzhihua.common.model.vos.LoginUserInfoVO;
+import com.panzhihua.common.model.vos.R;
+import com.panzhihua.sangeshenbian.model.entity.ComAct;
+import com.panzhihua.sangeshenbian.model.vo.RegionVO;
+import com.panzhihua.sangeshenbian.service.IdentityInformationService;
 import com.panzhihua.sangeshenbian.service.impl.StaticsService;
+import com.panzhihua.sangeshenbian.warpper.IdentityInformation;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author mitao
@@ -15,7 +29,15 @@
 @RestController
 @RequestMapping("/applet/statics")
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
-public class StaticsController {
+public class StaticsController extends BaseController {
     private final StaticsService staticsService;
+    private final IdentityInformationService identityInformationService;
 
+    @GetMapping("/region-tree")
+    @ApiOperation("获取区域树")
+    public R<List<RegionVO>> regionTree() {
+        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
+        return R.ok(staticsService.queryRegionTree(loginUserInfo));
+
+    }
 }
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/vo/AppComplaintRejectVO.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/vo/AppComplaintRejectVO.java
index 9ffdd0a..102dff5 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/vo/AppComplaintRejectVO.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/vo/AppComplaintRejectVO.java
@@ -20,7 +20,7 @@
 public class AppComplaintRejectVO extends Complaint {
     @ApiModelProperty("申请时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
-    private Date createTime;
+    private Date applyTime;
 
     @ApiModelProperty("申请人")
     private String reporter;
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java
index 2a2022e..8dc42d5 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java
@@ -116,6 +116,7 @@
                 PermissionsVO adminPermissions = new PermissionsVO();
                 adminPermissions.setIdentity(2);
                 adminPermissions.setIsFrozen(systemUser.getStatus() == 2);
+                adminPermissions.setLevelId(userLevel.getId());
                 if (accountLevel == 1) {
                     adminPermissions.setName(String.format("%s%s", "攀枝花市", "管理员"));
                 } else if (accountLevel == 2) {
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..91575e4 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,26 @@
 package com.panzhihua.sangeshenbian.service.impl;
 
+import com.beust.jcommander.internal.Lists;
+import com.panzhihua.common.exceptions.ServiceException;
+import com.panzhihua.common.model.vos.LoginUserInfoVO;
+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.SystemUserLevel;
+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.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 /**
  * @author mitao
@@ -21,5 +34,93 @@
     private final IBcRegionService bcRegionService;
     private final IComStreetService comStreetService;
     private final IComActService comActService;
+    private final SystemUserMapper systemUserMapper;
+
+    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);
+    }
 
 }
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/resources/mapper/ComplaintMapper.xml b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/resources/mapper/ComplaintMapper.xml
index 4a2e4f2..22d9a7e 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/resources/mapper/ComplaintMapper.xml
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/resources/mapper/ComplaintMapper.xml
@@ -602,15 +602,32 @@
     </select>
     <select id="queryRejectRecordPage" resultType="com.panzhihua.sangeshenbian.model.vo.AppComplaintRejectVO">
         SELECT
-            scar.*,
-            sc.serial_number,
-            sc.latitude,
-            sc.longitude,
-            sc.location,
-            sc.detailed_address,
-            sc.problem_type,
-            sc.name,
-            sc.contact_number
+        scar.id,
+        scar.complaint_id,
+        scar.auditor_id,
+        scar.audit_type,
+        scar.audit_status,
+        scar.reject_reason,
+        scar.comment,
+        scar.images,
+        scar.videos,
+        scar.create_time AS applyTime,
+        scar.system_user_id,
+        scar.reporter,
+        scar.department_name,
+        scar.department_id,
+        scar.latest_flag,
+        scar.report_type,
+        scar.superior_id,
+        scar.sort
+        sc.serial_number,
+        sc.latitude,
+        sc.longitude,
+        sc.location,
+        sc.detailed_address,
+        sc.problem_type,
+        sc.name,
+        sc.contact_number
         FROM
             sgsb_complaint_audit_record scar
                 LEFT JOIN sgsb_complaint sc ON scar.complaint_id = sc.id

--
Gitblit v1.7.1