|  |  |  | 
|---|
|  |  |  | map.put("orderMoney", 0); // 订单金额 | 
|---|
|  |  |  | map.put("commissionMoney", 0); // 分佣金额 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | BigDecimal orderMoney = orderQuantity.stream().map(TErpProcurement::getPayMoney).filter(Objects::nonNull).reduce(BigDecimal::add).get(); | 
|---|
|  |  |  | BigDecimal orderMoney = orderQuantity.stream().map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO,BigDecimal::add); | 
|---|
|  |  |  | map.put("orderMoney", orderMoney); | 
|---|
|  |  |  | BigDecimal commissionMoney = orderQuantity.stream().map(TErpProcurement::getSupplierMoney).filter(Objects::nonNull).reduce(BigDecimal::add).get(); | 
|---|
|  |  |  | BigDecimal commissionMoney = orderQuantity.stream().map(TErpProcurement::getSupplierMoney).reduce(BigDecimal.ZERO,BigDecimal::add); | 
|---|
|  |  |  | map.put("commissionMoney", commissionMoney); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(map); | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 供应商采购统计 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "供应商最近额30天采购统计", notes = "supplierThirtyProcurementStatistics:订单,supplierThirtyMoneyProcurementStatistics:金额") | 
|---|
|  |  |  | @ApiOperation(value = "诊所/供应商最近30天采购统计", notes = "supplierThirtyProcurementStatistics:订单,supplierThirtyMoneyProcurementStatistics:金额") | 
|---|
|  |  |  | @PostMapping(value = "/supplierThirtyProcurementStatistics") | 
|---|
|  |  |  | public R<Map<String, Object>> supplierThirtyProcurementStatistics() { | 
|---|
|  |  |  | Long userId = tokenService.getLoginUser().getUserId(); | 
|---|
|  |  |  | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("MM.dd"); | 
|---|
|  |  |  | for (int i = 0; i < 30; i++) { | 
|---|
|  |  |  | LocalDateTime timeNow = localDateTime.plusDays(i); | 
|---|
|  |  |  | List<SupplierThirtyProcurementStatisticsVO> vos = supplierThirtyProcurementStatistics.stream().filter(vo -> timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); | 
|---|
|  |  |  | List<SupplierThirtyProcurementStatisticsVO> vos = supplierThirtyProcurementStatistics.stream().filter(vo -> Objects.nonNull(vo.getPayTime()) && timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(vos)) { | 
|---|
|  |  |  | SupplierThirtyProcurementStatisticsVO vo = new SupplierThirtyProcurementStatisticsVO(); | 
|---|
|  |  |  | String time = format.format(DateUtils.localDateTimeToDate(timeNow)); | 
|---|
|  |  |  | 
|---|
|  |  |  | vo.setOrderCount(0); | 
|---|
|  |  |  | supplierThirtyProcurementStatistics.add(vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<SupplierThirtyMoneyProcurementStatisticsVO> moneyVOS = supplierThirtyMoneyProcurementStatistics.stream().filter(vo -> timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); | 
|---|
|  |  |  | List<SupplierThirtyMoneyProcurementStatisticsVO> moneyVOS = supplierThirtyMoneyProcurementStatistics.stream().filter(vo -> Objects.nonNull(vo.getPayTime()) && timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(moneyVOS)) { | 
|---|
|  |  |  | SupplierThirtyMoneyProcurementStatisticsVO vo = new SupplierThirtyMoneyProcurementStatisticsVO(); | 
|---|
|  |  |  | String time = format.format(DateUtils.localDateTimeToDate(timeNow)); | 
|---|
|  |  |  | 
|---|
|  |  |  | clinicSalesStatisticsVO.setSalesMoney(totalMoney); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 查询销售前十占比 | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsTypeVOS = sysOrderService.supplierSalesStatisticsGoodsType(crmClinic.getId(), startTime, endTime); | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsTypeVOS = sysOrderService.clinicSalesStatisticsGoodsType(crmClinic.getId(), startTime, endTime); | 
|---|
|  |  |  | // 判断集合是否大于9 | 
|---|
|  |  |  | if (clinicSalesStatisticsGoodsTypeVOS.size() > 9) { | 
|---|
|  |  |  | // 其余的添加到其他 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 查询30天销售统计 | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCountVOS; | 
|---|
|  |  |  | if (query.getTimeType() == 1 || query.getTimeType() == 2 || query.getTimeType() == 3) { | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.supplierSalesStatisticsGoodsCount(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.clinicSalesStatisticsGoodsCount(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.supplierSalesStatisticsGoodsCountMonth(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.clinicSalesStatisticsGoodsCountMonth(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("MM.dd"); | 
|---|
|  |  |  | SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy.MM"); | 
|---|
|  |  |  | 
|---|
|  |  |  | TCrmBranch branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class) | 
|---|
|  |  |  | .eq(TCrmBranch::getUserId, user.getUserId())); | 
|---|
|  |  |  | if (branch != null) { | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).eq(TCrmClinic::getBranchId, branch.getId())); | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).eq(TCrmClinic::getBranchId, branch.getId()).in(TCrmClinic::getStatus,Arrays.asList(3,4,5))); | 
|---|
|  |  |  | if (!list.isEmpty()) { | 
|---|
|  |  |  | List<String> crmClinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | eq.eq(TCrmClinic::getBranchId, branch.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | eq.in(TCrmClinic::getStatus,Arrays.asList(3,4,5)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(eq); | 
|---|
|  |  |  | branchAdminStatisticsTwoVo.setClinicNum(list.size()); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (branch != null) { | 
|---|
|  |  |  | LambdaQueryWrapper<TCrmClinic> eq = Wrappers.lambdaQuery(TCrmClinic.class); | 
|---|
|  |  |  | eq.eq(TCrmClinic::getBranchId, branch.getId()); | 
|---|
|  |  |  | eq.eq(TCrmClinic::getStatus, Arrays.asList(3,4,5)); | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(eq); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> clinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer roleType = user.getRoleType(); | 
|---|
|  |  |  | if (roleType == 1) { | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(); | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(new LambdaQueryWrapper<TCrmClinic>().in(TCrmClinic::getStatus,Arrays.asList(3,4,5))); | 
|---|
|  |  |  | if (!list.isEmpty()) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long branchCount = crmBranchService.count(); | 
|---|
|  |  |  | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | branchAdminStatisticsOneVo.setBranchMoney(list1.stream().filter(e -> e.getCommissionType() == 1).map(TErpProcurementCommission::getMoney).reduce(BigDecimal::add).get()); | 
|---|
|  |  |  | branchAdminStatisticsOneVo.setStaffMoney(list1.stream().filter(e -> e.getCommissionType() == 2).map(TErpProcurementCommission::getMoney).reduce(BigDecimal::add).get()); | 
|---|
|  |  |  | if(!collect3.isEmpty()){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | branchAdminStatisticsOneVo.setBranchMoney(collect3.stream().filter(e -> e.getCommissionType() == 1).map(TErpProcurementCommission::getMoney).reduce(BigDecimal::add).get()); | 
|---|
|  |  |  | branchAdminStatisticsOneVo.setStaffMoney(collect3.stream().filter(e -> e.getCommissionType() == 2).map(TErpProcurementCommission::getMoney).reduce(BigDecimal::add).get()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if (query.getSalespersonId() != null && !query.getSalespersonId().isEmpty()) { | 
|---|
|  |  |  | w.eq(TCrmClinic::getSalespersonId, query.getSalespersonId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | w.in(TCrmClinic::getStatus,Arrays.asList(3,4,5)); | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(w); | 
|---|
|  |  |  | branchAdminStatisticsOneVo.setClinicNum(list.size()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if(query.getBranchId()!=null && !query.getBranchId().isEmpty()){ | 
|---|
|  |  |  | eq.eq(TCrmClinic::getBranchId, query.getBranchId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | eq.in(TCrmClinic::getStatus,Arrays.asList(3,4,5)); | 
|---|
|  |  |  | List<TCrmClinic> list = crmClinicService.list(eq); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> clinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (query.getName() != null && !query.getName().isEmpty()) { | 
|---|
|  |  |  | collect = collect.stream().filter(e -> e.getGoodsName().equals(query.getName())).collect(Collectors.toList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (query.getType() == 1) { | 
|---|
|  |  |  | if (query.getType() == 1 && !collect.isEmpty()) { | 
|---|
|  |  |  | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); | 
|---|
|  |  |  | procurementStatisticsVO.setTime(LocalDate.now().toString()); | 
|---|
|  |  |  | procurementStatisticsVO.setCount(collect.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); | 
|---|
|  |  |  | procurementStatisticsVOS.add(procurementStatisticsVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (query.getType() == 2) { | 
|---|
|  |  |  | if (query.getType() == 2 && !collect.isEmpty()) { | 
|---|
|  |  |  | // 昨日的数据 | 
|---|
|  |  |  | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); | 
|---|
|  |  |  | procurementStatisticsVO.setTime(LocalDate.now().minusDays(1).toString()); | 
|---|
|  |  |  | 
|---|
|  |  |  | procurementStatisticsVOS.add(procurementStatisticsVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (query.getType() == 3) { | 
|---|
|  |  |  | if (query.getType() == 3 && !collect.isEmpty()) { | 
|---|
|  |  |  | // 近7天的数据 | 
|---|
|  |  |  | for (int i = 6; i >= 0; i--) { | 
|---|
|  |  |  | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); | 
|---|
|  |  |  | 
|---|
|  |  |  | procurementStatisticsVOS.add(procurementStatisticsVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (query.getType() == 4) { | 
|---|
|  |  |  | if (query.getType() == 4 && !collect.isEmpty()) { | 
|---|
|  |  |  | // 按月算 | 
|---|
|  |  |  | for (int i = 5; i >= 0; i--) { | 
|---|
|  |  |  | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (query.getType() == 5) { | 
|---|
|  |  |  | if (query.getType() == 5 && !collect.isEmpty()) { | 
|---|
|  |  |  | // 按月算 | 
|---|
|  |  |  | for (int i = 11; i >= 0; i--) { | 
|---|
|  |  |  | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); | 
|---|