update query user info

main
JH 10 months ago
parent 8d84c5aec3
commit 6911a66096

@ -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<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 = "批量上传歌曲")
@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<MultipartFile> files) {
return songService.batchUpload(files, token);
public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List<MultipartFile> files) {
return songService.batchUpload(files);
}
}

@ -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;
}

@ -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<MultipartFile> files, String token) {
UserLoginDto user = getUserInfoByToken(token);
public Result batchUpload(List<MultipartFile> 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;
}
}*/
/**
*

Loading…
Cancel
Save