Commit 416a951c366bbb5d065df9b6c7361d0f95eb3d86
Merge branch 'refs/heads/search'
# Conflicts: # shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
Showing
2 changed files
with
33 additions
and
61 deletions
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
... | ... | @@ -374,96 +374,74 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
374 | 374 | } |
375 | 375 | |
376 | 376 | private void suppleProducts(List<ProductDO> records) { |
377 | - if (records == null || records.isEmpty()) { // 【修改1】先检查 records 是否为空 | |
378 | - return; | |
379 | - } | |
380 | - | |
381 | 377 | Boolean productPriceShow = switchControlService.getEnabledByName(SwitchControlConstants.PRODUCT_PRICE_SHOW); |
382 | - | |
383 | - List<String> productIds = records.stream() | |
384 | - .map(ProductDO::getId) | |
385 | - .filter(Objects::nonNull) // 【修改2】确保 productId 不为 null | |
386 | - .collect(Collectors.toList()); | |
387 | - | |
388 | - if (productIds.isEmpty()) { // 【修改3】如果没有有效的 productId,则直接返回 | |
389 | - return; | |
390 | - } | |
391 | - | |
378 | + List<String> productIds = records.stream().map(ProductDO::getId).collect(Collectors.toList()); | |
392 | 379 | List<TicketTypeDO> tickeyTypeDOList = ticketTypeService.lambdaQuery() |
393 | 380 | .func(wrapper -> { |
394 | - if (CollUtil.isEmpty(productIds)) { | |
381 | + if (CollUtil.isEmpty(productIds)){ | |
395 | 382 | wrapper.apply("1!=1"); |
396 | - } else { | |
383 | + }else { | |
397 | 384 | wrapper.in(TicketTypeDO::getProductId, productIds); |
398 | 385 | } |
399 | 386 | }) |
400 | 387 | .list(); |
401 | - | |
402 | - Map<String, BigDecimal> pId2ttMinPriceMap = new HashMap<>(); | |
403 | - Map<String, BigDecimal> pId3ttMaxPriceMap = new HashMap<>(); | |
404 | - | |
388 | + Map<String,BigDecimal> pId2ttMinPriceMap = new HashMap<>(); | |
389 | + Map<String,BigDecimal> pId3ttMaxPriceMap = new HashMap<>(); | |
405 | 390 | for (TicketTypeDO ticketTypeDO : tickeyTypeDOList) { |
406 | - String productId = ticketTypeDO.getProductId(); | |
407 | - if (productId == null) continue; // 【修改4】确保 productId 不为空 | |
408 | - | |
409 | - pId2ttMinPriceMap.compute(productId, (key, val) -> | |
410 | - (val == null || ticketTypeDO.getPrice().compareTo(val) < 0) ? ticketTypeDO.getPrice() : val); | |
411 | - | |
412 | - pId3ttMaxPriceMap.compute(productId, (key, val) -> | |
413 | - (val == null || ticketTypeDO.getPrice().compareTo(val) > 0) ? ticketTypeDO.getPrice() : val); | |
391 | + if (Objects.isNull(pId2ttMinPriceMap.get(ticketTypeDO.getProductId()))){ | |
392 | + pId2ttMinPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice()); | |
393 | + }else { | |
394 | + if (pId2ttMinPriceMap.get(ticketTypeDO.getProductId()).compareTo(ticketTypeDO.getPrice())>0){ | |
395 | + pId2ttMinPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice()); | |
396 | + } | |
397 | + } | |
398 | + if (Objects.isNull(pId3ttMaxPriceMap.get(ticketTypeDO.getProductId()))){ | |
399 | + pId3ttMaxPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice()); | |
400 | + }else { | |
401 | + if (pId3ttMaxPriceMap.get(ticketTypeDO.getProductId()).compareTo(ticketTypeDO.getPrice())<0){ | |
402 | + pId3ttMaxPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice()); | |
403 | + } | |
404 | + } | |
414 | 405 | } |
415 | 406 | |
416 | 407 | records.forEach(product -> { |
417 | - if (product == null || product.getId() == null) { // 【修改5】检查 product 是否为空 | |
418 | - return; | |
419 | - } | |
420 | - | |
421 | - if (productPriceShow) { | |
422 | - if (pId2ttMinPriceMap.containsKey(product.getId())) { // 【修改6】确保 key 存在 | |
408 | + if (productPriceShow){ | |
409 | + if (Objects.nonNull(pId2ttMinPriceMap.get(product.getId()))){ | |
423 | 410 | BigDecimal originMinPrice = pId2ttMinPriceMap.get(product.getId()) |
424 | 411 | .divide(new BigDecimal("0.7"), 2, RoundingMode.HALF_UP) |
425 | 412 | .divide(new BigDecimal("0.5"), 2, RoundingMode.HALF_UP) |
426 | 413 | .multiply(new BigDecimal("0.148")) |
427 | 414 | .setScale(2, RoundingMode.HALF_UP); |
428 | - | |
429 | 415 | BigDecimal computedPrice = originMinPrice |
430 | 416 | .multiply(new BigDecimal("0.5")) |
431 | 417 | .setScale(2, RoundingMode.HALF_UP); |
432 | - | |
433 | 418 | product.setPrice(computedPrice); |
434 | 419 | product.setOriginMinPrice(originMinPrice); |
435 | 420 | } |
436 | - | |
437 | - if (pId3ttMaxPriceMap.containsKey(product.getId())) { // 【修改7】确保 key 存在 | |
421 | + if (Objects.nonNull(pId3ttMaxPriceMap.get(product.getId()))){ | |
438 | 422 | BigDecimal originMaxPrice = pId3ttMaxPriceMap.get(product.getId()) |
439 | 423 | .divide(new BigDecimal("0.7"), 2, RoundingMode.HALF_UP) |
440 | 424 | .divide(new BigDecimal("0.5"), 2, RoundingMode.HALF_UP) |
441 | 425 | .multiply(new BigDecimal("0.148")) |
442 | 426 | .setScale(2, RoundingMode.HALF_UP); |
443 | - | |
444 | 427 | BigDecimal computedPrice = originMaxPrice |
445 | 428 | .multiply(new BigDecimal("0.5")) |
446 | 429 | .setScale(2, RoundingMode.HALF_UP); |
447 | - | |
448 | 430 | product.setMaxPrice(computedPrice); |
449 | 431 | product.setOriginMaxPrice(originMaxPrice); |
450 | 432 | } |
451 | 433 | } |
452 | - | |
453 | - // 解析 productimageliststore | |
454 | - if (product.getProductimageliststore() != null) { // 【修改8】确保不为 null | |
434 | + //将productDO的productimageliststore解析为map | |
435 | + if (product.getProductimageliststore() != null) { | |
455 | 436 | List<Map> maps = JSON.parseArray(product.getProductimageliststore(), Map.class); |
456 | - if (maps != null && !maps.isEmpty()) { // 【修改9】确保 maps 不是空的 | |
437 | + if (CollUtil.isNotEmpty(maps)) { | |
457 | 438 | Map map = maps.get(0); |
458 | - if (map != null && map.get("fileKey") != null) { // 【修改10】确保 map 及 fileKey 存在 | |
459 | - product.setImageFileKey(map.get("fileKey").toString()); | |
460 | - } | |
439 | + product.setImageFileKey(map.get("fileKey").toString()); | |
461 | 440 | } |
462 | 441 | } |
463 | 442 | }); |
464 | 443 | } |
465 | 444 | |
466 | - | |
467 | 445 | @Override |
468 | 446 | public ServerResult listBySimilar(ProductQueryVO productQueryVO){ |
469 | 447 | if(StringUtils.isBlank(productQueryVO.getKeyword())){ |
... | ... | @@ -503,7 +481,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
503 | 481 | if (StringUtils.isNotBlank(productQueryVO.getKeyword())) { |
504 | 482 | // String keyword = productQueryVO.getKeyword().trim(); |
505 | 483 | |
506 | - // 先精准匹配 | |
484 | + // 先精确匹配完整的关键字 | |
507 | 485 | List<TicketTypeDO> tickeyTypeDOList = ticketTypeService.lambdaQuery() |
508 | 486 | .like(TicketTypeDO::getRank, keyword) |
509 | 487 | .list(); |
... | ... | @@ -518,29 +496,23 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
518 | 496 | } |
519 | 497 | |
520 | 498 | if (productIds.isEmpty()) { |
521 | - // 如果没有匹配到,进行分词处理 | |
522 | - String[] keywords = Arrays.stream(keyword.split("\\s+")) | |
523 | - .filter(StringUtils::isNotBlank) | |
524 | - .toArray(String[]::new); | |
499 | + // 如果没有匹配到,分词处理 | |
500 | + String[] keywords = keyword.split("\\s+"); | |
525 | 501 | |
526 | 502 | queryWapper.and(subQueryWapper -> { |
527 | - // **必须包含所有分词** | |
503 | + // 查询包含所有分词的记录 | |
528 | 504 | for (String key : keywords) { |
529 | - subQueryWapper.like("p.name", key); | |
505 | + subQueryWapper.like("p.name", key).or(); | |
530 | 506 | } |
531 | 507 | }); |
532 | - | |
533 | 508 | } else { |
534 | 509 | Set<String> finalProductIds = productIds; |
535 | 510 | |
536 | 511 | queryWapper.and(subQueryWapper -> { |
537 | - subQueryWapper.like("p.name", keyword) | |
538 | - .or() | |
539 | - .in(CollUtil.isNotEmpty(finalProductIds), "p.id", finalProductIds); | |
512 | + subQueryWapper.like("p.name", keyword).or().in(CollUtil.isNotEmpty(finalProductIds), "p.id", finalProductIds); | |
540 | 513 | }); |
541 | 514 | } |
542 | 515 | } |
543 | - | |
544 | 516 | List<ProductDO> productDOS = this.baseMapper.queryList(queryWapper); |
545 | 517 | // Split the keyword into individual words |
546 | 518 | String[] keywords = keyword.split("\\s+"); | ... | ... |