parent
1a9371cb49
commit
3dae08cdb9
@ -0,0 +1,41 @@
|
|||||||
|
package enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: yawei.huang
|
||||||
|
* @Package: enums
|
||||||
|
* @Project: luoo_parent
|
||||||
|
* @Date: 2024/5/15 13:24
|
||||||
|
* @Filename: RepresentativeTypeEnum
|
||||||
|
* @Describe:
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum RepresentativeTypeEnum {
|
||||||
|
ALBUM(1, "专辑"),
|
||||||
|
|
||||||
|
SONG(2, "歌曲"),
|
||||||
|
|
||||||
|
GOODS(3, "商品"),
|
||||||
|
|
||||||
|
SHOW(4, "演出");
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
|
||||||
|
RepresentativeTypeEnum(Integer code, String desc) {
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RepresentativeTypeEnum getByStatus(Integer code) {
|
||||||
|
for (RepresentativeTypeEnum al : RepresentativeTypeEnum.values()) {
|
||||||
|
if (al.code.equals(code)) {
|
||||||
|
return al;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.luoo.music.controller;
|
||||||
|
|
||||||
|
import api.Result;
|
||||||
|
import com.luoo.music.pojo.ArtistRepresentative;
|
||||||
|
import com.luoo.music.service.ArtistRepresentativeService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: yawei.huang
|
||||||
|
* @Package: com.luoo.music.controller
|
||||||
|
* @Project: luoo_parent
|
||||||
|
* @Date: 2024/5/15 13:29
|
||||||
|
* @Filename: ArtistRepresentativeController
|
||||||
|
* @Describe:
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
@Api(tags = "代表作")
|
||||||
|
@RequestMapping("/respresentative")
|
||||||
|
public class ArtistRepresentativeController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ArtistRepresentativeService artistRepresentativeService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询音乐人的代表作", notes = "查询音乐人的代表作")
|
||||||
|
@RequestMapping(value = "/artist/{id}", method = RequestMethod.GET)
|
||||||
|
public Result<ArtistRepresentative> getInfo(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
|
||||||
|
@ApiParam(value = "音乐人", required = true) @PathVariable String id) {
|
||||||
|
return Result.success(artistRepresentativeService.getInfo(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "设置音乐人的代表作", notes = "设置音乐人的代表作")
|
||||||
|
@RequestMapping(value = "/set", method = RequestMethod.POST)
|
||||||
|
public Result<Void> set(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
|
||||||
|
@ApiParam(value = "音乐人", required = true) @Validated @RequestBody ArtistRepresentative artistRepresentative) {
|
||||||
|
artistRepresentativeService.set(artistRepresentative);
|
||||||
|
return Result.success();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.luoo.music.dao;
|
||||||
|
|
||||||
|
import com.luoo.music.pojo.ArtistRepresentative;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: yawei.huang
|
||||||
|
* @Package: com.luoo.music.dao
|
||||||
|
* @Project: luoo_parent
|
||||||
|
* @Date: 2024/5/15 13:29
|
||||||
|
* @Filename: ArtistRepresentativeDao
|
||||||
|
* @Describe:
|
||||||
|
*/
|
||||||
|
public interface ArtistRepresentativeDao extends JpaRepository<ArtistRepresentative,String>, JpaSpecificationExecutor<ArtistRepresentative> {
|
||||||
|
|
||||||
|
public List<ArtistRepresentative> getAllByArtistId(String artistId);
|
||||||
|
|
||||||
|
public void deleteAllByArtistIdAndType(String artistId, Integer type);
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.luoo.music.pojo;
|
||||||
|
|
||||||
|
import dto.PmsProduct;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: yawei.huang
|
||||||
|
* @Package: com.luoo.music.pojo
|
||||||
|
* @Project: luoo_parent
|
||||||
|
* @Date: 2024/5/15 13:22
|
||||||
|
* @Filename: ArtistRepresentative
|
||||||
|
* @Describe: 代表作
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@Builder
|
||||||
|
@Table(name = "tb_artist_representative")
|
||||||
|
public class ArtistRepresentative {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@ApiModelProperty("id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@ApiModelProperty("音乐人id")
|
||||||
|
private String artistId;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@ApiModelProperty("所代表事物id")
|
||||||
|
private String representativeId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@ApiModelProperty("类型 1-代表专辑 2-代表歌曲 3-代表商品 4-代表演出(暂无)")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private ArtistAlbum artistAlbum;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private SongInfo songInfo;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private PmsProduct pmsProduct;
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
package com.luoo.music.service;
|
||||||
|
|
||||||
|
import com.luoo.music.config.MallConfig;
|
||||||
|
import com.luoo.music.dao.ArtistAlbumDao;
|
||||||
|
import com.luoo.music.dao.ArtistRepresentativeDao;
|
||||||
|
import com.luoo.music.dao.SongInfoDao;
|
||||||
|
import com.luoo.music.pojo.ArtistAlbum;
|
||||||
|
import com.luoo.music.pojo.ArtistRepresentative;
|
||||||
|
import com.luoo.music.pojo.SongInfo;
|
||||||
|
import dto.PmsProduct;
|
||||||
|
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.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: yawei.huang
|
||||||
|
* @Package: com.luoo.music.service
|
||||||
|
* @Project: luoo_parent
|
||||||
|
* @Date: 2024/5/15 13:30
|
||||||
|
* @Filename: ArtistRepresentativeService
|
||||||
|
* @Describe:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ArtistRepresentativeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ArtistRepresentativeDao artistRepresentativeDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SongInfoDao songInfoDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ArtistAlbumDao artistAlbumDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MallConfig mallConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IdWorker idWorker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据音乐人id查询代表作
|
||||||
|
*
|
||||||
|
* @param artistId 音乐人id
|
||||||
|
* @return 代表作实体对象
|
||||||
|
*/
|
||||||
|
public ArtistRepresentative getInfo(String artistId) {
|
||||||
|
|
||||||
|
ArtistRepresentative artistRepresentative = new ArtistRepresentative();
|
||||||
|
|
||||||
|
List<ArtistRepresentative> representativeList = artistRepresentativeDao.getAllByArtistId(artistId);
|
||||||
|
|
||||||
|
if (!representativeList.isEmpty()) {
|
||||||
|
for (ArtistRepresentative representative : representativeList) {
|
||||||
|
Integer type = representative.getType();
|
||||||
|
switch (type) {
|
||||||
|
case 1:
|
||||||
|
// 专辑
|
||||||
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(representative.getRepresentativeId()).get();
|
||||||
|
representative.setArtistAlbum(artistAlbum);
|
||||||
|
case 2:
|
||||||
|
// 歌曲
|
||||||
|
SongInfo songInfo = songInfoDao.findById(representative.getRepresentativeId()).get();
|
||||||
|
representative.setSongInfo(songInfo);
|
||||||
|
case 3:
|
||||||
|
// 商品
|
||||||
|
PmsProduct pmsProduct = restTemplate.getForObject(mallConfig.getProductUrl(), PmsProduct.class);
|
||||||
|
representative.setPmsProduct(pmsProduct);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return artistRepresentative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置代表作
|
||||||
|
*
|
||||||
|
* @param artistRepresentative 代表作对象
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void set(ArtistRepresentative artistRepresentative) {
|
||||||
|
// 同一音乐人同一类型只能有一条记录
|
||||||
|
artistRepresentativeDao.deleteAllByArtistIdAndType(artistRepresentative.getArtistId(), artistRepresentative.getType());
|
||||||
|
|
||||||
|
artistRepresentative.setId(String.valueOf(idWorker.nextId()));
|
||||||
|
artistRepresentativeDao.save(artistRepresentative);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
create table tb_artist_representative
|
||||||
|
(
|
||||||
|
id varchar(20) not null comment 'id'
|
||||||
|
primary key,
|
||||||
|
artist_id varchar(20) null comment '音乐人id',
|
||||||
|
representative_id varchar(20) null comment '所代表事物的id',
|
||||||
|
type int null comment '类型 1-代表专辑 2-代表歌曲 3-代表商品 4-代表演出(暂无)'
|
||||||
|
)
|
||||||
|
comment 'tb_artist_representative';
|
||||||
|
|
Loading…
Reference in new issue