|
|
@@ -2,11 +2,15 @@ package com.seecoder.BlueWhale.serviceImpl;
|
|
|
|
|
|
import com.seecoder.BlueWhale.enums.CategoryEnum;
|
|
|
import com.seecoder.BlueWhale.exception.BlueWhaleException;
|
|
|
+import com.seecoder.BlueWhale.po.Order;
|
|
|
import com.seecoder.BlueWhale.po.Product;
|
|
|
import com.seecoder.BlueWhale.po.Store;
|
|
|
+import com.seecoder.BlueWhale.repository.OrderRepository;
|
|
|
import com.seecoder.BlueWhale.repository.ProductRepository;
|
|
|
import com.seecoder.BlueWhale.repository.StoreRepository;
|
|
|
+import com.seecoder.BlueWhale.repository.UserRepository;
|
|
|
import com.seecoder.BlueWhale.service.ProductService;
|
|
|
+import com.seecoder.BlueWhale.vo.CommentVO;
|
|
|
import com.seecoder.BlueWhale.vo.ProductVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -28,6 +32,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
EntityManager entityManager;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ OrderRepository orderRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserRepository userRepository;
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean create(ProductVO productVO) {
|
|
|
if (productRepository.findByStoreIdAndName(productVO.getStoreId(),productVO.getName())!=null){
|
|
|
@@ -96,4 +106,19 @@ public class ProductServiceImpl implements ProductService {
|
|
|
List<Product> products=query.getResultList();
|
|
|
return products.stream().map(Product::toVO).collect(Collectors.toList());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CommentVO> getComments(Integer productId) {
|
|
|
+ List<Order> orders=orderRepository.findByProductIdAndFinishTimeNotNull(productId);
|
|
|
+ return orders.stream().map(x->{
|
|
|
+ CommentVO commentVO=new CommentVO();
|
|
|
+ commentVO.setOrderId(x.getId());
|
|
|
+ commentVO.setRating(x.getRating());
|
|
|
+ commentVO.setTime(x.getFinishTime());
|
|
|
+ commentVO.setComment(x.getContent());
|
|
|
+ commentVO.setUserId(x.getUserId());
|
|
|
+ commentVO.setUserName(userRepository.findById(x.getUserId()).get().getName());
|
|
|
+ return commentVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|