Commit 38d9ec925ceb3c699a1c0cfd747122f94a9eeb69
1 parent
45137b44
feat(shop): 产品列表增加价格显示并优化查询功能
- 在产品列表模板中添加价格显示,使用红色高亮 - 在 ProductDO 中添加 imageFileKey 字段,用于存储产品图片文件键 - 修改 ProductMapper.xml,支持自定义 SQL 查询 - 更新 ProductQueryVO,将 ids 类型从 List<Long> 改为 List<String> - 优化 ProductServiceImpl 中的产品查询逻辑,支持多条件查询和排序
Showing
5 changed files
with
11 additions
and
6 deletions
shop/src/main/java/com/canrd/shop/module/dto/ProductDO.java
shop/src/main/java/com/canrd/shop/module/vo/ProductQueryVO.java
... | ... | @@ -21,7 +21,7 @@ import java.util.List; |
21 | 21 | public class ProductQueryVO extends BasePageVO implements Serializable { |
22 | 22 | private static final long serialVersionUID = 108846000631816096L; |
23 | 23 | |
24 | - private List<Long> ids; | |
24 | + private List<String> ids; | |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * 产品id | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
... | ... | @@ -152,6 +152,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
152 | 152 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ |
153 | 153 | queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); |
154 | 154 | } |
155 | + queryWapper.in(CollUtil.isNotEmpty(productQueryVO.getIds()),"p.id",productQueryVO.getIds()); | |
155 | 156 | if(StringUtils.isNotBlank(productQueryVO.getKeyword())){ |
156 | 157 | List<TicketTypeDO> tickeyTypeDOList = ticketTypeService.lambdaQuery() |
157 | 158 | .like(TicketTypeDO::getRank, productQueryVO.getKeyword()) |
... | ... | @@ -225,16 +226,18 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
225 | 226 | Map<String,Integer> relatedCateId2Relevance = ebCategorysRelations.stream() |
226 | 227 | .collect(Collectors.toMap(EbCategorysRelation::getRelatedCategoryId, EbCategorysRelation::getRelevance,(a, b) -> a)); |
227 | 228 | TreeMap<String, Integer> cateId2Relevance = new TreeMap<>(relatedCateId2Relevance); |
228 | - StringJoiner orderByJoiner = new StringJoiner(" when "," order by case pcid when "," else 0 end limit 10 "); | |
229 | + StringJoiner orderByJoiner = new StringJoiner(" when "," order by case pc.id when "," else 0 end "); | |
229 | 230 | cateId2Relevance.forEach((k,v)->orderByJoiner.add("'"+k+"'"+" then "+v)); |
230 | 231 | QueryWrapper<ProductDO> objectQueryWrapper = new QueryWrapper<ProductDO>() |
231 | 232 | .in("pc.id", cateId2Relevance.keySet()) |
232 | - .select("id") | |
233 | + .select("distinct p.id","pc.id") | |
233 | 234 | .last(orderByJoiner.toString()); |
234 | 235 | List<ProductDO> relatedProducts = this |
235 | 236 | .list(objectQueryWrapper); |
236 | 237 | List<String> relatedProductIds = relatedProducts.stream() |
237 | 238 | .map(ProductDO::getId) |
239 | + .distinct() | |
240 | + .limit(10) | |
238 | 241 | .collect(Collectors.toList()); |
239 | 242 | product.setRelatedProductIds(relatedProductIds); |
240 | 243 | } |
... | ... | @@ -256,6 +259,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
256 | 259 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ |
257 | 260 | queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); |
258 | 261 | } |
262 | + queryWapper.in(CollUtil.isNotEmpty(productQueryVO.getIds()),"p.id",productQueryVO.getIds()); | |
259 | 263 | Set<String> productIds = null; |
260 | 264 | Map<String,List<TicketTypeDO>> pId2ttDOsMap = null; |
261 | 265 | boolean needLikeMatch = false; |
... | ... | @@ -400,7 +404,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
400 | 404 | */ |
401 | 405 | @Override |
402 | 406 | public ServerResult deleteById(ProductQueryVO productQueryVO) { |
403 | - List<Long> ids = productQueryVO.getIds(); | |
407 | + List<String> ids = productQueryVO.getIds(); | |
404 | 408 | if (CollUtil.isEmpty(ids)) { |
405 | 409 | return ServerResult.fail("ids 参数不能为空"); |
406 | 410 | } | ... | ... |
shop/src/main/resources/mapper/ProductMapper.xml
... | ... | @@ -36,7 +36,7 @@ |
36 | 36 | </select> |
37 | 37 | |
38 | 38 | <select id="selectList" resultMap="BaseResultMap"> |
39 | - select distinct p.id,p.name,p.productImageListStore,p.htmlFilePath,p.productCategory_id,pc.id as pcid | |
39 | + select ${ew.sqlSelect} | |
40 | 40 | from product p |
41 | 41 | left join productcategoryrelation pcr on p.id=pcr.productId |
42 | 42 | left join productcategory pc on pc.id=pcr.categoryId | ... | ... |
shop/src/main/resources/templates/canrud.ftl
... | ... | @@ -27202,6 +27202,7 @@ |
27202 | 27202 | </div> |
27203 | 27203 | <div data-v-f467c4e7="" class="v-card-text tw-text-left font-weight-medium title"> |
27204 | 27204 | <!--商品--> |
27205 | + <h3 data-v-f6bc2735="" style="color: red;"> ${item.price}</h3> | |
27205 | 27206 | <h4 data-v-f467c4e7="">${item.name}</h4> |
27206 | 27207 | </div> |
27207 | 27208 | <!----><span class="v-card__overlay"></span><span | ... | ... |