update query user info

main
JH 10 months ago
parent 8d84c5aec3
commit 6911a66096

@ -1,12 +1,45 @@
package com.luoo.music.client; package com.luoo.music.client;
import api.Result; 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.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.Objects;
@FeignClient("luoo-user") @FeignClient("luoo-user")
public interface UserClient { public interface UserClient {
@GetMapping("/admin") @GetMapping("/admin")
public Result findAll(); Result findAll();
@GetMapping("/cms/admin/{id}")
Result<AdminUser> findById(@PathVariable("id") String id);
/**
* ID
* @param userId
* @return
*/
default UserInfo queryUserInfoById(String userId){
if (StringUtils.isBlank(userId)) {
return null;
}
Result<AdminUser> 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;
}
} }

@ -92,8 +92,7 @@ public class CMSSongController {
@ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲") @ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲")
@RequestMapping(value = "/batch", method = RequestMethod.POST) @RequestMapping(value = "/batch", method = RequestMethod.POST)
public Result batchUpload(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List<MultipartFile> files) {
@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List<MultipartFile> files) { return songService.batchUpload(files);
return songService.batchUpload(files, token);
} }
} }

@ -2,6 +2,7 @@ package com.luoo.music.service;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import com.luoo.music.client.UserClient;
import com.luoo.music.dao.*; import com.luoo.music.dao.*;
import com.luoo.music.pojo.*; import com.luoo.music.pojo.*;
import com.luoo.music.request.cms.JournalAddModel; import com.luoo.music.request.cms.JournalAddModel;
@ -50,7 +51,8 @@ public class CMSJournalService {
@Autowired @Autowired
private SongInfoDao songDao; private SongInfoDao songDao;
@Autowired @Autowired
private JwtUtil jwtUtil; private UserClient userClient;
/** /**
@ -255,11 +257,11 @@ public class CMSJournalService {
journal.setJournalNo(param.getJournalNo()); journal.setJournalNo(param.getJournalNo());
journal.setTitle(param.getTitle()); journal.setTitle(param.getTitle());
journal.setContent(param.getContent()); journal.setContent(param.getContent());
if (StringUtils.isNotBlank(token)) { UserInfo userInfo = userClient.queryUserInfoById(param.getUserId());
UserLoginDto user = jwtUtil.getUserLoginDto(token); if (!Objects.isNull(userInfo)) {
journal.setUserId(user.getUserId()); journal.setUserId(userInfo.getId());
journal.setUserName(user.getNickName()); journal.setUserName(userInfo.getName());
journal.setUserType(user.getRoles()); journal.setUserType(userInfo.getType());
} }
return journal; return journal;
} }

@ -2,6 +2,7 @@ package com.luoo.music.service;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import com.luoo.music.client.UserClient;
import com.luoo.music.dao.*; import com.luoo.music.dao.*;
import com.luoo.music.pojo.*; import com.luoo.music.pojo.*;
import com.luoo.music.request.cms.SongAddModel; import com.luoo.music.request.cms.SongAddModel;
@ -56,7 +57,7 @@ public class CMSSongService {
@Autowired @Autowired
private TagDao tagDao; private TagDao tagDao;
@Autowired @Autowired
private JwtUtil jwtUtil; private UserClient userClient;
/** /**
* + * +
@ -235,11 +236,11 @@ public class CMSSongService {
song.setArtist(param.getArtist()); song.setArtist(param.getArtist());
song.setAlbum(param.getAlbum()); song.setAlbum(param.getAlbum());
song.setLyric(param.getLyric()); song.setLyric(param.getLyric());
UserLoginDto user = getUserInfoByToken(token); UserInfo userInfo = userClient.queryUserInfoById(param.getUserId());
if (!Objects.isNull(user)) { if (!Objects.isNull(userInfo)) {
song.setUserId(user.getUserId()); song.setUserId(userInfo.getId());
song.setUserName(user.getNickName()); song.setUserName(userInfo.getName());
song.setUserType(user.getRoles()); song.setUserType(userInfo.getType());
} }
return song; return song;
} }
@ -449,8 +450,7 @@ public class CMSSongService {
* @param files * @param files
* @return * @return
*/ */
public Result batchUpload(List<MultipartFile> files, String token) { public Result batchUpload(List<MultipartFile> files) {
UserLoginDto user = getUserInfoByToken(token);
for (MultipartFile file : files) for (MultipartFile file : files)
if (!file.isEmpty()) { if (!file.isEmpty()) {
String id = String.valueOf(idWorker.nextId()); String id = String.valueOf(idWorker.nextId());
@ -466,11 +466,6 @@ public class CMSSongService {
song.setUrl(keySuffix); song.setUrl(keySuffix);
song.setSize(file.isEmpty() ? 0L : file.getSize()); song.setSize(file.isEmpty() ? 0L : file.getSize());
song.setDuration(CommonUtil.getSongDuration(file)); song.setDuration(CommonUtil.getSongDuration(file));
if (!Objects.isNull(user)) {
song.setUserId(user.getUserId());
song.setUserName(user.getNickName());
song.setUserType(user.getRoles());
}
songDao.save(song); songDao.save(song);
} }
} }
@ -482,7 +477,7 @@ public class CMSSongService {
* @param token * @param token
* @return * @return
*/ */
private UserLoginDto getUserInfoByToken(String token) { /*private UserLoginDto getUserInfoByToken(String token) {
if (StringUtils.isNotBlank(token)) { if (StringUtils.isNotBlank(token)) {
try { try {
UserLoginDto user = jwtUtil.getUserLoginDto(token); UserLoginDto user = jwtUtil.getUserLoginDto(token);
@ -493,7 +488,7 @@ public class CMSSongService {
} }
} }
return null; return null;
} }*/
/** /**
* *

Loading…
Cancel
Save