package com.oying.modules.pc.search.rest; import cn.hutool.core.collection.CollUtil; import com.oying.modules.pc.common.core.domain.R; import com.oying.modules.pc.search.domain.dto.NearbyStoreQueryCriteria; import com.oying.modules.pc.search.domain.dto.StoreSearchDto; import com.oying.modules.pc.search.view.StoreSearchView; import com.oying.modules.pc.search.service.StoreSearchService; import com.oying.utils.PageResult; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Collections; import java.util.stream.Collectors; /** * 店铺 * * @author lzp * @date 2025-04-22 */ @RestController @RequestMapping("/api/pc/search") @RequiredArgsConstructor public class StoreSearchController { private final StoreSearchService storeSearchService; /** * 查询最近的店铺 */ @GetMapping("/near") public R> list(NearbyStoreQueryCriteria criteria) { return R.success(toStoreSearchVo(storeSearchService.findNearStores(criteria))); } private PageResult toStoreSearchVo(PageResult resources) { PageResult t = new PageResult<>(); t.setTotalElements(resources.getTotalElements()); if (CollUtil.isNotEmpty(resources.getContent())) { t.setContent(resources.getContent().stream().map(storeSearchDto -> { StoreSearchView searchView = new StoreSearchView(); searchView.setStoreId(storeSearchDto.getStoreId()); searchView.setStoreName(storeSearchDto.getStoreName()); searchView.setStoreLogoUrl(""); // 获取obs searchView.setDistance(storeSearchDto.getDistance()); searchView.setRecommendedProducts(Collections.emptyList()); return searchView; }).collect(Collectors.toList())); } if (CollUtil.isEmpty(t.getContent())) { t.setContent(Collections.emptyList()); } return t; } }