CollectionRepo.java 7.9 KB

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