From 806125e39de433c7c622acdabe8138876fae6973 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 21 十月 2025 10:23:06 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmBranchController.java |   68 ++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 3 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 36d9f54..89fa023 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,6 +1,8 @@
 package com.ruoyi.web.controller.api;
 
 
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.annotation.Log;
@@ -8,19 +10,31 @@
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.WebUtils;
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.dto.TCrmBranchDTO;
+import com.ruoyi.system.export.TCrmBranchExport;
+import com.ruoyi.system.export.TSysAppUserClinicExport;
+import com.ruoyi.system.export.TSysAppUserExport;
 import com.ruoyi.system.model.*;
 import com.ruoyi.system.query.TCrmBranchQuery;
+import com.ruoyi.system.query.TSysAppUserQuery;
 import com.ruoyi.system.service.*;
 import com.ruoyi.system.vo.TCrmBranchVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.apache.poi.ss.usermodel.Workbook;
 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.*;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -44,15 +58,17 @@
     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, TokenService tokenService) {
+    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;
     }
 
@@ -74,8 +90,17 @@
         Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
         Long userId = tokenService.getLoginUser().getUserId();
         LambdaQueryWrapper<TCrmBranch> wrapper = new LambdaQueryWrapper<>();
-        if (roleType == 1) {
+        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));
@@ -181,6 +206,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();
@@ -216,6 +248,36 @@
         crmChangePointsService.save(changePoints);
         return R.ok();
     }
-    
+
+    @Log(title = "crm分公司管理信息-分公司管理信息导出", businessType = BusinessType.EXPORT)
+    @ApiOperation(value = "分公司管理信息导出")
+    @PostMapping("/exportList")
+    public void exportList(@RequestBody TCrmBranchQuery query){
+        List<TCrmBranchExport> crmBranchExports = crmBranchService.exportList(query);
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmBranchExport.class, crmBranchExports);
+        HttpServletResponse response = WebUtils.response();
+        assert response != null;
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        ServletOutputStream outputStream = null;
+        try {
+            String fileName = URLEncoder.encode("分公司管理信息.xls", "utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
 }
 

--
Gitblit v1.7.1