|
@@ -162,49 +162,84 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
Page<PlaceVO> page = new Page<>(getPlaceListDTO.getCurrent(), getPlaceListDTO.getSize());
|
|
|
Page<PlaceVO> placeList = appSiteMapper.getPlaceList(page, getPlaceListDTO.getVenueType());
|
|
|
if (ObjectUtil.isNotEmpty(placeList)) {
|
|
|
+ // 提前收集所有场地ID
|
|
|
+ List<String> placeIds = placeList.getRecords().stream()
|
|
|
+ .map(PlaceVO::getId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 批量查询所有场地位置信息
|
|
|
+ List<AppSitePlace> allSitePlaces = new ArrayList<>();
|
|
|
+ if (!placeIds.isEmpty()) {
|
|
|
+ allSitePlaces = appSitePlaceMapper.selectList(
|
|
|
+ Wrappers.<AppSitePlace>lambdaQuery()
|
|
|
+ .in(AppSitePlace::getSiteId, placeIds)
|
|
|
+ .eq(AppSitePlace::getDelFlag, 0)
|
|
|
+ .eq(AppSitePlace::getStatus, 0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // 按场地ID分组场地位置信息
|
|
|
+ Map<String, List<AppSitePlace>> sitePlacesMap = allSitePlaces.stream()
|
|
|
+ .collect(Collectors.groupingBy(AppSitePlace::getSiteId));
|
|
|
+ // 收集所有场地位置ID用于查询价格规则
|
|
|
+ List<String> sitePlaceIds = allSitePlaces.stream()
|
|
|
+ .map(AppSitePlace::getId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 批量查询所有价格规则
|
|
|
+ List<AppSitePriceRules> allPriceRules = new ArrayList<>();
|
|
|
+ if (!sitePlaceIds.isEmpty()) {
|
|
|
+ allPriceRules = appSitePriceRulesMapper.selectList(
|
|
|
+ Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
+ .in(AppSitePriceRules::getSitePlaceId, sitePlaceIds)
|
|
|
+ .eq(AppSitePriceRules::getDelFlag, 0)
|
|
|
+ .eq(AppSitePriceRules::getStatus, 0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // 按场地位置ID分组价格规则
|
|
|
+ Map<String, List<AppSitePriceRules>> priceRulesMap = allPriceRules.stream()
|
|
|
+ .collect(Collectors.groupingBy(AppSitePriceRules::getSitePlaceId));
|
|
|
+ // 批量处理场地数据
|
|
|
placeList.getRecords().forEach(placeVO -> {
|
|
|
boolean ticketWhether = false;
|
|
|
- List<AppSitePriceRules> appSitePriceRules = new ArrayList<>();
|
|
|
- appSitePlaceMapper.selectList(Wrappers.<AppSitePlace>lambdaQuery()
|
|
|
- .eq(AppSitePlace::getSiteId, placeVO.getId())
|
|
|
- .eq(AppSitePlace::getDelFlag,0)
|
|
|
- .eq(AppSitePlace::getStatus,0)).forEach(appSitePlace -> {
|
|
|
- appSitePriceRules.addAll(appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
- .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId())
|
|
|
- .eq(AppSitePriceRules::getDelFlag, 0)
|
|
|
- .eq(AppSitePriceRules::getStatus, 0)));
|
|
|
- });
|
|
|
- if(!appSitePriceRules.isEmpty() ) ticketWhether = true;
|
|
|
- if(placeVO.getLatitude() != null && placeVO.getLongitude() != null){
|
|
|
- placeVO.setKm(PositionUtil.calculateDistance(getPlaceListDTO.getLatitude(), getPlaceListDTO.getLongitude(),
|
|
|
- placeVO.getLatitude().doubleValue(), placeVO.getLongitude().doubleValue()));
|
|
|
- }else{
|
|
|
+ // 检查是否有票价规则
|
|
|
+ List<AppSitePlace> sitePlaces = sitePlacesMap.getOrDefault(placeVO.getId(), Collections.emptyList());
|
|
|
+ for (AppSitePlace sitePlace : sitePlaces) {
|
|
|
+ List<AppSitePriceRules> priceRules = priceRulesMap.getOrDefault(
|
|
|
+ sitePlace.getId(), Collections.emptyList());
|
|
|
+ if (!priceRules.isEmpty()) {
|
|
|
+ ticketWhether = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 计算距离
|
|
|
+ if (placeVO.getLatitude() != null && placeVO.getLongitude() != null) {
|
|
|
+ placeVO.setKm(PositionUtil.calculateDistance(
|
|
|
+ getPlaceListDTO.getLatitude(),
|
|
|
+ getPlaceListDTO.getLongitude(),
|
|
|
+ placeVO.getLatitude().doubleValue(),
|
|
|
+ placeVO.getLongitude().doubleValue()));
|
|
|
+ } else {
|
|
|
placeVO.setKm(0.0);
|
|
|
}
|
|
|
+ // 获取评分信息
|
|
|
Long scoreNum = evaluateMapper.findByScoreNum(placeVO.getId());
|
|
|
- if(null == scoreNum){
|
|
|
+ if (null == scoreNum) {
|
|
|
scoreNum = 0L;
|
|
|
}
|
|
|
- Long scoreSum = evaluateMapper.findByAverageScore(placeVO.getId());//评论总评分
|
|
|
- if(null == scoreSum){
|
|
|
+ Long scoreSum = evaluateMapper.findByAverageScore(placeVO.getId());
|
|
|
+ if (null == scoreSum) {
|
|
|
scoreSum = 0L;
|
|
|
}
|
|
|
+ // 设置其他属性
|
|
|
placeVO.setCategory(getCategoryName(placeVO.getCategoryId()));
|
|
|
placeVO.setTicketWhether(ticketWhether);
|
|
|
placeVO.setGoodRate(calculateAverage(scoreSum, scoreNum));
|
|
|
placeVO.setComments(scoreNum);
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- if(getPlaceListDTO.getVenueType().equals("0-2")
|
|
|
- || getPlaceListDTO.getVenueType().equals("1-1")
|
|
|
- || getPlaceListDTO.getVenueType().equals("2-1")){
|
|
|
- // 按 km 升序排序(从近到远)
|
|
|
- placeList.getRecords().sort((p1, p2) -> {
|
|
|
- Double km1 = p1.getKm();
|
|
|
- Double km2 = p2.getKm();
|
|
|
- return km1.compareTo(km2);
|
|
|
- });
|
|
|
+ // 优化排序逻辑
|
|
|
+ if (Arrays.asList("0-2", "1-1", "2-1").contains(getPlaceListDTO.getVenueType())) {
|
|
|
+ placeList.getRecords().sort(Comparator.comparing(PlaceVO::getKm));
|
|
|
}
|
|
|
return placeList;
|
|
|
}
|