zepengdev
2025-06-16 7504b809da1a6188dfa03c06be3eb0f0a9fd0c8e
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.oying.modules.pc.store.rest;
 
import cn.hutool.core.util.ObjUtil;
import com.oying.modules.pc.product.domain.Product;
import com.oying.modules.pc.product.domain.dto.ProductQueryCriteria;
import com.oying.modules.pc.product.domain.enums.ProductStatusEnum;
import com.oying.modules.pc.product.service.ProductService;
import com.oying.modules.pc.store.domain.Store;
import com.oying.modules.pc.store.domain.dto.StoreQueryCriteria;
import com.oying.modules.pc.store.service.StoreQualificationService;
import com.oying.modules.pc.store.service.StoreQueryService;
import com.oying.modules.pc.store.service.StoreService;
import com.oying.modules.pc.store.view.CustomerStoreView;
import com.oying.modules.pc.utils.BusinessHoursUtils;
import com.oying.utils.PageResult;
import com.oying.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
 
/**
 * 店铺
 *
 * @author lzp
 * @date 2025-04-22
 */
@Api(tags = "店铺(客户端)")
@RestController
@RequestMapping("/api/pc/customer/store")
@RequiredArgsConstructor
public class StoreCustomerController {
 
    private final StoreService storeService;
    private final StoreQueryService storeQueryService;
    private final StoreQualificationService storeQualificationService;
    private final ProductService productService;
 
    @GetMapping(value = "/page")
    @ApiOperation("查询店铺")
    public ResponseEntity<?> getStoresByPage(StoreQueryCriteria criteria) {
        PageResult<Store> pagedStores = storeQueryService.findPagedStores(criteria);
        List<Store> stores = pagedStores.getContent();
        for (Store store : stores) {
            store.setProducts(this.getProductsByStoreId(store.getStoreId()));
        }
        return ResponseEntity.ok(R.success(pagedStores));
    }
 
    @GetMapping(value = "/{storeId}")
    @ApiOperation("查询店铺")
    public ResponseEntity<?> getStoreById(@PathVariable("storeId") Long storeId) {
        Store store = storeService.getById(storeId);
        CustomerStoreView view = new CustomerStoreView();
        BeanUtils.copyProperties(store, view);
        view.setBusinessHours(BusinessHoursUtils.formatBusinessHours(store.getOpenTime(), store.getCloseTime()));
        return ResponseEntity.ok(R.success(view));
    }
 
    @GetMapping(value = "/{storeId}/details")
    @ApiOperation("查询店铺")
    public ResponseEntity<?> getStoreDetailsById(@PathVariable("storeId") Long storeId) {
        Store store = storeService.getById(storeId);
        if (ObjUtil.isNotEmpty(store)) {
            store.setQualifications(storeQualificationService.queryByStoreId(storeId));
        }
        return ResponseEntity.ok(R.success(store));
    }
 
    private List<Product> getProductsByStoreId(Long storeId) {
        ProductQueryCriteria criteria = new ProductQueryCriteria();
        criteria.setStoreId(storeId);
        criteria.setStatus(ProductStatusEnum.AVAILABLE.getValue());
        criteria.setLimit(3);
        return productService.queryAll(criteria);
    }
 
}