|
|
@@ -26,6 +26,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
@@ -95,7 +96,7 @@ public class ProductService {
|
|
|
return product;
|
|
|
}
|
|
|
|
|
|
- public Page<Product> list(String search, Long batchId, List<ProductStatus> statuses, Pageable pageable) {
|
|
|
+ public Page<Product> list(String search, Long batchId, List<ProductStatus> statuses, Pageable pageable, Long userId) {
|
|
|
SaleBatch saleBatch = saleBatchRepo.findById(batchId).orElseThrow(new BusinessException("分类不存在"));
|
|
|
LocalTime now = LocalTime.now();
|
|
|
if (!saleBatch.getEnabled()
|
|
|
@@ -107,6 +108,7 @@ public class ProductService {
|
|
|
statuses = Collections.singletonList(ProductStatus.IN_STOCK);
|
|
|
}
|
|
|
boolean hideSelfProduct = sysConfigService.getBoolean("hide_self_product");
|
|
|
+
|
|
|
List<ProductStatus> finalStatuses = statuses;
|
|
|
return productRepo.findAll((Specification<Product>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
@@ -128,6 +130,18 @@ public class ProductService {
|
|
|
));
|
|
|
}
|
|
|
|
|
|
+ if (userId != null) {
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException(Translator.toLocale("user.not_found")));
|
|
|
+ BigDecimal period = sysConfigService.getBigDecimal("freshness_period _for_new");
|
|
|
+ if (new BigDecimal(ChronoUnit.DAYS.between(user.getCreatedAt(), LocalDateTime.now())).compareTo(period) < 1) {
|
|
|
+ BigDecimal newUserMax = sysConfigService.getBigDecimal("new_user_max");
|
|
|
+ predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("currentPrice"), newUserMax));
|
|
|
+ } else {
|
|
|
+ BigDecimal oldUserMin = sysConfigService.getBigDecimal("old_user_min");
|
|
|
+ predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("currentPrice"), oldUserMin));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return criteriaQuery.where(predicates.toArray(new Predicate[0]))
|
|
|
.getRestriction();
|
|
|
}, pageable);
|