diff --git a/luoo_common/src/main/java/dto/PmsProduct.java b/luoo_common/src/main/java/dto/PmsProduct.java new file mode 100644 index 0000000..b017767 --- /dev/null +++ b/luoo_common/src/main/java/dto/PmsProduct.java @@ -0,0 +1,133 @@ +package dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @Author: yawei.huang + * @Package: dto + * @Project: luoo_parent + * @Date: 2024/5/15 14:07 + * @Filename: PmsProduct + * @Describe: + */ +@Data +public class PmsProduct implements Serializable { + private Long id; + + private Long brandId; + + private Long productCategoryId; + + private Long feightTemplateId; + + private Long productAttributeCategoryId; + + private String name; + + private String pic; + + @ApiModelProperty(value = "货号") + private String productSn; + + @ApiModelProperty(value = "删除状态:0->未删除;1->已删除") + private Integer deleteStatus; + + @ApiModelProperty(value = "上架状态:0->下架;1->上架") + private Integer publishStatus; + + @ApiModelProperty(value = "新品状态:0->不是新品;1->新品") + private Integer newStatus; + + @ApiModelProperty(value = "推荐状态;0->不推荐;1->推荐") + private Integer recommandStatus; + + @ApiModelProperty(value = "审核状态:0->未审核;1->审核通过") + private Integer verifyStatus; + + @ApiModelProperty(value = "排序") + private Integer sort; + + @ApiModelProperty(value = "销量") + private Integer sale; + + private BigDecimal price; + + @ApiModelProperty(value = "促销价格") + private BigDecimal promotionPrice; + + @ApiModelProperty(value = "赠送的成长值") + private Integer giftGrowth; + + @ApiModelProperty(value = "赠送的积分") + private Integer giftPoint; + + @ApiModelProperty(value = "限制使用的积分数") + private Integer usePointLimit; + + @ApiModelProperty(value = "副标题") + private String subTitle; + + @ApiModelProperty(value = "市场价") + private BigDecimal originalPrice; + + @ApiModelProperty(value = "库存") + private Integer stock; + + @ApiModelProperty(value = "库存预警值") + private Integer lowStock; + + @ApiModelProperty(value = "单位") + private String unit; + + @ApiModelProperty(value = "商品重量,默认为克") + private BigDecimal weight; + + @ApiModelProperty(value = "是否为预告商品:0->不是;1->是") + private Integer previewStatus; + + @ApiModelProperty(value = "以逗号分割的产品服务:1->无忧退货;2->快速退款;3->免费包邮") + private String serviceIds; + + private String keywords; + + private String note; + + @ApiModelProperty(value = "画册图片,连产品图片限制为5张,以逗号分割") + private String albumPics; + + private String detailTitle; + + @ApiModelProperty(value = "促销开始时间") + private Date promotionStartTime; + + @ApiModelProperty(value = "促销结束时间") + private Date promotionEndTime; + + @ApiModelProperty(value = "活动限购数量") + private Integer promotionPerLimit; + + @ApiModelProperty(value = "促销类型:0->没有促销使用原价;1->使用促销价;2->使用会员价;3->使用阶梯价格;4->使用满减价格;5->限时购") + private Integer promotionType; + + @ApiModelProperty(value = "品牌名称") + private String brandName; + + @ApiModelProperty(value = "商品分类名称") + private String productCategoryName; + + @ApiModelProperty(value = "商品描述") + private String description; + + private String detailDesc; + + @ApiModelProperty(value = "产品详情网页内容") + private String detailHtml; + + @ApiModelProperty(value = "移动端网页详情") + private String detailMobileHtml; +} diff --git a/luoo_common/src/main/java/enums/RepresentativeTypeEnum.java b/luoo_common/src/main/java/enums/RepresentativeTypeEnum.java new file mode 100644 index 0000000..6bf1006 --- /dev/null +++ b/luoo_common/src/main/java/enums/RepresentativeTypeEnum.java @@ -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; + } +} diff --git a/luoo_music/src/main/java/com/luoo/music/config/MallConfig.java b/luoo_music/src/main/java/com/luoo/music/config/MallConfig.java index 84666bc..a45f985 100644 --- a/luoo_music/src/main/java/com/luoo/music/config/MallConfig.java +++ b/luoo_music/src/main/java/com/luoo/music/config/MallConfig.java @@ -64,4 +64,10 @@ public class MallConfig { * 属性歌曲id */ private Long songId; + + // 其他 + /** + * 获取商品的url接口 + */ + private String productUrl; } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/ArtistRepresentativeController.java b/luoo_music/src/main/java/com/luoo/music/controller/ArtistRepresentativeController.java new file mode 100644 index 0000000..9d787ee --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/controller/ArtistRepresentativeController.java @@ -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 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 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(); + + } +} diff --git a/luoo_music/src/main/java/com/luoo/music/dao/ArtistRepresentativeDao.java b/luoo_music/src/main/java/com/luoo/music/dao/ArtistRepresentativeDao.java new file mode 100644 index 0000000..4fa47a7 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dao/ArtistRepresentativeDao.java @@ -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, JpaSpecificationExecutor { + + public List getAllByArtistId(String artistId); + + public void deleteAllByArtistIdAndType(String artistId, Integer type); +} 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 new file mode 100644 index 0000000..02e627b --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistRepresentative.java @@ -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; +} 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 new file mode 100644 index 0000000..2562179 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/service/ArtistRepresentativeService.java @@ -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 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); + } +} diff --git a/luoo_music/src/main/resources/bootstrap.yml b/luoo_music/src/main/resources/bootstrap.yml index 4c90f91..0f5566b 100644 --- a/luoo_music/src/main/resources/bootstrap.yml +++ b/luoo_music/src/main/resources/bootstrap.yml @@ -68,3 +68,4 @@ mall: albumId: 76 albumName: 77 songId: 78 + productUrl: http://43.248.137.154:8085/product/detail/{id} diff --git a/luoo_music/src/main/resources/sql/20240515.sql b/luoo_music/src/main/resources/sql/20240515.sql new file mode 100644 index 0000000..aca31be --- /dev/null +++ b/luoo_music/src/main/resources/sql/20240515.sql @@ -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'; +