release- 代表作处理

release-2024-08-08
pikaqiudeshujia 6 months ago
parent 3dae08cdb9
commit c391a10086

@ -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<String, Object> map) {
return null;
}
}

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

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

@ -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<String, Object> 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;
}
/**
*
*

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

Loading…
Cancel
Save