diff --git a/luoo_common/src/main/java/constants/ErrorConstants.java b/luoo_common/src/main/java/constants/ErrorConstants.java index 4f86971..5e57e1d 100644 --- a/luoo_common/src/main/java/constants/ErrorConstants.java +++ b/luoo_common/src/main/java/constants/ErrorConstants.java @@ -28,6 +28,8 @@ public class ErrorConstants { public final static String ALBUM_SONG_LIST_IS_EMPTY = "专辑歌曲为空"; + public final static String STATE_ERROR = "状态错误"; + // 用户部分 public final static String REAL_NAME_APPROVE_IS_EXISTS = "该用户实名认证已存在"; 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 e5a995c..1832010 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 @@ -66,14 +66,6 @@ public class AlbumController { return Result.success(); } - @ApiOperation(value = "删除专辑", notes = "删除专辑") - @RequestMapping(value = "/delete", method = RequestMethod.POST) - public Result delete(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, - @ApiParam(value = "专辑id", required = true) String id) { - albumService.deleteAlbum(token, id); - return Result.success(); - } - @ApiOperation(value = "删除专辑中的歌曲", notes = "删除专辑中的歌曲") @RequestMapping(value = "/delete/song", method = RequestMethod.POST) public Result deleteAlbumSong(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @@ -91,13 +83,16 @@ 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); + @ApiOperation(value = "修改专辑状态", notes = "修改专辑状态") + @PostMapping(value = "/change/state/{id}/{state}") + public Result changeState(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, + @ApiParam(value = "专辑id") @PathVariable String id, + @ApiParam(value = "想要修改的状态值 -1:不可抗力原因不允许显示,0:新建,1:待审核,2:退回,3:待上架,4:已上架,5:已删除")@PathVariable Integer state) { + albumService.changeAlbumState(token, id, state); return Result.success(); } + + } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumUpdateDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumUpdateDTO.java index 13c3d34..e5f4b4e 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumUpdateDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumUpdateDTO.java @@ -1,8 +1,10 @@ package com.luoo.music.dto.response; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -19,55 +21,58 @@ import java.util.Date; public class AlbumUpdateDTO implements Serializable { - @NotNull - @ApiModelProperty("id") + @NotBlank private String id; /** * 专辑名称 */ + @NotBlank(message = "专辑名称不能为空") @ApiModelProperty("专辑名称") - @NotNull(message = "专辑名称不能为空") private String name; + /** + * 专辑类型 + */ + @NotNull(message = "专辑类型不能为空") + @ApiModelProperty("专辑类型") + private Integer type; + /** * 专辑封面 */ + @NotBlank(message = "专辑封面不能为空") @ApiModelProperty("专辑封面") - @NotNull(message = "专辑封面不能为空") private String image; /** - * 专辑版本 + * 专辑状态 */ - @ApiModelProperty("专辑版本") - private Integer version; + @NotNull(message = "专辑状态不能为空") + @ApiModelProperty("专辑状态 -1:不可抗力原因不允许显示 0:新建 1:待审核 2:退回 3:待上架 4:已上架 5:已删除") + private Integer state; /** * 发行日期 */ + @NotNull(message = "发行日期不能为空") @ApiModelProperty("发行日期") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date publishDate; /** * 主要风格 */ - @ApiModelProperty("主要风格") - @NotNull(message = "主要风格不能为空") + @NotBlank(message = "专辑风格不能为空") + @ApiModelProperty("专辑风格不能为空") private String mainStyle; - /** - * 次要风格 - */ - @NotNull(message = "次要风格不能为空") - @ApiModelProperty("次要风格") - private String subStyle; - /** * 专辑条码 */ @ApiModelProperty("专辑条码") private String barcode; + /** * 专辑描述 */ @@ -75,22 +80,9 @@ public class AlbumUpdateDTO implements Serializable { private String description; /** - * 音乐人id - */ - @ApiModelProperty("音乐人id") - private String artistId; - - /** - * 音乐人昵称 - */ - @ApiModelProperty("音乐人昵称") - private String artistName; - - /** - * 收费类型 1-下载 2-试听及下载 + * 专辑版本 */ - @ApiModelProperty("收费类型 1-下载 2-试听及下载") - private Integer chargeType; - + @ApiModelProperty("专辑版本") + private Integer version; } 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 f0309b1..05d3c38 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 @@ -31,10 +31,7 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -279,6 +276,54 @@ public class AlbumService { ArtistAlbum artistAlbum = new ArtistAlbum(); BeanUtils.copyProperties(albumUpdateDTO, artistAlbum); + ArtistAlbum old = checkAlbum(token, artistAlbum.getId()); + artistAlbum.setArtistId(old.getArtistId()); + artistAlbum.setArtistName(old.getArtistName()); + + checkUserIsSelf(token, artistAlbum); + artistAlbumDao.save(artistAlbum); + } + + @Transactional(rollbackFor = Exception.class) + public void changeAlbumState(String token, String id, Integer state) { + ArtistAlbum artistAlbum = checkAlbum(token, id); + + switch (state) { + case -1: + break; + case 1: + // 申请审核操作 + checkForApply(id, artistAlbum); + break; + case 4: + // 上架操作 + shelving(artistAlbum); + break; + case 5: + // 删除操作 + deleteAlbum(artistAlbum); + break; + default: + // 其他不允许操作 + throw new BizException(ErrorConstants.STATE_ERROR); + } + + artistAlbum.setState(state); + if(ObjectUtils.notEqual(state, AlbumStateEnum.FORCE.getCode())) { + // 强制下架不校验是否本人操作 + checkUserIsSelf(token, artistAlbum); + } + + artistAlbumDao.save(artistAlbum); + } + + /** + * 校验修改的用户是否是自己 + * + * @param token token + * @param artistAlbum 专辑 + */ + private void checkUserIsSelf(String token, ArtistAlbum artistAlbum) { UserLoginDto user = jwtUtil.getUserLoginDto(token); if (user != null) { if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) { @@ -291,22 +336,59 @@ public class AlbumService { throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE); } - artistAlbumDao.save(artistAlbum); } /** - * 删除专辑 + * 提交审核状态校验 * - * @param id 专辑id + * @param id 专辑id + * @param artistAlbum 专辑对象 */ - @Transactional(rollbackFor = Exception.class) - public void deleteAlbum(String token, String id) { - - ArtistAlbum artistAlbum = checkAlbum(token, id); + private void checkForApply(String id, ArtistAlbum artistAlbum) { + if (ObjectUtils.notEqual(AlbumStateEnum.SAVE.getCode(), artistAlbum.getState())) { + // 必须在新建状态下申请审核 + throw new BizException(ErrorConstants.MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE); + } + List songInfoList = songInfoDao.findByAlbumId(id); + if (songInfoList.isEmpty()) { + throw new BizException(ErrorConstants.ALBUM_SONG_LIST_IS_EMPTY); + } + for (SongInfo songInfo : songInfoList) { + AlbumSongRequireDTO albumSongRequireDTO = new AlbumSongRequireDTO(); + BeanUtils.copyProperties(songInfo, albumSongRequireDTO); + checkSong(albumSongRequireDTO); + } + } - artistAlbumDao.delete(artistAlbum); + /** + * 上架操作 + * + * @param artistAlbum 专辑对象 + */ + private void shelving(ArtistAlbum artistAlbum) { + // 只有待上架允许上架 + if (ObjectUtils.notEqual(AlbumStateEnum.WAIT_ARRIVE.getCode(), artistAlbum.getState())) { + throw new BizException(ErrorConstants.STATE_ERROR); + } + } - artistAlbumSongDao.deleteByAlbumId(id); + /** + * 删除专辑 + * + * @param artistAlbum 专辑对象 + */ + private void deleteAlbum(ArtistAlbum artistAlbum) { + + // 只有新建,待上架,已驳回状态下允许删除 + Integer state = artistAlbum.getState(); + Integer[] allowState = new Integer[]{ + AlbumStateEnum.SAVE.getCode(), + AlbumStateEnum.WAIT_ARRIVE.getCode(), + AlbumStateEnum.BACK.getCode() + }; + if (!Arrays.asList(allowState).contains(state)) { + throw new BizException(ErrorConstants.STATE_ERROR); + } } /** @@ -365,46 +447,18 @@ public class AlbumService { addSongForAlbum(albumSongAddDTO, user, artistAlbum); } - /** - * 提交审核 - * - * @param token token - * @param id 专辑id - */ - @Transactional(rollbackFor = Exception.class) - public void checkForApply(String token, String id) { - ArtistAlbum artistAlbum = checkAlbum(token, id); - if (ObjectUtils.notEqual(AlbumStateEnum.SAVE.getCode(), artistAlbum.getState())) { - // 必须在新建状态下申请审核 - throw new BizException(ErrorConstants.MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE); - } - ArtistAlbum album = getOne(id); - List songList = album.getSongList(); - if(songList.isEmpty()) { - throw new BizException(ErrorConstants.ALBUM_SONG_LIST_IS_EMPTY); - } - for (SongInfo songInfo : songList) { - AlbumSongRequireDTO albumSongRequireDTO = new AlbumSongRequireDTO(); - BeanUtils.copyProperties(songInfo, albumSongRequireDTO); - checkSong(albumSongRequireDTO); - } - - artistAlbum.setState(AlbumStateEnum.IN_APPROVE.getCode()); - artistAlbumDao.save(artistAlbum); - } - /** * 必填校验 * * @param albumSongRequireDTO 校验对象 */ private void checkSong(@Validated AlbumSongRequireDTO albumSongRequireDTO) { - if(ObjectUtils.notEqual(SongInfoChargeEnum.CHARGE.getCode(), albumSongRequireDTO.getCharge())) { - if(albumSongRequireDTO.getPrice() == null) { + if (ObjectUtils.notEqual(SongInfoChargeEnum.CHARGE.getCode(), albumSongRequireDTO.getCharge())) { + if (albumSongRequireDTO.getPrice() == null) { // 定价不能为空 throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY); } - if(albumSongRequireDTO.getPrice() <= 0) { + if (albumSongRequireDTO.getPrice() <= 0) { // 定价必须大于0 throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0); } @@ -420,12 +474,12 @@ public class AlbumService { */ private void addSongForAlbum(@Validated AlbumSongAddDTO albumSongAddDTO, UserLoginDto user, ArtistAlbum artistAlbum) { - if(ObjectUtils.equals(SongInfoChargeEnum.CHARGE.getCode(), albumSongAddDTO.getCharge())) { - if(albumSongAddDTO.getPrice() == null) { + if (ObjectUtils.equals(SongInfoChargeEnum.CHARGE.getCode(), albumSongAddDTO.getCharge())) { + if (albumSongAddDTO.getPrice() == null) { // 定价不能为空 throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY); } - if(albumSongAddDTO.getPrice() <= 0) { + if (albumSongAddDTO.getPrice() <= 0) { // 定价必须大于0 throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0); }