Commit d6a93998529aaf9a66440e3b8abcbeeac907ef6a
1 parent
93103ae7
feat 商品允许修改品类
Showing
5 changed files
with
84 additions
and
22 deletions
etrade-shop/src/main/java/com/diligrp/etrade/shop/api/StockApi.java
1 | 1 | package com.diligrp.etrade.shop.api; |
2 | 2 | |
3 | -import cn.hutool.core.collection.CollUtil; | |
4 | 3 | import com.diligrp.etrade.core.domain.Message; |
5 | 4 | import com.diligrp.etrade.shop.domain.request.StockAddRequest; |
6 | 5 | import com.diligrp.etrade.shop.domain.request.StockDeductRequest; |
7 | -import com.diligrp.etrade.shop.model.Stock; | |
8 | 6 | import com.diligrp.etrade.shop.service.StockService; |
9 | 7 | import com.diligrp.idempotent.spring.boot.annotation.Idempotent; |
10 | 8 | import org.springframework.web.bind.annotation.*; |
11 | 9 | |
12 | -import java.util.Collections; | |
13 | 10 | import java.util.List; |
14 | 11 | |
15 | 12 | /** |
... | ... | @@ -55,20 +52,4 @@ public class StockApi { |
55 | 52 | return Message.success(); |
56 | 53 | } |
57 | 54 | |
58 | - | |
59 | - /** | |
60 | - * Query stock data for a single product. | |
61 | - * | |
62 | - * @param productId The ID of the product to query stock data for. | |
63 | - * @return Stock data for the specified product. | |
64 | - */ | |
65 | - @GetMapping("/{productId}") | |
66 | - public Message<Stock> getStockByProductId(@PathVariable Long productId) { | |
67 | - List<Stock> stocks = stockService.listByProductIds(Collections.singletonList(productId)); | |
68 | - if (CollUtil.isEmpty(stocks)) { | |
69 | - return Message.failure("Stock data not found for the product ID: " + productId); | |
70 | - } | |
71 | - return Message.success(stocks.get(0)); | |
72 | - } | |
73 | - | |
74 | 55 | } | ... | ... |
etrade-shop/src/main/java/com/diligrp/etrade/shop/domain/request/ProductUpdateCo.java
... | ... | @@ -18,6 +18,24 @@ public class ProductUpdateCo implements Serializable { |
18 | 18 | private Long id; |
19 | 19 | |
20 | 20 | /** |
21 | + * 品类主键 | |
22 | + */ | |
23 | + @NotNull(message = "品类主键不能为空") | |
24 | + private Long categoryId; | |
25 | + | |
26 | + /** | |
27 | + * 品类主键全路径 | |
28 | + */ | |
29 | + @NotBlank(message = "品类主键全路径不能为空") | |
30 | + private String categoryIdPath; | |
31 | + | |
32 | + /** | |
33 | + * 名称全路径 | |
34 | + */ | |
35 | + @NotBlank(message = "名称全路径不能为空") | |
36 | + private String namePath; | |
37 | + | |
38 | + /** | |
21 | 39 | * 数据版本号 |
22 | 40 | */ |
23 | 41 | @NotNull(message = "数据版本号不能为空") |
... | ... | @@ -146,4 +164,28 @@ public class ProductUpdateCo implements Serializable { |
146 | 164 | public void setLabel(List<Integer> label) { |
147 | 165 | this.label = label; |
148 | 166 | } |
167 | + | |
168 | + public Long getCategoryId() { | |
169 | + return categoryId; | |
170 | + } | |
171 | + | |
172 | + public void setCategoryId(Long categoryId) { | |
173 | + this.categoryId = categoryId; | |
174 | + } | |
175 | + | |
176 | + public String getCategoryIdPath() { | |
177 | + return categoryIdPath; | |
178 | + } | |
179 | + | |
180 | + public void setCategoryIdPath(String categoryIdPath) { | |
181 | + this.categoryIdPath = categoryIdPath; | |
182 | + } | |
183 | + | |
184 | + public String getNamePath() { | |
185 | + return namePath; | |
186 | + } | |
187 | + | |
188 | + public void setNamePath(String namePath) { | |
189 | + this.namePath = namePath; | |
190 | + } | |
149 | 191 | } | ... | ... |
etrade-shop/src/main/java/com/diligrp/etrade/shop/domain/response/ProductDetailVo.java
... | ... | @@ -35,6 +35,11 @@ public class ProductDetailVo implements Serializable { |
35 | 35 | private Long categoryId; |
36 | 36 | |
37 | 37 | /** |
38 | + * 品类主键全路径 | |
39 | + */ | |
40 | + private String categoryIdPath; | |
41 | + | |
42 | + /** | |
38 | 43 | * 名称 |
39 | 44 | */ |
40 | 45 | private String name; |
... | ... | @@ -300,4 +305,12 @@ public class ProductDetailVo implements Serializable { |
300 | 305 | public void setLabel(List<Integer> label) { |
301 | 306 | this.label = label; |
302 | 307 | } |
308 | + | |
309 | + public String getCategoryIdPath() { | |
310 | + return categoryIdPath; | |
311 | + } | |
312 | + | |
313 | + public void setCategoryIdPath(String categoryIdPath) { | |
314 | + this.categoryIdPath = categoryIdPath; | |
315 | + } | |
303 | 316 | } | ... | ... |
etrade-shop/src/main/java/com/diligrp/etrade/shop/service/impl/ProductServiceImpl.java
... | ... | @@ -83,11 +83,16 @@ public class ProductServiceImpl implements ProductService { |
83 | 83 | ProductDo entity = JsonUtils.convertValue(co, ProductDo.class); |
84 | 84 | ProductDetailVo pd = mapper.detail(entity.getId()); |
85 | 85 | validateExist(pd); |
86 | - entity.setCategoryId(pd.getCategoryId()); | |
87 | 86 | //校验商品 |
88 | 87 | productAdapterService.validateProduct(pd, co.getVersion()); |
89 | 88 | |
90 | 89 | //1.更新商品,2.校验是否更新成功 |
90 | + if (StringUtils.isNotBlank(entity.getCategoryIdPath())) { | |
91 | + entity.setCategoryIdPathJson(Arrays.stream(entity.getCategoryIdPath().split(",")).map(Long::valueOf).toList()); | |
92 | + } | |
93 | + if (StringUtils.isNotBlank(entity.getNamePath())) { | |
94 | + entity.setNamePathJson(Arrays.stream(entity.getNamePath().split(",")).toList()); | |
95 | + } | |
91 | 96 | productAdapterService.validateUpdateSuccess(mapper.update(entity), pd.getAlias()); |
92 | 97 | |
93 | 98 | /* |
... | ... | @@ -443,8 +448,8 @@ public class ProductServiceImpl implements ProductService { |
443 | 448 | |
444 | 449 | /* |
445 | 450 | * 注意:品类的基础信息是一致的,但是对应不同市场其图片是不一样的 |
451 | + * 同步信息 | |
446 | 452 | */ |
447 | - //同步信息 | |
448 | 453 | co.setAlias(null); |
449 | 454 | mapper.productCategorySync(co); |
450 | 455 | } | ... | ... |
etrade-shop/src/main/resources/com/diligrp/etrade/dao/mapper/ProductMapper.xml
... | ... | @@ -50,6 +50,7 @@ |
50 | 50 | <result column="p.modified_time" property="modifiedTime"/> |
51 | 51 | <result column="p.code" property="code"/> |
52 | 52 | <result column="p.category_id" property="categoryId"/> |
53 | + <result column="p.category_id_path" property="categoryIdPath"/> | |
53 | 54 | <result column="p.name" property="name"/> |
54 | 55 | <result column="p.name_path" property="namePath"/> |
55 | 56 | <result column="p.alias" property="alias"/> |
... | ... | @@ -154,7 +155,26 @@ |
154 | 155 | </insert> |
155 | 156 | |
156 | 157 | <update id="update"> |
157 | - update product SET modifier_id = #{modifierId}, | |
158 | + update product | |
159 | + SET modifier_id = #{modifierId}, | |
160 | + <if test="categoryId != null"> | |
161 | + categoryId = #{categoryId}, | |
162 | + </if> | |
163 | + <if test="categoryIdPath != null"> | |
164 | + category_id_path = #{categoryIdPath}, | |
165 | + </if> | |
166 | + <if test="categoryIdPathJson != null"> | |
167 | + category_id_path_json = #{categoryIdPathJson}, | |
168 | + </if> | |
169 | + <if test="code != null"> | |
170 | + code = #{code}, | |
171 | + </if> | |
172 | + <if test="namePath != null"> | |
173 | + name_path = #{namePath}, | |
174 | + </if> | |
175 | + <if test="namePathJson != null"> | |
176 | + name_path_json = #{namePathJson}, | |
177 | + </if> | |
158 | 178 | <if test="alias != null and alias != ''"> |
159 | 179 | alias = #{alias}, |
160 | 180 | </if> |
... | ... | @@ -497,6 +517,7 @@ |
497 | 517 | , p.modified_time AS "p.modified_time" |
498 | 518 | , p.code AS "p.code" |
499 | 519 | , p.category_id AS "p.category_id" |
520 | + , p.category_id_path AS "p.category_id_path" | |
500 | 521 | , p.name AS "p.name" |
501 | 522 | , p.name_path AS "p.name_path" |
502 | 523 | , p.alias AS "p.alias" | ... | ... |