xin
2025-05-30 347909bae241fff128b628ea6d12992d7e5b4b10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.oying.modules.pc.search.rest;
 
import cn.hutool.core.collection.CollUtil;
import com.oying.utils.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<PageResult<StoreSearchView>> list(NearbyStoreQueryCriteria criteria) {
        return R.success(toStoreSearchVo(storeSearchService.findNearStores(criteria)));
    }
 
    private PageResult<StoreSearchView> toStoreSearchVo(PageResult<StoreSearchDto> resources) {
        PageResult<StoreSearchView> 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;
    }
}