From 6911a660963d3ed4ba449ab8c6205f6139427763 Mon Sep 17 00:00:00 2001 From: JH <935007339@qq.com> Date: Wed, 7 Feb 2024 08:02:22 +0800 Subject: [PATCH] update query user info --- .../com/luoo/music/client/UserClient.java | 35 ++++++++++++++++++- .../music/controller/CMSSongController.java | 5 ++- .../luoo/music/service/CMSJournalService.java | 14 ++++---- .../luoo/music/service/CMSSongService.java | 25 ++++++------- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/luoo_music/src/main/java/com/luoo/music/client/UserClient.java b/luoo_music/src/main/java/com/luoo/music/client/UserClient.java index 336beac..70f9b8f 100644 --- a/luoo_music/src/main/java/com/luoo/music/client/UserClient.java +++ b/luoo_music/src/main/java/com/luoo/music/client/UserClient.java @@ -1,12 +1,45 @@ package com.luoo.music.client; import api.Result; +import com.luoo.music.pojo.UserInfo; +import lombok.Data; +import org.apache.commons.lang.StringUtils; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +import java.util.Objects; @FeignClient("luoo-user") public interface UserClient { @GetMapping("/admin") - public Result findAll(); + Result findAll(); + + @GetMapping("/cms/admin/{id}") + Result findById(@PathVariable("id") String id); + + /** + * 通过用户ID获取用户信息 + * @param userId + * @return + */ + default UserInfo queryUserInfoById(String userId){ + if (StringUtils.isBlank(userId)) { + return null; + } + Result result = findById(userId); + AdminUser adminUser = result.getData(); + if (Objects.isNull(adminUser)) { + return null; + } + UserInfo user = UserInfo.builder().id(adminUser.getId()).name(adminUser.getLoginname()).type("admin").build(); + return user; + } + + @Data + class AdminUser{ + private String id; + private String loginname; + } } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java index 103e82b..40aea76 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java @@ -92,8 +92,7 @@ public class CMSSongController { @ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲") @RequestMapping(value = "/batch", method = RequestMethod.POST) - public Result batchUpload(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, - @ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List files) { - return songService.batchUpload(files, token); + public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List files) { + return songService.batchUpload(files); } } diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java index 483bd44..81ea603 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java @@ -2,6 +2,7 @@ package com.luoo.music.service; import api.PageResult; import api.Result; +import com.luoo.music.client.UserClient; import com.luoo.music.dao.*; import com.luoo.music.pojo.*; import com.luoo.music.request.cms.JournalAddModel; @@ -50,7 +51,8 @@ public class CMSJournalService { @Autowired private SongInfoDao songDao; @Autowired - private JwtUtil jwtUtil; + private UserClient userClient; + /** @@ -255,11 +257,11 @@ public class CMSJournalService { journal.setJournalNo(param.getJournalNo()); journal.setTitle(param.getTitle()); journal.setContent(param.getContent()); - if (StringUtils.isNotBlank(token)) { - UserLoginDto user = jwtUtil.getUserLoginDto(token); - journal.setUserId(user.getUserId()); - journal.setUserName(user.getNickName()); - journal.setUserType(user.getRoles()); + UserInfo userInfo = userClient.queryUserInfoById(param.getUserId()); + if (!Objects.isNull(userInfo)) { + journal.setUserId(userInfo.getId()); + journal.setUserName(userInfo.getName()); + journal.setUserType(userInfo.getType()); } return journal; } diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java index 28e5423..e5e12da 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java @@ -2,6 +2,7 @@ package com.luoo.music.service; import api.PageResult; import api.Result; +import com.luoo.music.client.UserClient; import com.luoo.music.dao.*; import com.luoo.music.pojo.*; import com.luoo.music.request.cms.SongAddModel; @@ -56,7 +57,7 @@ public class CMSSongService { @Autowired private TagDao tagDao; @Autowired - private JwtUtil jwtUtil; + private UserClient userClient; /** * 分页 + 条件检索 @@ -235,11 +236,11 @@ public class CMSSongService { song.setArtist(param.getArtist()); song.setAlbum(param.getAlbum()); song.setLyric(param.getLyric()); - UserLoginDto user = getUserInfoByToken(token); - if (!Objects.isNull(user)) { - song.setUserId(user.getUserId()); - song.setUserName(user.getNickName()); - song.setUserType(user.getRoles()); + UserInfo userInfo = userClient.queryUserInfoById(param.getUserId()); + if (!Objects.isNull(userInfo)) { + song.setUserId(userInfo.getId()); + song.setUserName(userInfo.getName()); + song.setUserType(userInfo.getType()); } return song; } @@ -449,8 +450,7 @@ public class CMSSongService { * @param files * @return */ - public Result batchUpload(List files, String token) { - UserLoginDto user = getUserInfoByToken(token); + public Result batchUpload(List files) { for (MultipartFile file : files) if (!file.isEmpty()) { String id = String.valueOf(idWorker.nextId()); @@ -466,11 +466,6 @@ public class CMSSongService { song.setUrl(keySuffix); song.setSize(file.isEmpty() ? 0L : file.getSize()); song.setDuration(CommonUtil.getSongDuration(file)); - if (!Objects.isNull(user)) { - song.setUserId(user.getUserId()); - song.setUserName(user.getNickName()); - song.setUserType(user.getRoles()); - } songDao.save(song); } } @@ -482,7 +477,7 @@ public class CMSSongService { * @param token * @return */ - private UserLoginDto getUserInfoByToken(String token) { + /*private UserLoginDto getUserInfoByToken(String token) { if (StringUtils.isNotBlank(token)) { try { UserLoginDto user = jwtUtil.getUserLoginDto(token); @@ -493,7 +488,7 @@ public class CMSSongService { } } return null; - } + }*/ /** * 读取歌词文件