From 00ef2e4c4c6a85af857be272cf74a7e43e6517f0 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期日, 16 三月 2025 03:42:16 +0800
Subject: [PATCH] 修改诉求流程和新增评价功能

---
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/HomeController.java |   63 +++++++++++++++++++++++++++----
 1 files changed, 55 insertions(+), 8 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 840cc85..83554c6 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
@@ -1,13 +1,13 @@
 package com.panzhihua.sangeshenbian.controller;
 
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.panzhihua.common.controller.BaseController;
 import com.panzhihua.common.model.vos.LoginUserInfoVO;
 import com.panzhihua.common.model.vos.R;
-import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo;
-import com.panzhihua.common.service.sangeshenbian.SystemUserService;
 import com.panzhihua.common.service.user.UserService;
 import com.panzhihua.sangeshenbian.model.entity.Banner;
+import com.panzhihua.sangeshenbian.model.entity.Department;
 import com.panzhihua.sangeshenbian.model.entity.SystemUser;
 import com.panzhihua.sangeshenbian.model.query.BasePage;
 import com.panzhihua.sangeshenbian.model.vo.ComplaintTodoVO;
@@ -15,8 +15,10 @@
 import com.panzhihua.sangeshenbian.model.vo.PartyCardInfoVO;
 import com.panzhihua.sangeshenbian.service.IBannerService;
 import com.panzhihua.sangeshenbian.service.IComplaintService;
+import com.panzhihua.sangeshenbian.service.IDepartmentService;
 import com.panzhihua.sangeshenbian.service.IMessageNotificationService;
 import com.panzhihua.sangeshenbian.service.ISystemUserService;
+import com.panzhihua.sangeshenbian.utils.BaiduMapUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
@@ -27,7 +29,11 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @author mitao
@@ -35,7 +41,7 @@
  */
 @RestController
 @RequestMapping("/applet/home")
-@RequiredArgsConstructor(onConstructor_=@Lazy)
+@RequiredArgsConstructor(onConstructor_ = @Lazy)
 @Api(tags = "首页相关接口")
 public class HomeController extends BaseController {
     private final IBannerService bannerService;
@@ -43,11 +49,14 @@
     private final IComplaintService complaintService;
     private final ISystemUserService systemUserService;
     private final UserService userService;
+    private final IDepartmentService departmentService;
+
     @ApiOperation("获取banner列表")
     @GetMapping("/banner-list")
     public R<List<Banner>> getBannerList() {
         return R.ok(bannerService.list());
     }
+
     @GetMapping("/party-card-info")
     @ApiOperation("获取党员证信息")
     public R<PartyCardInfoVO> getPartyCardInfo() {
@@ -55,31 +64,69 @@
         PartyCardInfoVO partyCardInfoVO = new PartyCardInfoVO();
         partyCardInfoVO.setName(loginUserInfo.getName());
         partyCardInfoVO.setIdCard(loginUserInfo.getIdCard());
-        partyCardInfoVO.setPartyOrganization(loginUserInfo.getCommunityName());
+        Optional<SystemUser> systemUserOpt = systemUserService.getSystemUserByPhone(loginUserInfo.getPhone());
+        systemUserOpt.ifPresent(systemUser -> {
+            // 使用Optional链式调用简化部门ID获取逻辑
+            Integer lastDepartmentId = Optional.ofNullable(systemUser.getFourDepartmentId())
+                    .orElseGet(() -> Optional.ofNullable(systemUser.getThreeDepartmentId())
+                            .orElseGet(systemUser::getTwoDepartmentId));
+
+            // 缓存部门查询结果避免重复查询
+            Map<Integer, Department> departmentCache = new HashMap<>();
+            Department first = departmentCache.computeIfAbsent(systemUser.getOneDepartmentId(),
+                    departmentService::getById);
+            Department last = null;
+            if (Objects.nonNull(lastDepartmentId)) {
+                 last = departmentCache.computeIfAbsent(lastDepartmentId,
+                        departmentService::getById);
+            }
+
+            // 使用Objects.toString简化字符串拼接
+            partyCardInfoVO.setPartyOrganization(
+                    Objects.isNull(last) ? Objects.toString(first.getName(), "") :
+                            Objects.toString(first.getName(), "") + "-" + Objects.toString(last.getName(), ""));
+        });
         return R.ok(partyCardInfoVO);
     }
+
     @PostMapping("/message")
     @ApiOperation("获取消息列表")
     public R<Page<MessageNotificationVO>> getMessageList(@RequestBody BasePage page) {
-        return R.ok(messageNotificationService.getMessageList(page,getUserId()));
+        return R.ok(messageNotificationService.getMessageList(page, getUserId()));
     }
+
     @PostMapping("/todo-list")
     @ApiOperation("获取待办诉求")
     public R<Page<ComplaintTodoVO>> getTodoList(@RequestBody BasePage page) {
-        return R.ok(complaintService.getTodoList(page,getLoginUserInfo()));
+        return R.ok(complaintService.getTodoList(page, getLoginUserInfo()));
     }
+
     @GetMapping("/current-user-info")
     @ApiOperation("获取三个身边当前用户信息 用于判断用户是否是上级")
     public R<SystemUser> getCurrentUserInfo() {
-        return R.ok(systemUserService.getSystemUserByPhone(getLoginUserInfo().getPhone()).orElse(null));
+        return R.ok(systemUserService.getSystemUserAdminByPhone(getLoginUserInfo().getPhone()).orElse(null));
     }
+
     /**
      * 标记已读
      */
     @PostMapping("/read")
     @ApiOperation("标记已读")
-    public R<?> read(){
+    public R<?> read() {
         messageNotificationService.read(getLoginUserInfo());
         return R.ok();
     }
+
+    /**
+     * 百度地图圆形区域检索
+     *
+     * @param query
+     * @param location
+     * @return
+     */
+    @GetMapping("/search-location")
+    @ApiOperation("百度地图圆形区域检索")
+    public R<JSONArray> searchLocation(String query, String location) {
+        return R.ok(BaiduMapUtil.searchLocation(query, location));
+    }
 }

--
Gitblit v1.7.1