xuhy
2025-12-25 73f5eefe0dee90e35b6a2bc9b7ec591e742a9324
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java
@@ -776,6 +776,8 @@
                        List<String> branchIdsFour = crmBranchService.list(new LambdaQueryWrapper<TCrmBranch>().in(TCrmBranch::getCorrelationPersonId, userIds).eq(TCrmBranch::getPersonType, 3).eq(TCrmBranch::getAuditStatus,2)).stream().map(TCrmBranch::getId).collect(Collectors.toList());
                        if(!branchIdsFour.isEmpty()){
                            branchIdsAll.addAll(branchIdsFour);
                            list.addAll(crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).in(TCrmClinic::getBranchId, branchIdsFour).in(TCrmClinic::getStatus, Arrays.asList(3, 4, 5))));
                        }
                    }
@@ -823,7 +825,8 @@
                    // 获取最近一年的时间
                    LocalDateTime time = LocalDateTime.now().minusYears(1);
                    List<TErpProcurement> procurementList = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().between(TErpProcurement::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now())).ne(TErpProcurement::getStatus, 6).isNotNull(TErpProcurement::getPayTime).in(TErpProcurement::getClinicId, crmClinicIds));
                    List<TErpProcurementCommission> list1 = erpProcurementCommissionService.list(new LambdaQueryWrapper<TErpProcurementCommission>().eq(TErpProcurementCommission::getBranchSalespersonId, branch.getId()).eq(TErpProcurementCommission::getCommissionType, 1).between(TErpProcurementCommission::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now())));
                    List<TErpProcurementCommission> list1 = erpProcurementCommissionService.list(new LambdaQueryWrapper<TErpProcurementCommission>().in(TErpProcurementCommission::getBranchSalespersonId,branchIdsAll).eq(TErpProcurementCommission::getCommissionType, 1).between(TErpProcurementCommission::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now())));
                    // list1 获取本月的
                    List<TErpProcurementCommission> list2 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(time.toLocalDate())).collect(Collectors.toList());
@@ -934,13 +937,41 @@
        BranchAdminStatisticsTwoVo branchAdminStatisticsTwoVo = new BranchAdminStatisticsTwoVo();
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        Set<String> branchIdsAll = new HashSet<>();
        if (roleType == 2) {
            TCrmBranch branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
            TCrmBranch branch =null;
            if(query.getBranchId()==null || query.getBranchId().isEmpty()){
                branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                    .eq(TCrmBranch::getUserId, user.getUserId()).eq(TCrmBranch::getAuditStatus,2)
                    .last("LIMIT 1"));
            }else {
                branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getId, query.getBranchId()).eq(TCrmBranch::getAuditStatus,2)
                        .last("LIMIT 1"));
            }
            if (branch != null) {
                // 先查自己本身的
                List<TCrmClinic> list = crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).eq(TCrmClinic::getBranchId, branch.getId()).in(TCrmClinic::getStatus, Arrays.asList(3, 4, 5)));
                if (branch.getPersonType() != null && branch.getPersonType() == 1) {
                    List<TCrmBranch> crmBranches = crmBranchService.list(new LambdaQueryWrapper<TCrmBranch>().eq(TCrmBranch::getCorrelationPersonId, branch.getUserId()).eq(TCrmBranch::getPersonType, 2).eq(TCrmBranch::getAuditStatus, 2));
                    List<String> branchIdsThree = crmBranchService.list(new LambdaQueryWrapper<TCrmBranch>().eq(TCrmBranch::getCorrelationPersonId, branch.getUserId()).eq(TCrmBranch::getPersonType, 3).eq(TCrmBranch::getAuditStatus,2)).stream().map(TCrmBranch::getId).collect(Collectors.toList());
                    if(!crmBranches.isEmpty()){
                        branchIdsAll.addAll(crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList()));
                        List<Long> userIds = crmBranches.stream().map(TCrmBranch::getUserId).collect(Collectors.toList());
                        List<String> branchIdsFour = crmBranchService.list(new LambdaQueryWrapper<TCrmBranch>().in(TCrmBranch::getCorrelationPersonId, userIds).eq(TCrmBranch::getPersonType, 3).eq(TCrmBranch::getAuditStatus,2)).stream().map(TCrmBranch::getId).collect(Collectors.toList());
                        if(!branchIdsFour.isEmpty()){
                            branchIdsAll.addAll(branchIdsFour);
                            list.addAll(crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).in(TCrmClinic::getBranchId, branchIdsFour).in(TCrmClinic::getStatus, Arrays.asList(3, 4, 5))));
                        }
                    }
                    if(!branchIdsThree.isEmpty()){
                        branchIdsAll.addAll(branchIdsThree);
                    }
                }
                // 如果是区
                if (branch.getPersonType() != null && branch.getPersonType() == 2) {
                    // 区查下面所有城市的公司
@@ -1049,13 +1080,40 @@
        SysUser user = tokenService.getLoginUser().getUser();
        SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM");
        Integer roleType = user.getRoleType();
        Set<String> branchIdsAll = new HashSet<>();
        if (roleType == 2) {
            TCrmBranch branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
            TCrmBranch branch =null;
            if(query.getBranchId()==null || query.getBranchId().isEmpty()){
                branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                    .eq(TCrmBranch::getUserId, user.getUserId()).eq(TCrmBranch::getAuditStatus,2)
                    .last("LIMIT 1"));
            }else {
                branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getId, query.getBranchId()).eq(TCrmBranch::getAuditStatus,2)
                        .last("LIMIT 1"));
            }
            if (branch != null) {
                // 先查自己本身的
                List<TCrmClinic> list = crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).eq(TCrmClinic::getBranchId, branch.getId()).in(TCrmClinic::getStatus, Arrays.asList(3, 4, 5)));
                if (branch.getPersonType() != null && branch.getPersonType() == 1) {
                    List<TCrmBranch> crmBranches = crmBranchService.list(new LambdaQueryWrapper<TCrmBranch>().eq(TCrmBranch::getCorrelationPersonId, branch.getUserId()).eq(TCrmBranch::getPersonType, 2).eq(TCrmBranch::getAuditStatus, 2));
                    List<String> branchIdsThree = crmBranchService.list(new LambdaQueryWrapper<TCrmBranch>().eq(TCrmBranch::getCorrelationPersonId, branch.getUserId()).eq(TCrmBranch::getPersonType, 3).eq(TCrmBranch::getAuditStatus,2)).stream().map(TCrmBranch::getId).collect(Collectors.toList());
                    if(!crmBranches.isEmpty()){
                        branchIdsAll.addAll(crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList()));
                        List<Long> userIds = crmBranches.stream().map(TCrmBranch::getUserId).collect(Collectors.toList());
                        List<String> branchIdsFour = crmBranchService.list(new LambdaQueryWrapper<TCrmBranch>().in(TCrmBranch::getCorrelationPersonId, userIds).eq(TCrmBranch::getPersonType, 3).eq(TCrmBranch::getAuditStatus,2)).stream().map(TCrmBranch::getId).collect(Collectors.toList());
                        if(!branchIdsFour.isEmpty()){
                            branchIdsAll.addAll(branchIdsFour);
                            list.addAll(crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).in(TCrmClinic::getBranchId, branchIdsFour).in(TCrmClinic::getStatus, Arrays.asList(3, 4, 5))));
                        }
                    }
                    if(!branchIdsThree.isEmpty()){
                        branchIdsAll.addAll(branchIdsThree);
                    }
                }
                // 如果是区
                if (branch.getPersonType() != null && branch.getPersonType() == 2) {
                    // 区查下面所有城市的公司