|
|
@@ -285,62 +285,39 @@ public class MerchantService {
|
|
|
merchantSettingsRepo.save(merchant);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 距离排序,如果有范围,范围内进行排序
|
|
|
+ * 带距离的商家,已按距离排好序
|
|
|
*
|
|
|
- * @param merchants 商家列表
|
|
|
+ * @param merchants 商户列表
|
|
|
* @param longitude 经度
|
|
|
* @param latitude 纬度
|
|
|
* @param range 范围
|
|
|
- * @return 商家及距离
|
|
|
+ * @return 商家列表
|
|
|
*/
|
|
|
- public Map<Merchant, Double> distanceSorting(Set<Merchant> merchants, Double longitude, Double latitude, Double range) {
|
|
|
+ public List<MerchantDTO> withDistance(Set<Merchant> merchants, Double longitude, Double latitude, Double range) {
|
|
|
//所有商家要按距离排序规则
|
|
|
- Map<Merchant, Double> map = new HashMap<>();
|
|
|
+ Map<Merchant, Double> merchantMap = new HashMap<>();
|
|
|
//算距离
|
|
|
for (Merchant m : merchants) {
|
|
|
if (ObjectUtil.isNotNull(m.getLatitude()) && ObjectUtil.isNotNull(m.getLongitude())) {
|
|
|
Double distance = MapUtils.distance(m.getLongitude(), m.getLatitude(), longitude, latitude);
|
|
|
if (range != null) {
|
|
|
if (distance < range) {
|
|
|
- map.put(m, distance);
|
|
|
+ merchantMap.put(m, distance);
|
|
|
}
|
|
|
} else {
|
|
|
- map.put(m, distance);
|
|
|
+ merchantMap.put(m, distance);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //排序
|
|
|
- List<Map.Entry<Merchant, Double>> list = new ArrayList<>(map.entrySet());
|
|
|
- list.sort(Comparator.comparing(Map.Entry<Merchant, Double>::getValue));
|
|
|
- //List<Merchant> mers = new ArrayList<>();
|
|
|
-
|
|
|
- Map<Merchant, Double> merchantMap = new HashMap<>();
|
|
|
- for (Map.Entry<Merchant, Double> m : list) {
|
|
|
- //mers.add(m.getKey());
|
|
|
- merchantMap.put(m.getKey(), m.getValue());
|
|
|
- }
|
|
|
-
|
|
|
- return merchantMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 带距离的商家
|
|
|
- *
|
|
|
- * @param merchants 商户列表
|
|
|
- * @param longitude 经度
|
|
|
- * @param latitude 纬度
|
|
|
- * @param range 范围
|
|
|
- * @return 商家列表
|
|
|
- */
|
|
|
- public List<MerchantDTO> withDistance(Set<Merchant> merchants, Double longitude, Double latitude, Double range) {
|
|
|
- Map<Merchant, Double> merchantMap = this.distanceSorting(merchants, longitude, latitude, range);
|
|
|
List<MerchantDTO> dtos = new ArrayList<>();
|
|
|
for (Map.Entry<Merchant, Double> m : merchantMap.entrySet()) {
|
|
|
merchantSettingsRepo.findByMerchantId(m.getKey().getId())
|
|
|
.ifPresent(s -> dtos.add(new MerchantDTO(m.getKey(), s, m.getValue())));
|
|
|
}
|
|
|
+ dtos.sort(Comparator.comparing(MerchantDTO::getDistance));
|
|
|
return dtos;
|
|
|
}
|
|
|
|
|
|
@@ -351,13 +328,13 @@ public class MerchantService {
|
|
|
List<HeatMapDTO> list = new ArrayList<>();
|
|
|
|
|
|
Set<Merchant> merchantSet = new HashSet<>(merchantRepo.findAll());
|
|
|
- Map<Merchant, Double> map = this.distanceSorting(merchantSet, longitude, latitude, 3000.0);
|
|
|
- map.keySet().forEach(m -> {
|
|
|
- long sum = orderInfoRepo.findAllByMerchantId(m.getId()).stream().mapToLong(OrderInfo::getId).count();
|
|
|
+ List<MerchantDTO> map = this.withDistance(merchantSet, longitude, latitude, 3000.0);
|
|
|
+
|
|
|
+ map.forEach(m -> {
|
|
|
+ long sum = orderInfoRepo.findAllByMerchantId(m.getMid()).stream().mapToLong(OrderInfo::getId).count();
|
|
|
list.add(new HeatMapDTO(sum, longitude, latitude));
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
-
|
|
|
}
|
|
|
}
|