CollectionRepo.java 6.9 KB

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