diff --git a/luoo_common/src/main/java/dto/PmsProduct.java b/luoo_common/src/main/java/dto/PmsProduct.java index b017767..5861827 100644 --- a/luoo_common/src/main/java/dto/PmsProduct.java +++ b/luoo_common/src/main/java/dto/PmsProduct.java @@ -1,11 +1,14 @@ package dto; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; +import java.util.Map; /** * @Author: yawei.huang @@ -16,6 +19,8 @@ import java.util.Date; * @Describe: */ @Data +@AllArgsConstructor +@NoArgsConstructor public class PmsProduct implements Serializable { private Long id; @@ -130,4 +135,8 @@ public class PmsProduct implements Serializable { @ApiModelProperty(value = "移动端网页详情") private String detailMobileHtml; + + public PmsProduct convertMapToPmsProduct(Map map) { + return null; + } } diff --git a/luoo_music/src/main/java/com/luoo/music/config/RestTemplateConfig.java b/luoo_music/src/main/java/com/luoo/music/config/RestTemplateConfig.java new file mode 100644 index 0000000..416f922 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/config/RestTemplateConfig.java @@ -0,0 +1,13 @@ +package com.luoo.music.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestTemplateConfig { + @Bean + RestTemplate restTemplate() { + return new RestTemplate(); + } +} diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistRepresentative.java b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistRepresentative.java index 02e627b..fe2c067 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistRepresentative.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistRepresentative.java @@ -45,11 +45,14 @@ public class ArtistRepresentative { private Integer type; @Transient + @ApiModelProperty("专辑信息") private ArtistAlbum artistAlbum; @Transient + @ApiModelProperty("歌曲信息") private SongInfo songInfo; @Transient + @ApiModelProperty("商品信息") private PmsProduct pmsProduct; } diff --git a/luoo_music/src/main/java/com/luoo/music/service/ArtistRepresentativeService.java b/luoo_music/src/main/java/com/luoo/music/service/ArtistRepresentativeService.java index 2562179..31b190a 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/ArtistRepresentativeService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/ArtistRepresentativeService.java @@ -8,13 +8,20 @@ import com.luoo.music.pojo.ArtistAlbum; import com.luoo.music.pojo.ArtistRepresentative; import com.luoo.music.pojo.SongInfo; import dto.PmsProduct; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; import util.IdWorker; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.util.List; +import java.util.Map; /** * @Author: yawei.huang @@ -24,6 +31,7 @@ import java.util.List; * @Filename: ArtistRepresentativeService * @Describe: */ +@Slf4j @Service public class ArtistRepresentativeService { @@ -64,15 +72,16 @@ public class ArtistRepresentativeService { case 1: // 专辑 ArtistAlbum artistAlbum = artistAlbumDao.findById(representative.getRepresentativeId()).get(); - representative.setArtistAlbum(artistAlbum); + artistRepresentative.setArtistAlbum(artistAlbum); case 2: // 歌曲 SongInfo songInfo = songInfoDao.findById(representative.getRepresentativeId()).get(); - representative.setSongInfo(songInfo); + artistRepresentative.setSongInfo(songInfo); case 3: // 商品 - PmsProduct pmsProduct = restTemplate.getForObject(mallConfig.getProductUrl(), PmsProduct.class); - representative.setPmsProduct(pmsProduct); + PmsProduct pmsProduct = restTemplate.getForObject(mallConfig.getProductUrl().replace("{id}", representative.getRepresentativeId()), PmsProduct.class); + artistRepresentative.setPmsProduct(pmsProduct); + break; default: break; @@ -82,6 +91,39 @@ public class ArtistRepresentativeService { return artistRepresentative; } + public static Object convertToObject(Class clazz, Map map) throws + IntrospectionException, InstantiationException, IllegalAccessException { + BeanInfo bi = Introspector.getBeanInfo(clazz); + + Object obj = clazz.newInstance(); + + PropertyDescriptor[] pds = bi.getPropertyDescriptors(); + + String pName; + for (PropertyDescriptor pd : pds) { + pName = pd.getName(); + if (map.containsKey(pName)) { + try { + if (pd.getPropertyType().getName().equals("java.lang.Long")) { + if(StringUtils.isNotEmpty(map.get(pName).toString())){ + pd.getWriteMethod().invoke(obj, Long.parseLong(map.get(pName).toString())); + } +// else{ +// pd.getWriteMethod().invoke(obj, map.get(pName)); +// } + } else { + pd.getWriteMethod().invoke(obj, map.get(pName)); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + return obj; + } + + /** * 设置代表作 * diff --git a/luoo_music/src/main/resources/bootstrap.yml b/luoo_music/src/main/resources/bootstrap.yml index 0f5566b..1267ad9 100644 --- a/luoo_music/src/main/resources/bootstrap.yml +++ b/luoo_music/src/main/resources/bootstrap.yml @@ -68,4 +68,5 @@ mall: albumId: 76 albumName: 77 songId: 78 - productUrl: http://43.248.137.154:8085/product/detail/{id} +# productUrl: http://43.248.137.154:8085/product/luoo/detail/{id} + productUrl: http://localhost:8085/product/luoo/detail/{id}