歌曲B方案编码-2

This commit is contained in:
weiyachao 2023-09-28 16:50:43 +08:00
parent e542f711e6
commit af6d04fe6a
4 changed files with 39 additions and 8 deletions

View File

@ -30,6 +30,14 @@ public class SearchResponse {
private String id;
private String name;
private List<Artist> artists;
@Data
public static class Artist{
private String name;
}
}
}

View File

@ -22,6 +22,14 @@ public class SingerSongsResponse {
private String id;
private String name;
private List<ArName> ar;
@Data
public static class ArName{
private String name;
}
}
}

View File

@ -25,6 +25,8 @@ public class SongInfoResponse {
private String name;
private String artistName;
}

View File

@ -20,7 +20,6 @@ import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import com.qiuguo.iot.third.resp.SearchResponse;
import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
/**
@ -41,8 +40,16 @@ public class MusicService {
if (ObjectUtils.isEmpty(keyword)) {
keyword = "追梦赤子心";
}
WebClient build = WebClient.builder().defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE).build();
String baseUrl = "http://bilibiliz.cn:8031";
WebClient build = WebClient.builder()
.defaultHeader("Content-Type", "application/json; charset=utf-8")
.defaultHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
.defaultHeader("Access-Control-Allow-Headers", "X-Requested-With,Content-Type")
.defaultHeader("Accept", "*")
.defaultHeader("Access-Control-Allow-Methods:", "PUT,POST,GET,DELETE,OPTIONS")
.defaultHeader("Access-Control-Allow-Methods:", "PUT,POST,GET,DELETE,OPTIONS")
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE)
.build();
String baseUrl = "http://121.40.172.241:8031";
if (type == 1) {
return build.get().uri(baseUrl.concat("/search?keywords=").concat(keyword).concat("&limit=10")).retrieve()
.bodyToMono(SearchResponse.class).flatMap(res -> {
@ -51,16 +58,18 @@ public class MusicService {
}
String ids = res.getResult().getSongs().stream().map(SearchResponse.Song::getId)
.collect(Collectors.joining(","));
Map<String, String> songMap = res.getResult().getSongs().stream()
.collect(Collectors.toMap(SearchResponse.Song::getId, SearchResponse.Song::getName));
Map<String,SearchResponse.Song > songMap = res.getResult().getSongs().stream()
.collect(Collectors.toMap(SearchResponse.Song::getId, Function.identity()));
return build.get().uri(baseUrl.concat("/song/url?id=").concat(ids)).retrieve()
.bodyToMono(SongInfoResponse.class).flatMap(song -> {
if (Objects.equals(200, song.getCode()) && song.getData().size() > 0) {
List<SongInfoResponse.ResultSong> data = song.getData();
for (SongInfoResponse.ResultSong datum : data) {
datum.setName(songMap.get(datum.getId()));
SearchResponse.Song innerSong = songMap.get(datum.getId());
datum.setName(innerSong.getName());
datum.setArtistName(ObjectUtils.isEmpty(innerSong.getArtists()) ? null
: innerSong.getArtists().get(0).getName());
}
return Mono.just(data);
}
@ -88,7 +97,11 @@ public class MusicService {
&& so.getData().size() > 0) {
List<SongInfoResponse.ResultSong> data = so.getData();
for (SongInfoResponse.ResultSong datum : data) {
datum.setName(songMap.get(datum.getId()).getName());
SingerSongsResponse.Song innerSong = songMap.get(datum.getId());
datum.setName(innerSong.getName());
datum.setArtistName(ObjectUtils.isEmpty(innerSong.getAr()) ? null
: innerSong.getAr().get(0).getName());
}
return Mono.just(data);
}