| | |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "平台业务员-首页统计(第三部分)") |
| | | @PostMapping(value = "/saleStatisticsThree") |
| | | public R<BranchAdminStatisticsThreeVo> saleStatisticsThree(@RequestBody @Validated BranchAdminStatisticsThreeQuery query) { |
| | | BranchAdminStatisticsThreeVo vo = new BranchAdminStatisticsThreeVo(); |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM"); |
| | | Integer roleType = user.getRoleType(); |
| | | if (roleType == 3) { |
| | | LambdaQueryWrapper<TCrmClinic> eq = Wrappers.lambdaQuery(TCrmClinic.class); |
| | | eq.eq(TCrmClinic::getSalespersonId, user.getUserId()); |
| | | 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 (clinicIds.isEmpty()) { |
| | | return R.ok(vo); |
| | | } |
| | | // 查询这个诊所的所有订单并算出商品种类数 和 商品数 |
| | | List<TErpProcurementGoods> erpProcurementGoods = erpProcurementService.branchAdminStatisticsThree(clinicIds); |
| | | |
| | | // 根据商品id算出商品种类数 |
| | | vo.setGoodsTypeCount((int) erpProcurementGoods.stream().map(TErpProcurementGoods::getGoodsId).distinct().count()); |
| | | |
| | | // 算出商品数 |
| | | vo.setGoodsCount(erpProcurementGoods.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | List<TErpProcurementGoods> collect = null; |
| | | switch (query.getType()) { |
| | | case 1: |
| | | // 通过payTime是今日的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | // 通过payTime是昨日的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 通过payTime是近7天的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 通过payTime是近半年的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 通过payTime是近一年的数据 |
| | | collect = erpProcurementGoods; |
| | | break; |
| | | } |
| | | vo.setMoneyProcurement(collect.stream().map(TErpProcurementGoods::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | |
| | | //collect 通过goodsId 分组并 根据purchaseCount 倒叙 |
| | | Map<String, List<TErpProcurementGoods>> collect2 = collect.stream().collect(groupingBy(TErpProcurementGoods::getGoodsId)); |
| | | 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()); |
| | | return clinicSalesStatisticsGoodsTypeVO; |
| | | }).sorted(Comparator.comparing(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).reversed()).limit(9).collect(Collectors.toList()); |
| | | // 总数 |
| | | int sum = collect.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum(); |
| | | int sum1 = thirtyMoneyProcurementStatisticsVOS.stream().mapToInt(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).sum(); |
| | | if (sum - sum1 > 0) { |
| | | ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO(); |
| | | clinicSalesStatisticsGoodsTypeVO.setGoodsCount(sum - sum1); |
| | | clinicSalesStatisticsGoodsTypeVO.setTypeName("其他"); |
| | | thirtyMoneyProcurementStatisticsVOS.add(clinicSalesStatisticsGoodsTypeVO); |
| | | } |
| | | vo.setThirtyMoneyProcurementStatisticsVOS(thirtyMoneyProcurementStatisticsVOS); |
| | | |
| | | |
| | | ArrayList<ProcurementStatisticsVO> procurementStatisticsVOS = new ArrayList<>(); |
| | | // 是否做了搜索 |
| | | if (query.getName() != null && !query.getName().isEmpty()) { |
| | | collect = collect.stream().filter(e -> e.getGoodsName().equals(query.getName())).collect(Collectors.toList()); |
| | | } |
| | | 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 && !collect.isEmpty()) { |
| | | // 昨日的数据 |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().minusDays(1).toString()); |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> e.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | |
| | | if (query.getType() == 3 && !collect.isEmpty()) { |
| | | // 近7天的数据 |
| | | for (int i = 6; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().minusDays(i).toString()); |
| | | int finalI = i; |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> e.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(finalI))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | if (query.getType() == 4 && !collect.isEmpty()) { |
| | | // 按月算 |
| | | for (int i = 5; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | LocalDateTime localDate = LocalDateTime.now().minusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(localDate); |
| | | String time = formatMonth.format(date); |
| | | procurementStatisticsVO.setTime(time); |
| | | // 按月算 年和月都要匹配 |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> time.equals(formatMonth.format(DateUtils.localDateTimeToDate(e.getPayTime())))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | |
| | | if (query.getType() == 5 && !collect.isEmpty()) { |
| | | // 按月算 |
| | | for (int i = 11; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | LocalDateTime localDate = LocalDateTime.now().minusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(localDate); |
| | | String time = formatMonth.format(date); |
| | | procurementStatisticsVO.setTime(time); |
| | | // 按月算 年和月都要匹配 |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> time.equals(formatMonth.format(DateUtils.localDateTimeToDate(e.getPayTime())))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | vo.setThirtyProcurementStatisticsVOS(procurementStatisticsVOS); |
| | | } |
| | | |
| | | return R.ok(vo); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "通过分公司id查询业务员列表") |
| | | @GetMapping(value = "/getSalespersonListByBranchId") |
| | | public R<List<TCrmSalesperson>> getSalespersonListByBranchId(@RequestParam String branchId) { |