From be5783c8a7e13bbc76d33c95643d75779cce21db Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期六, 18 七月 2026 15:39:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_business' into dev_business

---
 yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java |   51 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java
index 7946aea..6739ee2 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java
@@ -11,9 +11,12 @@
 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
+import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
 import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
 import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
 import cn.iocoder.yudao.module.crm.service.followup.CrmFollowUpRecordService;
+import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
 import io.swagger.v3.oas.annotations.Operation;
@@ -25,12 +28,17 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Stream;
 
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_DENIED;
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_NOT_EXISTS;
 
 
 @Tag(name = "绠$悊鍚庡彴 - 璺熻繘璁板綍")
@@ -45,6 +53,8 @@
     private CrmContactService contactService;
     @Resource
     private CrmBusinessService businessService;
+    @Resource
+    private CrmPermissionService permissionService;
 
     @Resource
     private AdminUserApi adminUserApi;
@@ -68,6 +78,13 @@
     @Parameter(name = "id", description = "缂栧彿", required = true, example = "1024")
     public CommonResult<CrmFollowUpRecordRespVO> getFollowUpRecord(@RequestParam("id") Long id) {
         CrmFollowUpRecordDO followUpRecord = followUpRecordService.getFollowUpRecord(id);
+        if (followUpRecord == null) {
+            throw exception(FOLLOW_UP_RECORD_NOT_EXISTS);
+        }
+        if (!permissionService.hasPermission(followUpRecord.getBizType(), followUpRecord.getBizId(),
+                getLoginUserId(), CrmPermissionLevelEnum.READ)) {
+            throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.getNameByType(followUpRecord.getBizType()));
+        }
         return success(BeanUtils.toBean(followUpRecord, CrmFollowUpRecordRespVO.class));
     }
 
@@ -77,22 +94,40 @@
         PageResult<CrmFollowUpRecordDO> pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO);
         // 1.1 鏌ヨ鑱旂郴浜哄拰鍟嗘満
         Map<Long, CrmContactDO> contactMap = contactService.getContactMap(
-                convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream()));
+                convertSetByFlatMap(pageResult.getList(), item -> {
+                    List<Long> contactIds = item.getContactIds();
+                    return contactIds != null ? contactIds.stream() : Stream.empty();
+                }));
         Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap(
-                convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream()));
+                convertSetByFlatMap(pageResult.getList(), item -> {
+                    List<Long> businessIds = item.getBusinessIds();
+                    return businessIds != null ? businessIds.stream() : Stream.empty();
+                }));
         // 1.2 鏌ヨ鐢ㄦ埛
         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
-                convertSet(pageResult.getList(), item -> Long.valueOf(item.getCreator())));
+                convertSet(pageResult.getList(), item -> {
+                    String creator = item.getCreator();
+                    return creator != null && !creator.isEmpty() ? Long.valueOf(creator) : null;
+                }));
         // 2. 鎷兼帴鏁版嵁
         PageResult<CrmFollowUpRecordRespVO> voPageResult = BeanUtils.toBean(pageResult, CrmFollowUpRecordRespVO.class, record -> {
             // 2.1 璁剧疆鑱旂郴浜哄拰鍟嗘満淇℃伅
             record.setBusinesses(new ArrayList<>()).setContacts(new ArrayList<>());
-            record.getContactIds().forEach(id -> MapUtils.findAndThen(contactMap, id, contact ->
-                    record.getContacts().add(new CrmBusinessRespVO().setId(contact.getId()).setName(contact.getName()))));
-            record.getBusinessIds().forEach(id -> MapUtils.findAndThen(businessMap, id, business ->
-                    record.getBusinesses().add(new CrmBusinessRespVO().setId(business.getId()).setName(business.getName()))));
+            List<Long> contactIds = record.getContactIds();
+            if (contactIds != null) {
+                contactIds.forEach(id -> MapUtils.findAndThen(contactMap, id, contact ->
+                        record.getContacts().add(new CrmBusinessRespVO().setId(contact.getId()).setName(contact.getName()))));
+            }
+            List<Long> businessIds = record.getBusinessIds();
+            if (businessIds != null) {
+                businessIds.forEach(id -> MapUtils.findAndThen(businessMap, id, business ->
+                        record.getBusinesses().add(new CrmBusinessRespVO().setId(business.getId()).setName(business.getName()))));
+            }
             // 2.2 璁剧疆鐢ㄦ埛淇℃伅
-            MapUtils.findAndThen(userMap, Long.valueOf(record.getCreator()), user -> record.setCreatorName(user.getNickname()));
+            String creator = record.getCreator();
+            if (creator != null && !creator.isEmpty()) {
+                MapUtils.findAndThen(userMap, Long.valueOf(creator), user -> record.setCreatorName(user.getNickname()));
+            }
         });
         return success(voPageResult);
     }

--
Gitblit v1.9.3