xuhy
2025-12-05 447985592c29f9e5c02a783088b1abf2112c032a
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmClinicController.java
@@ -15,6 +15,7 @@
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TCrmClinicAuditDTO;
import com.ruoyi.system.dto.TCrmClinicDTO;
import com.ruoyi.system.dto.UnbindDTO;
import com.ruoyi.system.export.TCrmChangePointsBranchExport;
import com.ruoyi.system.export.TCrmClinicAuditExport;
import com.ruoyi.system.export.TCrmClinicListExport;
@@ -39,10 +40,7 @@
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -97,7 +95,38 @@
            TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                    .eq(TCrmBranch::getUserId,userId)
                    .last("LIMIT 1"));
            query.setBranchId(crmBranch.getId());
            List<String> branchIds = new ArrayList<>();
            if(crmBranch != null && crmBranch.getPersonType() == 1){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 2)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                    List<Long> userIds = crmBranches.stream().map(TCrmBranch::getUserId).collect(Collectors.toList());
                    List<TCrmBranch> crmBranches1 = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                            .eq(TCrmBranch::getPersonType, 3)
                            .in(TCrmBranch::getCorrelationPersonId, userIds));
                    if(!CollectionUtils.isEmpty(crmBranches1)){
                        List<String> childrenIds = crmBranches1.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                        branchIds.addAll(childrenIds);
                    }
                }
            }
            if(crmBranch != null && crmBranch.getPersonType() == 2){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 3)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                }
                branchIds.add(crmBranch.getId());
            }
            if(crmBranch != null && crmBranch.getPersonType() == 3){
                branchIds.add(crmBranch.getId());
            }
//            query.setBranchId(crmBranch.getId());
            branchIds = branchIds.stream().distinct().collect(Collectors.toList());
            query.setBranchIds(branchIds);
        }
        if(roleType == 3){
            query.setUserId(userId);
@@ -277,6 +306,62 @@
    @ApiOperation(value = "诊所管理导出")
    @PostMapping("/exportList")
    public void exportList(@RequestBody TCrmClinicQuery query){
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        Long userId = tokenService.getLoginUser().getUserId();
        if(roleType == 2){
            query.setUserId(userId);
            query.setRoleType(roleType);
            // 查询账号绑定的分公司
            TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                    .eq(TCrmBranch::getUserId,userId)
                    .last("LIMIT 1"));
            List<String> branchIds = new ArrayList<>();
            if(crmBranch != null && crmBranch.getPersonType() == 1){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 2)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                    List<Long> userIds = crmBranches.stream().map(TCrmBranch::getUserId).collect(Collectors.toList());
                    List<TCrmBranch> crmBranches1 = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                            .eq(TCrmBranch::getPersonType, 3)
                            .in(TCrmBranch::getCorrelationPersonId, userIds));
                    if(!CollectionUtils.isEmpty(crmBranches1)){
                        List<String> childrenIds = crmBranches1.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                        branchIds.addAll(childrenIds);
                    }
                }
            }
            if(crmBranch != null && crmBranch.getPersonType() == 2){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 3)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                }
                branchIds.add(crmBranch.getId());
            }
            if(crmBranch != null && crmBranch.getPersonType() == 3){
                branchIds.add(crmBranch.getId());
            }
//            query.setBranchId(crmBranch.getId());
            branchIds = branchIds.stream().distinct().collect(Collectors.toList());
            query.setBranchIds(branchIds);
        }
        if(roleType == 3){
            query.setUserId(userId);
            query.setRoleType(roleType);
            // 查询账号绑定的业务员
            TCrmSalesperson crmSalesperson = crmSalespersonService.getOne(Wrappers.lambdaQuery(TCrmSalesperson.class)
                    .eq(TCrmSalesperson::getUserId,userId)
                    .last("LIMIT 1"));
            query.setSalespersonId(crmSalesperson.getId());
        }
        if (roleType == 1){
            query.setRoleType(roleType);
        }
        List<TCrmClinicListExport> crmClinicListExports = crmClinicService.exportList(query);
        for (TCrmClinicListExport crmClinicListExport : crmClinicListExports) {
            if(Objects.nonNull(crmClinicListExport.getLowProcurementMoney())){