| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package com.izouma.nineth.repo;
- import com.izouma.nineth.domain.Collection;
- import com.izouma.nineth.dto.RecommendCollection;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.cache.annotation.CachePut;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.data.jpa.repository.JpaRepository;
- import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
- import org.springframework.data.jpa.repository.Modifying;
- import org.springframework.data.jpa.repository.Query;
- import javax.annotation.Nonnull;
- import javax.transaction.Transactional;
- import java.time.LocalDateTime;
- import java.util.List;
- import java.util.Optional;
- public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
- @Query("update Collection t set t.del = true where t.id = ?1")
- @Modifying
- @Transactional
- @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
- void softDelete(Long id);
- @Transactional
- @Modifying
- @Query(value = "update collection_info c set c.on_shelf = ?2, c.salable = ?3, c.start_time = ?4, " +
- "c.schedule_sale = ?5, c.sort = ?6, c.detail = ?7, c.privileges = ?8, " +
- "c.properties = ?9, c.model3d = ?10 where c.id = ?1", nativeQuery = true)
- @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
- void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
- boolean schedule, int sort, String detail, String privileges,
- String properties, String model3d);
- @Cacheable("collection")
- Optional<Collection> findById(Long id);
- @Query("update Collection t set t.likes = t.likes + ?2 where t.id = ?1")
- @Modifying
- @Transactional
- void addLike(Long id, int num);
- @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
- "where l.userId = ?1 and l.del = false and c.del = false")
- List<Collection> userLikes(Long userId);
- List<Collection> findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime time);
- @Nonnull
- @CachePut(value = "collection", key = "#collection.id")
- Collection save(@Nonnull Collection collection);
- @Query("select new com.izouma.nineth.dto.RecommendCollection(c,r) from Collection c join Recommend r on c.id = r.collectionId " +
- "where c.del = false and c.onShelf = true and r.type = ?1 and c.projectId = ?2 order by r.sort desc")
- List<RecommendCollection> recommend(String type, int projectId);
- @Transactional
- @Modifying
- @Query("update Collection c set c.scheduleSale = false, c.startTime = null, c.onShelf = true, c.salable = true where c.id = ?1")
- @CacheEvict(value = "collection", key = "#id")
- void scheduleOnShelf(Long id);
- @Transactional
- @Modifying
- @Query("update Collection c set c.currentNumber = COALESCE(c.currentNumber, 0) + ?2 where c.id = ?1")
- @CacheEvict(value = "collection", key = "#id")
- void increaseNumber(Long id, int d);
- @Transactional
- @Modifying
- @Query("update Collection c set c.sale = COALESCE(c.sale, 0) + ?2 where c.id = ?1")
- @CacheEvict(value = "collection", key = "#id")
- void increaseSale(Long id, int d);
- @Transactional
- @Modifying
- @Query("update Collection c set c.stock = COALESCE(c.stock, 0) + ?2 where c.id = ?1")
- @CacheEvict(value = "collection", key = "#id")
- void increaseStock(Long id, int d);
- @Transactional
- @Modifying
- @Query("update Collection c set c.total = COALESCE(c.total, 0) + ?2 where c.id = ?1")
- @CacheEvict(value = "collection", key = "#id")
- void increaseTotal(Long id, int d);
- @Transactional
- @Modifying
- @Query("update Collection c set c.onShelf = ?2 where c.id = ?1")
- @CacheEvict(value = "collection", key = "#id")
- void setOnShelf(Long id, boolean onShelf);
- @Query("select c.currentNumber from Collection c where c.id = ?1")
- Optional<Integer> getCurrentNumber(Long id);
- @Query("select c.stock from Collection c where c.id = ?1")
- Integer getStock(Long id);
- List<Collection> findAllByIdIn(java.util.Collection<Long> ids);
- @Modifying
- @Transactional
- void deleteAllByIdIn(java.util.Collection<Long> id);
- @Query("select c.id from Collection c where c.assetId = ?1 and c.source = 'TRANSFER'")
- List<Long> findAllByAssetId(Long assetId);
- }
|