diff --git a/luoo_common/src/main/java/constants/ErrorConstants.java b/luoo_common/src/main/java/constants/ErrorConstants.java new file mode 100644 index 0000000..496fa81 --- /dev/null +++ b/luoo_common/src/main/java/constants/ErrorConstants.java @@ -0,0 +1,27 @@ +package constants; + +/** + * @Author: yawei.huang + * @Package: constants + * @Project: luoo_parent + * @Date: 2024/5/6 9:14 + * @Filename: ErrorConstants + * @Describe: 报错信息,方便国际化 + */ +public class ErrorConstants { + public final static String MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE = "必须在新建状态下申请审核"; + + public final static String MUST_OPERATE_IN_PERSON = "必须本人操作"; + + public final static String USER_VERIFICATION_FAILURE = "用户校验失败,请重新登录"; + + public final static String THE_SONG_DOES_NOT_EXIST = "该专辑不存在此歌曲"; + + public final static String ALBUM_DOES_NOT_EXIST = "专辑不存在,请刷新后重试"; + + public final static String CAUSE_OF_FORCE_MAJEURE = "专辑因不可抗力原因无法显示"; + + public final static String PRICE_CAN_NOT_BE_EMPTY = "定价不能为空"; + + public final static String PRICING_MUST_BE_GREATER_THAN_0 = "定价必须大于0"; +} diff --git a/luoo_common/src/main/java/enums/AlbumStateEnum.java b/luoo_common/src/main/java/enums/AlbumStateEnum.java index 35ae8b3..f9a149a 100644 --- a/luoo_common/src/main/java/enums/AlbumStateEnum.java +++ b/luoo_common/src/main/java/enums/AlbumStateEnum.java @@ -36,4 +36,13 @@ public enum AlbumStateEnum { this.code = code; this.desc = desc; } + + public static AlbumStateEnum getByStatus(Integer code) { + for (AlbumStateEnum al : AlbumStateEnum.values()) { + if (al.code.equals(code)) { + return al; + } + } + return null; + } } diff --git a/luoo_common/src/main/java/enums/SongInfoChargeEnum.java b/luoo_common/src/main/java/enums/SongInfoChargeEnum.java new file mode 100644 index 0000000..1d61307 --- /dev/null +++ b/luoo_common/src/main/java/enums/SongInfoChargeEnum.java @@ -0,0 +1,27 @@ +package enums; + +import lombok.Getter; + +/** + * @Author: yawei.huang + * @Package: enums + * @Project: luoo_parent + * @Date: 2024/5/6 9:52 + * @Filename: SongInfoChargeEnum + * @Describe: 歌曲是否免费 + */ +@Getter +public enum SongInfoChargeEnum { + CHARGE(1, "收费"), + FREE(2, "收费"); + + private Integer code; + + private String desc; + + + SongInfoChargeEnum(Integer code, String desc) { + this.code = code; + this.desc = desc; + } +} diff --git a/luoo_music/src/main/java/com/luoo/music/controller/AlbumController.java b/luoo_music/src/main/java/com/luoo/music/controller/AlbumController.java index 7c3f1e8..38e3f0a 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/AlbumController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/AlbumController.java @@ -90,5 +90,13 @@ public class AlbumController { return Result.success(); } + @ApiOperation(value = "申请审核", notes = "申请审核") + @RequestMapping(value = "/check/apply/{id}", method = RequestMethod.POST) + public Result checkForApply(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, + @ApiParam(value = "专辑id") @PathVariable String id) { + albumService.checkForApply(token, id); + return Result.success(); + } + } diff --git a/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java b/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java index 40ccc0e..2cc1010 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java @@ -42,9 +42,10 @@ public interface SongInfoDao extends JpaRepository, JpaSpecifi @Query(value = "select * from tb_song_info where match(name, artist, album) against(?1 IN BOOLEAN MODE) limit ?2,?3 ", nativeQuery = true) List fuzzySearch(String keyword, int offset, int limit); - @Query(value = "select * from tb_song_info where id in (\n" + - " select song_id from tb_artist_album_song where album_id = ?\n" + - " \n" + - " )", nativeQuery = true) + @Query(value = "select t2.* from tb_artist_album_song t1 \n" + + " left join tb_song_info t2 \n" + + " on t1.song_id = t2.id\n" + + " where t1.album_id = ?1\n" + + " ORDER BY t1.sort", nativeQuery = true) List findByAlbumId(String id); } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumAddDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumAddDTO.java index 0c90b3f..59b2900 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumAddDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumAddDTO.java @@ -25,39 +25,53 @@ public class AlbumAddDTO implements Serializable { @ApiModelProperty("专辑名称") @NotNull(message = "专辑名称不能为空") private String name; - /** - * 专辑封面 - */ - @ApiModelProperty("专辑封面") - private String image; + /** * 专辑版本 */ @ApiModelProperty("专辑版本") private Integer version; + /** - * 发行日期 + * 专辑类型 */ - @ApiModelProperty("发行日期") - private Date publishDate; + @ApiModelProperty("专辑类型") + @NotNull(message = "专辑类型不能为空") + private Integer type; + /** - * 主要风格 + * 专辑风格 */ - @ApiModelProperty("风格") - @NotNull(message = "风格不能为空") + @ApiModelProperty("专辑风格") + @NotNull(message = "专辑风格不能为空") private String mainStyle; + /** + * 发行日期 + */ + @ApiModelProperty("发行日期") + @NotNull(message = "发行日期不能为空") + private Date publishDate; + /** * 专辑条码 */ @ApiModelProperty("专辑条码") private String barcode; + /** * 专辑描述 */ @ApiModelProperty("专辑描述") private String description; + /** + * 专辑封面 + */ + @ApiModelProperty("专辑封面") + @NotNull(message = "专辑封面不能为空") + private String image; + /** * 音乐人id */ diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java index fca1c14..8ed88dd 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java @@ -23,14 +23,26 @@ public class AlbumSongAddDTO implements Serializable { @NotNull(message = "歌曲名称不能为空") private String name; - @ApiModelProperty("语种") - private Integer language; + @ApiModelProperty("歌曲版本") + @NotNull(message = "歌曲版本不能为空") + private Integer version; + + @ApiModelProperty("是否收费") + @NotNull(message = "是否收费不能为空") + private Integer charge; + + @ApiModelProperty("歌曲定价") + private Float price; + + @ApiModelProperty("歌手") + @NotBlank(message = "歌手不能为空") + private String albumStr; @ApiModelProperty("曲风") private List tags; - @ApiModelProperty("售价") - private float price; + @ApiModelProperty("语种") + private List language; @ApiModelProperty("作词") private String lyricName; @@ -38,9 +50,6 @@ public class AlbumSongAddDTO implements Serializable { @ApiModelProperty("作曲") private String compositionName; -// @ApiModelProperty("编曲") -// private String arrangementName; - @ApiModelProperty("歌词") private String lyric; @@ -48,12 +57,9 @@ public class AlbumSongAddDTO implements Serializable { @NotNull(message = "歌曲不能为空") private String url; - @ApiModelProperty("歌曲版本") - private Integer version; - - @ApiModelProperty("歌手") - @NotBlank(message = "歌手不能为空") - private String albumStr; + @ApiModelProperty("排序") + @NotNull(message = "排序不能为空") + private Integer sort; // @ApiModelProperty("mv") // private String mvUrl; diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java index 033448f..d68d128 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java @@ -35,11 +35,19 @@ public class ArtistAlbum implements Serializable { @Id private String id; + /** * 专辑名称 */ @ApiModelProperty("专辑名称") private String name; + + /** + * 专辑类型 + */ + @ApiModelProperty("专辑类型") + private Integer type; + /** * 专辑封面 */ @@ -49,7 +57,7 @@ public class ArtistAlbum implements Serializable { /** * 专辑状态 */ - @ApiModelProperty("专辑状态") + @ApiModelProperty("专辑状态 -1:不可抗力原因不允许显示 0:新建 1:待审核 2:退回 3:待上架 4:已上架 5:已删除") private Integer state; /** @@ -57,6 +65,7 @@ public class ArtistAlbum implements Serializable { */ @ApiModelProperty("发行日期") private Date publishDate; + /** * 主要风格 */ @@ -68,11 +77,13 @@ public class ArtistAlbum implements Serializable { */ @ApiModelProperty("专辑条码") private String barcode; + /** * 专辑描述 */ @ApiModelProperty("专辑描述") private String description; + /** * 创建时间 */ @@ -80,6 +91,7 @@ public class ArtistAlbum implements Serializable { @CreatedDate @ApiModelProperty("创建时间") private LocalDateTime createTime; + /** * 修改时间 */ @@ -87,21 +99,25 @@ public class ArtistAlbum implements Serializable { @LastModifiedDate @ApiModelProperty("修改时间") private LocalDateTime updateTime; + /** * 音乐人id */ @ApiModelProperty("音乐人id") private String artistId; + /** * 音乐人昵称 */ @ApiModelProperty("音乐人昵称") private String artistName; + /** * 创建人 */ @ApiModelProperty("创建人") private String createUser; + /** * 修改人 */ @@ -123,6 +139,9 @@ public class ArtistAlbum implements Serializable { @ApiModelProperty("风格列表") private List style; + @Transient + @ApiModelProperty("专辑状态-中文") + private String stateStr; } diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java index b0c74ce..ab4c4cf 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java @@ -11,6 +11,7 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.time.LocalDateTime; import java.util.List; @@ -102,6 +103,14 @@ public class SongInfo implements Serializable { @ApiModelProperty("作曲") private String compositionName; + @ApiModelProperty("是否收费") + @NotNull(message = "是否收费不能为空") + private Integer charge; + + @ApiModelProperty("歌曲定价") + private Float price; + + // @ApiModelProperty("编曲") // private String arrangementName; diff --git a/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java b/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java index 1f2bdca..455b827 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java @@ -8,8 +8,10 @@ import com.luoo.music.dto.response.AlbumSongAddDTO; import com.luoo.music.dto.response.AlbumUpdateDTO; import com.luoo.music.pojo.*; import com.luoo.music.util.Constants; +import constants.ErrorConstants; import dto.UserLoginDto; import enums.AlbumStateEnum; +import enums.SongInfoChargeEnum; import enums.SongInfoStateEnum; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; @@ -29,6 +31,7 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import javax.validation.Valid; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -86,6 +89,12 @@ public class AlbumService { result = albumPage.getContent(); for (ArtistAlbum artistAlbum : result) { + if (artistAlbum.getState() != null) { + // 中文状态名 + AlbumStateEnum byStatus = AlbumStateEnum.getByStatus(artistAlbum.getState()); + artistAlbum.setStateStr(byStatus != null ? byStatus.getDesc() : ""); + } + //todo 传递点赞,喜欢,评论,收益 } long totalElements = albumPage.getTotalElements(); @@ -168,23 +177,25 @@ public class AlbumService { public ArtistAlbum getOne(String id) { ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get(); if (artistAlbum == null) { - throw new RuntimeException("专辑不存在,请刷新后重试"); + // 专辑不存在,请刷新后重试 + throw new RuntimeException(ErrorConstants.ALBUM_DOES_NOT_EXIST); } if (ObjectUtils.equals(AlbumStateEnum.FORCE.getCode(), artistAlbum.getState())) { - throw new RuntimeException("专辑因不可抗力原因无法显示"); + // 专辑因不可抗力原因无法显示 + throw new RuntimeException(ErrorConstants.CAUSE_OF_FORCE_MAJEURE); } // 整个数据库所有的tag List tagAllList = tagDao.findAll(); Map tagMap = tagAllList.stream().collect(Collectors.toMap(Tag::getId, item -> item)); - log.info("------tagMap:{}",tagMap); + log.info("------tagMap:{}", tagMap); // 处理album基础信息 - if(StringUtils.isNotBlank(artistAlbum.getMainStyle())) { + if (StringUtils.isNotBlank(artistAlbum.getMainStyle())) { List style = new ArrayList<>(); String[] mainStyleArr = artistAlbum.getMainStyle().split(","); for (String s : mainStyleArr) { - if(StringUtils.isNotBlank(s)) { + if (StringUtils.isNotBlank(s)) { style.add(tagMap.get(s)); } } @@ -244,16 +255,15 @@ public class AlbumService { if (user != null) { artistAlbum.setCreateUser(user.getUserId()); } else { - throw new RuntimeException("用户校验失败,请重新登录"); + // 用户校验失败,请重新登录 + throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE); } artistAlbum.setState(AlbumStateEnum.SAVE.getCode()); artistAlbumDao.save(artistAlbum); // 处理歌曲对象 List songAddList = albumAddDTO.getSongAddList(); - if (songAddList.isEmpty()) { - throw new RuntimeException("专辑音乐不能为空!"); - } else { + if (!songAddList.isEmpty()) { for (AlbumSongAddDTO albumSongAddDTO : songAddList) { addSongForAlbum(albumSongAddDTO, user, artistAlbum); } @@ -274,11 +284,13 @@ public class AlbumService { UserLoginDto user = jwtUtil.getUserLoginDto(token); if (user != null) { if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) { - throw new RuntimeException("只允许本人操作!"); + // 必须本人操作 + throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE); } artistAlbum.setUpdateUser(user.getUserId()); } else { - throw new RuntimeException("用户校验失败,请重新登录"); + // 用户校验失败,请重新登 + throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE); } artistAlbumDao.save(artistAlbum); @@ -309,7 +321,8 @@ public class AlbumService { ArtistAlbumSong artistAlbumSong = artistAlbumSongDao.findById(id).get(); if (artistAlbumSong.getId() == null) { - throw new RuntimeException("该专辑不存在此歌曲"); + // 该专辑不存在此歌曲 + throw new RuntimeException(ErrorConstants.THE_SONG_DOES_NOT_EXIST); } checkAlbum(token, artistAlbumSong.getAlbumId()); @@ -322,7 +335,7 @@ public class AlbumService { * * @param token token * @param id 专辑id - * @return 如果是本人操作,返回该专辑对象 + * @return 如果是本人操作,返回该专辑对象 */ private ArtistAlbum checkAlbum(String token, String id) { ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get(); @@ -330,10 +343,12 @@ public class AlbumService { UserLoginDto user = jwtUtil.getUserLoginDto(token); if (user != null) { if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) { - throw new RuntimeException("只允许本人操作!"); + // 必须本人操作 + throw new RuntimeException(ErrorConstants.MUST_OPERATE_IN_PERSON); } } else { - throw new RuntimeException("用户校验失败,请重新登录"); + // 用户校验失败,请重新登录 + throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE); } return artistAlbum; } @@ -352,6 +367,16 @@ public class AlbumService { addSongForAlbum(albumSongAddDTO, user, artistAlbum); } + @Transactional(rollbackFor = Exception.class) + public void checkForApply(String token, String id) { + UserLoginDto user = jwtUtil.getUserLoginDto(token); + ArtistAlbum artistAlbum = checkAlbum(token, id); + if (ObjectUtils.notEqual(AlbumStateEnum.SAVE.getCode(), artistAlbum.getState())) { + // 必须在新建状态下申请审核 + throw new RuntimeException(ErrorConstants.MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE); + } + } + /** * 为专辑新增歌曲 * @@ -359,7 +384,18 @@ public class AlbumService { * @param user 当前登录用户 * @param artistAlbum 专辑对象 */ - private void addSongForAlbum(AlbumSongAddDTO albumSongAddDTO, UserLoginDto user, ArtistAlbum artistAlbum) { + private void addSongForAlbum(@Valid AlbumSongAddDTO albumSongAddDTO, UserLoginDto user, ArtistAlbum artistAlbum) { + + if(ObjectUtils.notEqual(SongInfoChargeEnum.CHARGE.getCode(), artistAlbum.getChargeType())) { + if(albumSongAddDTO.getPrice() == null) { + // 定价不能为空 + throw new RuntimeException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY); + } + if(albumSongAddDTO.getPrice() <= 0) { + // 定价必须大于0 + throw new RuntimeException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0); + } + } String albumName = artistAlbum.getName(); String artistName = artistAlbum.getArtistName(); @@ -374,7 +410,7 @@ public class AlbumService { if (user != null) { artistAlbum.setCreateUser(user.getUserId()); } else { - throw new RuntimeException("用户校验失败,请重新登录"); + throw new RuntimeException(ErrorConstants.MUST_OPERATE_IN_PERSON); } songInfoDao.save(songInfo); @@ -389,10 +425,11 @@ public class AlbumService { songInfoDao.updateSongLyricAndUrl(id, lyric, lyricUrl); } - // 曲风绑定 + // 曲风和语言绑定 List tags = albumSongAddDTO.getTags(); + List language = albumSongAddDTO.getLanguage(); + tags.addAll(language); if (!tags.isEmpty()) { - songTagDao.deleteBySongId(id); List songTagList = new ArrayList<>(); for (String item : tags) { SongTag songTag = new SongTag(); diff --git a/luoo_music/src/main/resources/sql/20240506.sql b/luoo_music/src/main/resources/sql/20240506.sql new file mode 100644 index 0000000..3ef5f33 --- /dev/null +++ b/luoo_music/src/main/resources/sql/20240506.sql @@ -0,0 +1,9 @@ +alter table tb_artist_album + add type int null comment '专辑类型' after name; + +alter table tb_song_info + add charge int null comment '是否收费 1-收费 2-免费'; + +alter table tb_artist_album_song + add sort int null comment '排序'; +