|
@@ -163,53 +163,38 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
public Page<PlaceVO> getPlaceList(GetPlaceListDTO getPlaceListDTO) {
|
|
|
Page<PlaceVO> page = new Page<>(getPlaceListDTO.getCurrent(), getPlaceListDTO.getSize());
|
|
|
Page<PlaceVO> placeList = appSiteMapper.getPlaceList(page, getPlaceListDTO.getVenueType());
|
|
|
-
|
|
|
List<PlaceVO> records = placeList.getRecords();
|
|
|
if (ObjectUtil.isNotEmpty(records)) {
|
|
|
int recordCount = records.size();
|
|
|
if (recordCount > 0) {
|
|
|
- // 预分配集合大小以减少扩容
|
|
|
List<String> placeIds = new ArrayList<>(recordCount);
|
|
|
-
|
|
|
- // 收集所有场地ID(使用传统循环提高性能)
|
|
|
- for (int i = 0; i < recordCount; i++) {
|
|
|
- PlaceVO placeVO = records.get(i);
|
|
|
+ for (PlaceVO placeVO : records) {
|
|
|
if (placeVO.getId() != null) {
|
|
|
placeIds.add(placeVO.getId());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 批量查询优化
|
|
|
Map<String, List<AppSitePlace>> sitePlacesMap = Collections.emptyMap();
|
|
|
Map<String, List<AppSitePriceRules>> priceRulesMap = Collections.emptyMap();
|
|
|
-
|
|
|
if (!placeIds.isEmpty()) {
|
|
|
- // 一次性查询所有场地位置信息
|
|
|
List<AppSitePlace> allSitePlaces = appSitePlaceMapper.selectList(
|
|
|
Wrappers.<AppSitePlace>lambdaQuery()
|
|
|
.in(AppSitePlace::getSiteId, placeIds)
|
|
|
.eq(AppSitePlace::getDelFlag, 0)
|
|
|
.eq(AppSitePlace::getStatus, 0)
|
|
|
);
|
|
|
-
|
|
|
if (!allSitePlaces.isEmpty()) {
|
|
|
- // 按场地ID分组场地位置信息
|
|
|
sitePlacesMap = new HashMap<>(placeIds.size());
|
|
|
for (AppSitePlace sitePlace : allSitePlaces) {
|
|
|
sitePlacesMap.computeIfAbsent(sitePlace.getSiteId(), k -> new ArrayList<>())
|
|
|
.add(sitePlace);
|
|
|
}
|
|
|
-
|
|
|
- // 收集所有场地位置ID用于查询价格规则
|
|
|
List<String> sitePlaceIds = new ArrayList<>(allSitePlaces.size());
|
|
|
- for (int i = 0; i < allSitePlaces.size(); i++) {
|
|
|
- String id = allSitePlaces.get(i).getId();
|
|
|
+ for (AppSitePlace allSitePlace : allSitePlaces) {
|
|
|
+ String id = allSitePlace.getId();
|
|
|
if (id != null) {
|
|
|
sitePlaceIds.add(id);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 批量查询所有价格规则
|
|
|
if (!sitePlaceIds.isEmpty()) {
|
|
|
List<AppSitePriceRules> allPriceRules = appSitePriceRulesMapper.selectList(
|
|
|
Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
@@ -217,8 +202,6 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
.eq(AppSitePriceRules::getDelFlag, 0)
|
|
|
.eq(AppSitePriceRules::getStatus, 0)
|
|
|
);
|
|
|
-
|
|
|
- // 按场地位置ID分组价格规则
|
|
|
if (!allPriceRules.isEmpty()) {
|
|
|
priceRulesMap = new HashMap<>(sitePlaceIds.size());
|
|
|
for (AppSitePriceRules priceRule : allPriceRules) {
|
|
@@ -229,17 +212,41 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 批量处理场地数据(使用传统循环提高性能)
|
|
|
- final Map<String, List<AppSitePlace>> finalSitePlacesMap = sitePlacesMap;
|
|
|
- final Map<String, List<AppSitePriceRules>> finalPriceRulesMap = priceRulesMap;
|
|
|
-
|
|
|
+ Map<String, Long> scoreNumMap = new HashMap<>();
|
|
|
+ Map<String, Long> scoreSumMap = new HashMap<>();
|
|
|
+ if (!placeIds.isEmpty()) {
|
|
|
+ for (String placeId : placeIds) {
|
|
|
+ scoreNumMap.put(placeId, evaluateMapper.findByScoreNum(placeId));
|
|
|
+ scoreSumMap.put(placeId, evaluateMapper.findByAverageScore(placeId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, String> categoryNameCache = new HashMap<>();
|
|
|
for (int i = 0; i < recordCount; i++) {
|
|
|
PlaceVO placeVO = records.get(i);
|
|
|
- processPlaceVO(placeVO, getPlaceListDTO, finalSitePlacesMap, finalPriceRulesMap);
|
|
|
- }
|
|
|
+ Long scoreNum = scoreNumMap.get(placeVO.getId());
|
|
|
+ Long scoreSum = scoreSumMap.get(placeVO.getId());
|
|
|
+ if (null == scoreNum) scoreNum = 0L;
|
|
|
+ if (null == scoreSum) scoreSum = 0L;
|
|
|
+ List<String> categoryNames = new ArrayList<>();
|
|
|
+ if (placeVO.getCategoryId() != null) {
|
|
|
+ String[] categoryIds = placeVO.getCategoryId().split(",");
|
|
|
+ for (String categoryId : categoryIds) {
|
|
|
+ String categoryName = categoryNameCache.get(categoryId);
|
|
|
+ if (categoryName == null) {
|
|
|
+ AppCategory category = appCategoryMapper.selectById(categoryId);
|
|
|
+ if (category != null) {
|
|
|
+ categoryName = category.getName();
|
|
|
+ categoryNameCache.put(categoryId, categoryName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (categoryName != null) {
|
|
|
+ categoryNames.add(categoryName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 排序优化
|
|
|
+ processPlaceVO(placeVO, getPlaceListDTO, sitePlacesMap, priceRulesMap, scoreNum, scoreSum, categoryNames);
|
|
|
+ }
|
|
|
sortPlacesIfNecessary(records, getPlaceListDTO.getVenueType());
|
|
|
}
|
|
|
}
|
|
@@ -252,14 +259,13 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
*/
|
|
|
private void processPlaceVO(PlaceVO placeVO, GetPlaceListDTO getPlaceListDTO,
|
|
|
Map<String, List<AppSitePlace>> sitePlacesMap,
|
|
|
- Map<String, List<AppSitePriceRules>> priceRulesMap) {
|
|
|
+ Map<String, List<AppSitePriceRules>> priceRulesMap,
|
|
|
+ Long scoreNum, Long scoreSum, List<String> categoryNames) {
|
|
|
// 检查是否有票价规则
|
|
|
boolean ticketWhether = false;
|
|
|
List<AppSitePlace> sitePlaces = sitePlacesMap.getOrDefault(placeVO.getId(), Collections.emptyList());
|
|
|
-
|
|
|
if (!sitePlaces.isEmpty()) {
|
|
|
- for (int i = 0; i < sitePlaces.size(); i++) {
|
|
|
- AppSitePlace sitePlace = sitePlaces.get(i);
|
|
|
+ for (AppSitePlace sitePlace : sitePlaces) { // 使用增强for循环替代索引循环
|
|
|
List<AppSitePriceRules> priceRules = priceRulesMap.getOrDefault(
|
|
|
sitePlace.getId(), Collections.emptyList());
|
|
|
if (!priceRules.isEmpty()) {
|
|
@@ -268,7 +274,6 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 计算距离
|
|
|
if (placeVO.getLatitude() != null && placeVO.getLongitude() != null) {
|
|
|
placeVO.setKm(PositionUtil.calculateDistance(
|
|
@@ -279,20 +284,7 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
} else {
|
|
|
placeVO.setKm(0.0);
|
|
|
}
|
|
|
-
|
|
|
- // 获取评分信息(考虑批量查询优化)
|
|
|
- Long scoreNum = evaluateMapper.findByScoreNum(placeVO.getId());
|
|
|
- if (null == scoreNum) {
|
|
|
- scoreNum = 0L;
|
|
|
- }
|
|
|
-
|
|
|
- Long scoreSum = evaluateMapper.findByAverageScore(placeVO.getId());
|
|
|
- if (null == scoreSum) {
|
|
|
- scoreSum = 0L;
|
|
|
- }
|
|
|
-
|
|
|
- // 设置其他属性
|
|
|
- placeVO.setCategory(getCategoryName(placeVO.getCategoryId()));
|
|
|
+ placeVO.setCategory(categoryNames);
|
|
|
placeVO.setTicketWhether(ticketWhether);
|
|
|
placeVO.setGoodRate(calculateAverage(scoreSum, scoreNum));
|
|
|
placeVO.setComments(scoreNum);
|
|
@@ -337,7 +329,7 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
AppSearchHot appSearchHot = appSearchHotMapper.selectOne(Wrappers.<AppSearchHot>lambdaQuery()
|
|
|
.eq(AppSearchHot::getSearchContent, searchDTO.getKeyword())
|
|
|
.last("LIMIT 1"));
|
|
|
- if(null == appSearchHot){
|
|
|
+ if(null == appSearchHot && null != searchDTO.getKeyword() && !searchDTO.getKeyword().isEmpty()){
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
Date tenYearsLater = Date.from(now.plusYears(10).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
appSearchHotMapper.insert(new AppSearchHot()
|
|
@@ -348,6 +340,7 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
.setIsRecommend(0)
|
|
|
.setStartTime(new Date()).setEndTime(tenYearsLater));
|
|
|
}else {
|
|
|
+ assert appSearchHot != null;
|
|
|
appSearchHotMapper.updateById(appSearchHot.setSearchCount(appSearchHot.getSearchCount() + 1));
|
|
|
}
|
|
|
}
|