2026-06-30 24681c81c09022f584a57006f2534b5f74723414
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package cn.iocoder.yudao.module.product.service.spu;
 
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuSaveReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateStatusReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import jakarta.validation.Valid;
import org.springframework.scheduling.annotation.Async;
 
import java.util.Collection;
import java.util.List;
import java.util.Map;
 
/**
 * 商品 SPU Service 接口
 *
 * @author 芋道源码
 */
public interface ProductSpuService {
 
    /**
     * 创建商品 SPU
     *
     * @param createReqVO 创建信息
     * @return 编号
     */
    Long createSpu(@Valid ProductSpuSaveReqVO createReqVO);
 
    /**
     * 更新商品 SPU
     *
     * @param updateReqVO 更新信息
     */
    void updateSpu(@Valid ProductSpuSaveReqVO updateReqVO);
 
    /**
     * 删除商品 SPU
     *
     * @param id 编号
     */
    void deleteSpu(Long id);
 
    /**
     * 获得商品 SPU
     *
     * @param id 编号
     * @return 商品 SPU
     */
    ProductSpuDO getSpu(Long id);
 
    /**
     * 获得商品 SPU
     *
     * @param id 编号
     * @param includeDeleted 是否包含已删除的
     * @return 商品 SPU
     */
    ProductSpuDO getSpu(Long id, boolean includeDeleted);
 
    /**
     * 获得商品 SPU 列表
     *
     * @param ids 编号数组
     * @return 商品 SPU 列表
     */
    List<ProductSpuDO> getSpuList(Collection<Long> ids);
 
    /**
     * 获得商品 SPU Map
     *
     * @param ids 编号数组
     * @return 商品 SPU Map
     */
    default Map<Long, ProductSpuDO> getSpuMap(Collection<Long> ids) {
        List<ProductSpuDO> list = getSpuList(ids);
        return CollectionUtils.convertMap(list, ProductSpuDO::getId);
    }
 
    /**
     * 获得指定状态的商品 SPU 列表
     *
     * @param status 状态
     * @return 商品 SPU 列表
     */
    List<ProductSpuDO> getSpuListByStatus(Integer status);
 
    /**
     * 获得商品 SPU 分页,提供给挂你兰后台使用
     *
     * @param pageReqVO 分页查询
     * @return 商品spu分页
     */
    PageResult<ProductSpuDO> getSpuPage(ProductSpuPageReqVO pageReqVO);
 
    /**
     * 获得商品 SPU 分页,提供给用户 App 使用
     *
     * @param pageReqVO 分页查询
     * @return 商品 SPU 分页
     */
    PageResult<ProductSpuDO> getSpuPage(AppProductSpuPageReqVO pageReqVO);
 
    /**
     * 更新商品 SPU 库存(增量)
     *
     * @param stockIncrCounts SPU 编号与库存变化(增量)的映射
     */
    void updateSpuStock(Map<Long, Integer> stockIncrCounts);
 
    /**
     * 更新 SPU 状态
     *
     * @param updateReqVO 更新请求
     */
    void updateSpuStatus(ProductSpuUpdateStatusReqVO updateReqVO);
 
    /**
     * 获取 SPU 列表标签对应的 Count 数量(支持按 name/categoryId/createTime 筛选)
     *
     * @param reqVO 筛选条件
     * @return Count 数量
     */
    Map<Integer, Long> getTabsCount(ProductSpuPageReqVO reqVO);
 
    /**
     * 通过分类 categoryId 查询 SPU 个数
     *
     * @param categoryId 分类 categoryId
     * @return SPU 数量
     */
    Long getSpuCountByCategoryId(Long categoryId);
 
 
    /**
     * 校验商品是否有效。如下情况,视为无效:
     * 1. 商品编号不存在
     * 2. 商品被禁用
     *
     * @param ids 商品编号数组
     * @return 商品 SPU 列表
     */
    List<ProductSpuDO> validateSpuList(Collection<Long> ids);
 
    /**
     * 更新商品 SPU 浏览量
     *
     * @param id        商品 SPU 编号
     * @param incrCount 增加的数量
     */
    @Async
    void updateBrowseCount(Long id, int incrCount);
 
}