| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package com.izouma.nineth.repo;
- import com.izouma.nineth.domain.User;
- import com.izouma.nineth.security.Authority;
- 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.transaction.Transactional;
- import java.util.List;
- import java.util.Optional;
- public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
- @Transactional
- @Modifying
- @Query("update User u set u.del = true where u.id = ?1")
- void softDelete(Long id);
- Optional<User> findByUsernameAndDelFalse(String username);
- List<User> findAllByAuthoritiesContainsAndDelFalse(Authority authority);
- Optional<User> findByOpenIdAndDelFalse(String openId);
- Optional<User> findByPhoneAndDelFalse(String phone);
- Optional<User> findByIdAndDelFalse(Long userId);
- @Transactional
- @Modifying
- @Query("update User u set u.followers = u.followers + ?1 where u.id = ?1")
- void addFollow(Long userId, int num);
- @Query("select distinct u from User u join Follow f on u.id = f.followUserId " +
- "where f.userId = ?1 and u.del = false ")
- List<User> userFollows(Long userId);
- @Query("select distinct u from User u join Follow f on u.id = f.userId " +
- "where f.followUserId = ?1 and u.del = false ")
- List<User> userFollowers(Long userId);
- @Transactional
- @Modifying
- @Query(value = "update user set follows = (select count(*) from follow " +
- "where follow.user_id = ?1) where user.id = ?1", nativeQuery = true)
- void updateFollows(Long userId);
- @Transactional
- @Modifying
- @Query(value = "update user set followers = (select count(*) from follow " +
- "where follow.follow_user_id = ?1) where user.id = ?1", nativeQuery = true)
- void updateFollowers(Long userId);
- @Transactional
- @Modifying
- @Query(value = "update collection_info join user on collection_info.minter_id = user.id " +
- "set collection_info.minter = user.nickname, " +
- " collection_info.minter_avatar = user.avatar " +
- "where user.id = ?1", nativeQuery = true)
- void updateMinterForCollection(Long userId);
- @Transactional
- @Modifying
- @Query(value = "update collection_info join user on collection_info.owner_id = user.id " +
- "set collection_info.owner = user.nickname, " +
- " collection_info.owner_avatar = user.avatar " +
- "where user.id = ?1", nativeQuery = true)
- void updateOwnerForCollection(Long userId);
- @Transactional
- @Modifying
- @Query(value = "update order_info join user on order_info.minter_id = user.id " +
- "set order_info.minter = user.nickname, " +
- " order_info.minter_avatar = user.avatar " +
- "where user.id = ?1", nativeQuery = true)
- void updateMinterForOrder(Long userId);
- @Transactional
- @Modifying
- @Query(value = "update asset join user on asset.minter_id = user.id " +
- "set asset.minter = user.nickname, " +
- " asset.minter_avatar = user.avatar " +
- "where user.id = ?1", nativeQuery = true)
- void updateMinterForAsset(Long userId);
- }
|