CollectionRepo.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 where c.id = ?1", nativeQuery = true)
  31. @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
  32. void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
  33. boolean schedule, int sort, String detail, String privileges,
  34. String properties, String model3d, int maxCount, String countId, boolean scanCode,
  35. boolean noSoldOut, int assignment, boolean couponPayment, String shareBg, String registerBg,
  36. Integer vipQuota, Boolean timeDelay, LocalDateTime saleTime, Integer holdDays, Boolean openQuota);
  37. @Cacheable("collection")
  38. Optional<Collection> findById(@Nonnull Long id);
  39. Optional<Collection> findByIdAndDelFalse(Long id);
  40. @Query("update Collection t set t.likes = t.likes + ?2 where t.id = ?1")
  41. @Modifying
  42. @Transactional
  43. @CacheEvict(value = "collection", key = "#id")
  44. void addLike(Long id, int num);
  45. @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
  46. "where l.userId = ?1 and l.del = false and c.del = false")
  47. List<Collection> userLikes(Long userId);
  48. List<Collection> findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime time);
  49. @Nonnull
  50. @CachePut(value = "collection", key = "#collection.id")
  51. Collection save(@Nonnull Collection collection);
  52. @Query("select new com.izouma.nineth.dto.RecommendCollection(c,r) from Collection c join Recommend r on c.id = r.collectionId " +
  53. "where c.del = false and c.onShelf = true and r.type = ?1 order by r.sort desc")
  54. List<RecommendCollection> recommend(String type);
  55. @Transactional
  56. @Modifying
  57. @Query("update Collection c set c.currentNumber = COALESCE(c.currentNumber, 0) + ?2 where c.id = ?1")
  58. @CacheEvict(value = "collection", key = "#id")
  59. void increaseNumber(Long id, int d);
  60. @Transactional
  61. @Modifying
  62. @Query("update Collection c set c.total = COALESCE(c.total, 0) + ?2 where c.id = ?1")
  63. @CacheEvict(value = "collection", key = "#id")
  64. void increaseTotal(Long id, int d);
  65. @Transactional
  66. @Modifying
  67. @Query("update Collection c set c.onShelf = ?2 where c.id = ?1")
  68. @CacheEvict(value = "collection", key = "#id")
  69. void setOnShelf(Long id, boolean onShelf);
  70. @Transactional
  71. @Modifying
  72. @Query("update Collection c set c.scheduleSale = false, c.startTime = null, c.onShelf = ?2, c.salable = true where c.id = ?1")
  73. @CacheEvict(value = "collection", key = "#id")
  74. void scheduleOnShelf(Long id, boolean onShelf);
  75. @Query("select c.currentNumber from Collection c where c.id = ?1")
  76. Optional<Integer> getCurrentNumber(Long id);
  77. List<Collection> findByScheduleSaleTrue();
  78. List<Collection> findByNameLike(String name);
  79. List<Collection> findByStockGreaterThan(int stock);
  80. @Query("update Collection c set c.stock = ?2 where c.id = ?1")
  81. @Transactional
  82. @Modifying
  83. int updateStock(Long id, int stock);
  84. @Query("update Collection c set c.sale = ?2 where c.id = ?1")
  85. @Transactional
  86. @Modifying
  87. int updateSale(Long id, int sale);
  88. @Query("select c.stock from Collection c where c.id = ?1")
  89. Integer getStock(Long id);
  90. @Query("select c.sale from Collection c where c.id = ?1")
  91. Integer getSale(Long id);
  92. @Query("select new com.izouma.nineth.dto.CollectionStockAndSale(c.id, c.stock, c.sale) from Collection c where c.stock > 0")
  93. List<CollectionStockAndSale> getStockAndSale();
  94. List<Collection> findAllByIdIn(java.util.Collection<Long> ids);
  95. @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from collection_info c", nativeQuery = true)
  96. List<List<String>> selectResource();
  97. @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)
  98. List<List<String>> selectResource(Long id);
  99. @Modifying
  100. @Transactional
  101. @Query(value = "update collection_info c set c.pic = ?2, c.model3d = ?3, c.minter_avatar = ?4, " +
  102. "c.owner_avatar = ?5, c.detail = ?6 where c.id = ?1", nativeQuery = true)
  103. int updateCDN(Long id, String pic, String model3d, String minterAvatar,
  104. String ownerAvatar, String detail);
  105. @Query("update Collection c set c.vipQuota = ?2 where c.id = ?1")
  106. @Transactional
  107. @Modifying
  108. int updateVipQuota(Long id, int vipQuota);
  109. @Query("select c.vipQuota from Collection c where c.id = ?1")
  110. Integer getVipQuota(Long id);
  111. }