| | |
| | | result.put("goodTags", evaluation.get("goodTags")); |
| | | result.put("badTags", evaluation.get("badTags")); |
| | | result.put("traffic", franchiseeTraffic(orders)); |
| | | result.put("vehicleClass", franchiseeCarGroup(cars, TAppUserCar::getVehicleUse, "未知用途", 5)); |
| | | result.put("vehicleBrand", franchiseeCarGroup(cars, TAppUserCar::getVehicleBrand, "其他", 5)); |
| | | result.put("vehicleClass", franchiseeOrderCarGroup(orders, cars, TAppUserCar::getVehicleUse, "未知用途", 5)); |
| | | result.put("vehicleBrand", franchiseeOrderCarGroup(orders, cars, TAppUserCar::getVehicleBrand, "其他", 5)); |
| | | return R.ok(result); |
| | | } |
| | | |
| | |
| | | .map(entry -> namedCount(entry.getKey(), entry.getValue())).collect(Collectors.toList()); |
| | | } |
| | | |
| | | private List<Map<String, Object>> franchiseeOrderCarGroup(List<TChargingOrder> orders, |
| | | List<TAppUserCar> cars, |
| | | java.util.function.Function<TAppUserCar, String> getter, |
| | | String emptyName, |
| | | int limit) { |
| | | Map<Long, TAppUserCar> carsById = cars.stream() |
| | | .filter(car -> car.getId() != null) |
| | | .collect(Collectors.toMap(TAppUserCar::getId, car -> car, (left, right) -> left)); |
| | | Map<String, Long> counts = orders.stream().collect(Collectors.groupingBy(order -> { |
| | | TAppUserCar car = carsById.get(order.getAppUserCarId()); |
| | | String value = car == null ? null : getter.apply(car); |
| | | return value == null || value.trim().isEmpty() ? emptyName : value; |
| | | }, Collectors.counting())); |
| | | return counts.entrySet().stream().sorted(Map.Entry.<String, Long>comparingByValue().reversed()).limit(limit) |
| | | .map(entry -> namedCount(entry.getKey(), entry.getValue())).collect(Collectors.toList()); |
| | | } |
| | | |
| | | private List<Map<String, Object>> namedCounts(String[] names, long[] values) { |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (int i = 0; i < names.length; i++) if (values[i] > 0) result.add(namedCount(names[i], values[i])); |