xin
2025-07-21 548bead175143ab846aaf0816f2ff1129050e94a
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.oying.modules.pc.product.rest;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.ProductImageService;
import com.oying.modules.pc.product.service.ProductLabelService;
import com.oying.modules.pc.product.service.ProductService;
import com.oying.modules.pc.product.view.ProductCustomerView;
import com.oying.modules.pc.product.view.ProductImageCustomerView;
import com.oying.modules.pc.product.view.ProductLabelCustomerView;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
 
/*
 *
 * @author lzp
 * @date 2025-04-30
 *
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "商品(客户端)")
@RequestMapping("/api/pc/customer/store/{storeId}/product")
public class ProductCustomerController {
 
    private final ProductService productService;
    private final ProductImageService productImageService;
    private final ProductLabelService productLabelService;
 
    @GetMapping(value = "/page")
    @ApiOperation("根据商品名称模糊匹配店铺内的商品")
    /*@PreAuthorize("@el.check('merchant:product:page')")*/
    public ResponseEntity<?> getProductsByPage(@PathVariable Long storeId,
                                               @RequestParam(value = "categoryId", required = false) Long categoryId,
                                               @RequestParam(value = "secondCategoryId", required = false) Long secondCategoryId,
                                               @RequestParam(value = "blurry", required = false) String blurry) {
 
        ProductQueryCriteria criteria = new ProductQueryCriteria();
        criteria.setStoreId(storeId);
        criteria.setCategoryId(categoryId);
        criteria.setSecondCategoryId(secondCategoryId);
        criteria.setBlurry(blurry);
        criteria.setShelfStatus(ProductStatusEnum.AVAILABLE.getValue());
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        PageResult<Product> productPageResult = productService.queryAll(criteria, page);
 
        List<Product> productList = Optional.ofNullable(productPageResult.getContent()).orElse(ListUtil.empty());
 
        PageResult<ProductCustomerView> viewPageResult = new PageResult<>(
                productList.stream().map(i -> {
                    ProductCustomerView view = new ProductCustomerView();
                    BeanUtil.copyProperties(i, view);
                    return view;
                }).collect(Collectors.toList()),
                productPageResult.getTotalElements());
        return ResponseEntity.ok(R.success(viewPageResult));
    }
 
    @GetMapping(value = "/{productId}/details")
    @ApiOperation("查询商品")
    /*@PreAuthorize("@el.check('merchant:product:byProductId')")*/
    public ResponseEntity<?> getProductDetails(@PathVariable Long productId) {
        Product product = productService.getById(productId);
        if (ObjUtil.isEmpty(product)) {
            return ResponseEntity.ok(R.success());
        }
        ProductCustomerView customerView = new ProductCustomerView();
        BeanUtil.copyProperties(product, customerView);
        if (ObjUtil.isNotEmpty(product)) {
            customerView.setImages(productImageService.queryImagesByProductId(productId).stream().map(i -> {
                ProductImageCustomerView imageCustomerView = new ProductImageCustomerView();
                BeanUtil.copyProperties(i, imageCustomerView, CopyOptions.create().setIgnoreNullValue(true));
                return imageCustomerView;
            }).collect(Collectors.toList()));
            customerView.setLabels(productLabelService.queryLabelsByProductId(productId).stream().map(i -> {
                ProductLabelCustomerView labelCustomerView = new ProductLabelCustomerView();
                BeanUtil.copyProperties(i, labelCustomerView, CopyOptions.create().setIgnoreNullValue(true));
                return labelCustomerView;
            }).collect(Collectors.toList()));
        }
        return ResponseEntity.ok(R.success(customerView));
    }
 
}