release- 代表作处理

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

@ -1,11 +1,14 @@
package dto; package dto;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.Map;
/** /**
* @Author: yawei.huang * @Author: yawei.huang
@ -16,6 +19,8 @@ import java.util.Date;
* @Describe: * @Describe:
*/ */
@Data @Data
@AllArgsConstructor
@NoArgsConstructor
public class PmsProduct implements Serializable { public class PmsProduct implements Serializable {
private Long id; private Long id;
@ -130,4 +135,8 @@ public class PmsProduct implements Serializable {
@ApiModelProperty(value = "移动端网页详情") @ApiModelProperty(value = "移动端网页详情")
private String detailMobileHtml; 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; private Integer type;
@Transient @Transient
@ApiModelProperty("专辑信息")
private ArtistAlbum artistAlbum; private ArtistAlbum artistAlbum;
@Transient @Transient
@ApiModelProperty("歌曲信息")
private SongInfo songInfo; private SongInfo songInfo;
@Transient @Transient
@ApiModelProperty("商品信息")
private PmsProduct pmsProduct; private PmsProduct pmsProduct;
} }

@ -8,13 +8,20 @@ import com.luoo.music.pojo.ArtistAlbum;
import com.luoo.music.pojo.ArtistRepresentative; import com.luoo.music.pojo.ArtistRepresentative;
import com.luoo.music.pojo.SongInfo; import com.luoo.music.pojo.SongInfo;
import dto.PmsProduct; import dto.PmsProduct;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import util.IdWorker; 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.List;
import java.util.Map;
/** /**
* @Author: yawei.huang * @Author: yawei.huang
@ -24,6 +31,7 @@ import java.util.List;
* @Filename: ArtistRepresentativeService * @Filename: ArtistRepresentativeService
* @Describe: * @Describe:
*/ */
@Slf4j
@Service @Service
public class ArtistRepresentativeService { public class ArtistRepresentativeService {
@ -64,15 +72,16 @@ public class ArtistRepresentativeService {
case 1: case 1:
// 专辑 // 专辑
ArtistAlbum artistAlbum = artistAlbumDao.findById(representative.getRepresentativeId()).get(); ArtistAlbum artistAlbum = artistAlbumDao.findById(representative.getRepresentativeId()).get();
representative.setArtistAlbum(artistAlbum); artistRepresentative.setArtistAlbum(artistAlbum);
case 2: case 2:
// 歌曲 // 歌曲
SongInfo songInfo = songInfoDao.findById(representative.getRepresentativeId()).get(); SongInfo songInfo = songInfoDao.findById(representative.getRepresentativeId()).get();
representative.setSongInfo(songInfo); artistRepresentative.setSongInfo(songInfo);
case 3: case 3:
// 商品 // 商品
PmsProduct pmsProduct = restTemplate.getForObject(mallConfig.getProductUrl(), PmsProduct.class); PmsProduct pmsProduct = restTemplate.getForObject(mallConfig.getProductUrl().replace("{id}", representative.getRepresentativeId()), PmsProduct.class);
representative.setPmsProduct(pmsProduct); artistRepresentative.setPmsProduct(pmsProduct);
break; break;
default: default:
break; break;
@ -82,6 +91,39 @@ public class ArtistRepresentativeService {
return artistRepresentative; 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 albumId: 76
albumName: 77 albumName: 77
songId: 78 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