|
|
@@ -1,5 +1,6 @@
|
|
|
package com.seecoder.BlueWhale.serviceImpl;
|
|
|
|
|
|
+import com.seecoder.BlueWhale.enums.CategoryEnum;
|
|
|
import com.seecoder.BlueWhale.repository.ProductRepository;
|
|
|
import com.seecoder.BlueWhale.repository.StoreRepository;
|
|
|
import com.seecoder.BlueWhale.exception.BlueWhaleException;
|
|
|
@@ -8,6 +9,7 @@ import com.seecoder.BlueWhale.po.Store;
|
|
|
import com.seecoder.BlueWhale.service.ProductService;
|
|
|
import com.seecoder.BlueWhale.vo.ProductVO;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -65,4 +67,21 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
return product.toVO();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ProductVO> getProductsWithCondition(String name, CategoryEnum category, Double price) {
|
|
|
+ List<String> conditions=new ArrayList<>();
|
|
|
+ if (name!=null && name.length()>0){
|
|
|
+ conditions.add("name = :name");
|
|
|
+ }
|
|
|
+ if (category!=null){
|
|
|
+ conditions.add("category = :category");
|
|
|
+ }
|
|
|
+ if (price!=null && price>0){
|
|
|
+ conditions.add("price <= :price");
|
|
|
+ }
|
|
|
+ String condition=String.join(",",conditions);
|
|
|
+ List<Product> products=productRepository.findProductsWithDynamicConditions(condition,name,category,price);
|
|
|
+ return products.stream().map(Product::toVO).collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|