From bf74fbaa6732c5a192555a856de585ac9f70f3aa Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 30 九月 2025 11:42:22 +0800
Subject: [PATCH] bug修改

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java
index 6938000..80277fc 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java
@@ -1,12 +1,14 @@
 package com.ruoyi.web.controller.api;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.dto.TCrmBranchDTO;
 import com.ruoyi.system.model.*;
 import com.ruoyi.system.query.TCrmBranchQuery;
@@ -16,6 +18,7 @@
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -42,14 +45,18 @@
     private final ISysUserService sysUserService;
     private final TCrmChangePointsService crmChangePointsService;
     private final TCrmPositionService crmPositionService;
+    private final TCrmSalespersonService crmSalespersonService;
+    private final TokenService tokenService;
     @Autowired
-    public TCrmBranchController(TCrmBranchService crmBranchService, TCrmBranchAreaService crmBranchAreaService, TCrmBranchSalaryService crmBranchSalaryService, ISysUserService sysUserService, TCrmChangePointsService crmChangePointsService, TCrmPositionService crmPositionService) {
+    public TCrmBranchController(TCrmBranchService crmBranchService, TCrmBranchAreaService crmBranchAreaService, TCrmBranchSalaryService crmBranchSalaryService, ISysUserService sysUserService, TCrmChangePointsService crmChangePointsService, TCrmPositionService crmPositionService, TCrmSalespersonService crmSalespersonService, TokenService tokenService) {
         this.crmBranchService = crmBranchService;
         this.crmBranchAreaService = crmBranchAreaService;
         this.crmBranchSalaryService = crmBranchSalaryService;
         this.sysUserService = sysUserService;
         this.crmChangePointsService = crmChangePointsService;
         this.crmPositionService = crmPositionService;
+        this.crmSalespersonService = crmSalespersonService;
+        this.tokenService = tokenService;
     }
 
     /**
@@ -67,9 +74,23 @@
     @ApiOperation(value = "获取crm分公司管理列表")
     @PostMapping(value = "/list")
     public R<List<TCrmBranch>> list() {
-        return R.ok(crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
-                .eq(TCrmBranch::getStatus,1)
-                .orderByDesc(TCrmBranch::getCreateTime)));
+        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
+        Long userId = tokenService.getLoginUser().getUserId();
+        LambdaQueryWrapper<TCrmBranch> wrapper = new LambdaQueryWrapper<>();
+        if (roleType == 2) {
+            wrapper.eq(TCrmBranch::getUserId, userId);
+        }
+        if(roleType == 3){
+            // 查询业务员信息
+            TCrmSalesperson crmSalesperson = crmSalespersonService.getOne(Wrappers.lambdaQuery(TCrmSalesperson.class)
+                    .eq(TCrmSalesperson::getUserId, userId)
+                    .last("LIMIT 1"));
+            if(Objects.nonNull(crmSalesperson)){
+                wrapper.eq(TCrmBranch::getId, crmSalesperson.getBranchId());
+            }
+        }
+        wrapper.eq(TCrmBranch::getStatus,1).orderByDesc(TCrmBranch::getCreateTime);
+        return R.ok(crmBranchService.list(wrapper));
     }
 
     /**
@@ -172,6 +193,13 @@
                 // 冻结
                 sysUser.setStatus("1");
                 sysUserService.updateUser(sysUser);
+                // 查询业务员
+                List<TCrmSalesperson> crmSalespersons = crmSalespersonService.list(Wrappers.lambdaQuery(TCrmSalesperson.class)
+                        .eq(TCrmSalesperson::getBranchId, id));
+                if(!CollectionUtils.isEmpty(crmSalespersons)){
+                    List<Long> userIds = crmSalespersons.stream().map(TCrmSalesperson::getUserId).collect(Collectors.toList());
+                    sysUserService.updateUserStatusByUserIds(userIds, "1");
+                }
                 break;
         }
         return R.ok();

--
Gitblit v1.7.1