diff --git a/luoo_common/src/main/java/constants/Constants.java b/luoo_common/src/main/java/constants/Constants.java index 751488f..f696694 100644 --- a/luoo_common/src/main/java/constants/Constants.java +++ b/luoo_common/src/main/java/constants/Constants.java @@ -10,7 +10,7 @@ public class Constants { public static final String TOKEN_ROLE_APP_USER="user"; public static final String TOKEN_ROLE_ADMIN_USER="admin"; - public static final String TOKEN_ROLE_TOURIST="tourist"; + //public static final String TOKEN_ROLE_TOURIST="tourist"; public static final String FOLDER_AVATAR = "avatar/"; diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index 2eed240..2e9d191 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -1,4 +1,5 @@ package com.luoo.music.controller; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,7 +21,11 @@ import annotation.VerifyParam; import api.PageResult; import api.Result; import constants.Constants; +import dto.UserLoginDto; +import enums.DateTimePatternEnum; import io.swagger.annotations.ApiOperation; +import util.DateUtil; +import util.JwtUtil; /** * 控制器层 @@ -34,23 +39,37 @@ public class JournalController { @Autowired private ArticleService articleService; - - @ApiOperation(value = "1.查询期刊信息") + @Autowired + private JwtUtil jwtUtil; + @ApiOperation(value = "1.查询期刊信息", notes="若token为空或token校验失败,默认返回最新的10期,期刊筛选条件对游客不可用") @GetMapping("/list") - @GlobalInterceptor(checkLogin = true) + @GlobalInterceptor public Result> page(@RequestHeader(value = "token", required = false) String token, @VerifyParam JournalQueryReq queryReq){ + UserLoginDto user=jwtUtil.getUserLoginDto(token); + if(null==user) { + queryReq.setLanguage(null); + queryReq.setStyle(null); + queryReq.setPageNum(1); + queryReq.setPageSize(10); + } Page
pageList = articleService.queryPage(queryReq); - List list=pageList.stream().map(a->getArticleRespDTO(a)).collect(Collectors.toList()); + List list=pageList.stream().map(a->getArticleRespDTO(a,user)).collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list) ); } - private JournalRespDTO getArticleRespDTO(Article article) { + private JournalRespDTO getArticleRespDTO(Article article, UserLoginDto user) { JournalRespDTO journalRespDTO=new JournalRespDTO(); journalRespDTO.setId(article.getId()); journalRespDTO.setJournalNo(article.getVolid()); journalRespDTO.setTitle(article.getTitle()); journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX+article.getImage()); + journalRespDTO.setDate(getEditDate(article)); + //TODO: 根据userId查询是否已收藏 return journalRespDTO; } + private String getEditDate(Article article) { + Date date=null==article.getUpdatetime()?article.getCreatetime():article.getUpdatetime(); + return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()); + } } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java index 91f0806..2415217 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java @@ -3,6 +3,7 @@ package com.luoo.music.controller; import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.pojo.Article; import com.luoo.music.pojo.Song; +import com.luoo.music.service.ArticleService; import com.luoo.music.service.SongService; import annotation.GlobalInterceptor; @@ -10,10 +11,12 @@ import annotation.VerifyParam; import api.PageResult; import api.Result; import constants.Constants; +import dto.UserLoginDto; import enums.VerifyRegexEnum; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import util.JwtUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -32,7 +35,10 @@ public class SongController { @Autowired private SongService songService; - + @Autowired + private ArticleService articleService; + @Autowired + private JwtUtil jwtUtil; /** * 查询全部数据 * @@ -43,24 +49,31 @@ public class SongController { return Result.success(songService.findAll()); } - @ApiOperation(value = "1.根据期刊号查询歌曲信息") + @ApiOperation(value = "1.根据期刊号查询歌曲信息",notes="若为游客,期刊号须在最新10期内") @GetMapping("/getByJournalNo/{journalNo}") - @GlobalInterceptor(checkLogin = true) + @GlobalInterceptor public Result> getByJournalNo(@RequestHeader(value = "token", required = false) String token, @PathVariable String journalNo) { + UserLoginDto user=jwtUtil.getUserLoginDto(token); + if(null==user&&!isLatest10(journalNo)) { + return Result.unauthorized(null); + } List songs = songService.findByVolid(journalNo); List results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList()); return Result.success(results); } + private boolean isLatest10(String journalNo) { + return articleService.isLatest10(journalNo); + } + @ApiOperation(value = "2.随机播放歌曲", notes = "雀乐FM") @ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false) }) @GetMapping("/random/{limit}") - @GlobalInterceptor(checkLogin = true) - public Result> random(@RequestHeader(value = "token", required = false) String token, - @PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) { + @GlobalInterceptor + public Result> random(@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) { List songs = songService.random(limit); List results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList()); return Result.success(results); diff --git a/luoo_music/src/main/java/com/luoo/music/dto/request/JournalQueryReq.java b/luoo_music/src/main/java/com/luoo/music/dto/request/JournalQueryReq.java index 02d8897..bb36450 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/request/JournalQueryReq.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/request/JournalQueryReq.java @@ -1,16 +1,9 @@ package com.luoo.music.dto.request; -import com.fasterxml.jackson.annotation.JsonFormat; - -import annotation.VerifyParam; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.time.LocalDateTime; /** * 标签列表查询参数 @@ -23,10 +16,8 @@ public class JournalQueryReq implements Serializable { private String style; @ApiModelProperty(value = "筛选条件:语言") private String language; - @VerifyParam(required=true) @ApiModelProperty(value = "分页: 页码,以1开始,即获取最新的几期", example = "1") private Integer pageNum = 1; - @VerifyParam(required=true) @ApiModelProperty(value = "分页: 每页数量", example = "10") private Integer pageSize = 10; } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java index 0eecdd9..a34332e 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java @@ -1,5 +1,7 @@ package com.luoo.music.dto.response; +import java.util.List; + import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -11,8 +13,16 @@ public class JournalRespDTO { private String journalNo; @ApiModelProperty(value = "期刊名") private String title; - @ApiModelProperty(value = "文案") - private String content; @ApiModelProperty(value = "期刊封面") private String image; + @ApiModelProperty(value = "期刊标签") + private List tags; + @ApiModelProperty(value = "文案") + private String content; + @ApiModelProperty(value = "编辑人") + private String editor; + @ApiModelProperty(value = "编辑日期,格式为: yyyy.MM.dd") + private String date; + @ApiModelProperty(value = "已收藏") + private boolean haveCollect; } diff --git a/luoo_music/src/main/java/com/luoo/music/service/ArticleService.java b/luoo_music/src/main/java/com/luoo/music/service/ArticleService.java index d08b4a9..dc1cb12 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/ArticleService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/ArticleService.java @@ -235,4 +235,10 @@ public class ArticleService { }; } + + + public boolean isLatest10(String journalNo) { + // TODO Auto-generated method stub + return true; + } } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index b07150b..35ff2c0 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -51,13 +51,13 @@ public class MyController { public static String UPLOAD_DIRECTORY = System.getProperty("user.dir") + File.separator+"luoo_uploads"+File.separator; - @ApiOperation(value = "1.获取个人信息") + @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") @GetMapping("/getUserInfo") @GlobalInterceptor public Result getUserInfo(@RequestHeader(value = "token", required = false) String token) { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); if (null == userLoginDto) { - return Result.validateFailed(); + return Result.unauthorized(null); } UserRespDTO userRespDTO = new UserRespDTO(); if (Constants.TOKEN_ROLE_APP_USER.equals(userLoginDto.getRoles())) { @@ -130,7 +130,7 @@ public class MyController { } //待优化 @ApiOperation(value = "4.下载个人头像") - @GetMapping(value = "/avatar", produces = MediaType.IMAGE_JPEG_VALUE) + @GetMapping(value = "/downloadAvatar", produces = MediaType.IMAGE_JPEG_VALUE) @GlobalInterceptor(checkLogin = true) public @ResponseBody byte[] getImage(@RequestHeader(value = "token", required = false) String token) throws IOException { diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java index f49b9cc..bf227f0 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java @@ -111,13 +111,14 @@ public class UserController { } } - + @Deprecated @ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist") @GetMapping("/touristLogin") public Result touristLogin() { - String nickName="游客-"+NickNameUtil.getRandomNickName(); - String token = jwtUtil.createJWT(String.valueOf(idWorker.nextId()),nickName,Constants.TOKEN_ROLE_TOURIST); - return Result.success(token); + //String nickName="游客-"+NickNameUtil.getRandomNickName(); + //String token = jwtUtil.createJWT(String.valueOf(idWorker.nextId()),nickName,Constants.TOKEN_ROLE_TOURIST); + //return Result.success(token); + return Result.success(""); } /**