xiongzhu 3 years ago
parent
commit
a2c34c282e

+ 5 - 0
src/main/java/com/izouma/nineth/repo/OrderRepo.java

@@ -4,6 +4,8 @@ import com.izouma.nineth.domain.Order;
 import com.izouma.nineth.enums.CollectionSource;
 import com.izouma.nineth.enums.OrderStatus;
 import com.izouma.nineth.enums.PayMethod;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -85,4 +87,7 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
 
     @Query(value = "select sum(price) from order_info where user_id = ?1 and status = 'FINISH'", nativeQuery = true)
     BigDecimal sumUserPrice(Long userId);
+
+    @Query("select o from Order o join Asset a on a.id = o.assetId join a.tags t on t.id = ?1 where o.userId not in ?2")
+    Page<Order> byTag(Long tagId, List<Long> excludeUserId, Pageable pageable);
 }

+ 3 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -617,6 +617,9 @@ public class CollectionService {
     }
 
     public Page<Collection> byTag(Long tagId, List<Long> excludeUserId, Pageable pageable) {
+        if (excludeUserId.isEmpty()) {
+            excludeUserId.add(0L);
+        }
         return collectionRepo.findAll((Specification<Collection>) (root, query, criteriaBuilder) -> {
             Join join = root.join("tags");
             return criteriaBuilder.and(criteriaBuilder.equal(join.get("id"), tagId),

+ 13 - 0
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -48,6 +48,7 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.context.event.EventListener;
 import org.springframework.core.env.Environment;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.redis.core.BoundSetOperations;
 import org.springframework.data.redis.core.BoundValueOperations;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -55,6 +56,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.Model;
 
+import javax.persistence.criteria.Join;
 import java.io.OutputStream;
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -1054,4 +1056,15 @@ public class OrderService {
         }
         return list;
     }
+
+    public Page<Order> byTag(Long tagId, List<Long> excludeUserId, Pageable pageable) {
+        if (excludeUserId.isEmpty()) {
+            excludeUserId.add(0L);
+        }
+        return orderRepo.findAll((root, query, criteriaBuilder) -> {
+            Join join = root.join("tags");
+            return criteriaBuilder.and(criteriaBuilder.equal(join.get("id"), tagId),
+                    criteriaBuilder.not(root.get("ownerId").in(excludeUserId)));
+        }, pageable);
+    }
 }

+ 5 - 2
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
@@ -217,8 +218,10 @@ public class CollectionController extends BaseController {
 
     @GetMapping("/byTag")
     @JsonView(Collection.View.Basic.class)
-    public Page<Collection> byTag(@RequestParam Long tagId) {
-        return null;
+    public Page<Collection> byTag(@RequestParam Long tagId,
+                                  @RequestParam(required = false, defaultValue = "0") List<Long> excludeUserId,
+                                  Pageable pageable) {
+        return collectionService.byTag(tagId, excludeUserId, pageable);
     }
 }
 

+ 8 - 0
src/main/java/com/izouma/nineth/web/OrderController.java

@@ -19,6 +19,7 @@ import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
@@ -195,5 +196,12 @@ public class OrderController extends BaseController {
                                 @RequestParam(defaultValue = "false") boolean notify) {
         return orderService.addOrder(collectionId, userIds, time, notify);
     }
+
+    @GetMapping("/byTag")
+    public Page<Order> byTag(@RequestParam Long tagId,
+                             @RequestParam(required = false, defaultValue = "0") List<Long> excludeUserId,
+                             Pageable pageable) {
+        return orderRepo.byTag(tagId, excludeUserId, pageable);
+    }
 }