CollectionRepo.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 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.math.BigDecimal;
  16. import java.time.LocalDateTime;
  17. import java.util.List;
  18. import java.util.Optional;
  19. public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
  20. @Query("update Collection t set t.del = true where t.id = ?1")
  21. @Modifying
  22. @Transactional
  23. @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
  24. void softDelete(Long id);
  25. @Transactional
  26. @Modifying
  27. @Query(value = "update collection_info c set c.on_shelf = ?2, c.salable = ?3, c.start_time = ?4, " +
  28. "c.schedule_sale = ?5, c.sort = ?6, c.detail = ?7, c.privileges = ?8, " +
  29. "c.properties = ?9, c.model3d = ?10, c.max_count = ?11, c.count_id = ?12, c.scan_code = ?13, " +
  30. "c.no_sold_out = ?14, c.assignment = ?15, c.coupon_payment = ?16, c.share_bg = ?17," +
  31. "c.register_bg = ?18, c.vip_quota = ?19, c.time_delay = ?20, c.sale_time = ?21, c.hold_days = ?22, " +
  32. "c.open_quota = ?23, c.total_quota = ?24, c.minimum_charge = ?25 " +
  33. "where c.id = ?1", nativeQuery = true)
  34. @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
  35. void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
  36. boolean schedule, int sort, String detail, String privileges,
  37. String properties, String model3d, int maxCount, String countId, boolean scanCode,
  38. boolean noSoldOut, int assignment, boolean couponPayment, String shareBg, String registerBg,
  39. Integer vipQuota, Boolean timeDelay, LocalDateTime saleTime, Integer holdDays, Boolean openQuota,
  40. Integer totalQuota, BigDecimal minimumCharge);
  41. @Cacheable("collection")
  42. Optional<Collection> findById(@Nonnull Long id);
  43. @Cacheable("collectionInfo")
  44. @Query("select new com.izouma.nineth.dto.CollectionInfoDTO(c,cp) from Collection c left join CollectionPrivilege cp " +
  45. "on c.id = cp.collectionId where c.id = ?1 ")
  46. Optional<CollectionInfoDTO> findInfoById(@Nonnull Long id);
  47. Optional<Collection> findByIdAndDelFalse(Long id);
  48. @Query("update Collection t set t.likes = t.likes + ?2 where t.id = ?1")
  49. @Modifying
  50. @Transactional
  51. @CacheEvict(value = "collection", key = "#id")
  52. void addLike(Long id, int num);
  53. @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
  54. "where l.userId = ?1 and l.del = false and c.del = false")
  55. List<Collection> userLikes(Long userId);
  56. List<Collection> findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime time);
  57. @Nonnull
  58. @CachePut(value = "collection", key = "#collection.id")
  59. Collection save(@Nonnull Collection collection);
  60. @Query("select new com.izouma.nineth.dto.RecommendCollection(c,r) from Collection c join Recommend r on c.id = r.collectionId " +
  61. "where c.del = false and c.onShelf = true and r.type = ?1 and r.category = 'COLLECTION' order by r.sort desc")
  62. List<RecommendCollection> recommend(String type);
  63. @Transactional
  64. @Modifying
  65. @Query("update Collection c set c.currentNumber = COALESCE(c.currentNumber, 0) + ?2 where c.id = ?1")
  66. @CacheEvict(value = "collection", key = "#id")
  67. void increaseNumber(Long id, int d);
  68. @Transactional
  69. @Modifying
  70. @Query("update Collection c set c.total = COALESCE(c.total, 0) + ?2 where c.id = ?1")
  71. @CacheEvict(value = "collection", key = "#id")
  72. void increaseTotal(Long id, int d);
  73. @Transactional
  74. @Modifying
  75. @Query("update Collection c set c.onShelf = ?2 where c.id = ?1")
  76. @CacheEvict(value = "collection", key = "#id")
  77. void setOnShelf(Long id, boolean onShelf);
  78. @Transactional
  79. @Modifying
  80. @Query("update Collection c set c.scheduleSale = false, c.startTime = null, 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. }