|
@@ -38,6 +38,7 @@ import com.yohoufo.product.service.impl.ProductBatchService; |
|
@@ -38,6 +38,7 @@ import com.yohoufo.product.service.impl.ProductBatchService; |
38
|
import com.yohoufo.product.service.impl.ProductPoolService;
|
38
|
import com.yohoufo.product.service.impl.ProductPoolService;
|
39
|
import com.yohoufo.product.service.impl.SeekToBuyStorageService;
|
39
|
import com.yohoufo.product.service.impl.SeekToBuyStorageService;
|
40
|
import com.yohoufo.product.service.impl.StoragePriceService;
|
40
|
import com.yohoufo.product.service.impl.StoragePriceService;
|
|
|
41
|
+import com.yohoufo.product.util.ThreadPoolFactory;
|
41
|
import org.apache.commons.collections.CollectionUtils;
|
42
|
import org.apache.commons.collections.CollectionUtils;
|
42
|
import org.apache.commons.lang3.StringUtils;
|
43
|
import org.apache.commons.lang3.StringUtils;
|
43
|
import org.slf4j.Logger;
|
44
|
import org.slf4j.Logger;
|
|
@@ -55,6 +56,7 @@ import java.math.BigDecimal; |
|
@@ -55,6 +56,7 @@ import java.math.BigDecimal; |
55
|
import java.util.*;
|
56
|
import java.util.*;
|
56
|
import java.util.concurrent.ExecutorService;
|
57
|
import java.util.concurrent.ExecutorService;
|
57
|
import java.util.concurrent.Executors;
|
58
|
import java.util.concurrent.Executors;
|
|
|
59
|
+import java.util.function.Predicate;
|
58
|
import java.util.stream.Collectors;
|
60
|
import java.util.stream.Collectors;
|
59
|
|
61
|
|
60
|
@RestController
|
62
|
@RestController
|
|
@@ -390,8 +392,7 @@ public class ProductController { |
|
@@ -390,8 +392,7 @@ public class ProductController { |
390
|
productService.sellerBatchUpdateStatus(skupList, dbStatus);
|
392
|
productService.sellerBatchUpdateStatus(skupList, dbStatus);
|
391
|
//清缓存
|
393
|
//清缓存
|
392
|
LOG.info("sellerUpdateStatus success and async clearProductCache skupList = {}", skupList);
|
394
|
LOG.info("sellerUpdateStatus success and async clearProductCache skupList = {}", skupList);
|
393
|
- clearBatchProductCache(skupList);
|
|
|
394
|
-
|
395
|
+ ThreadPoolFactory.cacheCleanExecutorService().submit(()->clearBatchProductCache(skupList));
|
395
|
return new ApiResponse(200, "更新成功!", Boolean.TRUE);
|
396
|
return new ApiResponse(200, "更新成功!", Boolean.TRUE);
|
396
|
} catch (Exception e) {
|
397
|
} catch (Exception e) {
|
397
|
LOG.error("sellerBatchUpdateStatus失败!", e);
|
398
|
LOG.error("sellerBatchUpdateStatus失败!", e);
|
|
@@ -601,14 +602,33 @@ public class ProductController { |
|
@@ -601,14 +602,33 @@ public class ProductController { |
601
|
private void clearBatchProductCache(List<Integer> skupList) {
|
602
|
private void clearBatchProductCache(List<Integer> skupList) {
|
602
|
try {
|
603
|
try {
|
603
|
LOG.info("in clearBatchProductCache skupList = {}", skupList);
|
604
|
LOG.info("in clearBatchProductCache skupList = {}", skupList);
|
604
|
- List<StoragePrice> spList = productService.getStoragePriceBySkupList(skupList);
|
|
|
605
|
- List<Integer> productIdList = spList.stream().map(StoragePrice::getProductId).distinct().collect(Collectors.toList());
|
|
|
606
|
- List<Integer> storageIdList = spList.stream().map(StoragePrice::getStorageId).distinct().collect(Collectors.toList());
|
605
|
+ List<StoragePrice> storagePriceList = productService.getStoragePriceBySkupList(skupList);
|
|
|
606
|
+ List<Integer> productIdList = storagePriceList.stream().map(StoragePrice::getProductId).distinct().collect(Collectors.toList());
|
|
|
607
|
+ List<Integer> storageIdList = storagePriceList.stream().map(StoragePrice::getStorageId).distinct().collect(Collectors.toList());
|
607
|
if (CollectionUtils.isNotEmpty(productIdList)) {
|
608
|
if (CollectionUtils.isNotEmpty(productIdList)) {
|
608
|
for (Integer productId : productIdList) {
|
609
|
for (Integer productId : productIdList) {
|
609
|
LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId);
|
610
|
LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId);
|
610
|
|
611
|
|
611
|
- storagePriceService.publishPriceUpdateEvent(productId);
|
612
|
+ storagePriceService.publishPriceUpdateEventIf(productId, oldSkupList -> {
|
|
|
613
|
+ // 缓存不存在,需要更新
|
|
|
614
|
+ if (CollectionUtils.isEmpty(oldSkupList)) {
|
|
|
615
|
+ return true;
|
|
|
616
|
+ }
|
|
|
617
|
+ // 比最低价要低,需要更新
|
|
|
618
|
+ Predicate<StoragePrice> pricePredicate = newPrice -> oldSkupList.stream()
|
|
|
619
|
+ .filter(oldPrice -> Objects.equals(newPrice.getStorageId(), oldPrice.getStorageId()))
|
|
|
620
|
+ .anyMatch(oldPrice -> newPrice.getPrice().compareTo(oldPrice.getPrice()) < 0);
|
|
|
621
|
+ if(storagePriceList.stream().anyMatch(pricePredicate)){
|
|
|
622
|
+ return true;
|
|
|
623
|
+ }
|
|
|
624
|
+ // 如果当前skup为缓存中商品,需要更新
|
|
|
625
|
+ Predicate<StoragePrice> sameSkupPredicate = newSkup -> oldSkupList.stream()
|
|
|
626
|
+ .anyMatch(oldSkup -> Objects.equals(newSkup.getSkup(), oldSkup.getSkup()));
|
|
|
627
|
+ if(storagePriceList.stream().anyMatch(sameSkupPredicate)){
|
|
|
628
|
+ return true;
|
|
|
629
|
+ }
|
|
|
630
|
+ return false;
|
|
|
631
|
+ });
|
612
|
|
632
|
|
613
|
//商品详情
|
633
|
//商品详情
|
614
|
cacheAop.clearCache(
|
634
|
cacheAop.clearCache(
|
|
@@ -659,7 +679,7 @@ public class ProductController { |
|
@@ -659,7 +679,7 @@ public class ProductController { |
659
|
}
|
679
|
}
|
660
|
}
|
680
|
}
|
661
|
Map<String, StoragePrice> distinctStorage = new HashMap<>();
|
681
|
Map<String, StoragePrice> distinctStorage = new HashMap<>();
|
662
|
- for(StoragePrice sp : spList) {
|
682
|
+ for(StoragePrice sp : storagePriceList) {
|
663
|
Integer skup = sp.getSkup();
|
683
|
Integer skup = sp.getSkup();
|
664
|
Integer storageId = sp.getStorageId();
|
684
|
Integer storageId = sp.getStorageId();
|
665
|
if (sp.getPreSaleFlag() != null && (sp.getPreSaleFlag() == 5 || sp.getPreSaleFlag() == 6)) {
|
685
|
if (sp.getPreSaleFlag() != null && (sp.getPreSaleFlag() == 5 || sp.getPreSaleFlag() == 6)) {
|