CollectionRepo.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.domain.Collection;
  3. import com.izouma.nineth.dto.CollectionInfoDTO;
  4. import com.izouma.nineth.dto.CollectionStockAndSale;
  5. import com.izouma.nineth.dto.RecommendCollection;
  6. import com.izouma.nineth.enums.CollectionSource;
  7. import org.springframework.cache.annotation.CacheEvict;
  8. import org.springframework.cache.annotation.CachePut;
  9. import org.springframework.cache.annotation.Cacheable;
  10. import org.springframework.data.jpa.repository.JpaRepository;
  11. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  12. import org.springframework.data.jpa.repository.Modifying;
  13. import org.springframework.data.jpa.repository.Query;
  14. import javax.annotation.Nonnull;
  15. import javax.transaction.Transactional;
  16. import java.math.BigDecimal;
  17. import java.time.LocalDateTime;
  18. import java.util.List;
  19. import java.util.Optional;
  20. import java.util.Set;
  21. public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
  22. @Query("update Collection t set t.del = true where t.id = ?1")
  23. @Modifying
  24. @Transactional
  25. @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
  26. void softDelete(Long id);
  27. @Transactional
  28. @Modifying
  29. @Query(value = "update collection_info c set c.on_shelf = ?2, c.salable = ?3, c.start_time = ?4, " +
  30. "c.schedule_sale = ?5, c.sort = ?6, c.detail = ?7, c.privileges = ?8, " +
  31. "c.properties = ?9, c.model3d = ?10, c.max_count = ?11, c.count_id = ?12, c.scan_code = ?13, " +
  32. "c.no_sold_out = ?14, c.assignment = ?15, c.coupon_payment = ?16, c.share_bg = ?17," +
  33. "c.register_bg = ?18, c.vip_quota = ?19, c.time_delay = ?20, c.sale_time = ?21, c.hold_days = ?22, " +
  34. "c.open_quota = ?23, c.total_quota = ?24, c.minimum_charge = ?25 " +
  35. "where c.id = ?1", nativeQuery = true)
  36. @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
  37. void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
  38. boolean schedule, int sort, String detail, String privileges,
  39. String properties, String model3d, int maxCount, String countId, boolean scanCode,
  40. boolean noSoldOut, int assignment, boolean couponPayment, String shareBg, String registerBg,
  41. Integer vipQuota, Boolean timeDelay, LocalDateTime saleTime, Integer holdDays, Boolean openQuota,
  42. Integer totalQuota, BigDecimal minimumCharge);
  43. @Cacheable("collection")
  44. Optional<Collection> findById(@Nonnull Long id);
  45. @Cacheable("collectionInfo")
  46. @Query("select new com.izouma.nineth.dto.CollectionInfoDTO(c,cp) from Collection c left join CollectionPrivilege cp " +
  47. "on c.id = cp.collectionId where c.id = ?1 ")
  48. Optional<CollectionInfoDTO> findInfoById(@Nonnull Long id);
  49. Optional<Collection> findByIdAndDelFalse(Long id);
  50. @Query("update Collection t set t.likes = t.likes + ?2 where t.id = ?1")
  51. @Modifying
  52. @Transactional
  53. @CacheEvict(value = "collection", key = "#id")
  54. void addLike(Long id, int num);
  55. @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
  56. "where l.userId = ?1 and l.del = false and c.del = false")
  57. List<Collection> userLikes(Long userId);
  58. List<Collection> findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime time);
  59. @Nonnull
  60. @CachePut(value = "collection", key = "#collection.id")
  61. Collection save(@Nonnull Collection collection);
  62. @Query("select new com.izouma.nineth.dto.RecommendCollection(c,r) from Collection c join Recommend r on c.id = r.collectionId " +
  63. "where c.del = false and c.onShelf = true and r.type = ?1 and r.category = 'COLLECTION' order by r.sort desc")
  64. List<RecommendCollection> recommend(String type);
  65. @Transactional
  66. @Modifying
  67. @Query("update Collection c set c.currentNumber = COALESCE(c.currentNumber, 0) + ?2 where c.id = ?1")
  68. @CacheEvict(value = "collection", key = "#id")
  69. void increaseNumber(Long id, int d);
  70. @Transactional
  71. @Modifying
  72. @Query("update Collection c set c.total = COALESCE(c.total, 0) + ?2 where c.id = ?1")
  73. @CacheEvict(value = "collection", key = "#id")
  74. void increaseTotal(Long id, int d);
  75. @Transactional
  76. @Modifying
  77. @Query("update Collection c set c.onShelf = ?2 where c.id = ?1")
  78. @CacheEvict(value = "collection", key = "#id")
  79. void setOnShelf(Long id, boolean onShelf);
  80. @Transactional
  81. @Modifying
  82. @Query("update Collection c set c.scheduleSale = false, c.startTime = null, c.onShelf = ?2, c.salable = true where c.id = ?1")
  83. @CacheEvict(value = "collection", key = "#id")
  84. void scheduleOnShelf(Long id, boolean onShelf);
  85. @Query("select c.currentNumber from Collection c where c.id = ?1")
  86. Optional<Integer> getCurrentNumber(Long id);
  87. List<Collection> findByScheduleSaleTrue();
  88. List<Collection> findByNameLike(String name);
  89. List<Collection> findByStockGreaterThan(int stock);
  90. @Query("update Collection c set c.stock = ?2 where c.id = ?1")
  91. @Transactional
  92. @Modifying
  93. int updateStock(Long id, int stock);
  94. @Query("update Collection c set c.sale = ?2 where c.id = ?1")
  95. @Transactional
  96. @Modifying
  97. int updateSale(Long id, int sale);
  98. @Query("select c.stock from Collection c where c.id = ?1")
  99. Integer getStock(Long id);
  100. @Query("select c.sale from Collection c where c.id = ?1")
  101. Integer getSale(Long id);
  102. @Query("select new com.izouma.nineth.dto.CollectionStockAndSale(c.id, c.stock, c.sale) from Collection c where c.stock > 0")
  103. List<CollectionStockAndSale> getStockAndSale();
  104. List<Collection> findAllByIdIn(java.util.Collection<Long> ids);
  105. @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from collection_info c", nativeQuery = true)
  106. List<List<String>> selectResource();
  107. @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from collection_info c where c.id = ?1", nativeQuery = true)
  108. List<List<String>> selectResource(Long id);
  109. @Modifying
  110. @Transactional
  111. @Query(value = "update collection_info c set c.pic = ?2, c.model3d = ?3, c.minter_avatar = ?4, " +
  112. "c.owner_avatar = ?5, c.detail = ?6 where c.id = ?1", nativeQuery = true)
  113. int updateCDN(Long id, String pic, String model3d, String minterAvatar,
  114. String ownerAvatar, String detail);
  115. @Query("update Collection c set c.vipQuota = ?2 where c.id = ?1")
  116. @Transactional
  117. @Modifying
  118. int updateVipQuota(Long id, int vipQuota);
  119. @Query("select c.vipQuota from Collection c where c.id = ?1")
  120. Integer getVipQuota(Long id);
  121. @Query("select c.assetId from Collection c where c.price >= ?1 and c.source = ?2 and c.startTime <= ?3 and c.salable = ?4")
  122. Set<Long> findResaleCollectionPriceOver20K(BigDecimal price, CollectionSource source, LocalDateTime startTime, boolean salable);
  123. List<Collection> findAllByNameLike(String name);
  124. }