UserPackageRepo.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. package com.izouma.jiashanxia.repo;
  2. import com.izouma.jiashanxia.domain.UserPackage;
  3. import com.izouma.jiashanxia.dto.UserPackageDTO;
  4. import com.izouma.jiashanxia.enums.PackageType;
  5. import org.springframework.data.jpa.repository.JpaRepository;
  6. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  7. import org.springframework.data.jpa.repository.Modifying;
  8. import org.springframework.data.jpa.repository.Query;
  9. import javax.transaction.Transactional;
  10. import java.util.List;
  11. public interface UserPackageRepo extends JpaRepository<UserPackage, Long>, JpaSpecificationExecutor<UserPackage> {
  12. @Query("update UserPackage t set t.del = true where t.id = ?1")
  13. @Modifying
  14. @Transactional
  15. void softDelete(Long id);
  16. List<UserPackage> findAllByUserId(Long userId);
  17. List<UserPackage> findAllByUserIdAndType(Long userId, PackageType type);
  18. @Query("update UserPackage t set t.userId = ?2 where t.userId = ?1 and t.type = 'TEAM'")
  19. @Modifying
  20. @Transactional
  21. void updateUserId(Long oldUserId,Long newUserId);
  22. @Query(value = "select goods_info.*, ifnull(user_package.num, 0) as num " +
  23. "from goods_info " +
  24. "left join user_package on goods_info.id = user_package.goods_info_id and user_package.user_id = ?1 " +
  25. "where goods_info.del = 0", nativeQuery = true)
  26. List<UserPackageDTO> userPackage(Long userId);
  27. }