xuhy
2025-10-31 d0a8a2af8ce2a07be6ec1dff70f8246ec2e9c263
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java
@@ -99,6 +99,11 @@
        TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                .eq(TCrmSupplier::getUserId, userId)
                .last("LIMIT 1"));
        // ***
        if(Objects.isNull(crmSupplier)){
            SysUser sysUser = sysUserService.selectUserById(userId);
            crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
        }
        Map<String, Object> map = new HashMap<>();
@@ -141,6 +146,11 @@
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, userId)
                    .last("LIMIT 1"));
            // ***
            if(Objects.isNull(crmSupplier)){
                SysUser sysUser = sysUserService.selectUserById(userId);
                crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
            }
            supplierAndClinicId = crmSupplier.getId();
        } else {
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
@@ -264,6 +274,11 @@
        TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                .eq(TCrmSupplier::getUserId, userId)
                .last("LIMIT 1"));
        // ***
        if(Objects.isNull(crmSupplier)){
            SysUser sysUser = sysUserService.selectUserById(userId);
            crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
        }
        // 查询药品总类和总数
        Integer typeTotalCount = erpProcurementService.supplierSalesStatisticsTypeCount(crmSupplier.getId());
        Integer totalCount = erpProcurementService.supplierSalesStatisticsCount(crmSupplier.getId());
@@ -309,6 +324,11 @@
        TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                .eq(TCrmSupplier::getUserId, userId)
                .last("LIMIT 1"));
        // ***
        if(Objects.isNull(crmSupplier)){
            SysUser sysUser = sysUserService.selectUserById(userId);
            crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
        }
        SupplierSalesStatisticsVO supplierSalesStatisticsVO = new SupplierSalesStatisticsVO();
        // 销售金额
        BigDecimal totalMoney = erpProcurementService.supplierSalesStatisticsMoney(crmSupplier.getId(), startTime, endTime);
@@ -860,7 +880,7 @@
                List<ClinicSalesStatisticsGoodsTypeVO> thirtyMoneyProcurementStatisticsVOS = collect2.entrySet().stream().map(entry -> {
                    ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO();
                    clinicSalesStatisticsGoodsTypeVO.setGoodsCount(entry.getValue().stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum());
                    clinicSalesStatisticsGoodsTypeVO.setTypeName(entry.getValue().get(0).getGoodsName());
                    clinicSalesStatisticsGoodsTypeVO.setGoodsName(entry.getValue().get(0).getGoodsName());
                    return clinicSalesStatisticsGoodsTypeVO;
                }).sorted(Comparator.comparing(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).reversed()).limit(9).collect(Collectors.toList());
                // 总数
@@ -869,7 +889,7 @@
                if (sum - sum1 > 0) {
                    ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO();
                    clinicSalesStatisticsGoodsTypeVO.setGoodsCount(sum - sum1);
                    clinicSalesStatisticsGoodsTypeVO.setTypeName("其他");
                    clinicSalesStatisticsGoodsTypeVO.setGoodsName("其他");
                    thirtyMoneyProcurementStatisticsVOS.add(clinicSalesStatisticsGoodsTypeVO);
                }
                vo.setThirtyMoneyProcurementStatisticsVOS(thirtyMoneyProcurementStatisticsVOS);
@@ -1214,7 +1234,7 @@
            List<ClinicSalesStatisticsGoodsTypeVO> thirtyMoneyProcurementStatisticsVOS = collect2.entrySet().stream().map(entry -> {
                ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO();
                clinicSalesStatisticsGoodsTypeVO.setGoodsCount(entry.getValue().stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum());
                clinicSalesStatisticsGoodsTypeVO.setTypeName(entry.getValue().get(0).getGoodsName());
                clinicSalesStatisticsGoodsTypeVO.setGoodsName(entry.getValue().get(0).getGoodsName());
                return clinicSalesStatisticsGoodsTypeVO;
            }).sorted(Comparator.comparing(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).reversed()).limit(9).collect(Collectors.toList());
            // 总数
@@ -1223,7 +1243,7 @@
            if (sum - sum1 > 0) {
                ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO();
                clinicSalesStatisticsGoodsTypeVO.setGoodsCount(sum - sum1);
                clinicSalesStatisticsGoodsTypeVO.setTypeName("其他");
                clinicSalesStatisticsGoodsTypeVO.setGoodsName("其他");
                thirtyMoneyProcurementStatisticsVOS.add(clinicSalesStatisticsGoodsTypeVO);
            }
            vo.setThirtyMoneyProcurementStatisticsVOS(thirtyMoneyProcurementStatisticsVOS);
@@ -1303,8 +1323,9 @@
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        if (roleType == 3) {
            TCrmSalesperson one = crmSalespersonService.getOne(new LambdaQueryWrapper<TCrmSalesperson>().eq(TCrmSalesperson::getUserId, user.getUserId()));
            LambdaQueryWrapper<TCrmClinic> eq = Wrappers.lambdaQuery(TCrmClinic.class);
            eq.eq(TCrmClinic::getSalespersonId, user.getUserId());
            eq.eq(TCrmClinic::getSalespersonId, one.getId());
            eq.in(TCrmClinic::getStatus, Arrays.asList(3, 4, 5));
            List<TCrmClinic> list = crmClinicService.list(eq);
@@ -1384,8 +1405,9 @@
        SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM");
        Integer roleType = user.getRoleType();
        if (roleType == 3) {
            TCrmSalesperson one = crmSalespersonService.getOne(new LambdaQueryWrapper<TCrmSalesperson>().eq(TCrmSalesperson::getUserId, user.getUserId()));
            LambdaQueryWrapper<TCrmClinic> eq = Wrappers.lambdaQuery(TCrmClinic.class);
            eq.eq(TCrmClinic::getSalespersonId, user.getUserId());
            eq.eq(TCrmClinic::getSalespersonId,one.getId());
            eq.in(TCrmClinic::getStatus, Arrays.asList(3, 4, 5));
            List<TCrmClinic> list = crmClinicService.list(eq);
@@ -1431,7 +1453,7 @@
            List<ClinicSalesStatisticsGoodsTypeVO> thirtyMoneyProcurementStatisticsVOS = collect2.entrySet().stream().map(entry -> {
                ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO();
                clinicSalesStatisticsGoodsTypeVO.setGoodsCount(entry.getValue().stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum());
                clinicSalesStatisticsGoodsTypeVO.setTypeName(entry.getValue().get(0).getGoodsName());
                clinicSalesStatisticsGoodsTypeVO.setGoodsName(entry.getValue().get(0).getGoodsName());
                return clinicSalesStatisticsGoodsTypeVO;
            }).sorted(Comparator.comparing(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).reversed()).limit(9).collect(Collectors.toList());
            // 总数
@@ -1440,7 +1462,7 @@
            if (sum - sum1 > 0) {
                ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO();
                clinicSalesStatisticsGoodsTypeVO.setGoodsCount(sum - sum1);
                clinicSalesStatisticsGoodsTypeVO.setTypeName("其他");
                clinicSalesStatisticsGoodsTypeVO.setGoodsName("其他");
                thirtyMoneyProcurementStatisticsVOS.add(clinicSalesStatisticsGoodsTypeVO);
            }
            vo.setThirtyMoneyProcurementStatisticsVOS(thirtyMoneyProcurementStatisticsVOS);