feat: 初始化音乐项目后台管理系统- 新增后台管理相关页面和功能组件
- 实现管理员评论管理、数据统计等功能 - 添加后台布局和路由管理 -配置数据库和Redis连接 - 实现文件上传和访问路径配置 - 添加Sa-Token安全配置
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Banner;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 轮播图数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface BannerRepository extends JpaRepository<Banner, Long> {
|
||||
|
||||
/**
|
||||
* 根据状态查询轮播图
|
||||
*
|
||||
* @param status 状态
|
||||
* @return 轮播图列表
|
||||
*/
|
||||
List<Banner> findByStatusOrderByOrderNumAsc(Integer status);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Comment;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 评论数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface CommentRepository extends JpaRepository<Comment, Long>, JpaSpecificationExecutor<Comment> {
|
||||
|
||||
/**
|
||||
* 根据目标ID和目标类型查询评论
|
||||
*
|
||||
* @param targetId 目标ID
|
||||
* @param targetType 目标类型
|
||||
* @param pageable 分页
|
||||
* @return 评论列表
|
||||
*/
|
||||
Page<Comment> findByTargetIdAndTargetTypeAndParentIdIsNullOrderByCreateTimeDesc(Long targetId, Integer targetType, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据父评论ID查询子评论
|
||||
*
|
||||
* @param parentId 父评论ID
|
||||
* @return 子评论列表
|
||||
*/
|
||||
List<Comment> findByParentIdOrderByCreateTimeAsc(Long parentId);
|
||||
|
||||
/**
|
||||
* 根据用户查询评论
|
||||
*
|
||||
* @param user 用户
|
||||
* @param pageable 分页
|
||||
* @return 评论列表
|
||||
*/
|
||||
Page<Comment> findByUserOrderByCreateTimeDesc(User user, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据目标ID和目标类型统计评论数量
|
||||
*
|
||||
* @param targetId 目标ID
|
||||
* @param targetType 目标类型
|
||||
* @return 评论数量
|
||||
*/
|
||||
long countByTargetIdAndTargetType(Long targetId, Integer targetType);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Music;
|
||||
import com.test.musichouduan.entity.MusicType;
|
||||
import com.test.musichouduan.entity.Singer;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 音乐数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface MusicRepository extends JpaRepository<Music, Long>, JpaSpecificationExecutor<Music> {
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询音乐
|
||||
*
|
||||
* @param name 名称
|
||||
* @param pageable 分页
|
||||
* @return 音乐列表
|
||||
*/
|
||||
Page<Music> findByNameContaining(String name, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据类型查询音乐
|
||||
*
|
||||
* @param type 类型
|
||||
* @param pageable 分页
|
||||
* @return 音乐列表
|
||||
*/
|
||||
@Query("SELECT m FROM Music m JOIN m.types t WHERE t = :type")
|
||||
Page<Music> findByType(MusicType type, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据歌手查询音乐
|
||||
*
|
||||
* @param singer 歌手
|
||||
* @param pageable 分页
|
||||
* @return 音乐列表
|
||||
*/
|
||||
@Query("SELECT m FROM Music m JOIN m.singers s WHERE s = :singer")
|
||||
Page<Music> findBySinger(Singer singer, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据歌手查询音乐
|
||||
*
|
||||
* @param singer 歌手
|
||||
* @param pageable 分页
|
||||
* @return 音乐列表
|
||||
*/
|
||||
Page<Music> findBySingersContaining(Singer singer, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 统计歌手的音乐数量
|
||||
*
|
||||
* @param singer 歌手
|
||||
* @return 音乐数量
|
||||
*/
|
||||
Long countBySingersContaining(Singer singer);
|
||||
|
||||
/**
|
||||
* 检查是否存在指定类型的音乐
|
||||
*
|
||||
* @param type 音乐类型
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByTypesContaining(MusicType type);
|
||||
|
||||
/**
|
||||
* 查询最新的音乐
|
||||
*
|
||||
* @param pageable 分页
|
||||
* @return 音乐列表
|
||||
*/
|
||||
@Query("SELECT m FROM Music m ORDER BY m.createTime DESC")
|
||||
List<Music> findLatest(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询播放次数最多的音乐
|
||||
*
|
||||
* @param pageable 分页
|
||||
* @return 音乐列表
|
||||
*/
|
||||
@Query("SELECT m FROM Music m ORDER BY m.playCount DESC")
|
||||
List<Music> findMostPlayed(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 统计包含指定类型的音乐数量
|
||||
*
|
||||
* @param type 音乐类型
|
||||
* @return 音乐数量
|
||||
*/
|
||||
long countByTypesContaining(MusicType type);
|
||||
|
||||
/**
|
||||
* 统计所有音乐的总播放量
|
||||
*
|
||||
* @return 总播放量
|
||||
*/
|
||||
@Query("SELECT COALESCE(SUM(m.playCount), 0) FROM Music m")
|
||||
long sumPlayCount();
|
||||
|
||||
/**
|
||||
* 统计各个音乐类型的音乐数量
|
||||
*
|
||||
* @return 音乐类型及其对应的音乐数量
|
||||
*/
|
||||
@Query("SELECT t.name, COUNT(m) FROM Music m JOIN m.types t GROUP BY t.name ORDER BY COUNT(m) DESC")
|
||||
List<Object[]> countByMusicType();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.MusicType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 音乐类型数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface MusicTypeRepository extends JpaRepository<MusicType, Long>, JpaSpecificationExecutor<MusicType> {
|
||||
|
||||
/**
|
||||
* 根据名称查找音乐类型
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 音乐类型
|
||||
*/
|
||||
Optional<MusicType> findByName(String name);
|
||||
|
||||
/**
|
||||
* 判断名称是否存在
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Music;
|
||||
import com.test.musichouduan.entity.PlayHistory;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 播放历史数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayHistoryRepository extends JpaRepository<PlayHistory, Long> {
|
||||
|
||||
/**
|
||||
/**
|
||||
/**
|
||||
* 根据用户查询播放历史
|
||||
*
|
||||
* @param user 用户
|
||||
* @param pageable 分页
|
||||
* @return 播放历史列表
|
||||
*/
|
||||
Page<PlayHistory> findByUserOrderByPlayTimeDesc(User user, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据用户和音乐查询播放历史
|
||||
*
|
||||
* @param user 用户
|
||||
* @param music 音乐
|
||||
* @return 播放历史
|
||||
*/
|
||||
Optional<PlayHistory> findByUserAndMusic(User user, Music music);
|
||||
|
||||
/**
|
||||
* 根据用户统计播放历史数量
|
||||
*
|
||||
* @param user 用户
|
||||
* @return 播放历史数量
|
||||
*/
|
||||
long countByUser(User user);
|
||||
|
||||
/**
|
||||
* 根据音乐统计播放次数
|
||||
*
|
||||
* @param music 音乐
|
||||
* @return 播放次数
|
||||
*/
|
||||
long countByMusic(Music music);
|
||||
|
||||
/**
|
||||
* 统计指定时间范围内的播放次数
|
||||
*
|
||||
* @param start 开始时间
|
||||
* @param end 结束时间
|
||||
* @return 播放次数
|
||||
*/
|
||||
|
||||
long countByPlayTimeBetween(LocalDateTime start, LocalDateTime end);
|
||||
|
||||
/**
|
||||
*记录播放历史
|
||||
* @param userId 用户ID
|
||||
* @param musicId 音乐ID
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "INSERT INTO play_history (user_id, music_id, play_time) VALUES (?1, ?2, NOW()) " +
|
||||
"ON DUPLICATE KEY UPDATE play_time = NOW()", nativeQuery = true)
|
||||
void recordPlayHistory(Long userId, Long musicId);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Playlist;
|
||||
import com.test.musichouduan.entity.PlaylistType;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 歌单数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface PlaylistRepository extends JpaRepository<Playlist, Long>, JpaSpecificationExecutor<Playlist> {
|
||||
|
||||
@Query("SELECT pt.name, COUNT(p) FROM Playlist p JOIN p.type pt GROUP BY pt.name")
|
||||
List<Object[]> countByPlaylistType();
|
||||
|
||||
/**
|
||||
* 根据类型统计歌单数量
|
||||
*
|
||||
* @param type 歌单类型
|
||||
* @return 歌单数量
|
||||
*/
|
||||
long countByType(PlaylistType type);
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询歌单
|
||||
*
|
||||
* @param name 名称
|
||||
* @param pageable 分页
|
||||
* @return 歌单列表
|
||||
*/
|
||||
Page<Playlist> findByNameContaining(String name, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据类型查询歌单
|
||||
*
|
||||
* @param type 类型
|
||||
* @param pageable 分页
|
||||
* @return 歌单列表
|
||||
*/
|
||||
Page<Playlist> findByType(PlaylistType type, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据创建者查询歌单
|
||||
*
|
||||
* @param creator 创建者
|
||||
* @param pageable 分页
|
||||
* @return 歌单列表
|
||||
*/
|
||||
Page<Playlist> findByCreator(User creator, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询官方歌单
|
||||
*
|
||||
* @param pageable 分页
|
||||
* @return 歌单列表
|
||||
*/
|
||||
Page<Playlist> findByIsOfficial(Integer isOfficial, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询最新的歌单
|
||||
*
|
||||
* @param pageable 分页
|
||||
* @return 歌单列表
|
||||
*/
|
||||
@Query("SELECT p FROM Playlist p ORDER BY p.createTime DESC")
|
||||
List<Playlist> findLatest(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询播放次数最多的歌单
|
||||
*
|
||||
* @param pageable 分页
|
||||
* @return 歌单列表
|
||||
*/
|
||||
@Query("SELECT p FROM Playlist p ORDER BY p.playCount DESC")
|
||||
List<Playlist> findMostPlayed(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 统计用户创建的歌单数量
|
||||
*
|
||||
* @param creator 创建者
|
||||
* @return 歌单数量
|
||||
*/
|
||||
long countByCreator(User creator);
|
||||
|
||||
/**
|
||||
* 检查是否存在指定类型的歌单
|
||||
*
|
||||
* @param type 歌单类型
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByType(PlaylistType type);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.PlaylistType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 歌单类型数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface PlaylistTypeRepository extends JpaRepository<PlaylistType, Long>, JpaSpecificationExecutor<PlaylistType> {
|
||||
|
||||
/**
|
||||
* 根据名称查找歌单类型
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 歌单类型
|
||||
*/
|
||||
Optional<PlaylistType> findByName(String name);
|
||||
|
||||
/**
|
||||
* 判断名称是否存在
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Singer;
|
||||
import com.test.musichouduan.entity.SingerType;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 歌手数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface SingerRepository extends JpaRepository<Singer, Long>, JpaSpecificationExecutor<Singer> {
|
||||
|
||||
@Query("SELECT st.name, COUNT(s) FROM Singer s JOIN s.type st GROUP BY st.name")
|
||||
List<Object[]> countBySingerType();
|
||||
|
||||
/**
|
||||
* 根据类型统计歌手数量
|
||||
*
|
||||
* @param type 歌手类型
|
||||
* @return 歌手数量
|
||||
*/
|
||||
long countByType(SingerType type);
|
||||
|
||||
/**
|
||||
* 根据名称查找歌手
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 歌手
|
||||
*/
|
||||
Optional<Singer> findByName(String name);
|
||||
|
||||
/**
|
||||
* 根据类型查找歌手
|
||||
*
|
||||
* @param type 类型
|
||||
* @param pageable 分页
|
||||
* @return 歌手列表
|
||||
*/
|
||||
Page<Singer> findByType(SingerType type, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询歌手
|
||||
*
|
||||
* @param name 名称
|
||||
* @param pageable 分页
|
||||
* @return 歌手列表
|
||||
*/
|
||||
Page<Singer> findByNameContaining(String name, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询最新的歌手
|
||||
*
|
||||
* @param limit 限制数量
|
||||
* @return 歌手列表
|
||||
*/
|
||||
@Query(value = "SELECT s FROM Singer s ORDER BY s.createTime DESC")
|
||||
List<Singer> findLatest(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询热门歌手(按照音乐数量排序)
|
||||
*
|
||||
* @param pageable 分页
|
||||
* @return 歌手列表
|
||||
*/
|
||||
@Query(value = "SELECT s.* FROM singer s LEFT JOIN (SELECT singer_id, COUNT(*) as music_count FROM music_singer GROUP BY singer_id) ms ON s.id = ms.singer_id ORDER BY COALESCE(ms.music_count, 0) DESC", nativeQuery = true)
|
||||
List<Singer> findHotSingers(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 检查是否存在指定类型的歌手
|
||||
*
|
||||
* @param type 歌手类型
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByType(SingerType type);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.SingerType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 歌手类型数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface SingerTypeRepository extends JpaRepository<SingerType, Long>, JpaSpecificationExecutor<SingerType> {
|
||||
|
||||
/**
|
||||
* 根据名称查找歌手类型
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 歌手类型
|
||||
*/
|
||||
Optional<SingerType> findByName(String name);
|
||||
|
||||
/**
|
||||
* 判断名称是否存在
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Music;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import com.test.musichouduan.entity.UserCollectMusic;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 用户收藏音乐数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface UserCollectMusicRepository extends JpaRepository<UserCollectMusic, Long> {
|
||||
|
||||
/**
|
||||
* 根据用户查询收藏的音乐
|
||||
*
|
||||
* @param user 用户
|
||||
* @param pageable 分页
|
||||
* @return 收藏的音乐列表
|
||||
*/
|
||||
Page<UserCollectMusic> findByUser(User user, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据用户和音乐查询收藏记录
|
||||
*
|
||||
* @param user 用户
|
||||
* @param music 音乐
|
||||
* @return 收藏记录
|
||||
*/
|
||||
Optional<UserCollectMusic> findByUserAndMusic(User user, Music music);
|
||||
|
||||
/**
|
||||
* 判断用户是否收藏了音乐
|
||||
*
|
||||
* @param user 用户
|
||||
* @param music 音乐
|
||||
* @return 是否收藏
|
||||
*/
|
||||
boolean existsByUserAndMusic(User user, Music music);
|
||||
|
||||
/**
|
||||
* 根据用户统计收藏的音乐数量
|
||||
*
|
||||
* @param user 用户
|
||||
* @return 收藏的音乐数量
|
||||
*/
|
||||
long countByUser(User user);
|
||||
|
||||
/**
|
||||
* 根据音乐统计被收藏的次数
|
||||
*
|
||||
* @param music 音乐
|
||||
* @return 被收藏的次数
|
||||
*/
|
||||
long countByMusic(Music music);
|
||||
|
||||
/**
|
||||
* 根据用户和音乐删除收藏记录
|
||||
*
|
||||
* @param user 用户
|
||||
* @param music 音乐
|
||||
*/
|
||||
void deleteByUserAndMusic(User user, Music music);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Playlist;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import com.test.musichouduan.entity.UserCollectPlaylist;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 用户收藏歌单数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface UserCollectPlaylistRepository extends JpaRepository<UserCollectPlaylist, Long> {
|
||||
|
||||
/**
|
||||
* 根据用户查询收藏的歌单
|
||||
*
|
||||
* @param user 用户
|
||||
* @param pageable 分页
|
||||
* @return 收藏的歌单列表
|
||||
*/
|
||||
Page<UserCollectPlaylist> findByUser(User user, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据用户和歌单查询收藏记录
|
||||
*
|
||||
* @param user 用户
|
||||
* @param playlist 歌单
|
||||
* @return 收藏记录
|
||||
*/
|
||||
Optional<UserCollectPlaylist> findByUserAndPlaylist(User user, Playlist playlist);
|
||||
|
||||
/**
|
||||
* 判断用户是否收藏了歌单
|
||||
*
|
||||
* @param user 用户
|
||||
* @param playlist 歌单
|
||||
* @return 是否收藏
|
||||
*/
|
||||
boolean existsByUserAndPlaylist(User user, Playlist playlist);
|
||||
|
||||
/**
|
||||
* 根据用户统计收藏的歌单数量
|
||||
*
|
||||
* @param user 用户
|
||||
* @return 收藏的歌单数量
|
||||
*/
|
||||
long countByUser(User user);
|
||||
|
||||
/**
|
||||
* 根据歌单统计被收藏的次数
|
||||
*
|
||||
* @param playlist 歌单
|
||||
* @return 被收藏的次数
|
||||
*/
|
||||
long countByPlaylist(Playlist playlist);
|
||||
|
||||
/**
|
||||
* 根据用户和歌单删除收藏记录
|
||||
*
|
||||
* @param user 用户
|
||||
* @param playlist 歌单
|
||||
*/
|
||||
void deleteByUserAndPlaylist(User user, Playlist playlist);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Singer;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import com.test.musichouduan.entity.UserCollectSinger;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 用户收藏歌手数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface UserCollectSingerRepository extends JpaRepository<UserCollectSinger, Long> {
|
||||
|
||||
/**
|
||||
* 根据用户查询收藏的歌手
|
||||
*
|
||||
* @param user 用户
|
||||
* @param pageable 分页
|
||||
* @return 收藏的歌手列表
|
||||
*/
|
||||
Page<UserCollectSinger> findByUser(User user, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据用户和歌手查询收藏记录
|
||||
*
|
||||
* @param user 用户
|
||||
* @param singer 歌手
|
||||
* @return 收藏记录
|
||||
*/
|
||||
Optional<UserCollectSinger> findByUserAndSinger(User user, Singer singer);
|
||||
|
||||
/**
|
||||
* 判断用户是否收藏了歌手
|
||||
*
|
||||
* @param user 用户
|
||||
* @param singer 歌手
|
||||
* @return 是否收藏
|
||||
*/
|
||||
boolean existsByUserAndSinger(User user, Singer singer);
|
||||
|
||||
/**
|
||||
* 根据用户统计收藏的歌手数量
|
||||
*
|
||||
* @param user 用户
|
||||
* @return 收藏的歌手数量
|
||||
*/
|
||||
long countByUser(User user);
|
||||
|
||||
/**
|
||||
* 根据歌手统计被收藏的次数
|
||||
*
|
||||
* @param singer 歌手
|
||||
* @return 被收藏的次数
|
||||
*/
|
||||
long countBySinger(Singer singer);
|
||||
|
||||
/**
|
||||
* 根据用户和歌手删除收藏记录
|
||||
*
|
||||
* @param user 用户
|
||||
* @param singer 歌手
|
||||
*/
|
||||
void deleteByUserAndSinger(User user, Singer singer);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Music;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import com.test.musichouduan.entity.UserMusic;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 用户音乐关联数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface UserMusicRepository extends JpaRepository<UserMusic, Long> {
|
||||
|
||||
/**
|
||||
* 判断用户是否已收藏音乐
|
||||
*
|
||||
* @param user 用户
|
||||
* @param music 音乐
|
||||
* @return 是否已收藏
|
||||
*/
|
||||
boolean existsByUserAndMusic(User user, Music music);
|
||||
|
||||
/**
|
||||
* 判断用户是否已收藏音乐
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param musicId 音乐ID
|
||||
* @return 是否已收藏
|
||||
*/
|
||||
boolean existsByUserIdAndMusicId(Long userId, Long musicId);
|
||||
|
||||
/**
|
||||
* 收藏音乐
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param musicId 音乐ID
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "INSERT INTO user_music (user_id, music_id, collect_time) VALUES (?1, ?2, NOW())", nativeQuery = true)
|
||||
void collectMusic(Long userId, Long musicId);
|
||||
|
||||
/**
|
||||
* 取消收藏音乐
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param musicId 音乐ID
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "DELETE FROM user_music WHERE user_id = ?1 AND music_id = ?2", nativeQuery = true)
|
||||
void uncollectMusic(Long userId, Long musicId);
|
||||
|
||||
/**
|
||||
* 获取用户收藏的音乐
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param pageable 分页
|
||||
* @return 用户音乐关联分页
|
||||
*/
|
||||
@Query("SELECT um FROM UserMusic um WHERE um.user.id = ?1")
|
||||
Page<UserMusic> findCollectedMusic(Long userId, Pageable pageable);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Playlist;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import com.test.musichouduan.entity.UserPlaylist;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 用户歌单关联数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface UserPlaylistRepository extends JpaRepository<UserPlaylist, Long> {
|
||||
|
||||
/**
|
||||
* 判断用户是否已收藏歌单
|
||||
*
|
||||
* @param user 用户
|
||||
* @param playlist 歌单
|
||||
* @return 是否已收藏
|
||||
*/
|
||||
boolean existsByUserAndPlaylist(User user, Playlist playlist);
|
||||
|
||||
/**
|
||||
* 判断用户是否已收藏歌单
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param playlistId 歌单ID
|
||||
* @return 是否已收藏
|
||||
*/
|
||||
boolean existsByUserIdAndPlaylistId(Long userId, Long playlistId);
|
||||
|
||||
/**
|
||||
* 收藏歌单
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param playlistId 歌单ID
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "INSERT INTO user_playlist (user_id, playlist_id, collect_time) VALUES (?1, ?2, NOW())", nativeQuery = true)
|
||||
void collectPlaylist(Long userId, Long playlistId);
|
||||
|
||||
/**
|
||||
* 取消收藏歌单
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param playlistId 歌单ID
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "DELETE FROM user_playlist WHERE user_id = ?1 AND playlist_id = ?2", nativeQuery = true)
|
||||
void uncollectPlaylist(Long userId, Long playlistId);
|
||||
|
||||
/**
|
||||
* 获取用户收藏的歌单
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param pageable 分页
|
||||
* @return 歌单分页
|
||||
*/
|
||||
@Query("SELECT up.playlist FROM UserPlaylist up WHERE up.user.id = ?1")
|
||||
Page<Playlist> findCollectedPlaylist(Long userId, Pageable pageable);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.User;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 用户数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
|
||||
|
||||
/**
|
||||
* 根据用户名查找用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户
|
||||
*/
|
||||
Optional<User> findByUsername(String username);
|
||||
|
||||
/**
|
||||
* 根据用户名或邮箱查找用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param email 邮箱
|
||||
* @return 用户
|
||||
*/
|
||||
Optional<User> findByUsernameOrEmail(String username, String email);
|
||||
|
||||
/**
|
||||
* 判断用户名是否存在
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByUsername(String username);
|
||||
|
||||
/**
|
||||
* 判断邮箱是否存在
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean existsByEmail(String email);
|
||||
|
||||
/**
|
||||
* 统计指定时间范围内创建的用户数量
|
||||
*
|
||||
* @param start 开始时间
|
||||
* @param end 结束时间
|
||||
* @return 用户数量
|
||||
*/
|
||||
long countByCreateTimeBetween(LocalDateTime start, LocalDateTime end);
|
||||
|
||||
/**
|
||||
* 查询最新注册的用户
|
||||
*
|
||||
* @param pageable 分页
|
||||
* @return 用户列表
|
||||
*/
|
||||
@Query("SELECT u FROM User u ORDER BY u.createTime DESC")
|
||||
List<User> findLatestUsers(Pageable pageable);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.test.musichouduan.repository;
|
||||
|
||||
import com.test.musichouduan.entity.Singer;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import com.test.musichouduan.entity.UserSinger;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 用户歌手关联数据访问层
|
||||
*/
|
||||
@Repository
|
||||
public interface UserSingerRepository extends JpaRepository<UserSinger, Long> {
|
||||
|
||||
/**
|
||||
* 判断用户是否已收藏歌手
|
||||
*
|
||||
* @param user 用户
|
||||
* @param singer 歌手
|
||||
* @return 是否已收藏
|
||||
*/
|
||||
boolean existsByUserAndSinger(User user, Singer singer);
|
||||
|
||||
/**
|
||||
* 判断用户是否已收藏歌手
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param singerId 歌手ID
|
||||
* @return 是否已收藏
|
||||
*/
|
||||
boolean existsByUserIdAndSingerId(Long userId, Long singerId);
|
||||
|
||||
/**
|
||||
* 收藏歌手
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param singerId 歌手ID
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "INSERT INTO user_singer (user_id, singer_id, collect_time) VALUES (?1, ?2, NOW())", nativeQuery = true)
|
||||
void collectSinger(Long userId, Long singerId);
|
||||
|
||||
/**
|
||||
* 取消收藏歌手
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param singerId 歌手ID
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "DELETE FROM user_singer WHERE user_id = ?1 AND singer_id = ?2", nativeQuery = true)
|
||||
void uncollectSinger(Long userId, Long singerId);
|
||||
|
||||
/**
|
||||
* 获取用户收藏的歌手
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param pageable 分页
|
||||
* @return 歌手分页
|
||||
*/
|
||||
@Query("SELECT us.singer FROM UserSinger us WHERE us.user.id = ?1")
|
||||
Page<Singer> findCollectedSinger(Long userId, Pageable pageable);
|
||||
}
|
||||
Reference in New Issue
Block a user