| | |
| | | import com.ruoyi.chargingPile.api.domain.SiteMenu; |
| | | import com.ruoyi.chargingPile.api.dto.GetSiteListDTO; |
| | | import com.ruoyi.chargingPile.api.feignClient.*; |
| | | import com.ruoyi.chargingPile.api.model.Partner; |
| | | import com.ruoyi.chargingPile.api.model.Site; |
| | | import com.ruoyi.chargingPile.api.model.TChargingGun; |
| | | import com.ruoyi.chargingPile.api.model.TChargingPile; |
| | | import com.ruoyi.chargingPile.api.model.TParkingRecord; |
| | | import com.ruoyi.chargingPile.api.model.TPartnerAppUser; |
| | | import com.ruoyi.chargingPile.api.vo.GetChargingGunByChargingPileIdsVo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.dto.ChargingOrderGroup; |
| | |
| | | import com.ruoyi.order.export.PayOrderExport; |
| | | import com.ruoyi.order.export.EnterpriseChargingDetailExport; |
| | | import com.ruoyi.order.service.*; |
| | | import com.ruoyi.order.support.FranchiseeUserStatistics; |
| | | import com.ruoyi.order.util.PreviousSixMonths; |
| | | import com.ruoyi.order.util.mongodb.service.UploadRealTimeMonitoringDataService; |
| | | import com.ruoyi.order.vo.EndOfChargePageInfo; |
| | |
| | | |
| | | @PostMapping("/app/franchisee/user") |
| | | public R<Map<String, Object>> franchiseeUser(@RequestBody(required = false) Map<String, Object> params) { |
| | | List<TChargingOrder> orders = franchiseeOrders(params); |
| | | Set<Long> users = orders.stream().map(TChargingOrder::getAppUserId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | List<Integer> siteIds = franchiseeSiteIds(params); |
| | | Partner partner = franchiseePartner(); |
| | | List<Integer> siteIds = partner == null ? Collections.emptyList() : franchiseeSiteIds(params, partner.getId()); |
| | | LocalDateTime[] range = franchiseeRange(params); |
| | | Set<Long> newUsers = new HashSet<>(); |
| | | if (!siteIds.isEmpty() && range[0] != null && range[1] != null) { |
| | | List<TChargingOrder> allOrders = franchiseeOrders(siteIds, null, range[1]); |
| | | Map<Long, LocalDateTime> firstOrder = new HashMap<>(); |
| | | for (TChargingOrder order : allOrders) { |
| | | if (order.getAppUserId() == null || order.getEndTime() == null) continue; |
| | | firstOrder.merge(order.getAppUserId(), order.getEndTime(), (oldTime, newTime) -> oldTime.isBefore(newTime) ? oldTime : newTime); |
| | | List<TChargingOrder> orders = franchiseeOrders(siteIds, range[0], range[1]).stream() |
| | | .filter(order -> Objects.equals(order.getStatus(), 5)) |
| | | .collect(Collectors.toList()); |
| | | Set<Long> users = orders.stream().map(TChargingOrder::getAppUserId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | List<TPartnerAppUser> relations = Collections.emptyList(); |
| | | if (partner != null && partner.getId() != null) { |
| | | R<List<TPartnerAppUser>> relationResult = partnerClient.getBoundAppUserRelations(partner.getId()); |
| | | if (relationResult != null && relationResult.getData() != null) { |
| | | relations = relationResult.getData(); |
| | | } |
| | | firstOrder.forEach((userId, firstTime) -> { if (!firstTime.isBefore(range[0])) newUsers.add(userId); }); |
| | | } |
| | | FranchiseeUserStatistics.Result userStatistics = FranchiseeUserStatistics.calculate( |
| | | orders, relations, range[0], range[1]); |
| | | |
| | | List<TAppUser> appUsers = Collections.emptyList(); |
| | | if (!users.isEmpty()) { |
| | |
| | | |
| | | Map<String, Object> evaluation = franchiseeEvaluation(siteIds); |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | Map<String, Object> summary = new LinkedHashMap<>(); summary.put("chargeUserCount", users.size()); summary.put("newUserCount", newUsers.size()); |
| | | result.put("summary", summary); |
| | | result.put("userStats", franchiseeUserTrend(orders, newUsers, range)); |
| | | result.put("summary", userStatistics.getSummary()); |
| | | result.put("userStats", userStatistics.getTrend()); |
| | | result.put("userTags", franchiseeUserTags(orders)); |
| | | Map<Integer, String> vipNames = new HashMap<>(); |
| | | R<List<TVip>> vipResult = vipClient.getAllVip(); |
| | |
| | | } |
| | | |
| | | private List<Integer> franchiseeSiteIds(Map<String, Object> params) { |
| | | if (tokenService.getLoginUserApplet() == null || tokenService.getLoginUserApplet().getUserId() == null) return Collections.emptyList(); |
| | | Long appUserId = tokenService.getLoginUserApplet().getUserId(); |
| | | R<com.ruoyi.chargingPile.api.model.Partner> partnerResult = partnerClient.getPartnerByAppUserId(appUserId); |
| | | com.ruoyi.chargingPile.api.model.Partner partner = partnerResult == null ? null : partnerResult.getData(); |
| | | Partner partner = franchiseePartner(); |
| | | if (partner == null || partner.getId() == null) return Collections.emptyList(); |
| | | return franchiseeSiteIds(params, partner.getId()); |
| | | } |
| | | |
| | | private Partner franchiseePartner() { |
| | | if (tokenService.getLoginUserApplet() == null || tokenService.getLoginUserApplet().getUserId() == null) return null; |
| | | Long appUserId = tokenService.getLoginUserApplet().getUserId(); |
| | | R<Partner> partnerResult = partnerClient.getPartnerByAppUserId(appUserId); |
| | | return partnerResult == null ? null : partnerResult.getData(); |
| | | } |
| | | |
| | | private List<Integer> franchiseeSiteIds(Map<String, Object> params, Integer partnerId) { |
| | | R<List<Site>> siteResult = siteClient.getSiteAll(); |
| | | List<Site> sites = siteResult == null ? null : siteResult.getData(); |
| | | List<Integer> siteIds = sites == null ? new ArrayList<>() : sites.stream().filter(s -> Objects.equals(s.getPartnerId(), partner.getId())).map(Site::getId).collect(Collectors.toList()); |
| | | List<Integer> siteIds = sites == null ? new ArrayList<>() : sites.stream().filter(s -> Objects.equals(s.getPartnerId(), partnerId)).map(Site::getId).collect(Collectors.toList()); |
| | | Object requestedSite = params == null ? null : params.get("siteId"); |
| | | if (requestedSite != null && !String.valueOf(requestedSite).isEmpty()) { |
| | | Integer siteId = Integer.valueOf(String.valueOf(requestedSite)); siteIds = siteIds.contains(siteId) ? Collections.singletonList(siteId) : Collections.singletonList(-1); |
| | | } |
| | | return siteIds; |
| | | } |
| | | |
| | | private Map<String, Object> franchiseeUserTrend(List<TChargingOrder> orders, Set<Long> newUsers, LocalDateTime[] range) { |
| | | LocalDate start = range[0] == null ? LocalDate.now() : range[0].toLocalDate(); |
| | | LocalDate end = range[1] == null ? start.plusDays(1) : range[1].toLocalDate(); |
| | | List<String> categories = new ArrayList<>(); |
| | | List<BigDecimal> chargeUsers = new ArrayList<>(), newUserCounts = new ArrayList<>(); |
| | | for (LocalDate day = start; day.isBefore(end); day = day.plusDays(1)) { |
| | | LocalDateTime dayStart = day.atStartOfDay(), dayEnd = day.plusDays(1).atStartOfDay(); |
| | | Set<Long> dayUsers = orders.stream().filter(order -> order.getAppUserId() != null && order.getEndTime() != null |
| | | && !order.getEndTime().isBefore(dayStart) && order.getEndTime().isBefore(dayEnd)) |
| | | .map(TChargingOrder::getAppUserId).collect(Collectors.toSet()); |
| | | long newCount = dayUsers.stream().filter(newUsers::contains).count(); |
| | | categories.add(day.toString().substring(5)); |
| | | chargeUsers.add(BigDecimal.valueOf(dayUsers.size())); |
| | | newUserCounts.add(BigDecimal.valueOf(newCount)); |
| | | } |
| | | Map<String, Object> chart = new LinkedHashMap<>(); chart.put("categories", categories); |
| | | Map<String, Object> chargeSeries = new LinkedHashMap<>(); chargeSeries.put("name", "充电用户"); chargeSeries.put("data", chargeUsers); |
| | | Map<String, Object> newSeries = new LinkedHashMap<>(); newSeries.put("name", "新增用户"); newSeries.put("data", newUserCounts); |
| | | chart.put("series", Arrays.asList(chargeSeries, newSeries)); return chart; |
| | | } |
| | | |
| | | private List<Map<String, Object>> franchiseeUserTags(List<TChargingOrder> orders) { |
| | |
| | | payOrderInfoDto.setThirdPayAmount(byId.getThirdPayAmount()); |
| | | payOrderInfoDto.setBalanceRefundAmount(byId.getBalanceRefundAmount()); |
| | | payOrderInfoDto.setThirdRefundAmount(byId.getThirdRefundAmount()); |
| | | payOrderInfoDto.setRefundableAmount(chargingOrderService.getManualRefundableAmount(byId.getId())); |
| | | return R.ok(payOrderInfoDto); |
| | | case 2: |
| | | TShoppingOrder byId1 = shoppingOrderService.getById(orderId); |